ryb 0.0.0.dev → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11238b9bd67d96a08c7072c8466245cb5962a906
4
- data.tar.gz: 882540d98d5604fd3c3b3e967483da36ffba608a
3
+ metadata.gz: fb707fc36a01b1334c37b6f5acbd1031223cc552
4
+ data.tar.gz: a27d120d06cf580cdca49645c7af9e6aa02379d0
5
5
  SHA512:
6
- metadata.gz: 50fd33ff6112e58b1af4e86da90572fad5d10a2e45d9b7e39996c886e2d67d006de5e41e5414013c98883a7243794716fbc3390408c9aa87355ab8357b8973e1
7
- data.tar.gz: 1edc20f2bcd3c0038b11940d1ebb8dc2c9db92c528eb81001c5510892180e2f26449a2e042fd983ec7d8f278add66a5f60e0770f671e3c83981267e1f1c893dd
6
+ metadata.gz: 39ebe38e3177c44a97fb97e3e2b26fbe58c4a983102b6f91f027ed9c9b38b1d538f6a32034f06e4f29fa8b4a11ebc88689ec01d0e81ae3c888be374aa0063a6c
7
+ data.tar.gz: 6dbc2896494cd9f84917bec08617ade889dadb18fe7ee0fd7fe24280cfbc3b61639aa4d99d8dc702394daa4c6219d49fdbbd8cd6519b941ec38c4e9862e2d03a
@@ -0,0 +1,5 @@
1
+ # Sublime Text 2/3
2
+ *.sublime-workspace
3
+
4
+ # RubyGems
5
+ *.gem
@@ -1,19 +1,86 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ryb (0.1.0.dev)
4
+ ryb (0.0.0.dev)
5
+ facets
5
6
  gli
7
+ ninja-gen
8
+ xcodeproj
6
9
 
7
10
  GEM
8
11
  remote: https://rubygems.org/
9
12
  specs:
13
+ activesupport (4.2.3)
14
+ i18n (~> 0.7)
15
+ json (~> 1.7, >= 1.7.7)
16
+ minitest (~> 5.1)
17
+ thread_safe (~> 0.3, >= 0.3.4)
18
+ tzinfo (~> 1.1)
19
+ aruba (0.8.1)
20
+ childprocess (~> 0.5.6)
21
+ contracts (~> 0.9)
22
+ cucumber (>= 1.3.19)
23
+ rspec-expectations (>= 2.99)
24
+ builder (3.2.2)
25
+ childprocess (0.5.6)
26
+ ffi (~> 1.0, >= 1.0.11)
27
+ claide (0.9.1)
28
+ colored (1.2)
29
+ contracts (0.11.0)
30
+ cucumber (2.0.2)
31
+ builder (>= 2.1.2)
32
+ cucumber-core (~> 1.2.0)
33
+ diff-lcs (>= 1.1.3)
34
+ gherkin (~> 2.12)
35
+ multi_json (>= 1.7.5, < 2.0)
36
+ multi_test (>= 0.1.2)
37
+ cucumber-core (1.2.0)
38
+ gherkin (~> 2.12.0)
39
+ diff-lcs (1.2.5)
40
+ facets (3.0.0)
41
+ ffi (1.9.10)
42
+ ffi (1.9.10-x86-mingw32)
43
+ gherkin (2.12.2)
44
+ multi_json (~> 1.3)
45
+ gherkin (2.12.2-x86-mingw32)
46
+ multi_json (~> 1.3)
10
47
  gli (2.13.1)
48
+ i18n (0.7.0)
49
+ json (1.8.3)
50
+ minitest (5.8.0)
51
+ multi_json (1.11.2)
52
+ multi_test (0.1.2)
53
+ ninja-gen (0.1.1.1)
54
+ rspec (3.3.0)
55
+ rspec-core (~> 3.3.0)
56
+ rspec-expectations (~> 3.3.0)
57
+ rspec-mocks (~> 3.3.0)
58
+ rspec-core (3.3.2)
59
+ rspec-support (~> 3.3.0)
60
+ rspec-expectations (3.3.1)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.3.0)
63
+ rspec-mocks (3.3.2)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.3.0)
66
+ rspec-support (3.3.0)
67
+ thread_safe (0.3.5)
68
+ tzinfo (1.2.2)
69
+ thread_safe (~> 0.1)
70
+ xcodeproj (0.26.3)
71
+ activesupport (>= 3)
72
+ claide (~> 0.9.1)
73
+ colored (~> 1.2)
11
74
 
12
75
  PLATFORMS
13
76
  ruby
77
+ x86-mingw32
14
78
 
15
79
  DEPENDENCIES
80
+ aruba
81
+ cucumber
82
+ rspec
16
83
  ryb!
17
84
 
18
85
  BUNDLED WITH
19
- 1.10.5
86
+ 1.10.6
data/README.md CHANGED
@@ -1 +1,6 @@
1
- # Rubify Your Builds
1
+ # [Rubify Your Build!](http://rubifyyourbuild.com/)
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/ryb.svg)](https://rubygems.org/gems/ryb)
4
+ [![Build Status](https://img.shields.io/travis/mtwilliams/ryb/master.svg)](https://travis-ci.org/mtwilliams/ryb)
5
+ [![Code Climate](https://img.shields.io/codeclimate/github/mtwilliams/ryb.svg)](https://codeclimate.com/github/mtwilliams/ryb)
6
+ [![Dependency Status](https://img.shields.io/gemnasium/mtwilliams/ryb.svg)](https://gemnasium.com/mtwilliams/ryb)
data/bin/ryb CHANGED
@@ -2,11 +2,14 @@
2
2
  $:.push File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
 
4
4
  require 'rubygems'
5
-
5
+ require 'facets'
6
6
  require 'gli'
7
+ require 'xcodeproj'
8
+ require 'ninja'
9
+
7
10
  require 'ryb'
8
- # TODO(mtwilliams): Refactor into Ryb::CLI/Ryb::Runner.
9
- # require 'ryb/cli'
11
+ # TODO(mtwilliams): Refactor into Ryb::Runner.
12
+ require 'rybfile'
10
13
 
11
14
  include GLI::App
12
15
 
@@ -27,9 +30,16 @@ command [:g, :gen, :generate] do |c|
27
30
  # TODO(mtwilliams): Sanity checks on `args'.
28
31
  toolset = args.shift
29
32
  # TODO(mtwilliams): Custom exception types.
30
- raise "Unknown toolset `#{toolset}'!" unless Ryb::Toolsets.available?(toolset)
33
+ raise "No toolset specified!" if toolset.nil?
34
+ raise "Unknown toolset `#{toolset}'!" unless %w{ninja}.include? toolset
35
+ rybfile = args.shift || 'Rybfile'
36
+ raise "No such file `#{rybfile}' exists!" unless File.exists?(rybfile)
37
+ rybfile = Rybfile.load(rybfile)
31
38
  puts "Generating project file(s) for `#{toolset}'..."
32
- # ...
39
+ case toolset
40
+ when 'ninja'
41
+ Ryb::Ninja.generate_build_file_for rybfile.project, root: '.', built: '_build'
42
+ end
33
43
  end
34
44
  end
35
45
 
data/lib/ryb.rb CHANGED
@@ -1,9 +1,28 @@
1
- require 'ryb/version'
1
+ require 'rbconfig'
2
2
 
3
- require 'ryb/project'
4
- require 'ryb/project_builder'
5
- require 'ryb/project_validator'
3
+ module Ryb
4
+ def self.platform
5
+ @platform ||= begin
6
+ case RbConfig::CONFIG['host_os']
7
+ when /mswin|msys|mingw/
8
+ :windows
9
+ when /mac os|darwin/
10
+ :macosx
11
+ when /linux/
12
+ :linux
13
+ when /bsd/
14
+ :bsd
15
+ else
16
+ raise 'Unknown or unsupported platform!'
17
+ end
18
+ end
19
+ end
6
20
 
7
- require 'ryb/toolsets'
21
+ require 'ryb/version'
8
22
 
9
- require 'ryb/dsl'
23
+ require 'ryb/project'
24
+ require 'ryb/library'
25
+ require 'ryb/application'
26
+
27
+ require 'ryb/ninja'
28
+ end
@@ -0,0 +1,24 @@
1
+ require 'ryb/name'
2
+ require 'ryb/properties'
3
+
4
+ require 'ryb/architecture'
5
+ require 'ryb/configuration'
6
+
7
+ module Ryb
8
+ class Application
9
+ include Properties::Named
10
+ include Properties::Defines
11
+ include Properties::Flags
12
+ include Properties::Paths
13
+ include Properties::Files
14
+ include Properties::Dependencies
15
+ include Properties::Architectures
16
+ include Properties::Targets
17
+ include Properties::Configurations
18
+
19
+ def initialize(name, opts={})
20
+ @name = Name.new(name, opts[:pretty])
21
+ yield self if block_given?
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,16 @@
1
+ require 'ryb/name'
2
+ require 'ryb/properties'
3
+
4
+ module Ryb
5
+ class Architecture
6
+ include Properties::Named
7
+ include Properties::Suffix
8
+ include Properties::Defines
9
+ include Properties::Flags
10
+
11
+ def initialize(name, opts={})
12
+ @name = Name.new(name, opts[:pretty])
13
+ yield self if block_given?
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ require 'ryb/architecture'
2
+
3
+ module Ryb
4
+ module Architectures
5
+ class X86 < Architecture
6
+ def initialize(&block)
7
+ super('x86', pretty: 'x86', &block)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'ryb/architecture'
2
+
3
+ module Ryb
4
+ module Architectures
5
+ class X86_64 < Architecture
6
+ def initialize(&block)
7
+ super('x86_64', pretty: 'x86_64', &block)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ require 'ryb/name'
2
+ require 'ryb/properties'
3
+
4
+ module Ryb
5
+ class Configuration
6
+ include Properties::Named
7
+ include Properties::Suffix
8
+ include Properties::Defines
9
+ include Properties::Flags
10
+
11
+ def initialize(name, opts={})
12
+ @name = Name.new(name, opts[:pretty])
13
+ yield self if block_given?
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ require 'ryb/name'
2
+ require 'ryb/properties'
3
+
4
+ require 'ryb/architecture'
5
+ require 'ryb/configuration'
6
+
7
+ module Ryb
8
+ class Library
9
+ include Properties::Named
10
+ include Properties::Defines
11
+ include Properties::Flags
12
+ include Properties::Paths
13
+ include Properties::Files
14
+ include Properties::Dependencies
15
+ include Properties::Architectures
16
+ include Properties::Targets
17
+ include Properties::Configurations
18
+
19
+ def initialize(name, opts={})
20
+ @name = Name.new(name, opts[:pretty])
21
+ yield self if block_given?
22
+ end
23
+
24
+ def linkage; @linkage ||= :static; end
25
+ def linkage=(new_linkage)
26
+ @linkage = new_linkage
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ module Ryb
2
+ class Name < String
3
+ attr_reader :pretty
4
+ def initialize(name, pretty)
5
+ super(name)
6
+ @pretty = pretty
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,181 @@
1
+ require 'ryb/project'
2
+ require 'ryb/windows'
3
+ require 'ryb/visual_studio'
4
+
5
+ module Ryb
6
+ module Ninja
7
+ def self.generate_build_file_for(project, opts={})
8
+ case Ryb.platform
9
+ when :windows
10
+ raise 'Unable to find Windows SDK.' unless Ryb::Windows.sdk?
11
+ raise 'Unable to find Visual Studio.' unless Ryb::VisualStudio.installed?
12
+
13
+ puts "Generating build.ninja..."
14
+ ::Ninja::File.new "#{opts[:root]}/build.ninja" do
15
+ variable 'root', opts[:root]
16
+ variable 'built', opts[:built]
17
+
18
+ # TODO(mtwilliams): Respect project.targets[:windows].sdk.
19
+ variable 'WindowsSdkDir', Ryb::Windows.sdk
20
+ variable 'VCInstallDir', Ryb::VisualStudio.install
21
+
22
+ variable 'cl', "cl.exe"
23
+ variable 'lib', "lib.exe"
24
+ variable 'link', "link.exe"
25
+
26
+ project.configurations.each do |_, config|
27
+ [:windows].map{|target| project.targets[target]}.compact.each do |target|
28
+ [:x86, :x86_64].map{|arch| project.architectures[arch]}.compact.each do |arch|
29
+ triplet = "#{config.name}_#{target.name}_#{arch.name}"
30
+ (project.applications + project.libraries).each do |buildable|
31
+ name = "#{buildable.name.pretty||buildable.name.capitalize} (#{config.name.pretty||config.name.capitalize}) for #{target.name.pretty||target.name.capitalize} (#{arch.name.pretty||arch.name.capitalize})"
32
+ puts " Adding '#{name}'..."
33
+ quadruplet = "#{buildable.name}_#{triplet}"
34
+ variable "#{quadruplet}_name", name
35
+ variable "#{quadruplet}_suffix",
36
+ "#{config.suffix||''}#{target.suffix||''}#{arch.suffix||''}"
37
+ defines = {}
38
+ flags = {}
39
+ if buildable.configurations[config.name]
40
+ defines = buildable.defines.merge(buildable.configurations[config.name].defines)
41
+ flags = buildable.flags.merge(buildable.configurations[config.name].flags)
42
+ else
43
+ defines = buildable.defines
44
+ flags = buildable.flags
45
+ end
46
+ defines = project.defines.merge(arch.defines.merge(target.defines.merge(config.defines.merge(defines))))
47
+ flags = arch.flags.merge(target.flags.merge(config.flags.merge(flags)))
48
+ # TODO(mtwilliams): Union paths after expansion.
49
+ paths = {:includes => project.paths[:includes] | buildable.paths[:includes],
50
+ :libraries => project.paths[:libraries] | buildable.paths[:libraries],
51
+ :binaries => project.paths[:binaries] | buildable.paths[:binaries]}
52
+ expand_path_variables = lambda {|path| path.gsub(/\$built/i, "${built}")}
53
+ includes = paths[:includes].map(&expand_path_variables).map{|path| File.expand_path(path)}
54
+ libraries = paths[:libraries].map(&expand_path_variables).map{|path| File.expand_path(path)}
55
+ binaries = paths[:binaries].map(&expand_path_variables).map{|path| File.expand_path(path)}
56
+ variable "#{quadruplet}_defines", defines.map{|name, value| "/D#{name}=#{value}"}.join(' ')
57
+ cflags = []
58
+ cflags.push("/I\"${WindowsSdkDir}/Include\" /I\"${VCInstallDir}/include\"")
59
+ cflags.push('/arch:IA32') if arch.name == 'x86'
60
+ if flags[:generate_debug_symbols]
61
+ cflags.push('/MDd /Zi')
62
+ else
63
+ cflags.push('/MD')
64
+ end
65
+ cflags.push({:none => '/Od /RTCsu /fp:precise /fp:except',
66
+ :size => '/O1 /fp:fast /fp:except-',
67
+ :speed => '/Ox /fp:fast /fp:except-'}[flags[:optimization]||:none])
68
+ includes.each{|includes_search_dir| cflags.push("/I\"#{includes_search_dir}\"")}
69
+ ldflags = []
70
+ if arch.name == 'x86'
71
+ ldflags.push('/machine:X86')
72
+ ldflags.push("/LIBPATH:\"${WindowsSdkDir}/Lib\" /LIBPATH:\"${VCInstallDir}/Lib\"")
73
+ elsif arch.name == 'x86_64'
74
+ ldflags.push('/machine:X64')
75
+ ldflags.push("/LIBPATH:\"${WindowsSdkDir}/Lib/x64\" /LIBPATH:\"${VCInstallDir}/Lib/amd64\"")
76
+ end
77
+ ldflags.push('/DEBUG') if flags[:generate_debug_symbols]
78
+ libraries.each{|libraries_search_dir| ldflags.push("/LIBPATH:\"#{libraries_search_dir}\"")}
79
+ binaries.each{|binaries_search_dir| ldflags.push("/LIBPATH:\"#{binaries_search_dir}\"")}
80
+ variable "#{quadruplet}_cflags", cflags.join(' ')
81
+ variable "#{quadruplet}_ldflags", ldflags.join(' ')
82
+ arflags = []
83
+ variable "#{quadruplet}_arflags", arflags.join(' ')
84
+ # TODO(mtwilliams): Refactor into cc, ld, and ar rules, using variables under build(s) for uncommonalities.
85
+ rule "cc_#{quadruplet}",
86
+ "${cl} /nologo /c /showIncludes /favor:blend /GF /GR- /W4 ${#{quadruplet}_cflags} ${#{quadruplet}_defines} /Fo$out $in",
87
+ :dependencies => :msvc
88
+ rule "ld_#{quadruplet}",
89
+ "${link} /nologo /manifest:no ${#{quadruplet}_ldflags} /OUT:$out $in"
90
+ rule "ar_#{quadruplet}",
91
+ "${lib} /nologo ${#{quadruplet}_arflags} /OUT:$out $in"
92
+ sources = buildable.files[:source].select{|file| /\.(c|cc|cpp)\z/.match(file)}
93
+ outputs_to_inputs = Hash[sources.map{|source| ["${built}/obj/#{source.gsub(/\.[^.]+\z/,'')}.#{triplet}.obj", "${root}/#{source}"]}]
94
+ build "cc_#{quadruplet}", outputs_to_inputs
95
+ output = "#{buildable.name}${#{quadruplet}_suffix}"
96
+ if buildable.is_a? Ryb::Application
97
+ build "ld_#{quadruplet}", "${built}/bin/#{output}.exe" => outputs_to_inputs.map{|object,_| object}
98
+ defaults "${built}/bin/#{output}.exe"
99
+ elsif buildable.is_a? Ryb::Library
100
+ case buildable.linkage
101
+ when :static
102
+ build "ar_#{quadruplet}", "${built}/lib/#{output}.lib" => outputs_to_inputs.map{|object,_| object}
103
+ when :dynamic
104
+ # TODO(mtwilliams): Specify -DLL.
105
+ build "ld_#{quadruplet}", "${built}/bin/#{output}.dll" => outputs_to_inputs.map{|object,_| object}
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+
114
+ # TODO(mtwilliams): Generate shell and batch scripts, instead.
115
+ puts "Generating Makefile..."
116
+ ::File.open("#{opts[:root]}/Makefile", 'w') do |f|
117
+ f.write "# This file was auto-generated by \"#{::File.basename($PROGRAM_NAME, ::File.extname($0))}\".\n"
118
+ f.write "# Do not modify! Instead, modify the aforementioned program.\n\n"
119
+
120
+ f.write "WindowsSdkDir := /#{Ryb::Windows.sdk.gsub(/\\/,'/').gsub(/\:/,'')}\n\n"
121
+ f.write "VCInstallDir := /#{Ryb::VisualStudio.install.gsub(/\\/,'/').gsub(/\:/,'')}\n"
122
+
123
+ f.write "# HACK: The Common7/IDE path might not exist in older versions of Microsoft Visual Studio.\n"
124
+ f.write "CommonTools := $(shell readlink -f \"$(VCInstallDir)/../Common7\")\n\n"
125
+
126
+ targets = []
127
+ project.configurations.each do |_, config|
128
+ [:windows].map{|target| project.targets[target]}.compact.each do |target|
129
+ [:x86, :x86_64].map{|arch| project.architectures[arch]}.compact.each do |arch|
130
+ triplet = "#{config.name}-#{target.name}-#{arch.name}"
131
+ (project.applications + project.libraries).each do |buildable|
132
+ quadruplet = "#{buildable.name}-#{triplet}"
133
+ targets.push(quadruplet)
134
+ end
135
+ end
136
+ end
137
+ end
138
+
139
+ f.write ".PHONY: all #{targets.join(' ')}\n"
140
+ f.write "all: #{targets.join(' ')}\n\n"
141
+
142
+ project.configurations.each do |_, config|
143
+ [:windows].map{|target| project.targets[target]}.compact.each do |target|
144
+ [:x86, :x86_64].map{|arch| project.architectures[arch]}.compact.each do |arch|
145
+ triplet = [config.name, target.name, arch.name]
146
+ (project.applications + project.libraries).each do |buildable|
147
+ quadruplet = [buildable.name, triplet]
148
+ case arch.name
149
+ when 'x86'
150
+ f.write "#{quadruplet.join('-')}: export PATH := $(WindowsSdkDir)/bin:$(CommonTools)/IDE:$(VCInstallDir)/bin:$(PATH)\n"
151
+ when 'x86_64'
152
+ f.write "#{quadruplet.join('-')}: export PATH := $(WindowsSdkDir)/bin/x64:$(CommonTools)/IDE:$(VCInstallDir)/bin/x86_amd64:$(VCInstallDir)/bin:$(PATH)\n"
153
+ end
154
+ f.write "#{quadruplet.join('-')}:\n"
155
+ suffix = "#{config.suffix||''}#{target.suffix||''}#{arch.suffix||''}"
156
+ if buildable.is_a? Ryb::Application
157
+ f.write "\t@ninja #{opts[:built]}/bin/#{buildable.name}#{suffix}.exe\n\n"
158
+ elsif buildable.is_a? Ryb::Library
159
+ case buildable.linkage
160
+ when :static
161
+ f.write "\t@ninja #{opts[:built]}/lib/#{buildable.name}#{suffix}.lib\n\n"
162
+ when :dynamic
163
+ f.write "\t@ninja #{opts[:built]}/bin/#{buildable.name}#{suffix}.dll\n\n"
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ puts "Done."
173
+ # when :macosx
174
+ # when :linux
175
+ # when :bsd
176
+ else
177
+ raise 'Unsupported platform!'
178
+ end
179
+ end
180
+ end
181
+ end