rscons 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Njg4YWQzOTg0NTU4OTRiYjBmZWJhYzY3ZjE0MDI4MWE1NGViZDc4Yg==
5
- data.tar.gz: !binary |-
6
- YzUyYWZiZjM5MjdmMDhkOTU2MjUzMTAwZmQ3NzY1ODkyOTljNmZjMA==
2
+ SHA1:
3
+ metadata.gz: 73ee962711592bf9731373cf08ae929d64143511
4
+ data.tar.gz: 466f6cfd67e4179e000d20bd3ab7fba11299a754
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZDNiNTlmZDU5YTNmM2M3OWJmYThhNGIyNjg2NjE4NzljMTRlZTlhMWNhMzVl
10
- MjQ5YWZmMjViYzZmNWVmZWQyNjM3YmNkZjBjMDJmMzhlMzMzYjcwMDlhOTdj
11
- OWVjYTg4NDA1Zjg4Y2U2ODgwNjNlZjA5MzA4ZTkyOWQ2OTBhMWQ=
12
- data.tar.gz: !binary |-
13
- ODQ2MjEwOTYwMjQ3YTA5Y2U0MjA1MGZlMzM3Zjg2ODE2ZWRkM2ZlMWVhYTg4
14
- NTE0Mzg3YzgwM2Y0YjNlZjcwZDliYzVjNTE5ZTI1NGQzYTRhMWFkYjZkODgx
15
- YzM4ZTZiYzZjYmI5NTQ1OTVlY2ExOTg5ZTRiYWIyODkxZTNiZGY=
6
+ metadata.gz: 8e4828bfc224834dd5cf866964f4f9be9c7b24961b368dd10c3fbbe9324fa6a9c8686e28b679205a1522136fdbaa8dfdc4c13e3b2ccfbc2b447d9093cb34e9f6
7
+ data.tar.gz: cfa0f57a698be0db5b7513ef8d75bac39af2313cb1426056ee4c36ca150884789e152f5bf3eb3ab3faa3d68672e083c364cc38f0388379a06766252d4aa4e5aa
data/lib/rscons.rb CHANGED
@@ -6,18 +6,21 @@ require_relative "rscons/varset"
6
6
  require_relative "rscons/version"
7
7
 
8
8
  # default builders
9
+ require_relative "rscons/builders/command"
9
10
  require_relative "rscons/builders/cfile"
10
11
  require_relative "rscons/builders/disassemble"
11
12
  require_relative "rscons/builders/library"
12
13
  require_relative "rscons/builders/object"
13
14
  require_relative "rscons/builders/preprocess"
14
15
  require_relative "rscons/builders/program"
16
+ require_relative "rscons/builders/simple_builder"
15
17
 
16
18
  # Namespace module for rscons classes
17
19
  module Rscons
18
20
  # Names of the default builders which will be added to all newly created
19
21
  # {Environment} objects.
20
22
  DEFAULT_BUILDERS = [
23
+ :Command,
21
24
  :CFile,
22
25
  :Disassemble,
23
26
  :Library,
@@ -30,6 +33,8 @@ module Rscons
30
33
  class BuildError < RuntimeError; end
31
34
 
32
35
  # Remove all generated files.
36
+ #
37
+ # @return [void]
33
38
  def self.clean
34
39
  cache = Cache.instance
35
40
  # remove all built files
@@ -118,6 +123,8 @@ module Rscons
118
123
  # Set the command executer array.
119
124
  #
120
125
  # @param val [Array<String>] Command used to execute commands.
126
+ #
127
+ # @return [Array<String>] Command used to execute commands.
121
128
  def self.command_executer=(val)
122
129
  @@command_executer = val
123
130
  end
@@ -9,6 +9,8 @@ module Rscons
9
9
  # Return the name of the builder.
10
10
  #
11
11
  # If not overridden this defaults to the last component of the class name.
12
+ #
13
+ # @return [String] The name of the builder.
12
14
  def name
13
15
  self.class.name.split(":").last
14
16
  end
@@ -44,7 +46,7 @@ module Rscons
44
46
  # file name from a given source file name.
45
47
  #
46
48
  # @param target [String] The target file name.
47
- # @param source [String, Array] The source file name(s).
49
+ # @param source [String] The source file name.
48
50
  # @param env [Environment] The Environment.
49
51
  #
50
52
  # @return [Boolean]
@@ -54,6 +56,20 @@ module Rscons
54
56
  false
55
57
  end
56
58
 
59
+ # Run the builder to produce a build target.
60
+ #
61
+ # @param target [String] Target file name.
62
+ # @param sources [Array<String>] Source file name(s).
63
+ # @param cache [Cache] The Cache object.
64
+ # @param env [Environment] The Environment executing the builder.
65
+ # @param vars [Hash,VarSet] Extra construction variables.
66
+ #
67
+ # @return [String,false]
68
+ # Name of the target file on success or false on failure.
69
+ def run(target, sources, cache, env, vars)
70
+ raise "This method must be overridden in a subclass"
71
+ end
72
+
57
73
  # Check if the cache is up to date for the target and if not execute the
58
74
  # build command.
59
75
  #
@@ -0,0 +1,32 @@
1
+ module Rscons
2
+ module Builders
3
+ # Execute a command that will produce the given target based on the given
4
+ # sources.
5
+ #
6
+ # @since 1.8.0
7
+ #
8
+ # Example:
9
+ # env.Command("docs.html", "docs.md",
10
+ # CMD => %w[pandoc -fmarkdown -thtml -o${_TARGET} ${_SOURCES}])
11
+ class Command < Builder
12
+ # Run the builder to produce a build target.
13
+ #
14
+ # @param target [String] Target file name.
15
+ # @param sources [Array<String>] Source file name(s).
16
+ # @param cache [Cache] The Cache object.
17
+ # @param env [Environment] The Environment executing the builder.
18
+ # @param vars [Hash,VarSet] Extra construction variables.
19
+ #
20
+ # @return [String,false]
21
+ # Name of the target file on success or false on failure.
22
+ def run(target, sources, cache, env, vars)
23
+ vars = vars.merge({
24
+ "_TARGET" => target,
25
+ "_SOURCES" => sources,
26
+ })
27
+ command = env.build_command("${CMD}", vars)
28
+ standard_build("CMD #{target}", target, command, sources, env, cache)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -62,7 +62,7 @@ module Rscons
62
62
  # file name from a given source file name.
63
63
  #
64
64
  # @param target [String] The target file name.
65
- # @param source [String, Array] The source file name(s).
65
+ # @param source [String] The source file name.
66
66
  # @param env [Environment] The Environment.
67
67
  #
68
68
  # @return [Boolean]
@@ -0,0 +1,39 @@
1
+ module Rscons
2
+ module Builders
3
+ # A Generic builder class whose name and operation is defined at
4
+ # instantiation.
5
+ #
6
+ # @since 1.8.0
7
+ class SimpleBuilder < Builder
8
+ # @return [String] The name of this builder.
9
+ attr_reader :name
10
+
11
+ # Create a new builder with the given name and action.
12
+ #
13
+ # @param name [String,Symbol] The name of the builder when registered.
14
+ # @param block [Block]
15
+ # The action to perform when the builder is processed. The provided
16
+ # block must return the target file on success or false on failure.
17
+ # The provided block should have the same signature as {Builder#run}.
18
+ def initialize(name, &block)
19
+ @name = name.to_s
20
+ @block = block
21
+ end
22
+
23
+ # Run the builder to produce a build target.
24
+ #
25
+ # @param target [String] Target file name.
26
+ # @param sources [Array<String>] Source file name(s).
27
+ # @param cache [Cache] The Cache object.
28
+ # @param env [Environment] The Environment executing the builder.
29
+ # @param vars [Hash,VarSet] Extra construction variables.
30
+ #
31
+ # @return [String,false]
32
+ # Name of the target file on success or false on failure.
33
+ def run(target, sources, cache, env, vars)
34
+ @block.call(target, sources, cache, env, vars)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
data/lib/rscons/cache.rb CHANGED
@@ -63,17 +63,23 @@ module Rscons
63
63
  end
64
64
 
65
65
  # Remove the cache file.
66
+ #
67
+ # @return [void]
66
68
  def clear
67
69
  FileUtils.rm_f(CACHE_FILE)
68
70
  initialize!
69
71
  end
70
72
 
71
73
  # Clear the cached file checksums.
74
+ #
75
+ # @return [void]
72
76
  def clear_checksum_cache!
73
77
  @lookup_checksums = {}
74
78
  end
75
79
 
76
80
  # Write the cache to disk to be loaded next time.
81
+ #
82
+ # @return [void]
77
83
  def write
78
84
  if @dirty || (@cache["version"] != VERSION)
79
85
  @cache["version"] = VERSION
@@ -86,9 +92,14 @@ module Rscons
86
92
 
87
93
  # Check if target(s) are up to date.
88
94
  #
89
- # @param targets [String, Array] The name(s) of the target file(s).
90
- # @param command [String, Array] The command used to build the target.
91
- # @param deps [Array] List of the target's dependency files.
95
+ # @param targets [String, Array<String>] The name(s) of the target file(s).
96
+ # @param command [String, Array, Hash]
97
+ # The command used to build the target. The command parameter can
98
+ # actually be a String, Array, or Hash and could contain information
99
+ # other than just the actual command used to build the target. For the
100
+ # purposes of the Cache, any difference in the command argument will
101
+ # trigger a rebuild.
102
+ # @param deps [Array<String>] List of the target's dependency files.
92
103
  # @param env [Environment] The Rscons::Environment.
93
104
  # @param options [Hash] Optional options.
94
105
  # @option options [Boolean] :strict_deps
@@ -148,9 +159,14 @@ module Rscons
148
159
 
149
160
  # Store cache information about target(s) built by a builder.
150
161
  #
151
- # @param targets [String, Array] The name of the target(s) built.
152
- # @param command [String, Array] The command used to build the target.
153
- # @param deps [Array] List of dependencies for the target.
162
+ # @param targets [String, Array<String>] The name of the target(s) built.
163
+ # @param command [String, Array, Hash]
164
+ # The command used to build the target. The command parameter can
165
+ # actually be a String, Array, or Hash and could contain information
166
+ # other than just the actual command used to build the target. For the
167
+ # purposes of the Cache, any difference in the command argument will
168
+ # trigger a rebuild.
169
+ # @param deps [Array<String>] List of dependencies for the target.
154
170
  # @param env [Environment] The {Rscons::Environment}.
155
171
  #
156
172
  # @return [void]
@@ -10,7 +10,7 @@ module Rscons
10
10
  # @return [Hash] Set of !{"builder_name" => builder_object} pairs.
11
11
  attr_reader :builders
12
12
 
13
- # :command, :short, or :off
13
+ # @return [Symbol] :command, :short, or :off
14
14
  attr_accessor :echo
15
15
 
16
16
  # @return [String, nil] The build root.
@@ -79,7 +79,7 @@ module Rscons
79
79
  #
80
80
  # Any options that #initialize receives can also be specified here.
81
81
  #
82
- # @return a new {Environment} object.
82
+ # @return [Environment] The newly created {Environment} object.
83
83
  def clone(options = {})
84
84
  clone = options[:clone] || Set[:variables, :builders]
85
85
  clone = Set[:variables, :builders, :build_root, :build_dirs, :build_hooks] if clone == :all
@@ -120,10 +120,32 @@ module Rscons
120
120
 
121
121
  # Add a {Builder} object to the Environment.
122
122
  #
123
- # @param builder [Builder] The {Builder} object to add.
123
+ # @overload add_builder(builder)
124
+ #
125
+ # Add the given builder to the Environment.
126
+ #
127
+ # @param builder [Builder] An instance of the builder to register.
128
+ #
129
+ # @overload add_builder(builder,&action)
130
+ #
131
+ # Create a new {Builders::SimpleBuilder} instance and add it to the
132
+ # environment.
133
+ #
134
+ # @since 1.8.0
135
+ #
136
+ # @param builder [String,Symbol]
137
+ # The name of the builder to add.
138
+ #
139
+ # @param action [Block]
140
+ # A block that will be called when the builder is executed to generate
141
+ # a target file. The provided block should have the same prototype as
142
+ # {Rscons::Builder#run}.
124
143
  #
125
144
  # @return [void]
126
- def add_builder(builder)
145
+ def add_builder(builder, &action)
146
+ if not builder.is_a? Rscons::Builder
147
+ builder = Rscons::Builders::SimpleBuilder.new(builder, &action)
148
+ end
127
149
  @builders[builder.name] = builder
128
150
  var_defs = builder.default_variables(self)
129
151
  if var_defs
@@ -184,8 +206,13 @@ module Rscons
184
206
  #
185
207
  # Source files from src_dir will produce object files under obj_dir.
186
208
  #
187
- # @param src_dir [String, Regexp] Path to the source directory.
188
- # @param obj_dir [String] Path to the object directory.
209
+ # @param src_dir [String, Regexp]
210
+ # Path to the source directory. If a Regexp is given, it will be matched
211
+ # to source file names.
212
+ # @param obj_dir [String]
213
+ # Path to the object directory. If a Regexp is given as src_dir, then
214
+ # obj_dir can contain backreferences to groups matched from the source
215
+ # file name.
189
216
  #
190
217
  # @return [void]
191
218
  def build_dir(src_dir, obj_dir)
@@ -223,25 +250,27 @@ module Rscons
223
250
  build_fname
224
251
  end
225
252
 
226
- # Access a construction variable or environment option.
253
+ # Get a construction variable's value.
227
254
  #
228
255
  # @see VarSet#[]
229
256
  def [](*args)
230
257
  @varset.send(:[], *args)
231
258
  end
232
259
 
233
- # Set a construction variable or environment option.
260
+ # Set a construction variable's value.
234
261
  #
235
262
  # @see VarSet#[]=
236
263
  def []=(*args)
237
264
  @varset.send(:[]=, *args)
238
265
  end
239
266
 
240
- # Add a set of construction variables or environment options.
267
+ # Add a set of construction variables to the Environment.
241
268
  #
242
- # @see VarSet#append
243
- def append(*args)
244
- @varset.append(*args)
269
+ # @param values [VarSet, Hash] New set of variables.
270
+ #
271
+ # @return [void]
272
+ def append(values)
273
+ @varset.append(values)
245
274
  end
246
275
 
247
276
  # Build all build targets specified in the Environment.
@@ -287,6 +316,8 @@ module Rscons
287
316
  end
288
317
 
289
318
  # Clear all targets registered for the Environment.
319
+ #
320
+ # @return [void]
290
321
  def clear_targets
291
322
  @targets = {}
292
323
  end
@@ -410,8 +441,9 @@ module Rscons
410
441
  #
411
442
  # This method is used internally by Rscons builders.
412
443
  #
413
- # @param sources [Array] List of source files to build.
414
- # @param suffixes [Array] List of suffixes to try to convert source files into.
444
+ # @param sources [Array<String>] List of source files to build.
445
+ # @param suffixes [Array<String>]
446
+ # List of suffixes to try to convert source files into.
415
447
  # @param cache [Cache] The Cache.
416
448
  # @param vars [Hash] Extra variables to pass to the builder.
417
449
  #
@@ -440,7 +472,7 @@ module Rscons
440
472
  #
441
473
  # @param builder [Builder] The Builder to use.
442
474
  # @param target [String] The target output file.
443
- # @param sources [Array] List of source files.
475
+ # @param sources [Array<String>] List of source files.
444
476
  # @param cache [Cache] The Cache.
445
477
  # @param vars [Hash] Extra variables to pass to the builder.
446
478
  #
@@ -506,10 +538,10 @@ module Rscons
506
538
  # Parse command-line flags for compilation/linking options into separate
507
539
  # construction variables.
508
540
  #
509
- # The parsed construction variables are returned in a Hash instead of
510
- # merging them directly to the Environment. They can be merged with
511
- # {#merge_flags}. The {#parse_flags!} version immediately merges the parsed
512
- # flags as well.
541
+ # For {#parse_flags}, the parsed construction variables are returned in a
542
+ # Hash instead of merging them directly to the Environment. They can be
543
+ # merged with {#merge_flags}. The {#parse_flags!} version immediately
544
+ # merges the parsed flags as well.
513
545
  #
514
546
  # Example:
515
547
  # # Import FreeType build options
@@ -628,6 +660,13 @@ module Rscons
628
660
  end
629
661
  end
630
662
 
663
+ # Print the Environment's construction variables for debugging.
664
+ def dump
665
+ @varset.to_h.sort.each do |var, val|
666
+ puts "#{var} => #{val.inspect}"
667
+ end
668
+ end
669
+
631
670
  private
632
671
 
633
672
  # Expand target and source paths before invoking builders.
data/lib/rscons/varset.rb CHANGED
@@ -58,7 +58,7 @@ module Rscons
58
58
  #
59
59
  # @param values [VarSet, Hash] New set of variables.
60
60
  #
61
- # @return [self]
61
+ # @return [VarSet] Returns self.
62
62
  def append(values)
63
63
  coa!
64
64
  if values.is_a?(VarSet)
@@ -121,6 +121,26 @@ module Rscons
121
121
  end
122
122
  end
123
123
 
124
+ # Return a Hash containing all variables in the VarSet.
125
+ #
126
+ # @since 1.8.0
127
+ #
128
+ # This method is not terribly efficient. It is intended to be used only by
129
+ # debugging code to dump out a VarSet's variables.
130
+ #
131
+ # @return [Hash] All variables in the VarSet.
132
+ def to_h
133
+ result = deep_dup(@my_vars)
134
+ @coa_vars.reduce(result) do |result, coa_vars|
135
+ coa_vars.each_pair do |key, value|
136
+ unless result.include?(key)
137
+ result[key] = deep_dup(value)
138
+ end
139
+ end
140
+ result
141
+ end
142
+ end
143
+
124
144
  private
125
145
 
126
146
  # Move all VarSet variables into the copy-on-access list.
@@ -1,4 +1,4 @@
1
1
  module Rscons
2
2
  # gem version
3
- VERSION = "1.7.0"
3
+ VERSION = "1.8.0"
4
4
  end
data/rscons.gemspec CHANGED
@@ -24,5 +24,6 @@ Gem::Specification.new do |gem|
24
24
  gem.add_development_dependency "rake"
25
25
  gem.add_development_dependency "simplecov"
26
26
  gem.add_development_dependency "yard"
27
+ gem.add_development_dependency "rdoc"
27
28
  gem.add_development_dependency "redcarpet"
28
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rscons
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Holtrop
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-25 00:00:00.000000000 Z
11
+ date: 2014-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -28,70 +28,84 @@ dependencies:
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdoc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: redcarpet
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ! '>='
101
+ - - '>='
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ! '>='
108
+ - - '>='
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  description: Software construction library inspired by SCons and implemented in Ruby.
@@ -106,11 +120,13 @@ files:
106
120
  - lib/rscons/build_target.rb
107
121
  - lib/rscons/builder.rb
108
122
  - lib/rscons/builders/cfile.rb
123
+ - lib/rscons/builders/command.rb
109
124
  - lib/rscons/builders/disassemble.rb
110
125
  - lib/rscons/builders/library.rb
111
126
  - lib/rscons/builders/object.rb
112
127
  - lib/rscons/builders/preprocess.rb
113
128
  - lib/rscons/builders/program.rb
129
+ - lib/rscons/builders/simple_builder.rb
114
130
  - lib/rscons/cache.rb
115
131
  - lib/rscons/environment.rb
116
132
  - lib/rscons/varset.rb
@@ -126,17 +142,17 @@ require_paths:
126
142
  - lib
127
143
  required_ruby_version: !ruby/object:Gem::Requirement
128
144
  requirements:
129
- - - ! '>='
145
+ - - '>='
130
146
  - !ruby/object:Gem::Version
131
147
  version: '0'
132
148
  required_rubygems_version: !ruby/object:Gem::Requirement
133
149
  requirements:
134
- - - ! '>='
150
+ - - '>='
135
151
  - !ruby/object:Gem::Version
136
152
  version: '0'
137
153
  requirements: []
138
154
  rubyforge_project:
139
- rubygems_version: 2.3.0
155
+ rubygems_version: 2.4.1
140
156
  signing_key:
141
157
  specification_version: 4
142
158
  summary: Software construction library inspired by SCons and implemented in Ruby