Compare commits

...
9 Commits
7 changed files with 49 additions and 14 deletions

No files matched your search

+2 -2
View File
@@ -8,9 +8,9 @@ module Rscons
'OBJSUFFIX' => '.o', 'OBJSUFFIX' => '.o',
'LIBSUFFIX' => '.a', 'LIBSUFFIX' => '.a',
'LDFLAGS' => [], 'LDFLAGS' => [],
'LIBPATHS' => [], 'LIBPATH' => [],
'LIBS' => [], 'LIBS' => [],
'LDCOM' => ['$LD', '-o', '$TARGET', '$LDFLAGS', '$SOURCES', '-L$[LIBPATHS]', '-l$[LIBS]'] 'LDCOM' => ['$LD', '-o', '$TARGET', '$LDFLAGS', '$SOURCES', '-L$[LIBPATH]', '-l$[LIBS]']
} }
end end
+5 -1
View File
@@ -80,6 +80,7 @@ module Rscons
# @return true value if the target is up to date, meaning that: # @return true value if the target is up to date, meaning that:
# - the target exists on disk # - the target exists on disk
# - the cache has information for the target # - the cache has information for the target
# - the target's checksum matches its checksum when it was last built
# - the command used to build the target is the same as last time # - the command used to build the target is the same as last time
# - all dependencies listed are also listed in the cache, or, if # - all dependencies listed are also listed in the cache, or, if
# :strict_deps was given in options, the list of dependencies is # :strict_deps was given in options, the list of dependencies is
@@ -93,6 +94,9 @@ module Rscons
# target must be registered in the cache # target must be registered in the cache
return false unless @cache[:targets].has_key?(target) return false unless @cache[:targets].has_key?(target)
# target must have the same checksum as when it was built last
return false unless @cache[:targets][target][:checksum] == lookup_checksum(target)
# command used to build target must be identical # command used to build target must be identical
return false unless @cache[:targets][target][:command] == command return false unless @cache[:targets][target][:command] == command
@@ -141,7 +145,7 @@ module Rscons
# Calculate and return a file's checksum # Calculate and return a file's checksum
# @param file [String] The file name. # @param file [String] The file name.
def calculate_checksum(file) def calculate_checksum(file)
@lookup_checksums[file] = Digest::MD5.hexdigest(File.read(file)).encode(__ENCODING__) rescue '' @lookup_checksums[file] = Digest::MD5.hexdigest(File.read(file, {mode: 'rb'})).encode(__ENCODING__) rescue ''
end end
end end
end end
+14 -9
View File
@@ -20,7 +20,7 @@ module Rscons
@varset = VarSet.new(variables) @varset = VarSet.new(variables)
@targets = {} @targets = {}
@builders = {} @builders = {}
@build_dirs = {} @build_dirs = []
@varset[:exclude_builders] ||= [] @varset[:exclude_builders] ||= []
unless @varset[:exclude_builders] == :all unless @varset[:exclude_builders] == :all
exclude_builders = Set.new(@varset[:exclude_builders] || []) exclude_builders = Set.new(@varset[:exclude_builders] || [])
@@ -52,9 +52,6 @@ module Rscons
@builders.each do |builder_name, builder| @builders.each do |builder_name, builder|
env.add_builder(builder) env.add_builder(builder)
end end
@build_dirs.each do |src_dir, obj_dir|
env.build_dir(src_dir, obj_dir)
end
env.append(@varset) env.append(@varset)
env.append(variables) env.append(variables)
@@ -79,7 +76,9 @@ module Rscons
# Specify a build directory for this Environment. # Specify a build directory for this Environment.
# Source files from src_dir will produce object files under obj_dir. # Source files from src_dir will produce object files under obj_dir.
def build_dir(src_dir, obj_dir) def build_dir(src_dir, obj_dir)
@build_dirs[src_dir.gsub('\\', '/')] = obj_dir.gsub('\\', '/') src_dir = src_dir.gsub('\\', '/') if src_dir.is_a?(String)
obj_dir = obj_dir.gsub('\\', '/')
@build_dirs << [src_dir, obj_dir]
end end
# Return the file name to be built from source_fname with suffix suffix. # Return the file name to be built from source_fname with suffix suffix.
@@ -89,8 +88,13 @@ module Rscons
def get_build_fname(source_fname, suffix) def get_build_fname(source_fname, suffix)
build_fname = source_fname.set_suffix(suffix).gsub('\\', '/') build_fname = source_fname.set_suffix(suffix).gsub('\\', '/')
@build_dirs.each do |src_dir, obj_dir| @build_dirs.each do |src_dir, obj_dir|
if src_dir.is_a?(Regexp)
build_fname.sub!(src_dir, obj_dir)
else
build_fname.sub!(/^#{src_dir}\//, "#{obj_dir}/") build_fname.sub!(/^#{src_dir}\//, "#{obj_dir}/")
end end
build_fname.gsub!('\\', '/')
end
FileUtils.mkdir_p(File.dirname(build_fname)) FileUtils.mkdir_p(File.dirname(build_fname))
build_fname build_fname
end end
@@ -212,10 +216,11 @@ module Rscons
if line =~ /^(.*)\\\s*$/ if line =~ /^(.*)\\\s*$/
buildup += ' ' + $1 buildup += ' ' + $1
else else
if line =~ /^(.*): (.*)$/ buildup += ' ' + line
target, tdeps = $1.strip, $2 if buildup =~ /^(.*): (.*)$/
if target == target mf_target, mf_deps = $1.strip, $2
deps += tdeps.split(' ').map(&:strip) if mf_target == target
deps += mf_deps.split(' ').map(&:strip)
end end
end end
buildup = '' buildup = ''
+1
View File
@@ -6,6 +6,7 @@ class String
def has_suffix?(suffix) def has_suffix?(suffix)
if suffix if suffix
suffix = [suffix] if suffix.is_a?(String) suffix = [suffix] if suffix.is_a?(String)
suffix = suffix.flatten
suffix.find {|s| self.end_with?(s)} suffix.find {|s| self.end_with?(s)}
end end
end end
+1 -1
View File
@@ -1,4 +1,4 @@
module Rscons module Rscons
# gem version # gem version
VERSION = "0.0.1" VERSION = "0.0.3"
end end
+2 -1
View File
@@ -10,7 +10,8 @@ Gem::Specification.new do |gem|
gem.email = ["jholtrop@gmail.com"] gem.email = ["jholtrop@gmail.com"]
gem.description = %q{Software construction library inspired by SCons and implemented in Ruby} gem.description = %q{Software construction library inspired by SCons and implemented in Ruby}
gem.summary = %q{Software construction library inspired by SCons and implemented in Ruby} gem.summary = %q{Software construction library inspired by SCons and implemented in Ruby}
gem.homepage = "" gem.homepage = "https://github.com/holtrop/rscons"
gem.license = 'MIT'
gem.files = `git ls-files`.split($/) gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+24
View File
@@ -0,0 +1,24 @@
module Rscons
describe Environment do
describe '.parse_makefile_deps' do
it 'handles dependencies on one line' do
File.should_receive(:read).with('makefile').and_return(<<EOS)
module.o: source.cc
EOS
env = Environment.new
env.parse_makefile_deps('makefile', 'module.o').should == ['source.cc']
end
it 'handles dependencies split across many lines' do
File.should_receive(:read).with('makefile').and_return(<<EOS)
module.o: module.c \\
module.h \\
other.h
EOS
env = Environment.new
env.parse_makefile_deps('makefile', 'module.o').should == [
'module.c', 'module.h', 'other.h']
end
end
end
end