forked from SwiftGen/SwiftGen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
executable file
·109 lines (87 loc) · 4.31 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
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/rake
require 'pathname'
require 'yaml'
require 'shellwords'
## [ Constants ] ##############################################################
WORKSPACE = 'SwiftGen'
SCHEME_NAME='swiftgen'
CONFIGURATION = 'Release'
POD_NAME = 'SwiftGen'
BUILD_DIR = File.absolute_path('./build')
BIN_NAME = 'swiftgen'
TEMPLATES_SRC_DIR = 'Resources/templates'
## [ Utils ] ##################################################################
def defaults(args)
bindir = args.bindir.nil? || args.bindir.empty? ? (Pathname.new(BUILD_DIR) + 'swiftgen/bin') : Pathname.new(args.bindir)
fmkdir = args.fmkdir.nil? || args.fmkdir.empty? ? bindir + '../lib' : Pathname.new(args.fmkdir)
tpldir = args.tpldir.nil? || args.tpldir.empty? ? bindir + '../templates' : Pathname.new(args.tpldir)
[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, [: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/#{CONFIGURATION}/swiftgen.app/Contents/Info.plist").to_s
Utils.run(
%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{SCHEME_NAME}" -configuration "#{CONFIGURATION}") +
%Q( -derivedDataPath "#{BUILD_DIR}" TEMPLATE_PATH="#{tpl_rel_path}") +
%Q( 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, [:bindir, :fmkdir, :tpldir] => :build do |task, args|
(bindir, fmkdir, tpldir) = defaults(args)
generated_bundle_path = "#{BUILD_DIR}/Build/Products/#{CONFIGURATION}/swiftgen.app/Contents"
Utils.print_header "Installing binary in #{bindir}"
Utils.run([
%Q(mkdir -p "#{bindir}"),
%Q(cp -f "#{generated_bundle_path}/MacOS/swiftgen" "#{bindir}/#{BIN_NAME}"),
], task, 'copy_binary')
Utils.print_header "Installing frameworks in #{fmkdir}"
Utils.run([
%Q(if [ -d "#{fmkdir}" ]; then rm -rf "#{fmkdir}"; fi),
%Q(mkdir -p "#{fmkdir}"),
%Q(cp -fR "#{generated_bundle_path}/Frameworks/" "#{fmkdir}"),
], task, 'copy_frameworks')
Utils.print_header "Fixing binary's @rpath"
Utils.run([
%Q(install_name_tool -delete_rpath "@executable_path/../Frameworks" "#{bindir}/#{BIN_NAME}"),
%Q(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([
%Q(mkdir -p "#{tpldir}"),
%Q(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 %Q(rm -fr #{BUILD_DIR})
end
end
task :default => 'cli:build'
## [ Playground Resources ] ###################################################
namespace :playground do
task :clean do
sh 'rm -rf SwiftGen.playground/Resources'
sh 'mkdir SwiftGen.playground/Resources'
end
task :images do
Utils.run(%Q(actool --compile SwiftGen.playground/Resources --platform iphoneos --minimum-deployment-target 7.0 --output-format=human-readable-text Resources/Fixtures/Images/Images.xcassets), task, xcrun: true)
end
task :storyboard do
Utils.run(%Q(ibtool --compile SwiftGen.playground/Resources/Wizard.storyboardc --flatten=NO Resources/Fixtures/Storyboards-iOS/Wizard.storyboard), task, xcrun: true)
end
task :strings do
Utils.run(%Q(plutil -convert binary1 -o SwiftGen.playground/Resources/Localizable.strings Resources/Fixtures/Strings/Localizable.strings), task, xcrun: true)
end
desc "Regenerate all the Playground resources based on the test fixtures.\nThis compiles the needed fixtures and place them in SwiftGen.playground/Resources"
task :resources => %w(clean images storyboard strings)
end