4
4
COMPILE=" compile"
5
5
CLEAN=" clean"
6
6
DEPENDENCIES=" install"
7
+ COMPILE_CACHED_DEPENDENCIES=" --use-cache"
8
+
7
9
DERIVED_DATA_DIR=" nef/DerivedData"
8
10
9
11
# : terminal setup
@@ -12,21 +14,26 @@ normal=$(tput sgr0)
12
14
13
15
red=$( tput setaf 1)
14
16
green=$( tput setaf 2)
17
+ required=$( tput setaf 222)
18
+ optional=$( tput setaf 230)
15
19
reset=$( tput sgr0)
16
20
21
+
17
22
# : IN - Check Args
18
23
19
24
# #
20
25
# printWrongArguments()
21
26
# #
22
27
printWrongArguments () {
23
28
echo " "
24
- echo " ${bold} nefc ${normal} [${bold} $COMPILE ${normal} | ${bold} $DEPENDENCIES ${normal} | ${bold} $CLEAN ${normal} ]${bold} ${normal} <project>"
29
+ echo " ${bold} nefc ${normal} [${bold} $COMPILE ${normal} | ${bold} $DEPENDENCIES ${normal} | ${bold} $CLEAN ${normal} ]${bold} ${normal} <project> <options> "
25
30
echo " "
26
31
echo " ${bold} $COMPILE ${normal} compile playground's pages for the selected project"
27
32
echo " ${bold} $DEPENDENCIES ${normal} builds dependencies in selected project"
28
33
echo " ${bold} $CLEAN ${normal} clean builds in selected project"
29
34
echo " "
35
+ echo " ${optional}${bold} $COMPILE_CACHED_DEPENDENCIES ${reset}${normal} is an option for '$COMPILE '. Use cached dependencies if it is possible. In another case, it will download and install them ${optional} [optional]${reset} "
36
+ echo " "
30
37
}
31
38
32
39
# #
@@ -43,18 +50,32 @@ printWrongConfig() {
43
50
# - Parameter `args`: list of arguments received from command line
44
51
# #
45
52
checkArguments () {
46
- # $0 and $1 in `args` are ref. to first and second parameter from command line
47
- # $0 - command
48
- # $1 - path
53
+ # $0 - `nefc`
54
+ # $1 - command
55
+ # $2 - path
56
+ # $3 - flag param
49
57
50
- if [ " $# " -ne 2 ]; then printWrongArguments $0 ; exit 1; fi
58
+ local command=" $1 "
59
+ local flag=" $3 "
60
+ local isValidCommand=" "
51
61
52
- local config=(" $COMPILE " " $CLEAN " " $DEPENDENCIES " )
53
- for e in " ${config[@]} " ; do [ $1 = $e ] && return 0; done
62
+ if [ " $# " -lt 2 ] || [ " $# " -gt 3 ]; then printWrongArguments $0 ; exit 1; fi
63
+
64
+ local validCommands=(" $COMPILE " " $CLEAN " " $DEPENDENCIES " )
65
+ for valid in " ${validCommands[@]} " ; do
66
+ if [ " $command " = " $valid " ]; then isValidCommand=" $command " ; fi
67
+ done
54
68
55
- printWrongConfig; exit 1
69
+ if [[ " $isValidCommand " = " " ]]; then
70
+ printWrongConfig; exit 1
71
+ elif [[ " $command " = " $COMPILE " ]]; then
72
+ if [[ " $flag " != " $COMPILE_CACHED_DEPENDENCIES " ]] && [[ " $flag " != " " ]]; then
73
+ printWrongArguments $0 ; exit 1;
74
+ fi
75
+ fi
56
76
}
57
77
78
+
58
79
# : - Dependencies
59
80
60
81
# #
@@ -70,23 +91,28 @@ dependencies() {
70
91
# : - Compile
71
92
72
93
# #
73
- # compile(String folder)
94
+ # compile(String folder, String flag )
74
95
# - Parameter `folder`: path to the project folder.
96
+ # - parameter `flag`: configuration for building.
75
97
# #
76
98
compile () {
77
- makeStructure " $1 "
78
- buildDependencies " $1 "
79
- buildProject " $1 "
99
+ local flag=" $2 "
100
+
101
+ makeStructure " $1 " " $flag "
102
+ buildDependencies " $1 " " $flag "
103
+ buildProject " $1 " " $flag "
80
104
copyFrameworks " $1 "
81
105
compilePlaygroundPages " $1 "
82
106
}
83
107
84
108
# #
85
- # buildProject(String folder) throws
109
+ # buildProject(String folder, String flag ) throws
86
110
# - Parameter `folder`: path to the project folder.
111
+ # - parameter `flag`: configuration for building.
87
112
# #
88
113
buildProject () {
89
- cd " $1 " # parameter `folder`
114
+ cd " $1 " # parameter `folder`
115
+ local flag=" $2 " # parameter `flag`
90
116
local logPath=" nef/log"
91
117
92
118
find . -name ' *.pbxproj' -print0 | while IFS= read -r -d $' \0' project; do
@@ -105,18 +131,22 @@ buildProject() {
105
131
106
132
echo -ne " ${reset} Building ${green} $workspaceName ${normal} ($schemeName ) ..."
107
133
108
- set +e
109
- xcodebuild -workspace " $workspace " -sdk " $sdk " -scheme " $schemeName " -derivedDataPath " $DERIVED_DATA_DIR " -configuration Debug 1> " $log " 2>&1
110
- installed=` grep " BUILD SUCCEEDED" " $log " `
111
- set -e
134
+ if [[ $( shouldBuildWorkspace " $workspace " " $flag " ) = " 1" ]]; then
135
+ set +e
136
+ xcodebuild -workspace " $workspace " -sdk " $sdk " -scheme " $schemeName " -derivedDataPath " $DERIVED_DATA_DIR " -configuration Debug 1> " $log " 2>&1
137
+ installed=` grep " BUILD SUCCEEDED" " $log " `
138
+ set -e
139
+ else
140
+ installed=" OK!"
141
+ fi
112
142
113
143
if [ " ${# installed} " -gt 0 ]; then
114
- echo " ✅"
144
+ echo " ✅"
115
145
else
116
- echo " ❌"
117
- echo " ${bold}${red} error: ${reset}${bold} building $workspaceName ${normal} "
118
- cat " $log "
119
- exit 1
146
+ echo " ❌"
147
+ echo " ${bold}${red} error: ${reset}${bold} building $workspaceName ${normal} "
148
+ cat " $log "
149
+ exit 1
120
150
fi
121
151
done
122
152
}
@@ -180,13 +210,32 @@ isPlatfromIOSPlaygroundPage() {
180
210
}
181
211
182
212
# #
183
- # buildDependencies(String folder)
213
+ # shouldBuildWorkspace(String workspace, String flag)
214
+ # - Parameter `workspace`
215
+ # - parameter `flag`: configuration for building.
216
+ # - Return `shouldBuildWorkspace` 1 - yes (is not cached); 0 - no (cached)
217
+ # #
218
+ shouldBuildWorkspace () {
219
+ local workspace=" $1 " # parameter `workspace`
220
+ local flag=" $2 " # parameter `flag`
221
+
222
+ local workspaceName=$( echo " $workspace " | rev | cut -d' /' -f 1 | rev | cut -d' .' -f 1)
223
+ local workspaceFwPath=" nef/build/fw/$workspaceName .framework"
224
+
225
+ [ -d " $DERIVED_DATA_DIR /build" ] && [ -d " $workspaceFwPath " ] && [ " $flag " = " $COMPILE_CACHED_DEPENDENCIES " ] && echo 0;
226
+ echo 1
227
+ }
228
+
229
+ # #
230
+ # buildDependencies(String folder, String flag)
184
231
# - Parameter `folder`: path to the project folder.
232
+ # - parameter `flag`: configuration for building.
185
233
# #
186
234
buildDependencies () {
187
235
local path=" $1 " # parameter `folder`
236
+ local flag=" $2 " # parameter `flag`
188
237
189
- buildPODS " $path "
238
+ buildPODS " $path " " $flag "
190
239
addPlaygroundReference " $path "
191
240
}
192
241
@@ -197,6 +246,7 @@ buildDependencies() {
197
246
buildPODS () {
198
247
cd " $1 "
199
248
249
+ local flag=" $2 "
200
250
local podfile=" Podfile"
201
251
local log=" nef/log/pod-install.log"
202
252
@@ -207,7 +257,12 @@ buildPODS() {
207
257
cd " $path "
208
258
209
259
set +e
210
- pod install --repo-update 1> " $log " 2>&1
260
+ if [[ " $flag " = " $COMPILE_CACHED_DEPENDENCIES " ]]; then
261
+ pod install 1> " $log " 2>&1
262
+ else
263
+ pod install --repo-update 1> " $log " 2>&1
264
+ fi
265
+
211
266
installed=` grep " Pod installation complete" " $log " `
212
267
set -e
213
268
@@ -269,16 +324,21 @@ playgroundForProjectPath() {
269
324
}
270
325
271
326
# #
272
- # makeStructure(String folder)
327
+ # makeStructure(String folder, String flag )
273
328
# - Parameter `folder`: path to the project folder.
329
+ # - parameter `flag`: configuration for building.
274
330
# #
275
331
makeStructure () {
276
332
set +e
277
- local projectFolder=$1 # parameter `folder`
333
+ local projectFolder=" $1 " # parameter `folder`
334
+ local flag=" $2 " # parameter `flag`
278
335
279
336
cd " $projectFolder "
280
337
281
- cleanStructure " $projectFolder "
338
+ if [[ " $flag " != " $COMPILE_CACHED_DEPENDENCIES " ]]; then
339
+ cleanStructure " $projectFolder "
340
+ fi
341
+
282
342
mkdir -p nef/build/fw
283
343
mkdir -p nef/build/output
284
344
mkdir -p nef/log
@@ -310,7 +370,7 @@ copyFrameworks() {
310
370
exit 1
311
371
fi
312
372
313
- cp -a $( find " $DERIVED_DATA_DIR /build" -name ' *.framework' ) nef/build/fw
373
+ cp -a $( find " $DERIVED_DATA_DIR /build" -name ' *.framework' ) nef/build/fw 2> /dev/null
314
374
echo " Copy ${green} frameworks${reset} ✅"
315
375
}
316
376
@@ -396,26 +456,28 @@ compilePlaygroundPage() {
396
456
local sources=" $playgroundPage /../../Sources"
397
457
local staticLib=" $playgroundName " $( date ' +_%H_%M_%S' )
398
458
local staticLibPath=" nef/build/fw/$staticLib "
459
+ local iOSFwPath=` xcode-select -p` " /Platforms/iPhoneOS.platform/Developer/Library/Frameworks"
460
+ local macOSFwPath=` xcode-select -p` " /Platforms/MacOSX.platform/Developer/Library/Frameworks"
399
461
400
462
platformIOS=$( isPlatfromIOSPlaygroundPage " $playgroundPage " )
401
463
hasSourceFolderFiles=$( ls " $sources " 2> /dev/null)
402
464
403
465
# A. macOS paltform
404
466
if [ " $platformIOS " -eq " 0" ]; then
405
467
if [ " ${# hasSourceFolderFiles} " -gt 0 ]; then
406
- xcrun -k swiftc -D NOT_IN_PLAYGROUND -emit-module " $sources " /* -F " nef/build/fw" -o " $staticLibPath " 1> " $llog " 2>&1
407
- xcrun -k swiftc -D NOT_IN_PLAYGROUND -static-executable " $staticLibPath " -F " nef/build/fw" " $file " -o " nef/build/output/$playgroundName " 1> " $log " 2>&1
468
+ xcrun -k swiftc -D NOT_IN_PLAYGROUND -emit-module " $sources " /* -F " nef/build/fw" -F " $macOSFwPath " - o " $staticLibPath " 1> " $llog " 2>&1
469
+ xcrun -k swiftc -D NOT_IN_PLAYGROUND -static-executable " $staticLibPath " -F " nef/build/fw" -F " $macOSFwPath " " $file " -o " nef/build/output/$playgroundName " 1> " $log " 2>&1
408
470
else
409
- xcrun -k swiftc -D NOT_IN_PLAYGROUND -F " nef/build/fw" " $file " -o " nef/build/output/$playgroundName " 1> " $log " 2>&1
471
+ xcrun -k swiftc -D NOT_IN_PLAYGROUND -F " nef/build/fw" -F " $macOSFwPath " " $file " -o " nef/build/output/$playgroundName " 1> " $log " 2>&1
410
472
fi
411
473
412
474
# B. iOS platform
413
475
else
414
476
if [ " ${# hasSourceFolderFiles} " -gt 0 ]; then
415
- xcrun -k -sdk " iphonesimulator" swiftc -D NOT_IN_PLAYGROUND -target " x86_64-apple-ios12.1-simulator" -emit-module " $sources " /* -F " nef/build/fw" -o " $staticLibPath " 1> " $llog " 2>&1
416
- xcrun -k -sdk " iphonesimulator" swiftc -D NOT_IN_PLAYGROUND -target " x86_64-apple-ios12.1-simulator" -static-executable " $staticLibPath " -F " nef/build/fw" " $file " -o " nef/build/output/$playgroundName " 1> " $log " 2>&1
477
+ xcrun -k -sdk " iphonesimulator" swiftc -D NOT_IN_PLAYGROUND -target " x86_64-apple-ios12.1-simulator" -emit-module " $sources " /* -F " nef/build/fw" -F " $iOSFwPath " - o " $staticLibPath " 1> " $llog " 2>&1
478
+ xcrun -k -sdk " iphonesimulator" swiftc -D NOT_IN_PLAYGROUND -target " x86_64-apple-ios12.1-simulator" -static-executable " $staticLibPath " -F " nef/build/fw" -F " $iOSFwPath " " $file " -o " nef/build/output/$playgroundName " 1> " $log " 2>&1
417
479
else
418
- xcrun -k -sdk " iphonesimulator" swiftc -D NOT_IN_PLAYGROUND -target " x86_64-apple-ios12.1-simulator" -F " nef/build/fw" " $file " -o " nef/build/output/$playgroundName " 1> " $log " 2>&1
480
+ xcrun -k -sdk " iphonesimulator" swiftc -D NOT_IN_PLAYGROUND -target " x86_64-apple-ios12.1-simulator" -F " nef/build/fw" -F " $iOSFwPath " " $file " -o " nef/build/output/$playgroundName " 1> " $log " 2>&1
419
481
fi
420
482
fi
421
483
@@ -427,6 +489,7 @@ compilePlaygroundPage() {
427
489
exit 1
428
490
}
429
491
492
+
430
493
# : - Clean
431
494
432
495
# #
@@ -463,6 +526,7 @@ cleanPODS() {
463
526
rm -rf ./* .xcworkspace 1> /dev/null 2> /dev/null
464
527
}
465
528
529
+
466
530
# : MAIN
467
531
set -e
468
532
checkArguments $@
475
539
fi
476
540
477
541
if [ $1 = " $COMPILE " ]; then
478
- compile " $projectPath "
542
+ flag=" $3 "
543
+ compile " $projectPath " " $flag "
479
544
elif [ $1 = " $DEPENDENCIES " ]; then
480
545
dependencies " $projectPath "
481
546
else
0 commit comments