Created
August 9, 2011 20:23
-
-
Save dgrijalva/1135097 to your computer and use it in GitHub Desktop.
Rakefile for building Go projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rake/clean' | |
require 'rake/testtask' | |
# Insert executable name here | |
TARGET = '' | |
CLEAN.include('**/*.6') | |
CLOBBER.include(TARGET) | |
def required_modules go_file | |
m = [] | |
File.read(go_file).lines.grep(/^import "\.\/.*"/) do |im| | |
m << im.match(/^import "\.\/(.*)"/)[1] | |
end | |
m | |
end | |
# List modules included in subdirectories | |
module_dirs = %w{} | |
# Build file tasks | |
compile_tasks = [] | |
six_files = [] | |
FileList['*.go'].each do |src| | |
compile_tasks << file(src.ext('.6') => [src] + required_modules(src).map{|m| m.ext('.6')}) do | |
puts `6g #{src}` | |
end | |
six_files << src.ext('.6') | |
end | |
module_dirs.each do |dir| | |
files = FileList[File.join(dir, '*.go')].select{|f| !f.match(/_test\.go$/)} | |
compile_tasks << file(dir.ext('.6') => files) do | |
puts `6g -o #{dir.ext('.6')} #{files.join(' ')}` | |
end | |
six_files << dir.ext('.6') | |
end | |
file TARGET => compile_tasks do | |
puts `6l -o #{TARGET} #{TARGET}.6` | |
end | |
desc "Build the project." | |
task :build => TARGET | |
task :default => :build | |
desc "Build and run the project." | |
task :start => :build do | |
# Insert default command line args here | |
exec("./#{TARGET}") | |
end | |
desc "Run all go files through gofmt" | |
task :gofmt do | |
FileList['**/*.go'].each do |file| | |
`gofmt -w #{file} #{file}` | |
end | |
end | |
Rake::TestTask.new do |t| | |
t.libs << "test" | |
t.test_files = FileList['test/*_test.rb'] | |
t.verbose = true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment