build-environment 1.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0001c02a60a21462a7e644815ae06687d5acac4bdeecafc62595039f70e9deb
4
- data.tar.gz: ba745fa38286124d8bf9892a11c6c5ccc79dce5e3730bace910448ae3d58f78c
3
+ metadata.gz: 26081ff1dff34f75a11c7e9f3aa779f30903f7934bc2ad7b40bf46143e85f631
4
+ data.tar.gz: 4b1fcd9e3dfab73e260eb6a135bd3cb194df6fc85a998af7db80e663f65f01cb
5
5
  SHA512:
6
- metadata.gz: 2fca1929969d76556766f4fa8e62e0029888eea3e3577c08f789eaeeedd1d8644b7e9ae04c00960640dea4e0f7d0ae51b340602af3021b01ff73a2d66f8e6bc5
7
- data.tar.gz: fa73b7209f17233c442c2a24232526d027ac7c81bc3d6173c41c4f7fbd51af9e92073c3d68c792639dfe89f66996ad42a2caea3360e6f264d25d73e716f2458b
6
+ metadata.gz: ef78ae3b18fd283abdc700382058f47f8a171bdba4c99cce3fb2f2cb476abc1646957c36912f29322c1084c8a2c5ebe89e1dcad360e3819d584fabae335dbe10
7
+ data.tar.gz: d43132d577da415079cde21d991f3decdc49dba8f758291e98d290a2a88ec348300a9e66325778817428caf68f0d127d1d9b3c5e83bceb4f975f0ce3ef655d70
data/.gitignore CHANGED
@@ -1,22 +1,4 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
1
+ /Gemfile.lock
2
+ /.rspec_status
3
+ /pkg
4
+ /.covered*
data/.rspec CHANGED
@@ -1,5 +1,3 @@
1
- --color
2
1
  --format documentation
3
- --backtrace
4
2
  --warnings
5
3
  --require spec_helper
data/.travis.yml CHANGED
@@ -8,13 +8,5 @@ matrix:
8
8
  - rvm: 2.4
9
9
  - rvm: 2.5
10
10
  - rvm: 2.6
11
- - rvm: truffleruby
12
- - rvm: jruby-head
13
- env: JRUBY_OPTS="--debug -X+O"
14
- - rvm: ruby-head
15
- - rvm: rbx-3
16
- allow_failures:
17
- - rvm: ruby-head
18
- - rvm: truffleruby
19
- - rvm: jruby-head
20
- - rvm: rbx-3
11
+ - rvm: 2.6
12
+ env: COVERAGE=BriefSummary,Coveralls
data/Gemfile CHANGED
@@ -2,8 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in build-environment.gemspec
4
4
  gemspec
5
-
6
- group :test do
7
- gem 'simplecov'
8
- gem 'coveralls', require: false
9
- end
data/Rakefile CHANGED
@@ -1,8 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec) do |task|
5
- task.rspec_opts = ["--require", "simplecov"] if ENV['COVERAGE']
6
- end
4
+ RSpec::Core::RakeTask.new(:spec)
7
5
 
8
6
  task :default => :spec
@@ -17,7 +17,8 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_development_dependency "bundler", "~> 1.3"
21
- spec.add_development_dependency "rspec", "~> 3.4.0"
20
+ spec.add_development_dependency "covered"
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rspec", "~> 3.4"
22
23
  spec.add_development_dependency "rake"
23
24
  end
@@ -21,29 +21,39 @@
21
21
  module Build
22
22
  # This is the basic environment data structure which is essentially a linked list of hashes. It is primarily used for organising build configurations across a wide range of different sub-systems, e.g. platform configuration, target configuration, local project configuration, etc.
23
23
  class Environment
24
- def initialize(parent = nil, values = nil, &block)
25
- @values = (values || {}).to_h
24
+ include Comparable
25
+
26
+ def initialize(parent = nil, values = nil, name: nil, &block)
26
27
  @parent = parent
28
+ @values = (values || {}).to_h
29
+ @update = block
27
30
 
28
- if block_given?
29
- Constructor.new(self).instance_exec(&block)
30
- end
31
+ @name = name
32
+ end
33
+
34
+ attr :parent
35
+ attr :values
36
+ attr :update
37
+ attr :name
38
+
39
+ def dup(parent: @parent, values: @values, update: @update)
40
+ self.class.new(parent, values.dup, name: @name, &update)
41
+ end
42
+
43
+ def <=> other
44
+ self.to_h <=> other.to_h
31
45
  end
32
46
 
33
47
  def freeze
34
- @values.freeze
48
+ return self if frozen?
49
+
35
50
  @parent.freeze
51
+ @values.freeze
52
+ @update.freeze
36
53
 
37
54
  super
38
55
  end
39
56
 
40
- def self.hash(values = {})
41
- self.new(nil, values)
42
- end
43
-
44
- attr :values
45
- attr :parent
46
-
47
57
  def lookup(name)
48
58
  if @values.include? name
49
59
  self
@@ -71,7 +81,19 @@ module Build
71
81
  end
72
82
 
73
83
  def to_s
74
- self.to_hash.to_s
84
+ buffer = String.new("\#<#{self.class} ")
85
+
86
+ if @name
87
+ buffer << @name.inspect << ' '
88
+ end
89
+
90
+ if @update
91
+ buffer << @update.source_location.join(':') << ' '
92
+ end
93
+
94
+ buffer << @values.to_s << '>'
95
+
96
+ return buffer
75
97
  end
76
98
  end
77
99
  end
@@ -33,25 +33,61 @@ module Build
33
33
  end
34
34
  end
35
35
 
36
+ def construct!(proxy, *arguments, &block)
37
+ constructor = Constructor.new(self, proxy)
38
+
39
+ if block_given?
40
+ constructor.instance_exec(*arguments, &block)
41
+ end
42
+
43
+ return self
44
+ end
45
+
36
46
  class Constructor
37
- def initialize(environment)
47
+ def initialize(environment, proxy = nil)
38
48
  @environment = environment
49
+ @proxy = proxy
39
50
  end
40
-
41
- def method_missing(name, value = nil, &block)
42
- if block_given?
51
+
52
+ def method_missing(name, *args, **options, &block)
53
+ if block_given? and args.empty?
43
54
  @environment[name] = block
55
+
56
+ return name
57
+ elsif !block_given? and args.any?
58
+ if args.count == 1
59
+ @environment[name] = args.first
60
+ else
61
+ @environment[name] = args
62
+ end
63
+
64
+ return name
65
+ end
66
+
67
+ if @proxy
68
+ # This is a bit of a hack, but I'm not sure if there is a better way.
69
+ if options.empty?
70
+ @proxy.send(name, *args, &block)
71
+ else
72
+ @proxy.send(name, *args, **options, &block)
73
+ end
44
74
  else
45
- @environment[name] = value
75
+ super
46
76
  end
47
-
48
- name
49
77
  end
50
-
78
+
79
+ def respond_to(*args)
80
+ super or @proxy&.respond_to(*args)
81
+ end
82
+
51
83
  def [] key
52
84
  @environment[key]
53
85
  end
54
-
86
+
87
+ def parent
88
+ @environment.parent
89
+ end
90
+
55
91
  def default(name)
56
92
  @environment[name] = Default.new(@environment[name])
57
93
 
@@ -87,19 +123,13 @@ module Build
87
123
  end
88
124
  end.flatten
89
125
 
90
- # Resequence based on order:
91
- first = Environment.new(nil, environments.shift)
92
- top = first
93
-
94
- environments.each do |tail|
95
- top = Environment.new(top, tail)
126
+ environments.inject(nil) do |parent, environment|
127
+ environment.dup(parent: parent)
96
128
  end
97
-
98
- return top
99
129
  end
100
130
 
101
- def merge(&block)
102
- self.class.new(self, &block)
131
+ def merge(**options, &block)
132
+ self.class.new(self, **options, &block)
103
133
  end
104
134
 
105
135
  # Convert the hierarchy of environments to an array where the parent comes before the child.
@@ -23,10 +23,6 @@ require 'digest/md5'
23
23
  module Build
24
24
  class Environment
25
25
  def to_h
26
- @values
27
- end
28
-
29
- def to_hash
30
26
  hash = {}
31
27
 
32
28
  # Flatten this chain of environments:
@@ -39,15 +35,23 @@ module Build
39
35
  Hash[hash.map{|key, value| [key, evaluator.object_value(value)]}]
40
36
  end
41
37
 
42
- def flatten
43
- self.class.new(nil, self.to_hash)
38
+ def evaluate(**options)
39
+ self.class.new(nil, self.to_h, **options)
40
+ end
41
+
42
+ def flatten(**options)
43
+ hash = {}
44
+
45
+ flatten_to_hash(hash)
46
+
47
+ return self.class.new(nil, hash, **options)
44
48
  end
45
49
 
46
50
  def defined
47
51
  @values.select{|name,value| Define === value}
48
52
  end
49
53
 
50
- def checksum(digester: Digest::MD5.new)
54
+ def checksum(digester: Digest::SHA1.new)
51
55
  checksum_recursively(digester)
52
56
 
53
57
  return digester.hexdigest
@@ -62,34 +66,58 @@ module Build
62
66
  def checksum_recursively(digester)
63
67
  sorted_keys.each do |key|
64
68
  digester.update(key.to_s)
65
- digester.update(@values[key].to_s)
69
+
70
+ case value = @values[key]
71
+ when Proc
72
+ digester.update(value.source_location.join)
73
+ else
74
+ digester.update(value.to_s)
75
+ end
66
76
  end
67
77
 
68
78
  @parent.checksum_recursively(digester) if @parent
69
79
  end
70
80
 
71
- # We fold in the ancestors one at a time from oldest to youngest.
72
- def flatten_to_hash(hash)
73
- if @parent
74
- @parent.flatten_to_hash(hash)
75
- end
76
-
81
+ def update_hash(hash)
77
82
  @values.each do |key, value|
78
83
  previous = hash[key]
79
-
84
+
80
85
  if Replace === value
81
86
  # Replace the parent value
82
87
  hash[key] = value
83
- elsif Array === previous
84
- # Merge with the parent value
85
- hash[key] = previous + Array(value)
86
88
  elsif Default === value
87
89
  # Update the parent value if not defined.
88
90
  hash[key] = previous || value
91
+ elsif Array === previous
92
+ # Merge with the parent value
93
+ hash[key] = previous + Array(value)
89
94
  else
90
95
  hash[key] = value
91
96
  end
92
97
  end
98
+
99
+ return self
100
+ end
101
+
102
+ # Apply the update function to this environment.
103
+ def update!
104
+ construct!(self, &@update)
105
+ @update = nil
106
+
107
+ return self
108
+ end
109
+
110
+ # We fold in the ancestors one at a time from oldest to youngest.
111
+ def flatten_to_hash(hash)
112
+ if parent = @parent
113
+ parent = parent.flatten_to_hash(hash)
114
+ end
115
+
116
+ if @update
117
+ self.dup(parent: parent).update!.update_hash(hash)
118
+ else
119
+ self.update_hash(hash)
120
+ end
93
121
  end
94
122
  end
95
123
  end
@@ -61,13 +61,13 @@ module Build
61
61
  end
62
62
 
63
63
  # Construct an environment from a given system environment:
64
- def self.system_environment(env = ENV)
65
- self.new(nil, Hash[env.map{|key, value| [key.downcase.to_sym, value]}])
64
+ def self.system_environment(env = ENV, **options)
65
+ self.new(nil, Hash[env.map{|key, value| [key.downcase.to_sym, value]}], **options)
66
66
  end
67
67
 
68
68
  # Make a hash appropriate for a process environment
69
69
  def export
70
- System::convert_to_shell(self)
70
+ System.convert_to_shell(self)
71
71
  end
72
72
  end
73
73
  end
@@ -1,5 +1,5 @@
1
1
  module Build
2
2
  class Environment
3
- VERSION = "1.1.5"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -0,0 +1,50 @@
1
+ # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'build/environment'
22
+ require 'build/environment/system'
23
+
24
+ require_relative 'rule'
25
+
26
+ RSpec.describe Build::Environment do
27
+ it "should update environment" do
28
+ static_library = "Freeb.a"
29
+
30
+ environment = Build::Environment.new do
31
+ libraries []
32
+
33
+ define Rule, "link.static-library" do
34
+ append libraries static_library
35
+ end
36
+ end.flatten
37
+
38
+ rules = environment.defined
39
+
40
+ flat_environment = environment.flatten
41
+
42
+ rules.each do |name, define|
43
+ constructor = Build::Environment::Constructor.new(flat_environment)
44
+ constructor.instance_exec(&define.block)
45
+ end
46
+
47
+ expect(flat_environment).to include(:libraries)
48
+ expect(flat_environment[:libraries]).to include(static_library)
49
+ end
50
+ end
@@ -20,24 +20,22 @@
20
20
 
21
21
  require 'build/environment'
22
22
 
23
- module Build::ChecksumSpec
24
- describe "Build::Environment#checksum" do
25
- it "should compute a checksum" do
26
- e = Build::Environment.hash(a: 10, b: 20)
27
-
28
- expect(e.checksum).to be == "0e29e95023819e0ecd2850edece5851a"
29
- end
23
+ RSpec.describe "Build::Environment#checksum" do
24
+ it "should compute a checksum" do
25
+ e = Build::Environment.new do
26
+ a 10
27
+ b 20
28
+ end.evaluate
30
29
 
31
- it "should compute same checksum when keys are in different order" do
32
- e = Build::Environment.hash(b: 20, a: 10)
33
-
34
- expect(e.checksum).to be == "0e29e95023819e0ecd2850edece5851a"
35
- end
30
+ expect(e.checksum).to be == "3a781e8f5250ccb2bca472085a4e366188621d8a"
31
+ end
32
+
33
+ it "should compute same checksum when keys are in different order" do
34
+ e = Build::Environment.new do
35
+ b 20
36
+ a 10
37
+ end.evaluate
36
38
 
37
- it "should handle both string and symbol keys" do
38
- e = Build::Environment.hash(:a => 20, "b" => 10)
39
-
40
- expect(e.checksum).to be == "613a92db2cc6a94709ce3174f01c29fe"
41
- end
39
+ expect(e.checksum).to be == "3a781e8f5250ccb2bca472085a4e366188621d8a"
42
40
  end
43
41
  end
@@ -20,72 +20,104 @@
20
20
 
21
21
  require 'build/environment'
22
22
 
23
- module Build::EnvironmentSpec
24
- describe Build::Environment do
25
- it "should chain environments together" do
26
- a = Build::Environment.new
27
- a[:cflags] = ["-std=c++11"]
28
-
29
- b = Build::Environment.new(a, {})
30
- b[:cflags] = ["-stdlib=libc++"]
31
- b[:rcflags] = lambda {cflags.reverse}
32
-
33
- expect(b.flatten.to_hash).to be == {:cflags => ["-std=c++11", "-stdlib=libc++"], :rcflags => ["-stdlib=libc++", "-std=c++11"]}
23
+ RSpec.describe Build::Environment do
24
+ context '#to_s' do
25
+ it "should generate empty string" do
26
+ expect(subject.to_s).to be == "#<Build::Environment {}>"
34
27
  end
35
28
 
36
- it "should resolve nested lambda" do
37
- a = Build::Environment.new do
38
- sdk "bob-2.6"
39
- cflags [->{"-sdk=#{sdk}"}]
40
- end
41
-
42
- b = Build::Environment.new(a) do
43
- sdk "bob-2.8"
29
+ it "should show update proc" do
30
+ environment = Build::Environment.new do
44
31
  end
45
32
 
46
- c = Build::Environment.new(b) do
47
- cflags ["-pipe"]
48
- end
49
-
50
- expect(b.flatten.to_hash.keys.sort).to be == [:cflags, :sdk]
51
-
52
- expect(Build::Environment::System::convert_to_shell(b.flatten)).to be == {
53
- 'SDK' => "bob-2.8",
54
- 'CFLAGS' => "-sdk=bob-2.8"
55
- }
56
-
57
- expect(c.flatten[:cflags]).to be == %W{-sdk=bob-2.8 -pipe}
33
+ expect(environment.to_s).to be =~ /environment_spec.rb/
58
34
  end
35
+ end
36
+
37
+ it "should chain environments together" do
38
+ a = Build::Environment.new
39
+ a[:cflags] = ["-std=c++11"]
59
40
 
60
- it "should combine environments" do
61
- a = Build::Environment.new(nil, {:name => 'a'})
62
- b = Build::Environment.new(a, {:name => 'b'})
63
- c = Build::Environment.new(nil, {:name => 'c'})
64
- d = Build::Environment.new(c, {:name => 'd'})
65
-
66
- top = Build::Environment.combine(b, d)
67
-
68
- expect(top.values).to be == d.values
69
- expect(top.parent.values).to be == c.values
70
- expect(top.parent.parent.values).to be == b.values
71
- expect(top.parent.parent.parent.values).to be == a.values
41
+ b = Build::Environment.new(a)
42
+ b[:cflags] = ["-stdlib=libc++"]
43
+ b[:rcflags] = lambda {cflags.reverse}
44
+
45
+ expect(b.evaluate).to be == {
46
+ :cflags => ["-std=c++11", "-stdlib=libc++"],
47
+ :rcflags => ["-stdlib=libc++", "-std=c++11"]
48
+ }
49
+ end
50
+
51
+ it "should resolve nested lambda" do
52
+ a = Build::Environment.new do
53
+ sdk "bob-2.6"
54
+ cflags [->{"-sdk=#{sdk}"}]
72
55
  end
73
56
 
74
- it "should combine defaults" do
75
- local = Build::Environment.new do
76
- architectures ["-m64"]
77
- end
57
+ b = Build::Environment.new(a) do
58
+ sdk "bob-2.8"
59
+ end
78
60
 
79
- platform = Build::Environment.new do
80
- default architectures ["-arch", "i386"]
81
- end
61
+ c = Build::Environment.new(b) do
62
+ cflags ["-pipe"]
63
+ end
64
+
65
+ expect(b.to_h.keys.sort).to be == [:cflags, :sdk]
66
+
67
+ expect(Build::Environment::System::convert_to_shell(b.evaluate)).to be == {
68
+ 'SDK' => "bob-2.8",
69
+ 'CFLAGS' => "-sdk=bob-2.8"
70
+ }
71
+
72
+ expect(c.evaluate[:cflags]).to be == %W{-sdk=bob-2.8 -pipe}
73
+ end
74
+
75
+ it "should combine environments" do
76
+ a = Build::Environment.new(nil, {:name => 'a'})
77
+ b = Build::Environment.new(a, {:name => 'b'})
78
+ c = Build::Environment.new(nil, {:name => 'c'})
79
+ d = Build::Environment.new(c, {:name => 'd'})
82
80
 
83
- combined = Build::Environment.combine(
84
- platform,
85
- local
86
- )
81
+ top = Build::Environment.combine(b, d)
87
82
 
88
- expect(combined[:architectures]).to be == ["-m64"]
83
+ expect(top.values).to be == d.values
84
+ expect(top.parent.values).to be == c.values
85
+ expect(top.parent.parent.values).to be == b.values
86
+ expect(top.parent.parent.parent.values).to be == a.values
87
+ end
88
+
89
+ it "should combine defaults" do
90
+ platform = Build::Environment.new do
91
+ os "linux"
92
+ compiler "cc"
93
+ architectures ["-march", "i386"]
94
+ end
95
+
96
+ expect(platform).to be == {
97
+ os: "linux",
98
+ compiler: "cc",
99
+ architectures: ["-march", "i386"]
100
+ }
101
+
102
+ local = Build::Environment.new do
103
+ compiler "clang"
104
+ default architectures ["-march", "i686"]
89
105
  end
106
+
107
+ expect(local).to be == {
108
+ compiler: "clang",
109
+ architectures: ["-march", "i686"]
110
+ }
111
+
112
+ combined = Build::Environment.combine(
113
+ platform,
114
+ local
115
+ ).flatten
116
+
117
+ expect(combined).to be == {
118
+ os: "linux",
119
+ compiler: "clang",
120
+ architectures: ["-march", "i386"]
121
+ }
90
122
  end
91
123
  end
@@ -22,35 +22,33 @@
22
22
 
23
23
  require 'build/environment'
24
24
 
25
- module Build::Environment::FreezeSpec
26
- describe "Build::Environment#freeze" do
27
- it "should not be frozen by default" do
28
- a = Build::Environment.new
29
- b = a.merge
30
-
31
- expect(a.frozen?).to be_falsey
32
- expect(b.frozen?).to be_falsey
33
- expect(b.parent).to be a
34
- end
25
+ RSpec.describe "Build::Environment#freeze" do
26
+ it "should not be frozen by default" do
27
+ a = Build::Environment.new
28
+ b = a.merge
35
29
 
36
- it "should freeze an environment and it's parent" do
37
- a = Build::Environment.new
38
- b = a.merge
39
-
40
- b.freeze
41
-
42
- expect(a.frozen?).to be_truthy
43
- expect(b.frozen?).to be_truthy
44
- end
30
+ expect(a.frozen?).to be_falsey
31
+ expect(b.frozen?).to be_falsey
32
+ expect(b.parent).to be a
33
+ end
34
+
35
+ it "should freeze an environment and it's parent" do
36
+ a = Build::Environment.new
37
+ b = a.merge
38
+
39
+ b.freeze
40
+
41
+ expect(a.frozen?).to be_truthy
42
+ expect(b.frozen?).to be_truthy
43
+ end
44
+
45
+ it "should only be partially frozen" do
46
+ a = Build::Environment.new
47
+ b = a.merge
48
+
49
+ a.freeze
45
50
 
46
- it "should only be partially frozen" do
47
- a = Build::Environment.new
48
- b = a.merge
49
-
50
- a.freeze
51
-
52
- expect(a.frozen?).to be_truthy
53
- expect(b.frozen?).to be_falsey
54
- end
51
+ expect(a.frozen?).to be_truthy
52
+ expect(b.frozen?).to be_falsey
55
53
  end
56
54
  end
@@ -0,0 +1,10 @@
1
+
2
+ class Rule
3
+ def initialize(process_name, type)
4
+ @process_name = process_name
5
+ @type = type
6
+ end
7
+
8
+ attr :process_name
9
+ attr :type
10
+ end
@@ -21,42 +21,32 @@
21
21
  require 'build/environment'
22
22
  require 'build/environment/system'
23
23
 
24
- module Build::Environment::SystemSpec
25
- class Rule
26
- def initialize(process_name, type)
27
- @process_name = process_name
28
- @type = type
29
- end
24
+ require_relative 'rule'
25
+
26
+ RSpec.describe Build::Environment do
27
+ it "should not export rule" do
28
+ a = Build::Environment.new do
29
+ cflags "-fPIC"
30
+
31
+ define Rule, "compile.foo" do
32
+ end
33
+ end.flatten
30
34
 
31
- attr :process_name
32
- attr :type
35
+ expect(a).to include(:cflags)
36
+ expect(a).to include('compile.foo')
37
+
38
+ exported = a.export
39
+
40
+ expect(exported.size).to be == 1
41
+ expect(exported).to_not include('COMPILE.FOO')
33
42
  end
34
43
 
35
- describe Build::Environment do
36
- it "should not export rule" do
37
- a = Build::Environment.new do
38
- cflags "-fPIC"
39
-
40
- define Rule, "compile.foo" do
41
- end
42
- end
43
-
44
- expect(a).to include(:cflags)
45
- expect(a).to include('compile.foo')
46
-
47
- exported = a.export
48
-
49
- expect(exported.size).to be == 1
50
- expect(exported).to_not include('COMPILE.FOO')
51
- end
44
+ let(:system_environment) {Build::Environment.system_environment}
45
+
46
+ it "shold load current ENV" do
47
+ ENV['TEST_KEY'] = 'test-value'
52
48
 
53
- it "shold load current ENV" do
54
- ENV['TEST_KEY'] = 'test-value'
55
-
56
- e = Build::Environment::system_environment
57
-
58
- expect(e.values).to include(:path, :user, :home)
59
- expect(e[:test_key]).to be == 'test-value'
60
- end
49
+ expect(system_environment.values).to include(:path, :user, :home)
50
+ expect(system_environment[:test_key]).to be == 'test-value'
61
51
  end
62
52
  end
@@ -0,0 +1,50 @@
1
+ # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'build/environment'
22
+ require 'build/environment/system'
23
+
24
+ require_relative 'rule'
25
+
26
+ RSpec.describe Build::Environment do
27
+ it "can execute update functions" do
28
+ platform = Build::Environment.new do
29
+ libraries []
30
+
31
+ root "/usr"
32
+ bin ->{File.join(root, "bin")}
33
+ compiler ->{File.join(bin, "clang")}
34
+
35
+ append libraries "m"
36
+ end
37
+
38
+ task = Build::Environment.new(platform) do
39
+ library_path = File.join(parent.checksum, "Time.a")
40
+
41
+ append libraries library_path
42
+ end
43
+
44
+ environment = task.flatten do |environment|
45
+ environment.update!
46
+ end
47
+
48
+ expect(environment[:libraries].count).to be == 2
49
+ end
50
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,25 +1,10 @@
1
1
 
2
- if ENV['COVERAGE']
3
- begin
4
- require 'simplecov'
5
-
6
- SimpleCov.start do
7
- add_filter "/spec/"
8
- end
9
-
10
- if ENV['TRAVIS']
11
- require 'coveralls'
12
- Coveralls.wear!
13
- end
14
- rescue LoadError
15
- warn "Could not load simplecov: #{$!}"
16
- end
17
- end
18
-
19
- require "bundler/setup"
20
- require "build/environment"
2
+ require 'covered/rspec'
3
+ require 'build/environment'
21
4
 
22
5
  RSpec.configure do |config|
6
+ config.disable_monkey_patching!
7
+
23
8
  # Enable flags like --only-failures and --next-failure
24
9
  config.example_status_persistence_file_path = ".rspec_status"
25
10
 
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: build-environment
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-05 00:00:00.000000000 Z
11
+ date: 2019-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: covered
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - "~>"
31
+ - - ">="
18
32
  - !ruby/object:Gem::Version
19
- version: '1.3'
33
+ version: '0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - "~>"
38
+ - - ">="
25
39
  - !ruby/object:Gem::Version
26
- version: '1.3'
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: 3.4.0
47
+ version: '3.4'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: 3.4.0
54
+ version: '3.4'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -73,10 +87,13 @@ files:
73
87
  - lib/build/environment/flatten.rb
74
88
  - lib/build/environment/system.rb
75
89
  - lib/build/environment/version.rb
90
+ - spec/build/environment/build_spec.rb
76
91
  - spec/build/environment/checksum_spec.rb
77
92
  - spec/build/environment/environment_spec.rb
78
93
  - spec/build/environment/freeze_spec.rb
94
+ - spec/build/environment/rule.rb
79
95
  - spec/build/environment/system_spec.rb
96
+ - spec/build/environment/update_spec.rb
80
97
  - spec/spec_helper.rb
81
98
  homepage: ''
82
99
  licenses:
@@ -97,13 +114,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
114
  - !ruby/object:Gem::Version
98
115
  version: '0'
99
116
  requirements: []
100
- rubygems_version: 3.0.1
117
+ rubygems_version: 3.0.2
101
118
  signing_key:
102
119
  specification_version: 4
103
120
  summary: A nested hash data structure for controlling build environments.
104
121
  test_files:
122
+ - spec/build/environment/build_spec.rb
105
123
  - spec/build/environment/checksum_spec.rb
106
124
  - spec/build/environment/environment_spec.rb
107
125
  - spec/build/environment/freeze_spec.rb
126
+ - spec/build/environment/rule.rb
108
127
  - spec/build/environment/system_spec.rb
128
+ - spec/build/environment/update_spec.rb
109
129
  - spec/spec_helper.rb