ninja-build-helpers 0.2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ce48a426f3d6d879ffad5d0fab0c82a33c8e990
4
+ data.tar.gz: 897ee4091f2f345b94d63ad740dcce329b5559db
5
+ SHA512:
6
+ metadata.gz: c76c826622bbd9dc59c106afb0eea96b6267b2d9ff5793534f95e2f81224f7b795e5b45600c4857dbf7ad3b85d8c5a648832c9a1534247018b1de696cec35969
7
+ data.tar.gz: cc25f5b95fad38d4de197136e765f9829845d5e3668392969c183b4a2bc60ea1a6e4b0daa2de59e8210bb4f88b9c9736a900e556c2257b9fec516677f52a8b04
@@ -0,0 +1,5 @@
1
+ # Sublime Text 2/3
2
+ *.sublime-workspace
3
+
4
+ # RubyGems
5
+ *.gem
data/AUTHORS ADDED
@@ -0,0 +1,2 @@
1
+ Michael Williams <m.t.williams@live.com>
2
+ Phillip Cao <ftechz@gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
@@ -0,0 +1,5 @@
1
+ # Ninja Build Helpers
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/ninja.svg)](https://rubygems.org/gems/ninja-build-helpers)
4
+
5
+ Helpers for generating Ninja build files using Ruby.
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,21 @@
1
+ # ===-- lib/ninja.rb -------------------------------------*- mode: Ruby -*-=== #
2
+ #
3
+ # _____ _ _
4
+ # | | |_|___ |_|___
5
+ # | | | | | | | | .'|
6
+ # |_|___|_|_|_|_| |__,|
7
+ # |___|
8
+ #
9
+ # This file is distributed under the terms described in LICENSE.
10
+ #
11
+ # ===----------------------------------------------------------------------=== #
12
+
13
+ module Ninja
14
+ require_relative 'ninja/version'
15
+ require_relative 'ninja/delegator'
16
+ require_relative 'ninja/variable'
17
+ require_relative 'ninja/response_file'
18
+ require_relative 'ninja/rule'
19
+ require_relative 'ninja/build'
20
+ require_relative 'ninja/file'
21
+ end
@@ -0,0 +1,36 @@
1
+ module Ninja
2
+ class Build
3
+ attr_reader :rule,
4
+ :inputs,
5
+ :implicit_inputs,
6
+ :output,
7
+ :variables
8
+
9
+ def initialize(desc={})
10
+ Description.validate!(desc)
11
+
12
+ @rule = desc[:rule]
13
+ @inputs = [*desc[:inputs]]
14
+ @implicit_inputs = [*desc[:implicit_inputs]]
15
+ @output = desc[:output]
16
+ @variables = desc[:variables]
17
+ end
18
+
19
+ module Description #:nodoc:
20
+ def self.validate!(desc)
21
+ # This might be overkill, but we want this to be idiot-proof.
22
+ raise "Rule not specified." unless desc.include?(:rule)
23
+ raise "Expected rule to be a string composed of [a-Z,0-9,-,_] characters." unless /\A([-\w]+?)+\z/.match(desc[:rule])
24
+
25
+ raise "Inputs not specified." unless desc.include?(:inputs)
26
+ # TODO(mtwilliams): Check type of elements.
27
+ raise "Expected inputs to be an array of paths." unless desc[:inputs].is_a?(Array)
28
+ raise "Output not specified." unless desc.include?(:output)
29
+ # TODO(mtwilliams): Check if paths exist.
30
+ raise "Expected output to be a path." unless desc[:output].is_a?(String)
31
+ raise "Variables not specified." unless desc.include?(:variables)
32
+ raise "Expected variables to be an array of variables." unless desc[:variables].is_a?(Array)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ module Ninja
2
+ class Delegator
3
+ def initialize(context, opts={})
4
+ @context = context
5
+ # TODO(mtwilliams): Hide standard methods, too.
6
+ @hidden = ((opts[:except] || []).map(&:to_sym))
7
+ @hooks = Hash[((opts.select{|k,_| /^on_.+/.match(k)}).map{|k,v| [k[3..-1].to_sym, v]})]
8
+ end
9
+
10
+ def method_missing(name, *args, &block)
11
+ name = name.to_sym
12
+ super if @hidden.include? name
13
+ if @context.respond_to? name
14
+ response = @context.send(name, *args, &block)
15
+ @hooks[name].call(response) if @hooks.include? name
16
+ else
17
+ super
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,115 @@
1
+ module Ninja
2
+ class File
3
+ def initialize(path=nil, &block)
4
+ @variables = []
5
+ @rules = []
6
+ @builds = []
7
+ @subninjas = []
8
+ @defaults = []
9
+ Delegator.new(self, :except => [:save]).instance_eval(&block) if block_given?
10
+ self.save(path) if path
11
+ end
12
+
13
+ def variable(name, value)
14
+ @variables.push(Ninja::Variable.new(name, value))
15
+ end
16
+
17
+ def rule(name, command, opts={})
18
+ additional = {}
19
+
20
+ if opts[:response_file]
21
+ additional[:response_file] = Ninja::ResponseFile.new("$out.rsp", opts[:response_file])
22
+ end
23
+
24
+ @rules.push(Ninja::Rule.new(:name => name,
25
+ :command => command,
26
+ :dependencies => opts[:dependencies],
27
+ :description => opts[:description],
28
+ **additional))
29
+ end
30
+
31
+ def build(rule, outputs_to_inputs={}, variables={}, implicit_inputs=[])
32
+ buildVariables = []
33
+ variables.each do |name, value|
34
+ buildVariables.push Ninja::Variable.new(name, value)
35
+ end
36
+ outputs_to_inputs.each do |output, inputs|
37
+ @builds.push(Ninja::Build.new(:rule => rule, :inputs => [*inputs], :implicit_inputs => [*implicit_inputs], :output => output, :variables => buildVariables))
38
+ end
39
+ end
40
+
41
+ def subninja(filename)
42
+ @subninjas.push(filename)
43
+ end
44
+
45
+ def alias(from, to)
46
+ # Pretty clever, huh?
47
+ @builds.push(Ninja::Build.new(:rule => 'phony', :inputs => [*to], :output => from))
48
+ end
49
+
50
+ def defaults(outputs)
51
+ # TODO(mtwilliams): Accept variables (\$[\w]|\$\{[\w]\}).
52
+ # raise "Expected output(s) to be paths." unless [*outputs].all?{|output| /\A(?:[-\w\.]+\/?)+\z/.match(output)}
53
+ @defaults.push(*outputs)
54
+ end
55
+
56
+ def save(path)
57
+ raise "Path not specified!" unless path
58
+ # TODO(mtwilliams): Check if everything up to |path| exists.
59
+ ::File.open(path, 'w') do |f|
60
+ f.write "# This file was auto-generated by \"#{::File.basename($PROGRAM_NAME, ::File.extname($0))}\".\n"
61
+ f.write "# Do not modify! Instead, modify the aforementioned program.\n\n"
62
+ f.write "# We require Ninja >= 1.3 for `deps` and >= 1.5 for `msvc_deps_prefix`.\n"
63
+ f.write "ninja_required_version = 1.5\n\n"
64
+
65
+ @subninjas.each do |subninja|
66
+ f.write "subninja #{subninja}\n"
67
+ end
68
+ f.write "\n" unless @subninjas.empty?
69
+
70
+ @variables.each do |variable|
71
+ # TODO(mtwilliams): Escape.
72
+ f.write "#{variable.name} = #{variable.value}\n"
73
+ end
74
+ f.write "\n" unless @variables.empty?
75
+
76
+ @rules.each do |rule|
77
+ f.write "rule #{rule.name}\n"
78
+ if rule.dependencies
79
+ if (rule.dependencies == :gcc) or (rule.dependencies == :clang)
80
+ f.write " depfile = $out.d\n"
81
+ f.write " deps = gcc\n"
82
+ elsif rule.dependencies == :msvc
83
+ # TODO(mtwilliams): Handle non-English output.
84
+ # f.write " msvc_deps_prefix = Note: including file: \n"
85
+ f.write " deps = msvc\n"
86
+ else
87
+ f.write " depfile = #{rule.dependencies}\n"
88
+ end
89
+ end
90
+ f.write " command = #{rule.command}\n"
91
+ if rule.response_file
92
+ f.write " rspfile = #{rule.response_file.name}\n"
93
+ f.write " rspfile_content = #{rule.response_file.contents}\n"
94
+ end
95
+ f.write "\n"
96
+ end
97
+
98
+ @builds.each do |build|
99
+ f.write "build #{build.output}: #{build.rule} #{build.inputs.join(' ')} #{'| ' + build.implicit_inputs.join(' ') unless build.implicit_inputs.empty?}\n"
100
+ build.variables.each do |variable|
101
+ f.write " #{variable.name} = #{variable.value}\n"
102
+ end
103
+ end
104
+
105
+ unless @defaults.empty?
106
+ f.write "\n" unless @builds.empty?
107
+ f.write "default #{@defaults.join(' ')}\n" unless @defaults.empty?
108
+ end
109
+
110
+ # TODO(mtwilliams): Execute other files (via 'subninja').
111
+ # TODO(mtwilliams): Specify pools, to optimize compilation times.
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,13 @@
1
+ module Ninja
2
+ class ResponseFile
3
+ attr_reader :name,
4
+ :contents
5
+
6
+ def initialize(name, contents)
7
+ raise "Name not specified." unless name
8
+
9
+ @name = name
10
+ @contents = contents
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,43 @@
1
+ module Ninja
2
+ class Rule
3
+ attr_reader :name,
4
+ :command,
5
+ :dependencies,
6
+ :response_file
7
+
8
+ def initialize(desc={})
9
+ Description.validate!(desc)
10
+
11
+ @name = desc[:name]
12
+ @command = desc[:command]
13
+ @dependencies = desc[:dependencies]
14
+ @response_file = desc[:response_file]
15
+ end
16
+
17
+ module Description #:nodoc:
18
+ def self.validate!(desc)
19
+ # This might be overkill, but we want this to be idiot-proof.
20
+ raise "Name not specified." unless desc.include?(:name)
21
+ raise "Expected name to be a string composed of [a-Z,0-9,-,_] characters." unless /\A([-\w]+?)+\z/.match(desc[:name])
22
+
23
+ raise "Command not specified." unless desc.include?(:command)
24
+ # TODO(mtwilliams): Check response file.
25
+ # raise "Input not used by the command." unless desc[:command].include? '$in'
26
+ # raise "Output not used by the command." unless desc[:command].include? '$out'
27
+
28
+ if desc[:dependencies]
29
+ if desc[:dependencies].is_a?(String)
30
+ elsif desc[:dependencies].is_a?(Symbol)
31
+ raise "Unknown or unsupported dependency auto-detection method: '#{desc[:dependencies]}'." unless [:gcc, :clang, :msvc].include?(desc[:dependencies])
32
+ else
33
+ raise "Expected dependencies to be name or auto-detection method."
34
+ end
35
+ end
36
+
37
+ if desc[:response_file]
38
+ raise "Expected a `Ninja::Responsefile`." unless desc[:response_file].is_a?(ResponseFile)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,14 @@
1
+ module Ninja
2
+ class Variable
3
+ attr_reader :name,
4
+ :value
5
+
6
+ def initialize(name, value)
7
+ raise "Name not specified." unless name
8
+ raise "Expected name to be a string made of [a-Z,_,-,0-9] characters." unless /\w/.match(name)
9
+
10
+ @name = name
11
+ @value = value
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Ninja
2
+ module VERSION #:nodoc:
3
+ MAJOR, MINOR, PATCH, PRE = [0, 2, 0, 0]
4
+ STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
5
+ end
6
+
7
+ # Returns the semantic version of Ninja.
8
+ def self.version
9
+ Ninja::VERSION::STRING
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ $:.push File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
2
+ require 'ninja/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'ninja-build-helpers'
6
+ s.version = Ninja.version
7
+ s.platform = Gem::Platform::RUBY
8
+ s.author = 'Phillip Cao'
9
+ s.email = 'ftechz@gmail.com'
10
+ s.homepage = 'https://github.com/ftechz/ninja-build-helpers-rb'
11
+ s.summary = 'Helpers to generate Ninja build files.'
12
+ s.description = 'Ninja is a simple Ruby DSL for generating ninja build files.'
13
+ s.license = 'Public Domain'
14
+
15
+ s.required_ruby_version = '>= 1.9.3'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ # TODO(mtwilliams): Handle this gracefuly in `bin/ninja'.
21
+ s.require_paths = %w(lib)
22
+
23
+ s.add_development_dependency 'rspec'
24
+ s.add_development_dependency 'cucumber'
25
+ s.add_development_dependency 'aruba'
26
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ninja-build-helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Phillip Cao
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cucumber
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: aruba
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Ninja is a simple Ruby DSL for generating ninja build files.
56
+ email: ftechz@gmail.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".gitignore"
62
+ - AUTHORS
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - lib/ninja.rb
68
+ - lib/ninja/build.rb
69
+ - lib/ninja/delegator.rb
70
+ - lib/ninja/file.rb
71
+ - lib/ninja/response_file.rb
72
+ - lib/ninja/rule.rb
73
+ - lib/ninja/variable.rb
74
+ - lib/ninja/version.rb
75
+ - ninja-build-helpers-rb.gemspec
76
+ homepage: https://github.com/ftechz/ninja-build-helpers-rb
77
+ licenses:
78
+ - Public Domain
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 1.9.3
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.6.13
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Helpers to generate Ninja build files.
100
+ test_files: []