rscons 1.9.3 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rscons.rb +53 -1
- data/lib/rscons/builder.rb +184 -11
- data/lib/rscons/builders/cfile.rb +18 -3
- data/lib/rscons/builders/command.rb +24 -9
- data/lib/rscons/builders/disassemble.rb +20 -4
- data/lib/rscons/builders/library.rb +37 -16
- data/lib/rscons/builders/object.rb +35 -22
- data/lib/rscons/builders/preprocess.rb +25 -17
- data/lib/rscons/builders/program.rb +35 -12
- data/lib/rscons/builders/shared_library.rb +116 -0
- data/lib/rscons/builders/shared_object.rb +113 -0
- data/lib/rscons/cache.rb +7 -2
- data/lib/rscons/cli.rb +4 -0
- data/lib/rscons/environment.rb +394 -104
- data/lib/rscons/job_set.rb +93 -0
- data/lib/rscons/threaded_command.rb +63 -0
- data/lib/rscons/version.rb +1 -1
- metadata +7 -3
@@ -2,6 +2,7 @@ module Rscons
|
|
2
2
|
module Builders
|
3
3
|
# A default Rscons builder that produces a static library archive.
|
4
4
|
class Library < Builder
|
5
|
+
|
5
6
|
# Return default construction variables for the builder.
|
6
7
|
#
|
7
8
|
# @param env [Environment] The Environment using the builder.
|
@@ -16,28 +17,48 @@ module Rscons
|
|
16
17
|
}
|
17
18
|
end
|
18
19
|
|
20
|
+
# Set up a build operation using this builder.
|
21
|
+
#
|
22
|
+
# @param options [Hash] Builder setup options.
|
23
|
+
#
|
24
|
+
# @return [Object]
|
25
|
+
# Any object that the builder author wishes to be saved and passed back
|
26
|
+
# in to the {#run} method.
|
27
|
+
def setup(options)
|
28
|
+
target, sources, env, vars = options.values_at(:target, :sources, :env, :vars)
|
29
|
+
suffixes = env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars)
|
30
|
+
# Register builders to build each source to an object file or library.
|
31
|
+
env.register_builds(target, sources, suffixes, vars)
|
32
|
+
end
|
33
|
+
|
19
34
|
# Run the builder to produce a build target.
|
20
35
|
#
|
21
|
-
# @param
|
22
|
-
# @param sources [Array<String>] Source file name(s).
|
23
|
-
# @param cache [Cache] The Cache object.
|
24
|
-
# @param env [Environment] The Environment executing the builder.
|
25
|
-
# @param vars [Hash,VarSet] Extra construction variables.
|
36
|
+
# @param options [Hash] Builder run options.
|
26
37
|
#
|
27
38
|
# @return [String,false]
|
28
39
|
# Name of the target file on success or false on failure.
|
29
|
-
def run(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
standard_build("AR #{target}", target, command, objects, env, cache)
|
39
|
-
end
|
40
|
+
def run(options)
|
41
|
+
target, sources, cache, env, vars, objects = options.values_at(:target, :sources, :cache, :env, :vars, :setup_info)
|
42
|
+
vars = vars.merge({
|
43
|
+
'_TARGET' => target,
|
44
|
+
'_SOURCES' => objects,
|
45
|
+
})
|
46
|
+
options[:sources] = objects
|
47
|
+
command = env.build_command("${ARCMD}", vars)
|
48
|
+
standard_threaded_build("AR #{target}", target, command, objects, env, cache)
|
40
49
|
end
|
50
|
+
|
51
|
+
# Finalize a build.
|
52
|
+
#
|
53
|
+
# @param options [Hash]
|
54
|
+
# Finalize options.
|
55
|
+
#
|
56
|
+
# @return [String, nil]
|
57
|
+
# The target name on success or nil on failure.
|
58
|
+
def finalize(options)
|
59
|
+
standard_finalize(options)
|
60
|
+
end
|
61
|
+
|
41
62
|
end
|
42
63
|
end
|
43
64
|
end
|
@@ -3,6 +3,7 @@ module Rscons
|
|
3
3
|
# A default Rscons builder which knows how to produce an object file from
|
4
4
|
# various types of source files.
|
5
5
|
class Object < Builder
|
6
|
+
|
6
7
|
# Mapping of known sources from which to build object files.
|
7
8
|
KNOWN_SUFFIXES = {
|
8
9
|
"AS" => "ASSUFFIX",
|
@@ -61,54 +62,66 @@ module Rscons
|
|
61
62
|
# Return whether this builder object is capable of producing a given target
|
62
63
|
# file name from a given source file name.
|
63
64
|
#
|
64
|
-
# @param target [String]
|
65
|
-
#
|
66
|
-
# @param
|
65
|
+
# @param target [String]
|
66
|
+
# The target file name.
|
67
|
+
# @param source [String]
|
68
|
+
# The source file name.
|
69
|
+
# @param env [Environment]
|
70
|
+
# The Environment.
|
67
71
|
#
|
68
72
|
# @return [Boolean]
|
69
73
|
# Whether this builder object is capable of producing a given target
|
70
74
|
# file name from a given source file name.
|
71
75
|
def produces?(target, source, env)
|
72
|
-
target.end_with?(*env['OBJSUFFIX']) and
|
73
|
-
|
74
|
-
|
76
|
+
target.end_with?(*env['OBJSUFFIX']) and
|
77
|
+
KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
78
|
+
source.end_with?(*env[suffix_var])
|
79
|
+
end
|
75
80
|
end
|
76
81
|
|
77
82
|
# Run the builder to produce a build target.
|
78
83
|
#
|
79
|
-
# @param
|
80
|
-
# @param sources [Array<String>] Source file name(s).
|
81
|
-
# @param cache [Cache] The Cache object.
|
82
|
-
# @param env [Environment] The Environment executing the builder.
|
83
|
-
# @param vars [Hash,VarSet] Extra construction variables.
|
84
|
+
# @param options [Hash] Builder run options.
|
84
85
|
#
|
85
|
-
# @return [String,
|
86
|
-
#
|
87
|
-
|
86
|
+
# @return [String, ThreadedCommand]
|
87
|
+
# Target file name if target is up to date or a {ThreadedCommand}
|
88
|
+
# to execute to build the target.
|
89
|
+
def run(options)
|
90
|
+
target, sources, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
88
91
|
vars = vars.merge({
|
89
92
|
'_TARGET' => target,
|
90
93
|
'_SOURCES' => sources,
|
91
94
|
'_DEPFILE' => Rscons.set_suffix(target, env.expand_varref("${DEPFILESUFFIX}", vars)),
|
92
95
|
})
|
93
96
|
com_prefix = KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
94
|
-
sources.first.end_with?(*env.expand_varref("${#{suffix_var}}"))
|
97
|
+
sources.first.end_with?(*env.expand_varref("${#{suffix_var}}", vars))
|
95
98
|
end.tap do |v|
|
96
99
|
v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
|
97
100
|
end.first
|
98
101
|
command = env.build_command("${#{com_prefix}CMD}", vars)
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
102
|
+
# Store vars back into options so new keys are accessible in #finalize.
|
103
|
+
options[:vars] = vars
|
104
|
+
standard_threaded_build("#{com_prefix} #{target}", target, command, sources, env, cache)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Finalize the build operation.
|
108
|
+
#
|
109
|
+
# @param options [Hash] Builder finalize options.
|
110
|
+
#
|
111
|
+
# @return [String, nil]
|
112
|
+
# Name of the target file on success or nil on failure.
|
113
|
+
def finalize(options)
|
114
|
+
if options[:command_status]
|
115
|
+
target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
104
116
|
if File.exists?(vars['_DEPFILE'])
|
105
117
|
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], target)
|
106
118
|
FileUtils.rm_f(vars['_DEPFILE'])
|
107
119
|
end
|
108
|
-
cache.register_build(target, command, deps.uniq, env)
|
120
|
+
cache.register_build(target, options[:tc].command, deps.uniq, env)
|
121
|
+
target
|
109
122
|
end
|
110
|
-
target
|
111
123
|
end
|
124
|
+
|
112
125
|
end
|
113
126
|
end
|
114
127
|
end
|
@@ -20,15 +20,13 @@ module Rscons
|
|
20
20
|
|
21
21
|
# Run the builder to produce a build target.
|
22
22
|
#
|
23
|
-
# @param
|
24
|
-
# @param sources [Array<String>] Source file name(s).
|
25
|
-
# @param cache [Cache] The Cache object.
|
26
|
-
# @param env [Environment] The Environment executing the builder.
|
27
|
-
# @param vars [Hash,VarSet] Extra construction variables.
|
23
|
+
# @param options [Hash] Builder run options.
|
28
24
|
#
|
29
|
-
# @return [String,
|
30
|
-
#
|
31
|
-
|
25
|
+
# @return [String, ThreadedCommand]
|
26
|
+
# Target file name if target is up to date or a {ThreadedCommand}
|
27
|
+
# to execute to build the target.
|
28
|
+
def run(options)
|
29
|
+
target, sources, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
32
30
|
if sources.find {|s| s.end_with?(*env.expand_varref("${CXXSUFFIX}", vars))}
|
33
31
|
pp_cc = "${CXX}"
|
34
32
|
depgen = "${CXXDEPGEN}"
|
@@ -42,17 +40,27 @@ module Rscons
|
|
42
40
|
"_SOURCES" => sources,
|
43
41
|
"_DEPFILE" => Rscons.set_suffix(target, env.expand_varref("${DEPFILESUFFIX}", vars)))
|
44
42
|
command = env.build_command("${CPP_CMD}", vars)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
# Store vars back into options so new keys are accessible in #finalize.
|
44
|
+
options[:vars] = vars
|
45
|
+
standard_threaded_build("#{name} #{target}", target, command, sources, env, cache)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Finalize the build operation.
|
49
|
+
#
|
50
|
+
# @param options [Hash] Builder finalize options.
|
51
|
+
#
|
52
|
+
# @return [String, nil]
|
53
|
+
# Name of the target file on success or nil on failure.
|
54
|
+
def finalize(options)
|
55
|
+
if options[:command_status]
|
56
|
+
target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
57
|
+
if File.exists?(vars['_DEPFILE'])
|
58
|
+
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], nil)
|
59
|
+
FileUtils.rm_f(vars['_DEPFILE'])
|
52
60
|
end
|
53
|
-
cache.register_build(target, command, deps.uniq, env)
|
61
|
+
cache.register_build(target, options[:tc].command, deps.uniq, env)
|
62
|
+
target
|
54
63
|
end
|
55
|
-
target
|
56
64
|
end
|
57
65
|
|
58
66
|
end
|
@@ -3,6 +3,7 @@ module Rscons
|
|
3
3
|
# A default Rscons builder that knows how to link object files into an
|
4
4
|
# executable program.
|
5
5
|
class Program < Builder
|
6
|
+
|
6
7
|
# Return default construction variables for the builder.
|
7
8
|
#
|
8
9
|
# @param env [Environment] The Environment using the builder.
|
@@ -38,27 +39,36 @@ module Rscons
|
|
38
39
|
#
|
39
40
|
# @return [BuildTarget]
|
40
41
|
def create_build_target(options)
|
42
|
+
env, target, vars = options.values_at(:env, :target, :vars)
|
41
43
|
my_options = options.dup
|
42
|
-
unless
|
43
|
-
my_options[:target] +=
|
44
|
+
unless File.basename(target)["."]
|
45
|
+
my_options[:target] += env.expand_varref("${PROGSUFFIX}", vars)
|
44
46
|
end
|
45
47
|
super(my_options)
|
46
48
|
end
|
47
49
|
|
50
|
+
# Set up a build operation using this builder.
|
51
|
+
#
|
52
|
+
# @param options [Hash] Builder setup options.
|
53
|
+
#
|
54
|
+
# @return [Object]
|
55
|
+
# Any object that the builder author wishes to be saved and passed back
|
56
|
+
# in to the {#run} method.
|
57
|
+
def setup(options)
|
58
|
+
target, sources, env, vars = options.values_at(:target, :sources, :env, :vars)
|
59
|
+
suffixes = env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars)
|
60
|
+
# Register builders to build each source to an object file or library.
|
61
|
+
env.register_builds(target, sources, suffixes, vars)
|
62
|
+
end
|
63
|
+
|
48
64
|
# Run the builder to produce a build target.
|
49
65
|
#
|
50
|
-
# @param
|
51
|
-
# @param sources [Array<String>] Source file name(s).
|
52
|
-
# @param cache [Cache] The Cache object.
|
53
|
-
# @param env [Environment] The Environment executing the builder.
|
54
|
-
# @param vars [Hash,VarSet] Extra construction variables.
|
66
|
+
# @param options [Hash] Builder run options.
|
55
67
|
#
|
56
68
|
# @return [String,false]
|
57
69
|
# Name of the target file on success or false on failure.
|
58
|
-
def run(
|
59
|
-
|
60
|
-
objects = env.build_sources(sources, env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars).flatten, cache, vars)
|
61
|
-
return false unless objects
|
70
|
+
def run(options)
|
71
|
+
target, sources, cache, env, vars, objects = options.values_at(:target, :sources, :cache, :env, :vars, :setup_info)
|
62
72
|
ld = env.expand_varref("${LD}", vars)
|
63
73
|
ld = if ld != ""
|
64
74
|
ld
|
@@ -74,9 +84,22 @@ module Rscons
|
|
74
84
|
'_SOURCES' => objects,
|
75
85
|
'LD' => ld,
|
76
86
|
})
|
87
|
+
options[:sources] = objects
|
77
88
|
command = env.build_command("${LDCMD}", vars)
|
78
|
-
|
89
|
+
standard_threaded_build("LD #{target}", target, command, objects, env, cache)
|
79
90
|
end
|
91
|
+
|
92
|
+
# Finalize a build.
|
93
|
+
#
|
94
|
+
# @param options [Hash]
|
95
|
+
# Finalize options.
|
96
|
+
#
|
97
|
+
# @return [String, nil]
|
98
|
+
# The target name on success or nil on failure.
|
99
|
+
def finalize(options)
|
100
|
+
standard_finalize(options)
|
101
|
+
end
|
102
|
+
|
80
103
|
end
|
81
104
|
end
|
82
105
|
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module Rscons
|
2
|
+
module Builders
|
3
|
+
# A default Rscons builder that knows how to link object files into a
|
4
|
+
# shared library.
|
5
|
+
class SharedLibrary < Builder
|
6
|
+
|
7
|
+
# Return default construction variables for the builder.
|
8
|
+
#
|
9
|
+
# @param env [Environment] The Environment using the builder.
|
10
|
+
#
|
11
|
+
# @return [Hash] Default construction variables for the builder.
|
12
|
+
def default_variables(env)
|
13
|
+
{
|
14
|
+
'SHLIBPREFIX' => (RUBY_PLATFORM =~ /mingw/ ? '' : 'lib'),
|
15
|
+
'SHLIBSUFFIX' => (RUBY_PLATFORM =~ /mingw/ ? '.dll' : '.so'),
|
16
|
+
'SHLDFLAGS' => ['${LDFLAGS}', '-shared'],
|
17
|
+
'SHLD' => nil,
|
18
|
+
'SHLIBDIRPREFIX' => '-L',
|
19
|
+
'SHLIBLINKPREFIX' => '-l',
|
20
|
+
'SHLDCMD' => ['${SHLD}', '-o', '${_TARGET}', '${SHLDFLAGS}', '${_SOURCES}', '${SHLIBDIRPREFIX}${LIBPATH}', '${SHLIBLINKPREFIX}${LIBS}']
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
# Return a set of build features that this builder provides.
|
25
|
+
#
|
26
|
+
# @return [Array<String>]
|
27
|
+
# Set of build features that this builder provides.
|
28
|
+
def features
|
29
|
+
%w[shared]
|
30
|
+
end
|
31
|
+
|
32
|
+
# Create a BuildTarget object for this build target.
|
33
|
+
#
|
34
|
+
# The build target filename is given a platform-dependent suffix if no
|
35
|
+
# other suffix is given.
|
36
|
+
#
|
37
|
+
# @param options [Hash]
|
38
|
+
# Options to create the BuildTarget with.
|
39
|
+
# @option options [Environment] :env
|
40
|
+
# The Environment.
|
41
|
+
# @option options [String] :target
|
42
|
+
# The user-supplied target name.
|
43
|
+
# @option options [Array<String>] :sources
|
44
|
+
# The user-supplied source file name(s).
|
45
|
+
#
|
46
|
+
# @return [BuildTarget]
|
47
|
+
def create_build_target(options)
|
48
|
+
env, target, vars = options.values_at(:env, :target, :vars)
|
49
|
+
my_options = options.dup
|
50
|
+
libprefix = env.expand_varref("${SHLIBPREFIX}", vars)
|
51
|
+
unless File.basename(target).start_with?(libprefix)
|
52
|
+
my_options[:target].sub!(%r{^(.*/)?([^/]+)$}, "\\1#{libprefix}\\2")
|
53
|
+
end
|
54
|
+
unless File.basename(target)["."]
|
55
|
+
my_options[:target] += env.expand_varref("${SHLIBSUFFIX}", vars)
|
56
|
+
end
|
57
|
+
super(my_options)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Set up a build operation using this builder.
|
61
|
+
#
|
62
|
+
# @param options [Hash] Builder setup options.
|
63
|
+
#
|
64
|
+
# @return [Object]
|
65
|
+
# Any object that the builder author wishes to be saved and passed back
|
66
|
+
# in to the {#run} method.
|
67
|
+
def setup(options)
|
68
|
+
target, sources, env, vars = options.values_at(:target, :sources, :env, :vars)
|
69
|
+
suffixes = env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars)
|
70
|
+
# Register builders to build each source to an object file or library.
|
71
|
+
env.register_builds(target, sources, suffixes, vars,
|
72
|
+
features: %w[shared])
|
73
|
+
end
|
74
|
+
|
75
|
+
# Run the builder to produce a build target.
|
76
|
+
#
|
77
|
+
# @param options [Hash] Builder run options.
|
78
|
+
#
|
79
|
+
# @return [String,false]
|
80
|
+
# Name of the target file on success or false on failure.
|
81
|
+
def run(options)
|
82
|
+
target, sources, cache, env, vars, objects = options.values_at(:target, :sources, :cache, :env, :vars, :setup_info)
|
83
|
+
ld = env.expand_varref("${SHLD}", vars)
|
84
|
+
ld = if ld != ""
|
85
|
+
ld
|
86
|
+
elsif sources.find {|s| s.end_with?(*env.expand_varref("${DSUFFIX}", vars))}
|
87
|
+
"${SHDC}"
|
88
|
+
elsif sources.find {|s| s.end_with?(*env.expand_varref("${CXXSUFFIX}", vars))}
|
89
|
+
"${SHCXX}"
|
90
|
+
else
|
91
|
+
"${SHCC}"
|
92
|
+
end
|
93
|
+
vars = vars.merge({
|
94
|
+
'_TARGET' => target,
|
95
|
+
'_SOURCES' => objects,
|
96
|
+
'SHLD' => ld,
|
97
|
+
})
|
98
|
+
options[:sources] = objects
|
99
|
+
command = env.build_command("${SHLDCMD}", vars)
|
100
|
+
standard_threaded_build("SHLD #{target}", target, command, objects, env, cache)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Finalize a build.
|
104
|
+
#
|
105
|
+
# @param options [Hash]
|
106
|
+
# Finalize options.
|
107
|
+
#
|
108
|
+
# @return [String, nil]
|
109
|
+
# The target name on success or nil on failure.
|
110
|
+
def finalize(options)
|
111
|
+
standard_finalize(options)
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module Rscons
|
2
|
+
module Builders
|
3
|
+
# A default Rscons builder which knows how to produce an object file which
|
4
|
+
# is capable of being linked into a shared library from various types of
|
5
|
+
# source files.
|
6
|
+
class SharedObject < Builder
|
7
|
+
|
8
|
+
# Mapping of known sources from which to build object files.
|
9
|
+
KNOWN_SUFFIXES = {
|
10
|
+
"AS" => "ASSUFFIX",
|
11
|
+
"SHCC" => "CSUFFIX",
|
12
|
+
"SHCXX" => "CXXSUFFIX",
|
13
|
+
"SHDC" => "DSUFFIX",
|
14
|
+
}
|
15
|
+
|
16
|
+
# Return default construction variables for the builder.
|
17
|
+
#
|
18
|
+
# @param env [Environment] The Environment using the builder.
|
19
|
+
#
|
20
|
+
# @return [Hash] Default construction variables for the builder.
|
21
|
+
def default_variables(env)
|
22
|
+
pic_flags = (RUBY_PLATFORM =~ /mingw/ ? [] : ['-fPIC'])
|
23
|
+
{
|
24
|
+
'SHCCFLAGS' => ['${CCFLAGS}'] + pic_flags,
|
25
|
+
|
26
|
+
'SHCC' => '${CC}',
|
27
|
+
'SHCFLAGS' => [],
|
28
|
+
'SHCCCMD' => ['${SHCC}', '-c', '-o', '${_TARGET}', '${CCDEPGEN}', '${INCPREFIX}${CPPPATH}', '${CPPFLAGS}', '${SHCFLAGS}', '${SHCCFLAGS}', '${_SOURCES}'],
|
29
|
+
|
30
|
+
'SHCXX' => '${CXX}',
|
31
|
+
'SHCXXFLAGS' => [],
|
32
|
+
'SHCXXCMD' => ['${SHCXX}', '-c', '-o', '${_TARGET}', '${CXXDEPGEN}', '${INCPREFIX}${CPPPATH}', '${CPPFLAGS}', '${SHCXXFLAGS}', '${SHCCFLAGS}', '${_SOURCES}'],
|
33
|
+
|
34
|
+
'SHDC' => 'gdc',
|
35
|
+
'SHDFLAGS' => ['${DFLAGS}'] + pic_flags,
|
36
|
+
'SHDCCMD' => ['${SHDC}', '-c', '-o', '${_TARGET}', '${INCPREFIX}${D_IMPORT_PATH}', '${SHDFLAGS}', '${_SOURCES}'],
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
# Return a set of build features that this builder provides.
|
41
|
+
#
|
42
|
+
# @return [Array<String>]
|
43
|
+
# Set of build features that this builder provides.
|
44
|
+
def features
|
45
|
+
%w[shared]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Return whether this builder object is capable of producing a given target
|
49
|
+
# file name from a given source file name.
|
50
|
+
#
|
51
|
+
# @param target [String]
|
52
|
+
# The target file name.
|
53
|
+
# @param source [String]
|
54
|
+
# The source file name.
|
55
|
+
# @param env [Environment]
|
56
|
+
# The Environment.
|
57
|
+
#
|
58
|
+
# @return [Boolean]
|
59
|
+
# Whether this builder object is capable of producing a given target
|
60
|
+
# file name from a given source file name.
|
61
|
+
def produces?(target, source, env)
|
62
|
+
target.end_with?(*env['OBJSUFFIX']) and
|
63
|
+
KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
64
|
+
source.end_with?(*env[suffix_var])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Run the builder to produce a build target.
|
69
|
+
#
|
70
|
+
# @param options [Hash] Builder run options.
|
71
|
+
#
|
72
|
+
# @return [String, ThreadedCommand]
|
73
|
+
# Target file name if target is up to date or a {ThreadedCommand}
|
74
|
+
# to execute to build the target.
|
75
|
+
def run(options)
|
76
|
+
target, sources, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
77
|
+
vars = vars.merge({
|
78
|
+
'_TARGET' => target,
|
79
|
+
'_SOURCES' => sources,
|
80
|
+
'_DEPFILE' => Rscons.set_suffix(target, env.expand_varref("${DEPFILESUFFIX}", vars)),
|
81
|
+
})
|
82
|
+
com_prefix = KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
83
|
+
sources.first.end_with?(*env.expand_varref("${#{suffix_var}}", vars))
|
84
|
+
end.tap do |v|
|
85
|
+
v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
|
86
|
+
end.first
|
87
|
+
command = env.build_command("${#{com_prefix}CMD}", vars)
|
88
|
+
# Store vars back into options so new keys are accessible in #finalize.
|
89
|
+
options[:vars] = vars
|
90
|
+
standard_threaded_build("#{com_prefix} #{target}", target, command, sources, env, cache)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Finalize the build operation.
|
94
|
+
#
|
95
|
+
# @param options [Hash] Builder finalize options.
|
96
|
+
#
|
97
|
+
# @return [String, nil]
|
98
|
+
# Name of the target file on success or nil on failure.
|
99
|
+
def finalize(options)
|
100
|
+
if options[:command_status]
|
101
|
+
target, deps, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
102
|
+
if File.exists?(vars['_DEPFILE'])
|
103
|
+
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], target)
|
104
|
+
FileUtils.rm_f(vars['_DEPFILE'])
|
105
|
+
end
|
106
|
+
cache.register_build(target, options[:tc].command, deps.uniq, env)
|
107
|
+
target
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|