-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrake.rb
80 lines (65 loc) · 1.87 KB
/
crake.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
#!ruby
require 'optparse'
#
# setup the load path so that we can require crake's files from any dir
#
crake_dir = File.expand_path(File.dirname(__FILE__))
crake_lib_dir = File.join(crake_dir, 'lib')
$LOAD_PATH.unshift crake_lib_dir unless $LOAD_PATH.include? crake_lib_dir
require 'crake/dsl'
require 'crake/project_task'
#
# extend the top-level object with the DSL module, so that the namespace pollution we cause is minimal
#
self.extend CRake::DSL
#
# process the command-line arguments
#
options = {}
OptionParser.new do |opts|
options[:crakefile] = 'CRakefile.rb'
opts.on('-f', '--file CRAKEFILE', 'Specify which crakefile to process') do |f|
options[:crakefile] = f
end
opts.on_tail('-h', '--help', 'Shows this help message') do
puts opts
exit
end
end.parse!
if not File.exists? options[:crakefile]
puts "[crake] error: crakefile '#{options[:crakefile]}' does not exist"
exit 1
end
# ARGV is left with the unprocessed arguments. The first one should be the target to be built, and the rest - parameters
# that will go in crake's environment
target = ARGV.shift || "default"
if target.include? '='
ARGV.unshift target
target = "default"
end
env = {}
ARGV.each do |arg|
if arg =~ /(?<lhs>.*)=(?<rhs>.*)/
env[Regexp.last_match(:lhs)] = Regexp.last_match(:rhs)
else
env[arg] = true
end
end
#
# process the user's crakefile itself
#
crakefile_path = File.join(Dir.pwd, options[:crakefile])
crakefile_dir = File.dirname(crakefile_path)
# set the pwd to the crakefile's directory before requiring it so that requires from the crakefile will work with paths
# relative to the crakefile itself
Dir.chdir crakefile_dir
require crakefile_path
#
# now build the specified projects
#
target_task = CRake::ProjectTask.get_defined.find { |t| t.name == target }
if target_task == nil
puts "[crake] error: target #{target} not found"
exit 1
end
target_task.build