ninja-rake 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE.txt +20 -0
  2. data/README.md +58 -0
  3. data/TODO +2 -0
  4. data/lib/ninja.rb +201 -0
  5. metadata +155 -0
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Akira Hayakawa
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # ninja-rake
2
+ Make your Ninja more powerful with the power of Ruby on Rake Framework!
3
+
4
+ ## Motivation
5
+ Ninja is a build tool brilliant ever however it lacks some paramount functionalities such as script descpriptiveness:
6
+ you can not use typical data structures (for example array, map, set etc)
7
+ and general algorithms (for example map, filter, sort etc) equipped with the modern scripting languages in your raw Ninja script.
8
+ This makes Ninja hard to be deployed into your projects.
9
+
10
+ This is the result of the developer of Ninja decided not to provide these functinalities to keep Ninja as simple as possible
11
+ and let users (like you!) to generate Ninja file by your own scripting however,
12
+ I believe there should be some de-facto standard for scripting and I again believe it is Ruby that I love the most.
13
+
14
+ Using this ninja-rake library you can write Ninja code with Ruby language which enables
15
+ using plenty of data structures and algorithms in Ruby standard library.
16
+ Moreover, your script can easily collaborate with Rake which is
17
+ the state of the art framework for describing daily tasks including building softwares.
18
+
19
+ ## Install
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ rule = Ninja::Rule.new("gcc -c $in -o $out"), # rule have unique ID.
25
+ build1 = Ninja::Build.new(
26
+ rule,
27
+ Ninja::Target.new("a.o"),
28
+ Ninja::Explicitly.new("a.c", "b.c"),
29
+ Ninja::Implicitly.new("c.c"))
30
+ build2 = Ninja::Build.new(rule, ...)
31
+ Ninja.end_of_ninja(build1, build2)
32
+ ```
33
+
34
+ will produce a Rake task that create "build.ninja" file that is written as
35
+
36
+ ~~~
37
+ rule ID
38
+ command = gcc -c $in -o $out
39
+ build1 a.o: ID a.c b.c | c.c
40
+ build2 ...: ID ...
41
+ ~~~
42
+
43
+ ## Roadmap
44
+ * Rule generator which enables to build GPGPU project written in CUDA 4.0.
45
+
46
+ ## Contributing to ninja-rake
47
+
48
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
49
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
50
+ * Fork the project
51
+ * Start a feature/bugfix branch
52
+ * Commit and push until you are happy with your contribution
53
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
54
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
55
+
56
+ ## Copyright
57
+ Copyright (c) 2011 Akira Hayakawa (@akiradeveloper).
58
+ See LICENSE.txt for further details.
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ # TODO
2
+
@@ -0,0 +1,201 @@
1
+ require "set"
2
+ require "uuidtools"
3
+
4
+ module Ninja
5
+
6
+ DEFAULT_NINJA_FILENAME = "build.ninja"
7
+
8
+ def self.create_UUID
9
+ UUIDTools::UUID.random_create
10
+ end
11
+
12
+ class Rule
13
+ def initialize(rule_desc, depfile="")
14
+ @rule_desc = rule_desc
15
+ @depfile = depfile
16
+ @unique_name = Ninja.create_UUID
17
+ end
18
+
19
+ def unique_name
20
+ @unique_name
21
+ end
22
+
23
+ def depfile_line
24
+ if @depfile == ""
25
+ ""
26
+ else
27
+ " depfile = #{@depfile}\n"
28
+ end
29
+ end
30
+
31
+ def to_ninja_format
32
+ """
33
+ rule #{unique_name}
34
+ #{depfile_line} command = #{@rule_desc}
35
+ """
36
+ end
37
+
38
+ def name
39
+ @unique_name
40
+ end
41
+ end
42
+
43
+ class Target
44
+ def initialize(*xs)
45
+ @dep = xs.flatten
46
+ end
47
+
48
+ def to_a
49
+ @dep
50
+ end
51
+
52
+ def to_ninja_format
53
+ @dep.join " "
54
+ end
55
+ end
56
+
57
+ class Explicitly
58
+ def initialize(*xs)
59
+ @dep = xs.flatten
60
+ end
61
+
62
+ def to_ninja_format
63
+ "#{@dep.join(" ")}"
64
+ end
65
+ end
66
+
67
+ class Implicitly
68
+ def initialize(*xs)
69
+ @dep = xs.flatten
70
+ end
71
+
72
+ def to_ninja_format
73
+ "| #{@dep.join(" ")}"
74
+ end
75
+ end
76
+
77
+ class Build
78
+ def initialize(rule, target, explicit_dep, implicit_dep=nil)
79
+ @rule = rule
80
+ @target = target
81
+ @explicit_dep = explicit_dep
82
+ @implicit_dep = implicit_dep
83
+ # order-only dep is not supported because I do not get how we need it.
84
+ end
85
+
86
+ def get_target_object
87
+ @target
88
+ end
89
+
90
+ def get_rule_object
91
+ @rule
92
+ end
93
+
94
+ def implicit_dep_line
95
+ if @implicit_dep == nil
96
+ ""
97
+ else
98
+ @implicit_dep.to_ninja_format
99
+ end
100
+ end
101
+
102
+ def to_ninja_format
103
+ """
104
+ build #{@target.to_ninja_format}: #{@rule.name} #{@explicit_dep.to_ninja_format} #{implicit_dep_line}
105
+ """
106
+ end
107
+ end
108
+
109
+ def self.__to_ninja_format(xs)
110
+ xs.map{ |x| x.to_ninja_format }.join "\n\n"
111
+ end
112
+
113
+ def self.rules(ninjas)
114
+ __rules = ninjas.map{ |x| x.get_rule_object }
115
+ Set.new(__rules).to_a
116
+ end
117
+
118
+ def self.to_ninja_format(ninjas)
119
+ xs = (rules(ninjas) + ninjas).flatten
120
+ __to_ninja_format(xs)
121
+ end
122
+
123
+ def self.create_ninja_file(ninjas)
124
+ namespace :ninja do
125
+ desc("generate ninja file if ninja.rake is changed")
126
+ file DEFAULT_NINJA_FILENAME => "ninja.rake" do
127
+ puts "--- REGENERATING THE NINJA FILE NOW ---"
128
+ f = File.new(DEFAULT_NINJA_FILENAME, "w")
129
+ txt = to_ninja_format(ninjas)
130
+ f.write(txt)
131
+ f.close
132
+ end
133
+ end
134
+ end
135
+
136
+ def self.make_ninja_task(target)
137
+ namespace :ninja do
138
+ namespace :build do
139
+ task target => DEFAULT_NINJA_FILENAME do
140
+ sh "ninja #{target}"
141
+ end
142
+ task :all => target
143
+ end
144
+ namespace :clean do
145
+ task target => DEFAULT_NINJA_FILENAME do
146
+ sh "ninja -t clean #{target}"
147
+ end
148
+ task :all => target
149
+ end
150
+ end
151
+ end
152
+
153
+ def self.end_of_ninja(*ninjas)
154
+ create_ninja_file(ninjas.flatten)
155
+
156
+ ninjas.each do |ninja|
157
+ ninja.get_target_object.to_a.each do |target|
158
+ make_ninja_task(target)
159
+ end
160
+ end
161
+ end
162
+
163
+ # Facade
164
+ # To Hide the implementation
165
+ def self.Rule(rule, depfile="")
166
+ Ninja::Rule.new(rule, depfile)
167
+ end
168
+
169
+ def self.Build(rule, target, explicit, implicit=nil)
170
+ Ninja::Build.new(rule, target, explicit, implicit)
171
+ end
172
+
173
+ def self.Target(*xs)
174
+ Ninja::Target.new(xs)
175
+ end
176
+
177
+ def self.Explicitly(*xs)
178
+ Ninja::Explicitly.new(xs)
179
+ end
180
+
181
+ def self.Implicitly(*xs)
182
+ Ninja::Implicitly.new(xs)
183
+ end
184
+ end # end of Ninja module
185
+
186
+ if __FILE__ == $0
187
+ puts Ninja.Rule("gcc -c $in -o $out").to_ninja_format
188
+
189
+ p Ninja.Rule("gcc -MMD -MF $out.d -c $in -o $out", "$out.d")
190
+ r1 = Ninja.Rule("gcc -MMD -MF $out.d -c $in -o $out", "$out.d")
191
+ b0 = Ninja.Build(
192
+ r1,
193
+ Ninja.Target("a", ["b", "c"]),
194
+ Ninja.Explicitly(["d"], "e"), Ninja.Implicitly("f"))
195
+ b1 = Ninja.Build(r1, Ninja.Target("a", ["b", "c"]), Ninja.Explicitly(["d"], "e"), Ninja.Implicitly("f"))
196
+ b2 = Ninja.Build(r1, Ninja.Target("a", ["b", "c"]), Ninja.Explicitly(["d"], "e"))
197
+ puts b1.to_ninja_format
198
+ puts b2.to_ninja_format
199
+ puts Ninja.rules([b1, b2])
200
+ puts Ninja.to_ninja_format([b1, b2])
201
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ninja-rake
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Akira Hayakawa
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-07-07 00:00:00 +09:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: uuidtools
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 1
30
+ - 2
31
+ version: 2.1.2
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ - 8
45
+ - 7
46
+ version: 0.8.7
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: shoulda
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: bundler
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 1
72
+ - 0
73
+ - 0
74
+ version: 1.0.0
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 1
87
+ - 6
88
+ - 3
89
+ version: 1.6.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ name: rcov
95
+ requirement: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: *id006
106
+ description: ninja-rake enables you to play Ninja on the Rake framework
107
+ email: ruby.wktk@gmail.com
108
+ executables: []
109
+
110
+ extensions: []
111
+
112
+ extra_rdoc_files:
113
+ - LICENSE.txt
114
+ - README.md
115
+ - TODO
116
+ files:
117
+ - lib/ninja.rb
118
+ - LICENSE.txt
119
+ - README.md
120
+ - TODO
121
+ has_rdoc: true
122
+ homepage: http://github.com/akiradeveloper/ninja-rake
123
+ licenses:
124
+ - MIT
125
+ post_install_message:
126
+ rdoc_options: []
127
+
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ hash: 1823693513408219891
136
+ segments:
137
+ - 0
138
+ version: "0"
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ requirements: []
148
+
149
+ rubyforge_project:
150
+ rubygems_version: 1.3.7
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: Let your Ninja more powerful with Ruby
154
+ test_files: []
155
+