forked from SwiftGen/SwiftGen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
executable file
·99 lines (80 loc) · 3.52 KB
/
Rakefile
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
#!/usr/bin/rake
require 'pathname'
require 'yaml'
require 'shellwords'
if ENV['BUNDLE_GEMFILE'].nil?
puts "\u{274C} Please use bundle exec"
exit 1
end
## [ Constants ] ##############################################################
WORKSPACE = 'SwiftGen'.freeze
SCHEME_NAME = 'swiftgen'.freeze
CONFIGURATION = 'Debug'.freeze
RELEASE_CONFIGURATION = 'Release'.freeze
POD_NAME = 'SwiftGen'.freeze
MIN_XCODE_VERSION = 10.0
BUILD_DIR = File.absolute_path('./build')
BIN_NAME = 'swiftgen'.freeze
TEMPLATES_SRC_DIR = 'templates'.freeze
## [ Utils ] ##################################################################
def path(str)
return nil if str.nil? || str.empty?
Pathname.new(str)
end
def defaults(args)
bindir = path(args.bindir) || (Pathname.new(BUILD_DIR) + 'swiftgen/bin')
fmkdir = path(args.fmkdir) || (bindir + '../lib')
tpldir = path(args.tpldir) || (bindir + '../templates')
[bindir, fmkdir, tpldir].map(&:expand_path)
end
## [ Build Tasks ] ############################################################
namespace :cli do
desc "Build the CLI binary and its frameworks as an app bundle\n" \
"(in #{BUILD_DIR})"
task :build, %i[bindir tpldir] do |task, args|
(bindir, _, tpldir) = defaults(args)
tpl_rel_path = tpldir.relative_path_from(bindir)
Utils.print_header 'Building Binary'
plist_file = (Pathname.new(BUILD_DIR) + "Build/Products/#{RELEASE_CONFIGURATION}/swiftgen.app/Contents/Info.plist").to_s
Utils.run(
%(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{SCHEME_NAME}" -configuration "#{RELEASE_CONFIGURATION}") +
%( -derivedDataPath "#{BUILD_DIR}" TEMPLATE_PATH="#{tpl_rel_path}") +
%( SWIFTGEN_OTHER_LDFLAGS="-sectcreate __TEXT __info_plist #{plist_file.shellescape}"),
task, xcrun: true, formatter: :xcpretty
)
end
desc "Install the binary in $bindir, frameworks in $fmkdir, and templates in $tpldir\n" \
'(defaults $bindir=./build/swiftgen/bin/, $fmkdir=$bindir/../lib, $tpldir=$bindir/../templates'
task :install, %i[bindir fmkdir tpldir] => :build do |task, args|
(bindir, fmkdir, tpldir) = defaults(args)
generated_bundle_path = "#{BUILD_DIR}/Build/Products/#{RELEASE_CONFIGURATION}/swiftgen.app/Contents"
Utils.print_header "Installing binary in #{bindir}"
Utils.run([
%(mkdir -p "#{bindir}"),
%(cp -f "#{generated_bundle_path}/MacOS/swiftgen" "#{bindir}/#{BIN_NAME}")
], task, 'copy_binary')
Utils.print_header "Installing frameworks in #{fmkdir}"
Utils.run([
%(if [ -d "#{fmkdir}" ]; then rm -rf "#{fmkdir}"; fi),
%(mkdir -p "#{fmkdir}"),
%(cp -fR "#{generated_bundle_path}/Frameworks/" "#{fmkdir}")
], task, 'copy_frameworks')
Utils.print_header "Fixing binary's @rpath"
Utils.run([
%(install_name_tool -delete_rpath "@executable_path/../Frameworks" "#{bindir}/#{BIN_NAME}"),
%(install_name_tool -add_rpath "@executable_path/#{fmkdir.relative_path_from(bindir)}" "#{bindir}/#{BIN_NAME}")
], task, 'fix_rpath', xcrun: true)
Utils.print_header "Installing templates in #{tpldir}"
Utils.run([
%(mkdir -p "#{tpldir}"),
%(cp -r "#{TEMPLATES_SRC_DIR}/" "#{tpldir}")
], task, 'copy_templates')
Utils.print_info "Finished installing. Binary is available in: #{bindir}"
end
desc "Delete the build directory\n" \
"(#{BUILD_DIR})"
task :clean do
sh %(rm -fr #{BUILD_DIR})
end
end
task :default => 'cli:build'