ryb 0.1.3.1 → 0.2.0.2

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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +36 -47
  3. data/NOTES +0 -0
  4. data/README.md +3 -1
  5. data/TODO +4 -0
  6. data/bin/ryb +2 -42
  7. data/lib/ryb.rb +31 -20
  8. data/lib/ryb/cli.rb +103 -0
  9. data/lib/ryb/code.rb +7 -0
  10. data/lib/ryb/configuration.rb +18 -12
  11. data/lib/ryb/configurations.rb +9 -0
  12. data/lib/ryb/dependencies.rb +7 -0
  13. data/lib/ryb/dependency.rb +30 -0
  14. data/lib/ryb/dsl.rb +280 -0
  15. data/lib/ryb/environment.rb +9 -0
  16. data/lib/ryb/flags.rb +17 -0
  17. data/lib/ryb/gem.rb +58 -0
  18. data/lib/ryb/helpers/defaults.rb +26 -0
  19. data/lib/ryb/helpers/pretty_string.rb +47 -0
  20. data/lib/ryb/languages.rb +13 -0
  21. data/lib/ryb/name.rb +3 -5
  22. data/lib/ryb/ninja.rb +257 -200
  23. data/lib/ryb/paths.rb +7 -0
  24. data/lib/ryb/preprocessor.rb +10 -0
  25. data/lib/ryb/product.rb +31 -0
  26. data/lib/ryb/project.rb +6 -29
  27. data/lib/ryb/source_file.rb +62 -0
  28. data/lib/ryb/visual_studio.rb +93 -57
  29. data/lib/rybfile.rb +30 -10
  30. data/lib/rybfile/walker.rb +202 -0
  31. data/lib/yb.rb +4 -0
  32. data/lib/ybfile.rb +3 -0
  33. data/ryb.gemspec +18 -13
  34. data/ryb.sublime-project +18 -17
  35. metadata +45 -31
  36. data/lib/ryb/application.rb +0 -24
  37. data/lib/ryb/architecture.rb +0 -16
  38. data/lib/ryb/architectures/x86.rb +0 -11
  39. data/lib/ryb/architectures/x86_64.rb +0 -11
  40. data/lib/ryb/library.rb +0 -29
  41. data/lib/ryb/properties.rb +0 -10
  42. data/lib/ryb/properties/architectures.rb +0 -32
  43. data/lib/ryb/properties/configurations.rb +0 -29
  44. data/lib/ryb/properties/defines.rb +0 -31
  45. data/lib/ryb/properties/dependencies.rb +0 -23
  46. data/lib/ryb/properties/files.rb +0 -25
  47. data/lib/ryb/properties/flags.rb +0 -33
  48. data/lib/ryb/properties/named.rb +0 -17
  49. data/lib/ryb/properties/paths.rb +0 -37
  50. data/lib/ryb/properties/suffix.rb +0 -17
  51. data/lib/ryb/properties/targets.rb +0 -36
  52. data/lib/ryb/target.rb +0 -16
  53. data/lib/ryb/targets/linux.rb +0 -11
  54. data/lib/ryb/targets/macosx.rb +0 -33
  55. data/lib/ryb/targets/windows.rb +0 -13
  56. data/lib/ryb/version.rb +0 -11
  57. data/lib/ryb/windows.rb +0 -40
  58. data/lib/ryb/xcode.rb +0 -145
@@ -0,0 +1,280 @@
1
+ module Ryb
2
+ module DomainSpecificLanguage
3
+ module Configurations
4
+ def configuration(name, opts={}, &block)
5
+ @spec.configurations ||= []
6
+
7
+ existing_config = find_by_canonical_name(@spec.configurations, name)
8
+ config = existing_config || Ryb::Configuration.new
9
+ existing_pretty_name = config.name.pretty if existing_config
10
+ config.name = Ryb::Name.new(name, :pretty => existing_pretty_name || opts[:pretty])
11
+
12
+ @spec.configurations << config unless existing_config
13
+
14
+ DomainSpecificLanguage.for(config).instance_eval(&block)
15
+ end
16
+
17
+ def platform(name, opts={}, &block)
18
+ # TODO(mtwilliams): Refactor this.
19
+ @spec.platforms ||= []
20
+
21
+ existing_platform = find_by_canonical_name(@spec.platforms, name)
22
+ platform = existing_platform || Ryb::Platform.new
23
+ existing_pretty_name = platform.name.pretty if existing_platform
24
+ platform.name ||= Ryb::Name.new(name, :pretty => existing_pretty_name || opts[:pretty])
25
+
26
+ @spec.platforms << platform unless existing_platform
27
+
28
+ DomainSpecificLanguage.for(platform).instance_eval(&block)
29
+ end
30
+
31
+ def architecture(name, opts={}, &block)
32
+ # TODO(mtwilliams): Refactor this.
33
+ @spec.architectures ||= []
34
+
35
+ existing_arch = find_by_canonical_name(@spec.architectures, name)
36
+ arch = existing_arch || Ryb::Architecture.new
37
+ existing_pretty_name = arch.name.pretty if existing_arch
38
+ arch.name ||= Ryb::Name.new(name, :pretty => existing_pretty_name || opts[:pretty])
39
+
40
+ @spec.architectures << arch unless existing_arch
41
+
42
+ DomainSpecificLanguage.for(arch).instance_eval(&block)
43
+ end
44
+
45
+ private
46
+ def find_by_canonical_name(ary_of_named_things, name)
47
+ (ary_of_named_things.select do |existing_thing|
48
+ existing_thing.name.canonicalize == name.to_s
49
+ end).first
50
+ end
51
+ end
52
+
53
+ module Environment
54
+ def add_include_path(path)
55
+ @spec.paths ||= Paths.new
56
+ @spec.paths.includes = @spec.paths.includes + [path]
57
+ end
58
+
59
+ def add_include_paths(*paths_and_patterns)
60
+ [*paths_and_patterns].each do |path_or_pattern|
61
+ [*(Dir.glob(path_or_pattern))].each do |path|
62
+ add_include_path(path)
63
+ end
64
+ end
65
+ end
66
+
67
+ def add_library_path(path)
68
+ @spec.paths ||= Paths.new
69
+ @spec.paths.libraries = @spec.paths.libraries + [path]
70
+ end
71
+
72
+ def add_library_paths(*paths_and_patterns)
73
+ [*paths_and_patterns].each do |path_or_pattern|
74
+ [*(Dir.glob(path_or_pattern))].each do |path|
75
+ add_library_path(path)
76
+ end
77
+ end
78
+ end
79
+
80
+ def add_binary_path(path)
81
+ @spec.paths ||= Paths.new
82
+ @spec.paths.binaries = @spec.paths.binaries + [path]
83
+ end
84
+
85
+ def add_binary_paths(*paths_and_patterns)
86
+ [*paths_and_patterns].each do |path_or_pattern|
87
+ [*(Dir.glob(path_or_pattern))].each do |path|
88
+ add_binary_path(path)
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ module Preprocessor
95
+ def define(defines)
96
+ @spec.defines ||= Hash.new
97
+ @spec.defines = @spec.defines.merge(defines)
98
+ end
99
+ end
100
+
101
+ module Flags
102
+ def treat_warnings_as_errors=(flag)
103
+ @spec.treat_warnings_as_errors = flag
104
+ end
105
+
106
+ def generate_debug_symbols=(flag)
107
+ @spec.generate_debug_symbols = flag
108
+ end
109
+
110
+ def link_time_code_generation=(flag)
111
+ @spec.link_time_code_generation = flag
112
+ end
113
+
114
+ def optimize=(goal)
115
+ @spec.optimize = goal
116
+ end
117
+ end
118
+
119
+ module Code
120
+ def add_source_file(file)
121
+ case file
122
+ when SourceFile
123
+ @spec.sources ||= []
124
+ @spec.sources = @spec.sources + [file]
125
+ when String
126
+ add_source_file(SourceFile.new(file))
127
+ end
128
+ end
129
+
130
+ def add_source_files(*files_and_patterns)
131
+ [*files_and_patterns].each do |file_or_pattern|
132
+ case file_or_pattern
133
+ when SourceFile
134
+ add_source_file(file_or_pattern)
135
+ when String
136
+ [*(Dir.glob(file_or_pattern))].each do |file|
137
+ add_source_file(file)
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
143
+
144
+ module Dependencies
145
+ def add_dependency(product)
146
+ @spec.dependencies ||= []
147
+ @spec.dependencies = @spec.dependencies + [Ryb::InternalDependency.new(product)]
148
+ end
149
+
150
+ def add_external_dependency(lib_or_framework)
151
+ @spec.dependencies ||= []
152
+ @spec.dependencies = @spec.dependencies + [Ryb::ExternalDependency.new(lib_or_framework)]
153
+ end
154
+ end
155
+
156
+ class Configuration
157
+ def initialize(config)
158
+ @spec = @config = config
159
+ end
160
+
161
+ def prefix=(prefix)
162
+ @config.prefix = prefix
163
+ end
164
+
165
+ def suffix=(suffix)
166
+ @config.suffix = suffix
167
+ end
168
+
169
+ include Environment
170
+ include Preprocessor
171
+ include Flags
172
+ include Code
173
+ include Dependencies
174
+ end
175
+
176
+ class Platform < Configuration
177
+ def initialize(platform)
178
+ super(platform)
179
+ @platform = platform
180
+ end
181
+ end
182
+
183
+ class Architecture < Configuration
184
+ def initialize(arch)
185
+ super(arch)
186
+ @arch = arch
187
+ end
188
+ end
189
+
190
+ class Product
191
+ def initialize(product)
192
+ @spec = @product = product
193
+ end
194
+
195
+ def author=(author)
196
+ @product.author = author
197
+ end
198
+
199
+ def description=(description)
200
+ @product.description = description
201
+ end
202
+
203
+ def license=(license)
204
+ @product.license = license
205
+ end
206
+
207
+ def version=(version)
208
+ @product.version = version
209
+ end
210
+
211
+ include Configurations
212
+ include Environment
213
+ include Preprocessor
214
+ include Flags
215
+ include Code
216
+ include Dependencies
217
+ end
218
+
219
+ class Application < Product
220
+ def initialize(app)
221
+ super(app)
222
+ @app = app
223
+ end
224
+ end
225
+
226
+ class Library < Product
227
+ def initialize(lib)
228
+ super(lib)
229
+ @lib = lib
230
+ end
231
+
232
+ def linkage=(linkage)
233
+ @lib.linkage = linkage
234
+ end
235
+ end
236
+
237
+ class Project
238
+ def initialize(project)
239
+ @spec = @project = project
240
+ end
241
+
242
+ include Configurations
243
+ include Environment
244
+ include Preprocessor
245
+
246
+ def application(name, opts={}, &block)
247
+ # TODO(mtwilliams): Verify uniqueness.
248
+ app = Ryb::Application.new
249
+ app.name = Ryb::Name.new(name, :pretty => opts[:pretty])
250
+ DomainSpecificLanguage.for(app).instance_eval(&block)
251
+ @project.products ||= []
252
+ @project.products = @project.products + [app]
253
+ end
254
+
255
+ def library(name, opts={}, &block)
256
+ # TODO(mtwilliams): Verify uniqueness.
257
+ lib = Ryb::Library.new
258
+ lib.name = Ryb::Name.new(name, :pretty => opts[:pretty])
259
+ DomainSpecificLanguage.for(lib).instance_eval(&block)
260
+ @project.products ||= []
261
+ @project.products = @project.products + [lib]
262
+ end
263
+ end
264
+
265
+ FOR = {Ryb::Configuration => Configuration,
266
+ Ryb::Platform => Platform,
267
+ Ryb::Architecture => Architecture,
268
+ Ryb::Application => Application,
269
+ Ryb::Library => Library,
270
+ Ryb::Project => Project}
271
+
272
+ def self.for(obj)
273
+ # TODO(mtwilliams): Use `__poured__` rather than manually building?
274
+ # poured = spec.class_variable_get(:@@__poured__)
275
+
276
+ # Hide behind a SimpleDelegator so users don't play with our internals.
277
+ SimpleDelegator.new(FOR[obj.class].new(obj))
278
+ end
279
+ end
280
+ end
@@ -0,0 +1,9 @@
1
+ module Ryb
2
+ module Environment
3
+ include Pour::Pourable
4
+
5
+ property :paths, Typespec.struct[:includes => Typespec.array[Typespec.string],
6
+ :libraries => Typespec.array[Typespec.string],
7
+ :binaries => Typespec.array[Typespec.string]]
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module Ryb
2
+ module Flags
3
+ include Pour::Pourable
4
+
5
+ # Prevent code that raises warnings from succesfully compiling.
6
+ property :treat_warnings_as_errors, Typespec.boolean
7
+
8
+ # Have the compiler generate debugging information.
9
+ property :generate_debug_symbols, Typespec.boolean
10
+
11
+ # Link (and optimize) code as late as possible.
12
+ property :link_time_code_generation, Typespec.boolean
13
+
14
+ # Optimize for size, or speed, or neither.
15
+ property :optimize, Typespec.enum[:nothing, :size, :speed]
16
+ end
17
+ end
@@ -0,0 +1,58 @@
1
+ require 'ostruct'
2
+
3
+ module Ryb
4
+ module Gem
5
+ # The name of this Gem.
6
+ def self.name
7
+ "ryb"
8
+ end
9
+
10
+ # The name and email address of the primary author.
11
+ def self.author
12
+ self.authors.first
13
+ end
14
+
15
+ # The name and email addresses of all authors.
16
+ def self.authors
17
+ [["Michael Williams", "m.t.williams@live.com"]].map do |author|
18
+ name, email = author
19
+ OpenStruct.new(name: name, email: email)
20
+ end
21
+ end
22
+
23
+ # This Gem's homepage URL.
24
+ def self.homepage
25
+ "https://RubifiyYourBuild.com/"
26
+ end
27
+
28
+ # This Gem's URL.
29
+ def self.url
30
+ "https://rubygems.org/gems/#{self.name}"
31
+ end
32
+
33
+ # A short summary of this Gem.
34
+ def self.summary
35
+ "Rubifiy your builds!"
36
+ end
37
+
38
+ # A full description of this Gem.
39
+ def self.description
40
+ "Ryb is a clean and extensible Ruby library and tool that generates build files for Visual Studio, XCode, Make, and Ninja."
41
+ end
42
+
43
+ module VERSION #:nodoc:
44
+ MAJOR, MINOR, PATCH, PRE = [0, 2, 0, 2]
45
+ STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
46
+ end
47
+
48
+ # The semantic version of the this Gem.
49
+ def self.version
50
+ Gem::VERSION::STRING
51
+ end
52
+
53
+ # The license covering this Gem.
54
+ def self.license
55
+ "Public Domain"
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,26 @@
1
+ module Ryb
2
+ module Helpers
3
+ module Defaults
4
+ def self.targets
5
+ @@targets = begin
6
+ case RbConfig::CONFIG["host_os"]
7
+ when /mswin|windows|mingw|cygwin/i
8
+ ['windows']
9
+ when /darwin/i
10
+ ['macosx']
11
+ when /linux/i
12
+ ['linux']
13
+ end
14
+ end
15
+ end
16
+
17
+ def self.toolchains
18
+ @@toolchains ||= {
19
+ 'windows' => 'msvc',
20
+ 'macosx' => 'clang+llvm',
21
+ 'linux' => 'gcc'
22
+ }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,47 @@
1
+ module Ryb
2
+ module Helpers
3
+ class PrettyString < String
4
+ # @!attribute [r] pretty
5
+ # @return [String] A more readable description of the string.
6
+ attr_reader :pretty
7
+
8
+ # @param [Hash] opts Optional arguments.
9
+ # @param [String] str The string.
10
+ # @param opts [String] :pretty A more readable description of the string.
11
+ def initialize(str, opts={})
12
+ super(str.to_s)
13
+ @pretty = opts[:pretty] if opts.include? :pretty
14
+ end
15
+
16
+ # Perform the comparision on the non-pretty values of all derivatives
17
+ # of strings, i.e. coerce any stringy values into ::String before
18
+ # comparing.
19
+ #
20
+ # @example
21
+ # greeting_1 = PrettyString.new('greeting', pretty: 'Eh!')
22
+ # greeting_2 = PrettyString.new('greeting', pretty: 'Aloha!')
23
+ # greeting_1 == greeting_2 #=> true
24
+ alias :eql? :==
25
+ def ==(other)
26
+ if other.is_a? String
27
+ self.to_s == other.to_s
28
+ else
29
+ super(other)
30
+ end
31
+ end
32
+
33
+ # @return [String] A more readable description of the string.
34
+ #
35
+ # @example
36
+ # greeting = PrettyString.new("greeting", pretty: "How you doin'?") #=> "greeting"
37
+ # greeting.inspect #=> <Ryb::Helpers::PrettyString "greeting" @pretty: "How you doin'?">
38
+ def inspect
39
+ if self.pretty
40
+ "<#{self.class.to_s} \"#{self.to_s}\" @pretty: \"#{self.pretty}\">"
41
+ else
42
+ "<#{self.class.to_s} \"#{self.to_s}\">"
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,13 @@
1
+ module Ryb
2
+ module Languages
3
+ SUPPORTED = [:c, :cpp, :csharp]
4
+
5
+ def self.supported
6
+ SUPPORTED
7
+ end
8
+
9
+ def self.supported?(language)
10
+ supported.include?(language)
11
+ end
12
+ end
13
+ end