build-environment 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f012093ceab4f38096a0f1b49a80b6c0de0ec75d
4
+ data.tar.gz: 7be8813be74fe6f4b7708b243be04b8e2e795eb6
5
+ SHA512:
6
+ metadata.gz: a9a8a44708e5b21e6bdcd65f4f160547b294cd6e076184b68c9230929c4564b91bf26042c8c81fe100e060619d6d2d0809aed8848128ab0207a2e0450f583139
7
+ data.tar.gz: f7199c17fadd8c062c4ef47b0e5fbe96a13ff01071491ea3ef68e69c909ed4366d92af3daec0ec77df2792512d1f464116eebfb51446be8c3d45d7c298eecab4
@@ -0,0 +1,22 @@
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
@@ -0,0 +1,9 @@
1
+
2
+ SimpleCov.start do
3
+ add_filter "/spec/"
4
+ end
5
+
6
+ if ENV['TRAVIS']
7
+ require 'coveralls'
8
+ Coveralls.wear!
9
+ end
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0"
4
+ - "2.1"
5
+ env: COVERAGE=true
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in build-environment.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'simplecov'
8
+ gem 'coveralls', require: false
9
+ end
@@ -0,0 +1,74 @@
1
+ # Build::Environment
2
+
3
+ Build::Environment provides a nested hash data structure which can contain lambdas for evaluating environments for generating appropriate build environments.
4
+
5
+ [![Build Status](https://secure.travis-ci.org/ioquatix/build-environment.svg)](http://travis-ci.org/ioquatix/build-environment)
6
+ [![Code Climate](https://codeclimate.com/github/ioquatix/build-environment.svg)](https://codeclimate.com/github/ioquatix/build-environment)
7
+ [![Coverage Status](https://coveralls.io/repos/ioquatix/build-environment/badge.svg)](https://coveralls.io/r/ioquatix/build-environment)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'build-environment'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install build-environment
22
+
23
+ ## Usage
24
+
25
+ A build environment in essence is a key-value storage, but it maintains a linked list so that lookups can be propagated towards the root. This allows a parent to provide, say, defaults, while the child can override these. The envirionment can contain strings, arrays and lambdas, which are evaluated when converting the environment into a hash.
26
+
27
+ a = Build::Environment.new
28
+ a[:cflags] = ["-std=c++11"]
29
+
30
+ b = Build::Environment.new(a, {})
31
+ b[:cflags] = ["-stdlib=libc++"]
32
+ b[:rcflags] = lambda {cflags }
33
+
34
+ b.flatten
35
+
36
+ ### Key Logic
37
+
38
+ When flattening an environment:
39
+
40
+ - String values overwrite each other.
41
+ - Array keys are concatenated.
42
+ - Symbols are redirected (i.e. refer to another key-value)
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
51
+
52
+ ## License
53
+
54
+ Released under the MIT license.
55
+
56
+ Copyright, 2012, 2015, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
57
+
58
+ Permission is hereby granted, free of charge, to any person obtaining a copy
59
+ of this software and associated documentation files (the "Software"), to deal
60
+ in the Software without restriction, including without limitation the rights
61
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
62
+ copies of the Software, and to permit persons to whom the Software is
63
+ furnished to do so, subject to the following conditions:
64
+
65
+ The above copyright notice and this permission notice shall be included in
66
+ all copies or substantial portions of the Software.
67
+
68
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
69
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
70
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
71
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
72
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
73
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
74
+ THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ task.rspec_opts = ["--require", "simplecov"] if ENV['COVERAGE']
6
+ end
7
+
8
+ task :default => :spec
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'build/environment/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "build-environment"
8
+ spec.version = Build::Environment::VERSION
9
+ spec.authors = ["Samuel Williams"]
10
+ spec.email = ["samuel.williams@oriontransfer.co.nz"]
11
+ spec.summary = %q{A nested hash data structure for controlling build environments.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+
23
+ spec.add_development_dependency "rspec", "~> 3.1.0"
24
+ end
@@ -0,0 +1,25 @@
1
+ # Copyright, 2012, 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_relative 'environment/base'
22
+ require_relative 'environment/constructor'
23
+ require_relative 'environment/evaluator'
24
+ require_relative 'environment/flatten'
25
+ require_relative 'environment/system'
@@ -0,0 +1,62 @@
1
+ # Copyright, 2012, 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
+ module Build
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
+ class Environment
24
+ def initialize(parent = nil, values = nil, &block)
25
+ @values = (values || {}).to_h
26
+ @parent = parent
27
+
28
+ if block_given?
29
+ Constructor.new(self).instance_exec(&block)
30
+ end
31
+ end
32
+
33
+ def self.hash(**values)
34
+ self.new(nil, values)
35
+ end
36
+
37
+ attr :values
38
+ attr :parent
39
+
40
+ def lookup(name)
41
+ if @values.include? name
42
+ self
43
+ elsif @parent
44
+ @parent.lookup(name)
45
+ end
46
+ end
47
+
48
+ def [] (key)
49
+ environment = lookup(key)
50
+
51
+ environment ? environment.values[key] : nil
52
+ end
53
+
54
+ def []= (key, value)
55
+ @values[key] = value
56
+ end
57
+
58
+ def to_s
59
+ "<#{self.class} #{self.values}>"
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,131 @@
1
+ # Copyright, 2012, 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
+ module Build
22
+ class Environment
23
+ Default = Struct.new(:value)
24
+ Replace = Struct.new(:value)
25
+
26
+ class Define
27
+ def initialize(klass, &block)
28
+ @klass = klass
29
+ @block = block
30
+ end
31
+
32
+ attr :klass
33
+ attr :block
34
+
35
+ def to_s
36
+ "<#{@klass.name} #{@block.source_location.join(':')}>"
37
+ end
38
+ end
39
+
40
+ class Constructor
41
+ def initialize(environment)
42
+ @environment = environment
43
+ end
44
+
45
+ def method_missing(name, value = nil, &block)
46
+ if block_given?
47
+ @environment[name] = block
48
+ else
49
+ @environment[name] = value
50
+ end
51
+
52
+ name
53
+ end
54
+
55
+ def [] key
56
+ @environment[key]
57
+ end
58
+
59
+ def default(name)
60
+ @environment[name] = Default.new(@environment[name])
61
+
62
+ return name
63
+ end
64
+
65
+ def replace(name)
66
+ @environment[name] = Replace.new(@environment[name])
67
+
68
+ return name
69
+ end
70
+
71
+ def append(name)
72
+ @environment[name] = Array(@environment[name])
73
+
74
+ return name
75
+ end
76
+
77
+ def define(klass, name, &block)
78
+ @environment[name] = Define.new(klass, &block)
79
+
80
+ return name
81
+ end
82
+ end
83
+
84
+ def self.combine(*environments)
85
+ # Flatten the list of environments:
86
+ environments = environments.collect do |environment|
87
+ if Environment === environment
88
+ environment.to_a
89
+ else
90
+ environment
91
+ end
92
+ end.flatten
93
+
94
+ # Resequence based on order:
95
+ first = Environment.new(nil, environments.shift)
96
+ top = first
97
+
98
+ environments.each do |tail|
99
+ top = Environment.new(top, tail)
100
+ end
101
+
102
+ return top
103
+ end
104
+
105
+ def merge(&block)
106
+ self.class.combine(
107
+ self,
108
+ self.class.new(&block)
109
+ )
110
+ end
111
+
112
+ # Convert the hierarchy of environments to an array where the parent comes before the child.
113
+ def to_a
114
+ flat = []
115
+
116
+ flatten_to_array(flat)
117
+
118
+ return flat
119
+ end
120
+
121
+ protected
122
+
123
+ def flatten_to_array(array)
124
+ if @parent
125
+ @parent.flatten_to_array(array)
126
+ end
127
+
128
+ array << self
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,51 @@
1
+ # Copyright, 2012, 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
+ module Build
22
+ class Environment
23
+ class Evaluator
24
+ def initialize(environment)
25
+ @environment = environment
26
+ end
27
+
28
+ def method_missing(name)
29
+ object_value(@environment[name])
30
+ end
31
+
32
+ # Compute the literal object value for a given key:
33
+ def object_value(value)
34
+ case value
35
+ when Array
36
+ value.collect{|item| object_value(item)}.flatten
37
+ when Symbol
38
+ object_value(@environment[value])
39
+ when Proc
40
+ object_value(instance_exec(&value))
41
+ when Default
42
+ object_value(value.value)
43
+ when Replace
44
+ object_value(value.value)
45
+ else
46
+ value
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,102 @@
1
+ # Copyright, 2012, 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 'digest/md5'
22
+
23
+ module Build
24
+ class Environment
25
+ def to_h
26
+ @values
27
+ end
28
+
29
+ def to_hash
30
+ hash = {}
31
+
32
+ # Flatten this chain of environments:
33
+ flatten_to_hash(hash)
34
+
35
+ # Evaluate all items to their respective object value:
36
+ evaluator = Evaluator.new(hash)
37
+
38
+ # Evaluate all the individual environment values so that they are flat:
39
+ Hash[hash.map{|key, value| [key, evaluator.object_value(value)]}]
40
+ end
41
+
42
+ def flatten
43
+ self.class.new(nil, self.to_hash)
44
+ end
45
+
46
+ def defined
47
+ @values.select{|name,value| Define === value}
48
+ end
49
+
50
+ def inspect(output = $stdout, indent = "")
51
+ @values.each do |(key, value)|
52
+ output.puts "#{indent}#{key}: #{value}"
53
+ end
54
+
55
+ @parent.inspect(output, indent + "\t") if @parent
56
+ end
57
+
58
+ # This should be stable within environments that produce the same results.
59
+ def checksum
60
+ digester = Digest::MD5.new
61
+
62
+ checksum_recursively(digester)
63
+
64
+ return digester.hexdigest
65
+ end
66
+
67
+ protected
68
+
69
+ def checksum_recursively(digester)
70
+ @values.each do |(key, value)|
71
+ digester.update(key.to_s)
72
+ digester.update(value.to_s)
73
+ end
74
+
75
+ @parent.checksum_recursively(digester) if @parent
76
+ end
77
+
78
+ # We fold in the ancestors one at a time from oldest to youngest.
79
+ def flatten_to_hash(hash)
80
+ if @parent
81
+ @parent.flatten_to_hash(hash)
82
+ end
83
+
84
+ @values.each do |key, value|
85
+ previous = hash[key]
86
+
87
+ if Replace === value
88
+ # Replace the parent value
89
+ hash[key] = value
90
+ elsif Array === previous
91
+ # Merge with the parent value
92
+ hash[key] = previous + Array(value)
93
+ elsif Default === value
94
+ # Update the parent value if not defined.
95
+ hash[key] = previous || value
96
+ else
97
+ hash[key] = value
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,47 @@
1
+ # Copyright, 2012, 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
+ module Build
22
+ class Environment
23
+ module System
24
+ def self.shell_escape(value)
25
+ case value
26
+ when Array
27
+ value.flatten.collect{|argument| shell_escape(argument)}.join(' ')
28
+ else
29
+ # Ensure that any whitespace has been escaped:
30
+ value.to_s.gsub(/ /, '\ ')
31
+ end
32
+ end
33
+
34
+ def self.convert_to_shell(environment)
35
+ Hash[environment.values.map{|key, value| [
36
+ key.to_s.upcase,
37
+ shell_escape(value)
38
+ ]}]
39
+ end
40
+ end
41
+
42
+ # Construct an environment from a given system environment:
43
+ def self.system_environment(env = ENV)
44
+ self.new(Hash[env.map{|key, value| [key.downcase.to_sym, value]}])
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ module Build
2
+ class Environment
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,91 @@
1
+ # Copyright, 2012, 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
+
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"]}
34
+ end
35
+
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"
44
+ end
45
+
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}
58
+ end
59
+
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
72
+ end
73
+
74
+ it "should combine defaults" do
75
+ local = Build::Environment.new do
76
+ architectures ["-m64"]
77
+ end
78
+
79
+ platform = Build::Environment.new do
80
+ default architectures ["-arch", "i386"]
81
+ end
82
+
83
+ combined = Build::Environment.combine(
84
+ platform,
85
+ local
86
+ )
87
+
88
+ expect(combined[:architectures]).to be == ["-m64"]
89
+ end
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: build-environment
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.0
55
+ description:
56
+ email:
57
+ - samuel.williams@oriontransfer.co.nz
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".simplecov"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - build-environment.gemspec
69
+ - lib/build/environment.rb
70
+ - lib/build/environment/base.rb
71
+ - lib/build/environment/constructor.rb
72
+ - lib/build/environment/evaluator.rb
73
+ - lib/build/environment/flatten.rb
74
+ - lib/build/environment/system.rb
75
+ - lib/build/environment/version.rb
76
+ - spec/build/environment/environment_spec.rb
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.2.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: A nested hash data structure for controlling build environments.
101
+ test_files:
102
+ - spec/build/environment/environment_spec.rb