forked from araxara/cappuccino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.rb
176 lines (132 loc) · 4.08 KB
/
common.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
require 'rake'
def gem_command
case RUBY_PLATFORM
when /win32/
'gem.bat'
when /java/
'jruby -S gem'
else
'gem'
end
end
begin
require 'rubygems'
require 'plist'
rescue LoadError
puts 'Plist gem not installed, installing...'
cmd = "#{gem_command} install plist"
puts cmd
puts %x(#{cmd})
end
# Read in and set up development environment variables.
if !ENV['BUILD_PATH']
# Global Cappuccino build directory
if ENV['CAPP_BUILD']
ENV['BUILD_PATH'] = ENV['CAPP_BUILD']
# Maintain backwards compatibility with steam.
elsif ENV['STEAM_BUILD']
ENV['BUILD_PATH'] = ENV['STEAM_BUILD']
# Just build here.
else
ENV['BUILD_PATH'] = File.join(File.dirname(__FILE__), 'Build')
end
end
ENV['BUILD_PATH'] = File.expand_path(ENV['BUILD_PATH'])
if !ENV['CONFIG']
ENV['CONFIG'] = 'Release'
end
$CONFIGURATION = ENV['CONFIG']
$BUILD_DIR = ENV['BUILD_PATH']
$PRODUCT_DIR = File.join($BUILD_DIR, $CONFIGURATION)
$ENVIRONMENT_DIR = File.join($BUILD_DIR, $CONFIGURATION, 'env')
$ENVIRONMENT_BIN_DIR = File.join($ENVIRONMENT_DIR, 'bin')
$ENVIRONMENT_LIB_DIR = File.join($ENVIRONMENT_DIR, 'lib')
$ENVIRONMENT_FRAMEWORKS_DIR = File.join($ENVIRONMENT_LIB_DIR, 'Frameworks')
$HOME_DIR = File.expand_path(File.dirname(__FILE__))
$LICENSE_FILE = File.expand_path(File.join(File.dirname(__FILE__), 'LICENSE'))
if !(defined? COMMON_DO_ONCE)
COMMON_DO_ONCE = true
$LOAD_PATH << File.join($HOME_DIR, 'Rake', 'lib')
ENV['PATH'] = $ENVIRONMENT_BIN_DIR + ':' + ENV['PATH']
end
require 'objective-j'
def serialized_env
env = ""
env += %{CONFIG="#{ENV['CONFIG']}" } if ENV['CONFIG']
env += %{BUILD_DIR="#{ENV['BUILD_DIR']}" } if ENV['BUILD_DIR']
return env
end
def subrake(directories, task_name)
directories.each do |directory|
if (File.directory?(directory) && File.file?(File.join(directory, "Rakefile")))
system %{cd #{directory} && #{$serialized_env} #{$0} #{task_name}}
else
puts "subrake missing: " + directory
end
end
end
# Shared Resrouces in env
$JSJAR_PATH = File.expand_path(File.join($HOME_DIR, 'Tools/Utilities/js.jar'))
$ENVIRONMENT_JS = File.join($ENVIRONMENT_LIB_DIR, 'js.jar')
file_d $ENVIRONMENT_JS do
cp($JSJAR_PATH, $ENVIRONMENT_JS)
end
def js2java(inputfile, className, debug)
debugString = '-nosource -debug' if debug
IO.popen("java -classpath #{$JSJAR_PATH}:. #{debugString} org.mozilla.javascript.tools.jsc.Main -o #{className} #{inputfile}") do |shrinksafe|
puts shrinksafe.read
end
end
def cat(files, outfile)
File.open(outfile, "w") do |concated|
files.each do |file|
concated.write IO.read(file)
end
end
end
def executable_exists?(name)
ENV["PATH"].split(":").any? {|p| File.executable? File.join(p, name) }
end
$OBJJ_TEMPLATE_EXECUTABLE = File.join($HOME_DIR, 'Rake', 'lib', 'objj-executable')
def make_objj_executable(path)
cp($OBJJ_TEMPLATE_EXECUTABLE, path)
File.chmod 0755, path
end
task :build => [$ENVIRONMENT_JS]
task :default => [:build]
task :release do
ENV['CONFIG'] = 'Release'
spawn_rake(:build)
end
task :debug do
ENV['CONFIG'] = 'Debug'
spawn_rake(:build)
end
task :all => [:debug, :release]
task 'clean-debug' do
ENV['CONFIG'] = 'Debug'
spawn_rake(:clean)
end
task :cleandebug => ['clean-debug']
task 'clean-release' do
ENV['CONFIG'] = 'Release'
spawn_rake(:clean)
end
task :cleanrelease => ['clean-release']
task 'clean-all' => ['clean-debug', 'clean-release']
task :cleanall => ['clean-all']
task 'clobber-debug' do
ENV['CONFIG'] = 'Debug'
spawn_rake(:clobber)
end
task :clobberdebug => ['clobber-debug']
task 'clobber-release' do
ENV['CONFIG'] = 'Release'
spawn_rake(:clobber)
end
task :clobberrelease => ['clobber-release']
task 'clobber-all' => ['clobber-debug', 'clobber-release']
task :clobberall => ['clobber-all']
def spawn_rake(task_name)
system %{#{$serialized_env} #{$0} #{task_name}}
end