Skip to content

Commit

Permalink
#341 Increase robustness of build system
Browse files Browse the repository at this point in the history
Get rid of annoying forwarding tasks and delayed requires in the
package file. The artifact rakefile will now, before it builds the
binary, do a check on whether there are any source files that weren’t
there before the build, and JIT include them.
  • Loading branch information
SanderMertens committed Oct 4, 2015
1 parent f82db99 commit be73dd5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 70 deletions.
26 changes: 18 additions & 8 deletions build/artefact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@
end.join(" ") +
USE_COMPONENT.map {|i| "#{ENV['CORTO_HOME']}/lib/corto/#{VERSION}/components/lib" + i + ".so"}.join(" ") +
USE_LIBRARY.map {|i| "#{ENV['CORTO_HOME']}/lib/corto/#{VERSION}/libraries/lib" + i + ".so"}.join(" ")

# Check if there were any new files created during code generation
Rake::FileList["src/*.c"].each do |file|
if not SOURCES.include? file
obj = file.ext(".o").pathmap(".corto/obj/%f")
build_source(file, obj, true)
objects += " " + obj
end
end

cc_command = "cc #{objects} #{cflags} #{corto_lib} #{libpath} #{libmapping} #{use_link} #{lflags}"
sh cc_command
if ENV['silent'] != "true" then
Expand All @@ -130,19 +140,19 @@
task :postbuild

rule '__api.o' => ->(t){t.pathmap(".corto/%f").ext(".c")} do |task|
build_source(task, false)
build_source(task.source, task.name, false)
end
rule '__meta.o' => ->(t){t.pathmap(".corto/%f").ext(".c")} do |task|
build_source(task, false)
build_source(task.source, task.name, false)
end
rule '__wrapper.o' => ->(t){t.pathmap(".corto/%f").ext(".c")} do |task|
build_source(task, false)
build_source(task.source, task.name, false)
end
rule '__load.o' => ->(t){t.pathmap(".corto/%f").ext(".c")} do |task|
build_source(task, false)
build_source(task.source, task.name, false)
end
rule '.o' => ->(t){t.pathmap("src/%f").ext(".c")} do |task|
build_source(task, true)
build_source(task.source, task.name, true)
end

task :all => :default
Expand All @@ -153,15 +163,15 @@
sh "corto test"
end

def build_source(task, echo)
def build_source(source, target, echo)
verbose(false)
if not File.exists? ".corto/obj" then
sh "mkdir -p .corto/obj"
end
if echo
if ENV['silent'] != "true" then
sh "echo '#{task.source}'"
sh "echo '#{source}'"
end
end
sh "cc -c #{CFLAGS.join(" ")} #{DEFINES.map {|d| "-D" + d}.join(" ")} #{INCLUDE.map {|i| "-I" + i}.join(" ")} #{task.source} -o #{task.name}"
sh "cc -c #{CFLAGS.join(" ")} #{DEFINES.map {|d| "-D" + d}.join(" ")} #{INCLUDE.map {|i| "-I" + i}.join(" ")} #{source} -o #{target}"
end
68 changes: 6 additions & 62 deletions build/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,71 +63,15 @@
end
end

task :default => "include/#{TARGET}__type.h" do
require "./.corto/dep.rb"

# Delay running inherited tasks - we first need to run
# code generation for us to know which source files
# have to be compiled.
require "#{ENV['CORTO_BUILD']}/component"
Rake::Task["prebuild"].invoke
Rake::Task["binary"].invoke
Rake::Task["postbuild"].invoke
end

clobber_count = 1
clean_count = 1
collect_count = 1
install_count = 1

task :clean do
# Recursively call clean, prevent infinite recursion
if clean_count == 1 then
clean_count += 1
Rake::Task["clean"].reenable
require "#{ENV['CORTO_BUILD']}/component"
Rake::Task["clean"].execute
if File.exists?(".corto/dep.rb")
sh "rake clean -f .corto/dep.rb"
end
end
end

task :clobber do
# Recursively call clobber, prevent infinite recursion
if clobber_count == 1 then
clobber_count += 1
Rake::Task["clobber"].reenable
require "#{ENV['CORTO_BUILD']}/component"
Rake::Task["clobber"].execute
if File.exists?(".corto/dep.rb")
sh "rake clobber -f .corto/dep.rb"
end
end
end

task :collect do
# Recursively call collect, prevent infinite recursion
if collect_count == 1 then
collect_count += 1
Rake::Task["collect"].reenable
require "#{ENV['CORTO_BUILD']}/component"
Rake::Task["collect"].execute
end
end

task :install do
# Recursively call collect, prevent infinite recursion
if install_count == 1 then
install_count += 1
Rake::Task["install"].reenable
require "#{ENV['CORTO_BUILD']}/component"
Rake::Task["install"].execute
end
end
task :default => "include/#{TARGET}__type.h"

if File.exists? "test" then
COMPONENTS ||=[] << "test"
end

if File.exists? "./.corto/dep.rb"
require "./.corto/dep.rb"
end

require "#{ENV['CORTO_BUILD']}/component"
require "#{ENV['CORTO_BUILD']}/subrake"

0 comments on commit be73dd5

Please sign in to comment.