forked from cappuccino/cappuccino
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.rb
160 lines (123 loc) · 3.95 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
require 'rake'
require 'pathname'
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_NARWHAL_BIN_DIR= File.join($ENVIRONMENT_DIR, 'bin')
$ENVIRONMENT_BIN_DIR = File.join($ENVIRONMENT_DIR, 'packages', 'objj', 'bin')
$ENVIRONMENT_LIB_DIR = File.join($ENVIRONMENT_DIR, 'packages', 'objj', '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, 'Tools', 'Rake', 'lib')
ENV['PATH'] = $ENVIRONMENT_NARWHAL_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}})
rake abort if ($? != 0)
else
puts "warning: subrake missing: " + directory +" (this is not necessarily an error, "+directory+" may be optional)"
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, 'Tools', 'Rake', 'lib', 'objj-executable')
def make_objj_executable(path)
cp($OBJJ_TEMPLATE_EXECUTABLE, path)
File.chmod(0755, path)
symlink_executable(path)
end
def symlink_executable(source)
relative = Pathname.new(source).relative_path_from(Pathname.new($ENVIRONMENT_NARWHAL_BIN_DIR))
destination = File.join($ENVIRONMENT_NARWHAL_BIN_DIR, File.basename(source))
FileUtils.ln_sf(relative, destination)
end
task :build
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}}
rake abort if ($? != 0)
end