ninja-gen 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/AUTHORS +1 -0
- data/Gemfile +2 -0
- data/LICENSE +24 -0
- data/README.md +8 -0
- data/Rakefile +0 -0
- data/lib/ninja.rb +20 -0
- data/lib/ninja/build.rb +30 -0
- data/lib/ninja/delegator.rb +21 -0
- data/lib/ninja/file.rb +77 -0
- data/lib/ninja/rule.rb +36 -0
- data/lib/ninja/variable.rb +14 -0
- data/lib/ninja/version.rb +11 -0
- data/ninja.gemspec +26 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 451b908f2bce1a65c8a0724c07f971594c34ab7d
|
4
|
+
data.tar.gz: f40509209c1f10f52c7426581d7ecb4f147a3fcb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f46fcfeb64826966e689afb45c5fcd92632720aad6332001402afed24644c2b03f505930c03be6c17c26639a20dd238d2331d7ebf1ce01784fe7c31cefd8fa5a
|
7
|
+
data.tar.gz: 7c5b1a4534bdec4bfc6bc5e46fedba9ad90a00bed1b8112c62a725c40c364b6ef522f6818ca93f70bfbc11e18a6f72211173d05741737cf255cab65f39c6b2b4
|
data/.gitignore
ADDED
data/AUTHORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Michael Williams <m.t.williams@live.com>
|
data/Gemfile
ADDED
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/>
|
data/README.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Ninja
|
2
|
+
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/ninja.svg)](https://rubygems.org/gems/ninja)
|
4
|
+
[![Build Status](https://img.shields.io/travis/mtwilliams/ninja/master.svg)](https://travis-ci.org/mtwilliams/ninja)
|
5
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/mtwilliams/ninja.svg)](https://codeclimate.com/github/mtwilliams/ninja)
|
6
|
+
[![Dependency Status](https://img.shields.io/gemnasium/mtwilliams/ninja.svg)](https://gemnasium.com/mtwilliams/ninja)
|
7
|
+
|
8
|
+
Generate Ninja build files using Ruby.
|
data/Rakefile
ADDED
File without changes
|
data/lib/ninja.rb
ADDED
@@ -0,0 +1,20 @@
|
|
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 'ninja/version'
|
15
|
+
require 'ninja/delegator'
|
16
|
+
require 'ninja/variable'
|
17
|
+
require 'ninja/rule'
|
18
|
+
require 'ninja/build'
|
19
|
+
require 'ninja/file'
|
20
|
+
end
|
data/lib/ninja/build.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Ninja
|
2
|
+
class Build
|
3
|
+
attr_reader :rule,
|
4
|
+
:inputs,
|
5
|
+
:output
|
6
|
+
|
7
|
+
def initialize(desc={})
|
8
|
+
Description.validate!(desc)
|
9
|
+
|
10
|
+
@rule = desc[:rule]
|
11
|
+
@inputs = [*desc[:inputs]]
|
12
|
+
@output = desc[:output]
|
13
|
+
end
|
14
|
+
|
15
|
+
module Description #:nodoc:
|
16
|
+
def self.validate!(desc)
|
17
|
+
# This might be overkill, but we want this to be idiot-proof.
|
18
|
+
raise "Rule not specified." unless desc.include?(:rule)
|
19
|
+
raise "Expected rule to be a string composed of [a-Z,0-9,-,_] characters." unless /\A([-\w]+?)+\z/.match(desc[:rule])
|
20
|
+
|
21
|
+
raise "Inputs not specified." unless desc.include?(:inputs)
|
22
|
+
# TODO(mtwilliams): Check type of elements.
|
23
|
+
raise "Expected inputs to be an array of paths." unless desc[:inputs].is_a?(Array)
|
24
|
+
raise "Output not specified." unless desc.include?(:output)
|
25
|
+
# TODO(mtwilliams): Check if paths exist.
|
26
|
+
raise "Expected output to be a path." unless desc[:output].is_a?(String)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
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
|
data/lib/ninja/file.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
module Ninja
|
2
|
+
class File
|
3
|
+
def initialize(path=nil, &block)
|
4
|
+
@variables = []
|
5
|
+
@rules = []
|
6
|
+
@builds = []
|
7
|
+
@defaults = []
|
8
|
+
Delegator.new(self, :except => [:save]).instance_eval(&block) if block_given?
|
9
|
+
self.save(path) if path
|
10
|
+
end
|
11
|
+
|
12
|
+
def variable(name, value)
|
13
|
+
@variables.push(Ninja::Variable.new(name, value))
|
14
|
+
end
|
15
|
+
|
16
|
+
def rule(name, command, opts={})
|
17
|
+
@rules.push(Ninja::Rule.new(:name => name,
|
18
|
+
:command => command,
|
19
|
+
:dependencies => opts[:dependencies]))
|
20
|
+
end
|
21
|
+
|
22
|
+
def build(rule, outputs_to_inputs={})
|
23
|
+
outputs_to_inputs.each do |output, inputs|
|
24
|
+
@builds.push(Ninja::Build.new(:rule => rule, :inputs => [*inputs], :output => output))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def default(outputs)
|
29
|
+
raise "Expected output(s) to be paths." unless [*outputs].all?{|output| /\A(?:[-\w\.]+\/?)+\z/.match(output)}
|
30
|
+
@defaults.push(*outputs)
|
31
|
+
end
|
32
|
+
|
33
|
+
def save(path)
|
34
|
+
raise "Path not specified!" unless path
|
35
|
+
# TODO(mtwilliams): Check if everything up to |path| exists.
|
36
|
+
::File.open(path, 'w') do |f|
|
37
|
+
f.write "# This file was auto-generated by \"#{::File.basename($PROGRAM_NAME, ::File.extname($0))}\".\n"
|
38
|
+
f.write "# Do not modify! Instead, modify the aforementioned program.\n\n"
|
39
|
+
f.write "# We require Ninja >= 1.3 for `deps` and >= 1.5 for `msvc_deps_prefix`.\n"
|
40
|
+
f.write "ninja_required_version = 1.5\n\n"
|
41
|
+
|
42
|
+
@variables.each do |variable|
|
43
|
+
# TODO(mtwilliams): Escape.
|
44
|
+
f.write "#{variable.name} = #{variable.value}\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
@rules.each do |rule|
|
48
|
+
f.write "rule #{rule.name}\n"
|
49
|
+
if rule.dependencies
|
50
|
+
if (rule.dependencies == :gcc) or (rule.dependencies == :clang)
|
51
|
+
f.write " depfile = $out.d\n"
|
52
|
+
f.write " deps = gcc\n"
|
53
|
+
elsif rule.dependencies == :msvc
|
54
|
+
# TODO(mtwilliams): Handle non-English output.
|
55
|
+
f.write " msvc_deps_prefix = Note: including file: \n"
|
56
|
+
f.write " deps = msvc\n"
|
57
|
+
else
|
58
|
+
f.write " depfile = #{rule.dependencies}\n"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
f.write " command = #{rule.command}\n\n"
|
62
|
+
end
|
63
|
+
|
64
|
+
@builds.each do |build|
|
65
|
+
f.write "build #{build.output}: #{build.rule} #{build.inputs.join(' ')}\n"
|
66
|
+
end
|
67
|
+
f.write "\n" unless @builds.empty?
|
68
|
+
|
69
|
+
f.write "default #{@defaults.join(' ')}\n" unless @defaults.empty?
|
70
|
+
|
71
|
+
# TODO(mtwilliams): Aliases (via the 'phony' rule).
|
72
|
+
# TODO(mtwilliams): Execute other files (via 'subninja').
|
73
|
+
# TODO(mtwilliams): Specify pools, to optimize compilation times.
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/ninja/rule.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Ninja
|
2
|
+
class Rule
|
3
|
+
attr_reader :name,
|
4
|
+
:command,
|
5
|
+
:dependencies
|
6
|
+
|
7
|
+
def initialize(desc={})
|
8
|
+
Description.validate!(desc)
|
9
|
+
|
10
|
+
@name = desc[:name]
|
11
|
+
@command = desc[:command]
|
12
|
+
@dependencies = desc[:dependencies]
|
13
|
+
end
|
14
|
+
|
15
|
+
module Description #:nodoc:
|
16
|
+
def self.validate!(desc)
|
17
|
+
# This might be overkill, but we want this to be idiot-proof.
|
18
|
+
raise "Name not specified." unless desc.include?(:name)
|
19
|
+
raise "Expected name to be a string composed of [a-Z,0-9,-,_] characters." unless /\A([-\w]+?)+\z/.match(desc[:name])
|
20
|
+
|
21
|
+
raise "Command not specified." unless desc.include?(:command)
|
22
|
+
raise "Input not used by the command." unless desc[:command].include? '$in'
|
23
|
+
raise "Output not used by the command." unless desc[:command].include? '$out'
|
24
|
+
|
25
|
+
if desc[:dependencies]
|
26
|
+
if desc[:dependencies].is_a?(String)
|
27
|
+
elsif desc[:dependencies].is_a?(Symbol)
|
28
|
+
raise "Unknown or unsupported dependency auto-detection method: '#{desc[:dependencies]}'." unless [:gcc, :clang, :msvc].include?(desc[:dependencies])
|
29
|
+
else
|
30
|
+
raise "Expected dependencies to be name or auto-detection method."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
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
|
data/ninja.gemspec
ADDED
@@ -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-gen'
|
6
|
+
s.version = Ninja.version
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.author = 'Michael Williams'
|
9
|
+
s.email = 'm.t.williams@live.com'
|
10
|
+
s.homepage = 'https://github.com/mtwilliams/ninja'
|
11
|
+
s.summary = '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,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ninja-gen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Williams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-17 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: m.t.williams@live.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/rule.rb
|
72
|
+
- lib/ninja/variable.rb
|
73
|
+
- lib/ninja/version.rb
|
74
|
+
- ninja.gemspec
|
75
|
+
homepage: https://github.com/mtwilliams/ninja
|
76
|
+
licenses:
|
77
|
+
- Public Domain
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.9.3
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.5
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Generate Ninja build files.
|
99
|
+
test_files: []
|