class Dest::Rake
Public Class Methods
setup()
click to toggle source
Quick access to setting up the Rake
environment
# File lib/dest/rake.rb, line 7 def self.setup self.new.setup end
Public Instance Methods
compile(source, object)
click to toggle source
# File lib/dest/rake.rb, line 34 def compile source, object # Ensure we have the directory dir = File.dirname object FileUtils.mkdir_p dir # Then build sh "clang #{source} #{flags} -o #{object}" end
flags()
click to toggle source
# File lib/dest/rake.rb, line 21 def flags return @flags if @flags flags = [] flags << '-S' # Only run preprocess and compilation steps flags << '-Wall' # All warnings flags << '-emit-llvm' flags << '-fobjc-arc' if project.compile_flags flags << project.compile_flags end @flags = flags.join ' ' end
objectsify(fn)
click to toggle source
# File lib/dest/rake.rb, line 17 def objectsify fn fn.sub(/\.m$/, '.bc').sub project.dir, @build_dir end
project()
click to toggle source
# File lib/dest/rake.rb, line 13 def project Dest::Project.current end
setup()
click to toggle source
Set up rake hooks
# File lib/dest/rake.rb, line 50 def setup @build_dir = File.join project.dir, 'build' unless Dir.exists? @build_dir Dir.mkdir @build_dir end task 'default' => 'build' desc 'Build the project' task 'build' => project.target do puts "Built #{File.basename project.target}".green end self.setup_target self.setup_source_files if project.test_target self.setup_test_target self.setup_test_files end desc 'Clean up build artifacts and target' task 'clean' do sh "rm -f #{project.target}" project.sources.each do |fn| fn = objectsify fn sh "rm -f #{fn}" end end namespace 'test' do desc 'Build the test target' task 'build' => project.test_target do puts "Built #{File.basename project.test_target}".green end desc 'Clean test build artifacts' task 'clean' do sh "rm -f #{project.test_target}" project.test_sources.each do |fn| fn = objectsify fn sh "rm -f #{fn}" end end end end
setup_source_files()
click to toggle source
Set up a file task for every source file
# File lib/dest/rake.rb, line 103 def setup_source_files project.sources.each do |src| # Figure out where stuff should come from and go to source_file = src object_file = objectsify src compile_task object_file, source_file end#project.sources.each end
setup_target()
click to toggle source
Build the target file from the sources
# File lib/dest/rake.rb, line 98 def setup_target link_target_task project.target, (project.sources + [project.main]).map {|fn| objectsify fn } end
setup_test_files()
click to toggle source
Set up test source files and test target tasks
# File lib/dest/rake.rb, line 113 def setup_test_files project.test_sources.each do |src| compile_task objectsify(src), src end end
setup_test_target()
click to toggle source
# File lib/dest/rake.rb, line 118 def setup_test_target link_target_task project.test_target, (project.sources + project.test_sources).map {|fn| objectsify fn }, :frameworks => project.test_frameworks end
time_action(name) { || ... }
click to toggle source
# File lib/dest/rake.rb, line 42 def time_action name start = Time.now yield diff = ((Time.now - start) * 1000).round puts name + " (#{diff.to_s} ms)".light_black end
Private Instance Methods
compile_task(object, source)
click to toggle source
# File lib/dest/rake.rb, line 125 def compile_task object, source file object => source do |t| # Try to strip off the leading directory fn = source.sub project.dir+'/', '' time_action "Compiling #{fn}" do compile source, object end end end
link_target_task(target, objects, opts = {})
click to toggle source
# File lib/dest/rake.rb, line 134 def link_target_task target, objects, opts = {} file target => objects do |t| # Little message time_action "Linking #{File.basename target} from #{objects.length.to_s} objects" do # Then figure out our frameworks and objects objects = objects.join ' ' frameworks = project.frameworks if opts[:frameworks] opts[:frameworks].each {|f| frameworks << f } end # Concatenate all the frameworks together frameworks = frameworks.map {|f| "-framework #{f}" }.join ' ' flags = project.link_flags || '' sh "clang #{objects} -lobjc #{frameworks} #{flags} -o #{target}" end end end