-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiosctrl
1747 lines (1405 loc) · 54.2 KB
/
iosctrl
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
use strict;
use warnings;
$::VERSION = 1.1;
use Data::Dumper;
use Getopt::Long qw| :config auto_abbrev bundling_override no_ignore_case auto_version |; # perl core
use Mac::PropertyList qw| :all |; # CPAN
use ardnew::IO qw| :all |;
use ardnew::Lists qw| :all |;
use ardnew::Files qw| :all |;
use ardnew::Util qw| :all |;
$| = 1; # autoflush on write
use constant
{
_HEADER_COLOR => "blue",
_ERROR_COLOR => "red",
};
my %OPCMD =
(
clean => qr(clean|release)i,
build => qr(build|release)i,
);
my $VERBOSITY = 0; # global, don't ever write to it after the GetOpt call.
my $ROW_WIDTH_MIN = 40;
my $SELFPATH = abspath $0;
my $SELFNAME = basename $SELFPATH;
my $SELFVERSION = $::VERSION;
use constant
{
_FALSE => 0,
_TRUE => not 0,
};
use constant
{
_PBXPROJ => 'project.pbxproj',
};
use constant
{
_TAB => " " x 4,
_MIN_ROW_WIDTH => 60,
_COL_SEP => " | ",
};
use constant
{
_OUTPUT_FORMAT => q|s/ /-/g,%p__%v__%o__%d__%t|,
_SOURCE_FORMAT => q|s/ /-/g,__%v__%o__%d__%t|,
};
my %DEVICE_FAMILY =
(
q|iPod/iPhone| => [ '1', qr/^\s*1\s*$/i, qr/^\s*(i)?(pod|phone)(os|simulator)?\s*$/i, ],
q|iPad| => [ '2', qr/^\s*2\s*$/i, qr/^\s*(i)?(pad)(os|simulator)?\s*$/i, ],
q|Universal| => [ '1,2', qr/^\s*1\s*,\s*2\s*$/i, qr/^\s*(universal)\s*$/i, ],
q|Apple TV| => [ '3', qr/^\s*3\s*$/i, qr/^\s*(apple)?(tv)(os|simulator)?\s*$/i, ],
q|Apple Watch| => [ '4', qr/^\s*4\s*$/i, qr/^\s*(apple)?(watch)(os|simulator)?\s*$/i, ],
);
sub usage_short
{
return << "USAGE"
general usage:
$SELFNAME [-?hHlv]
project/toolchain query:
$SELFNAME [-v] [-l] [-d device] [-t devtype] [-r runtime] [-k sdk]
$SELFNAME [-v] [-l] [-p project]
compiler/package control:
$SELFNAME [-v] [-p project] [-k sdk] [-a family] [-e osversion] [-s scheme] [-c config] [-b bundle] [-m devteam] [-i profile] [-o output] [-O format] [-z compression] COMMAND
$SELFNAME [-v] [-p project] [-X xcodeconf] [-o output] [-O format] [-z compression] COMMAND
USAGE
}
sub usage_long
{
my ($usage_short) = usage_short;
return << "USAGE"
================================================================================
description:
$SELFNAME $::VERSION
command-line interface to create and configure iOS simulator instances;
and to build and export iOS executables from Xcode project source files
synopsis:
the primary functions of this script are to (1) build a distributable
package containing project sources for SCM and an .ipa suitable for
installation on an iOS device, and (2) install and run an app in any
specified iOS device and iOS runtime/SDK combination available.
the simplest way to perform these tasks are as follows:
(1) first configure the project so that you can build and export an .ipa
directly from Xcode. next, identify the corresponding configuration
using:
$SELFNAME -l -p <path/to/project.xcodeproj>
then, taking note of the desired configuration index from the previous
command, simply run the following command to generate a zip-compressed
distribution package:
$SELFNAME -p <path/to/project.xcodeproj> -X <index> -z -- release
(2) TBD
================================================================================
$usage_short
--------------------------------------------------------------------------------
commands:
clean deletes all of the intermediate build files and
exported archives and executable .ipa's; forces
the compiler to rebuild everything
build compiles the project and codesigns the executable
into an .app, then creates a distributable .ipa
release performs a clean+build of the project
----
general options:
-h, --help display short usage info
-?, --????????
-H, --helpmore display this super friendly usage info!
-v, --verbose print detailed information of operations; add
additional flags (e.g. -vv) to increase verbosity
-l, --list list all available configuration options for the
simulator, runtime, and SDK. combining this option
with many of the configuration options [-dtrk]
will display only the respective matching items,
and each of those can be filtered by specifying
an argument.
EXAMPLE:
to list all available iPad device types:
$SELFNAME -l -y ipad
to list all available iOS 11 simulators:
$SELFNAME -l -d "ios 11"
-p, --project=PROJECT path to the .xcodeproj directory. when combined
with [-l], all available build configurations are
listed (use this to identify settings that were
configured in Xcode or to view available options
for [-X] argument)
EXAMPLE:
to list all available project options:
$SELFNAME -l -p MyProject.xcodeproj
----
options for controlling the simulator:
-d, --device[=DEVICE] specify the simulator device to use
-t, --devtype[=DEVTYPE] specify the simulator device type to use
-r, --runtime[=RUNTIME] specify the iOS runtime to use
----
options for building an app:
-o, --output=OUTPUT directory to output compiled executables and
exported .ipa's
-O, --outputformat[=FMT] specify the output file format with printf-style
format-strings. most of the short options for
building the app may also be used as specifiers
with the following changes/additions:
\%p - project name (without ".xcodeproj")
\%d - current date
\%t - current time
\%v - detected app version
\%o - target device OS and version
if the format string begins with a substitution
expression followed by a comma (i.e. "s///,") then
that substitution will be performed on the final
resulting file name
EXAMPLE:
to include project, configuration, and scheme:
-O "\%p \%c \%s"
to specify an exact file name:
-O "my archive 1"
project name, replacing all spaces with "-":
-O "s/ /-/,%p"
NOTE:
if [-O] or its FMT argument is not provided,
the default format is used:
"s/ /-/g,\%p__\%v__\%o__\%d__\%t"
-S, --source=SOURCE path to the project source directory to include in
the output and optionally compress using the given
[-z] compression argument. the destination name
will be the the same as default [-O] but with the
string "-Source" appended to the project name
-z, --compress[=XS] compress the output directory using XS compression
where XS is one of "zip", "gzip", or "bzip2". the
file extension can be specified by appending it to
XS. so [-z bzip2.tbz] will use bzip2 compression
and append the file extension ".tbz" to the
archive name. if extension is unspecified, the
defaults ".zip", ".tar.gz", and ".tar.bz2" will be
used, respectively. if XS is not specified, the
default compression zip with extension ".zip" will
be used
-X, --xcodeconf=CONF specify a preconfigured set of build settings that
were configured in Xcode. use arguments [-lp] to
view available settings
NOTE:
using this option is preferred as it will
automatically detect -all- required settings
for building and exporting the app. also, any
automatically detected settings may be
overridden by options specified here at the
command line
-V, --appversion=VERSION set the app version number to use for software
publishing. this corresponds to the project plist
key CFBundleShortVersionString, or the project
"Version" seen in Xcode
NOTE:
this option actually modifies the project's
Info.plist file. use with caution!
-B, --appbuild=BUILD set the app build identity to use for software
publishing. this corresponds to the project plist
key CFBundleVersion, or the project "Build" seen
in Xcode
NOTE:
this option actually modifies the project's
Info.plist file. use with caution!
-k, --sdk[=SDK] specify the iOS SDK to use for compiling. valid
values can be seen by combining this with [-l] to
view available SDKs. if this option is not given
when specifying [-X], a best effort is made to
select the appropriate SDK. but when the project's
target iOS version doesn't match the SDK version
-verbatim-, an asterisk (*) is placed after the
identified SDK in verbose (-v) messages to
indicate a potential mismatch in SDK and target OS
-a, --family=FAMILY specify the device family to use. valid values are
"iphone", "ipod", "ipad", "universal", "watch",
or "tv" (NOTE: "watch" and "tv" untested!). this
option can be automatically set by specifying an
SDK [-k]
-e, --osversion=VERSION specify the OS version to use as deployment
target. this option can be automatically set by
specifying an SDK [-k]
-s, --scheme=SCHEME specify the project's build/run scheme
-c, --config=CONFIG specify the build configuration for the given
build/run scheme
-b, --bundle=BUNDLE specify the app bundle identifier to use
-m, --devteam=DEVTEAM specify the build team identifier
-i, --profile=PROFILE specify the provisioning profile to use for
codesigning the app; this may be either the UUID
or the descriptive name shown in Xcode
================================================================================
NOTE/BUGS
note that -if- the final option provided is one that optionally accepts an
argument (e.g. [-O], [-z]) and you do NOT provide an argument, then be sure
to indicate what follows is an argument to the script and not an argument to
the option. this is done using the traditional delimiter "--". meaning
everything that follows "--" will not be processed by the getopt parsing
library and will instead be left in ARGV. the synopsis above demonstrates an
instance where this is necessary, as we want "release" to be the script
command and not an argument to [-z] (we want [-z] to use its default implied
value of "zip").
USAGE
}
sub usage
{
my ($more) = @_;
return $more ? usage_long : usage_short . <<MORE;
** NOTE **
see [-H|--helpmore] for extended usage information
MORE
}
# ======================================================================================================================
# SUBROUTINES
# ======================================================================================================================
sub shell_cmd
{
# see the perldoc on 'system' for more info
my ($cmd) = join " ", @_;
my ($ret);
my (@out);
# each element of @_ may contain spaces (i.e. multiple terms)
my ($program_name) = ($cmd =~ /\w+/g);
if ($VERBOSITY > 0)
{
my $subcmd = $cmd;
# remove all outermost surrounding parentheses
while ($subcmd =~ s/^\s*\(\s*(.*)\s*\)\s*$/$1/g) { ; }
sinfo "forking child process:";
sinfo _TAB . $subcmd;
}
open my $io, "-|", $cmd . " 2>&1"
or ohno clr([_ERROR_COLOR], "could not execute '$program_name': $!");
while (<$io>)
{
push @out, $_ if wantarray;
if ($VERBOSITY > 1)
{
chomp;
sinfo _TAB x 2 . $_;
}
}
close $io;
my ($ret_wait) = ($ret = $?);
if (-1 == $ret)
{
ohno clr([_ERROR_COLOR], "failed to fork or wait for child: $!");
}
elsif ($ret & 127)
{
my $sig = sprintf "%d", $ret & 127;
ohno clr([_ERROR_COLOR], "child died with signal $sig");
}
else
{
$ret >>= 8;
if ($VERBOSITY > 1)
{
sinfo "child terminated:";
sinfo _TAB . "returned $ret ($ret_wait)";
}
}
# scalar context just returns the exit value of the command; list context will
# return (in order): the cmd exit value, the wait(2) syscall return value, and
# a list containing each line output from the command (STDOUT -and- STDERR)
return
wantarray ? ($ret, $ret_wait, @out) : $ret;
}
sub subshell_cmd
{
# same as sub shell_cmd{}, but encloses command in parens "(...)" so that you
# can safely navigate the fs, prepare env, etc. without affecting the current
# environment in which this script is executing. if you `cd` somewhere, the
# subshell will exit when finished -- leaving PWD unchanged
return 0 unless 0 < @_;
my ($cmd) = do { local $" = q| |; "( @_ )" };
my ($ret_s, @ret_l);
sinfo "spawning subshell ...(" if $VERBOSITY > 0;
{
if (wantarray) { @ret_l = shell_cmd $cmd }
else { $ret_s = shell_cmd $cmd }
}
sinfo ")... returned from subshell" if $VERBOSITY > 0;
return
wantarray ? @ret_l : $ret_s;
}
sub compress_archive
{
my ($archive, $scheme, $extension, $prefix_name, $prefix_version) = @_;
my $file_path = "${archive}${extension}";
my $archive_prefix = $prefix_name;
$archive_prefix .= " $prefix_version"
if defined $prefix_version and length trim($prefix_version) > 0;
sinfo "compressing archive ($scheme):";
sinfo _TAB . "$file_path";
if ($scheme eq "zip")
{
ohno clr([_ERROR_COLOR], 'cannot create Zip archive: system utility "zip" not found')
unless 0 == system 'type -t tar 2>&1 > /dev/null';
my $archive_path = dirname $archive;
my $archive_name = basename $archive;
# bizarre bug: zip will not actually operate unless it can print messages to
# stdout (or if operating in --quiet|-q mode). and since we don't read from
# stdout outside of $VERBOSITY > 1, zip fails to commence...
my $qflag = $VERBOSITY > 1 ? '' : 'q';
subshell_cmd
"cd '$archive_path'; ".
"mv '$archive_name' '$archive_prefix'; ".
"zip -${qflag}r '$file_path' '$archive_prefix'; ".
"mv '$archive_prefix' '$archive_name'; ".
"";
}
elsif ($scheme eq "gzip" or $scheme eq "bzip2")
{
ohno clr([_ERROR_COLOR], 'cannot create tar archive: system utility "tar" not found')
unless 0 == system 'type -t tar 2>&1 > /dev/null';
my $zflag; # compression flag passed to tar
if ($scheme eq "gzip")
{
ohno clr([_ERROR_COLOR], 'cannot create GZip archive: system utility "gzip" not found')
unless 0 == system 'type -t gzip 2>&1 > /dev/null';
$zflag = 'z';
}
elsif ($scheme eq "bzip2")
{
ohno clr([_ERROR_COLOR], 'cannot create BZip2 archive: system utility "bzip2" not found')
unless 0 == system 'type -t bzip2 2>&1 > /dev/null';
$zflag = 'j';
}
my $archive_path = dirname $archive;
my $archive_name = basename $archive;
subshell_cmd
"cd '$archive_path'; ".
"mv '$archive_name' '$archive_prefix'; ".
"tar -c${zflag}vf '$file_path' '$archive_prefix'; ".
"mv '$archive_prefix' '$archive_name'; ".
"";
}
return $file_path;
}
sub header_line
{
my ($width, $title, $text_color) = @_;
my $line = "=" x max _MIN_ROW_WIDTH, $width; $title = " $title ";
substr($line, 3, length $title) = $title;
$line =~
s/^\s*(=+ )(.+)( =+)\s*$/
clr([_HEADER_COLOR], $1) .
clr([$text_color], $2) .
clr([_HEADER_COLOR], $3)
/e;
return $line;
}
sub get_description_for_family
{
my ($family) = @_;
for my $desc (keys %DEVICE_FAMILY)
{
my @f = @{$DEVICE_FAMILY{$desc}};
return $desc if $family =~ $f[1];
}
}
sub get_family_for_description
{
my ($desc) = @_;
return ${$DEVICE_FAMILY{q|iPod/iPhone|}}[0]
if $desc =~ ${$DEVICE_FAMILY{q|iPod/iPhone|}}[2];
return ${$DEVICE_FAMILY{q|iPad|}}[0]
if $desc =~ ${$DEVICE_FAMILY{q|iPad|}}[2];
return ${$DEVICE_FAMILY{q|Universal|}}[0]
if $desc =~ ${$DEVICE_FAMILY{q|Universal|}}[2];
return ${$DEVICE_FAMILY{q|Apple TV|}}[0]
if $desc =~ ${$DEVICE_FAMILY{q|Apple TV|}}[2];
return ${$DEVICE_FAMILY{q|Apple Watch|}}[0]
if $desc =~ ${$DEVICE_FAMILY{q|Apple Watch|}}[2];
}
sub get_sdk_for_family_osversion
{
my ($family, $osversion, @sdk) = @_;
if ($VERBOSITY > 0)
{
sinfo "identifying SDK for target family and OS";
{
local $/;
sinfo _TAB . "$family $osversion";
}
}
# do some sanitation on the family strings
$family =~ s/^.*(ip[ao]d|universal).*$/iphone/i; # iPod/iPad/iPhone all use the iPhone SDK
$family =~ s/^.*tv.*$/tv/i;
$family =~ s/^.*watch.*$/watch/i;
sub matched
{
my ($match, $exact) = @_;
my $sdkvalue = join "", @{$match};
pout " -> $sdkvalue" . ($exact ? "" : " (*)")
if $VERBOSITY > 0;
return $sdkvalue;
}
if (my ($match) = grep { join("", @{$_}) =~ /${family}.*${osversion}$/i } @sdk)
{
# found exact match
return matched($match, 1);
}
else
{
my ($match) = first { ${$_}[0] =~ /$family/i } @sdk;
return matched($match, 0) if defined $match;
}
return undef;
}
sub get_devices
{
my ($device) = @_;
my ($io, $curr, %result);
sinfo "parsing devices from xcrun"
if $VERBOSITY > 0;
open $io, "-|", 'xcrun simctl list devices'
or ohno clr([_ERROR_COLOR], 'could not open pipe for "xcrun": ' . $!);
$curr = undef;
while (<$io>)
{
next if 1 == $.;
next if /^-- Unavailable:/;
($result{($curr = $1)} = []), next if (/^-- (.+) --$/);
my ($name, $udid, $stat) =
/^\s+(.+)\s+\(([0-9A-F]+-[0-9A-F]+-[0-9A-F]+-[0-9A-F]+-[0-9A-F]+)\)\s+(\s*\(.+\))+$/g;
next if $stat =~ /unavailable/i;
if (defined $device)
{
next unless any { /$device/i } $curr, $name, $udid, $stat;
}
$stat = join "|", map { s/[()]//g; $_ } $stat =~ /\([^)]+\)/g;
push @{$result{$curr}}, [ $name, $udid, $stat ];
}
close $io;
# remove the device types that have no available devices
%result = map { $_ => $result{$_} } grep { 0 < @{$result{$_}} } keys %result;
return %result;
}
sub get_device_types
{
my ($device_type) = @_;
my ($io, %result);
sinfo "parsing devicetypes from xcrun"
if $VERBOSITY > 0;
open $io, "-|", 'xcrun simctl list devicetypes'
or ohno clr([_ERROR_COLOR], 'could not open pipe for "xcrun": ' . $!);
while (<$io>)
{
next if 1 == $.;
my ($desc, $name) = /^\s*(.+)\s+\(([^)]+)\)\s*$/g;
if (defined $device_type)
{
next unless any { /$device_type/i } $desc, $name;
}
$result{$name} = $desc;
}
close $io;
return %result;
}
sub get_runtimes
{
my ($runtime) = @_;
my ($io, %result);
sinfo "parsing runtimes from xcrun"
if $VERBOSITY > 0;
open $io, "-|", 'xcrun simctl list runtimes'
or ohno clr([_ERROR_COLOR], 'could not open pipe for "xcrun": ' . $!);
while (<$io>)
{
next if 1 == $.;
my ($desc, $version, $build, $name) =
/^\s*(.+)\s+\(([^)]+)\s+-\s+([^)]+)\)\s+-\s+(\S+)\s*$/;
if (defined $runtime)
{
next unless any { /$runtime/i } $desc, $version, $build, $name;
}
$result{$name} = [ $desc, $build ];
}
close $io;
return %result;
}
sub get_sdks
{
my ($sdk) = @_;
my ($io, $curr, %result);
sinfo "parsing SDKs from xcodebuild"
if $VERBOSITY > 0;
open $io, "-|", 'xcodebuild -showsdks'
or ohno clr([_ERROR_COLOR], 'could not open pipe for "xcodebuild": ' . $!);
$curr = undef;
while (<$io>)
{
if (/^(.+) SDKs:/)
{
$curr = $1;
$result{$curr} = [];
}
elsif (defined $curr)
{
if (my ($version, $ident) = /^\s+.+?([\d\.]+)\s+-sdk\s+(\S+)\1\s*$/)
{
if (defined $sdk)
{
next unless any { /$sdk/i } $curr, $version, $ident;
}
push @{$result{$curr}}, [ $ident, $version ];
}
}
}
close $io;
return %result;
}
sub get_project_settings
{
my ($pbxproj_path) = @_;
ohno clr([_ERROR_COLOR], 'cannot parse project file: system utility "plutil" not found')
unless 0 == system 'type -t plutil 2>&1 > /dev/null';
sinfo "converting project file to XML"
if $VERBOSITY > 0;
my $project_xml = `plutil -convert xml1 -o - '$pbxproj_path'`;
sinfo "parsing project data"
if $VERBOSITY > 0;
my $project_data = parse_plist($project_xml);
my %project_key = %{${$project_data->as_perl}{objects}};
my %project_key_type;
for my $key (keys %project_key)
{
$project_key_type{$project_key{$key}{isa}} = []
unless exists $project_key_type{$project_key{$key}{isa}};
push @{$project_key_type{$project_key{$key}{isa}}}, $key;
}
my @build_config;
for my $scheme (@{$project_key_type{PBXNativeTarget}})
{
my $scheme_name = ${$project_key{$scheme}}{name};
my $config_list = ${$project_key{$scheme}}{buildConfigurationList};
for my $build_config (@{${$project_key{$config_list}}{buildConfigurations}})
{
my $config_name = ${$project_key{$build_config}}{name};
my %config_settings = %{${$project_key{$build_config}}{buildSettings}};
my $desc_name = sprintf '%s, %s', $scheme_name, $config_name;
my $desc_prop = sprintf 'osversion="%s";family="%s";codesign="%s";ident="%s";bundle="%s";profile="%s";profilespec="%s";team="%s"',
$config_settings{IPHONEOS_DEPLOYMENT_TARGET},
sprintf("%s (%s)",
get_description_for_family($config_settings{TARGETED_DEVICE_FAMILY}),
$config_settings{TARGETED_DEVICE_FAMILY}),
$config_settings{CODE_SIGN_STYLE},
$config_settings{CODE_SIGN_IDENTITY},
$config_settings{PRODUCT_BUNDLE_IDENTIFIER},
$config_settings{PROVISIONING_PROFILE},
$config_settings{PROVISIONING_PROFILE_SPECIFIER},
$config_settings{DEVELOPMENT_TEAM};
push @build_config,
{
_DESC_NAME => $desc_name,
_DESC_PROP => $desc_prop,
_SCHEME => $scheme_name,
_CONFIG => $config_name,
os_version => $config_settings{IPHONEOS_DEPLOYMENT_TARGET},
family => $config_settings{TARGETED_DEVICE_FAMILY},
codesign_type => $config_settings{CODE_SIGN_STYLE},
codesign_id => $config_settings{CODE_SIGN_IDENTITY},
bundle_id => $config_settings{PRODUCT_BUNDLE_IDENTIFIER},
prov_profile => $config_settings{PROVISIONING_PROFILE},
prov_spec => $config_settings{PROVISIONING_PROFILE_SPECIFIER},
dev_team => $config_settings{DEVELOPMENT_TEAM},
};
}
}
@build_config = sort { ${$a}{_DESC_NAME} cmp ${$b}{_DESC_NAME} } @build_config;
}
sub set_app_version
{
my ($proj_path, $version, $build) = @_;
my $proj_plist =
catpath
dirname($proj_path),
rmfileext(basename($proj_path)),
"Info.plist";
ohno clr([_ERROR_COLOR], 'cannot parse project file: system utility "plutil" not found')
unless 0 == system 'type -t plutil 2>&1 > /dev/null';
if (defined $version and length trim($version) > 0)
{
if ($VERBOSITY > 0)
{
sinfo "setting Info.plist key:";
sinfo _TAB . "CFBundleShortVersionString = $version";
}
my $exec_retcode =
shell_cmd
"plutil ".
"-replace CFBundleShortVersionString ".
"-string '$version' ".
"'$proj_plist' ".
"";
if (0 != $exec_retcode)
{
ohno clr([_ERROR_COLOR], "failed to change project version string, re-run with verbose>=2 (-vv) to view plutil log");
}
}
if (defined $build and length trim($build) > 0)
{
if ($VERBOSITY > 0)
{
sinfo "setting Info.plist key:";
sinfo _TAB . "CFBundleVersion = $build";
}
my $exec_retcode =
shell_cmd
"plutil ".
"-replace CFBundleVersion ".
"-string '$build' ".
"'$proj_plist' ".
"";
if (0 != $exec_retcode)
{
ohno clr([_ERROR_COLOR], "failed to change project build string, re-run with verbose>=2 (-vv) to view plutil log");
}
}
}
sub get_app_version
{
my ($proj_path) = @_;
my $proj_plist =
catpath
dirname($proj_path),
rmfileext(basename($proj_path)),
"Info.plist";
my $app_data = parse_plist_file($proj_plist)->as_perl;
my $app_version = "";
$app_version .= "${$app_data}{CFBundleShortVersionString}"
if exists ${$app_data}{CFBundleShortVersionString};
$app_version .= " ${$app_data}{CFBundleVersion}"
if exists ${$app_data}{CFBundleVersion};
return $app_version;
}
# ======================================================================================================================
# PARSE COMMAND LINE ARGUMENTS
# ======================================================================================================================
my ( $cloHelp, $cloHelpMore, $cloVerbose, $cloList, $cloProject,
$cloDevice, $cloDevType, $cloRuntime,
$cloOutput, $cloOutputFormat, $cloSource, $cloCompress, $cloXcodeConf, $cloAppVersion, $cloAppBuild, $cloSDK, $cloFamily, $cloOSVersion, $cloScheme, $cloConfig, $cloBundle, $cloDevTeam, $cloProfile );
final usage unless @ARGV > 0;
GetOptions(
"help|h|?!" => \$cloHelp,
"helpmore|H!" => \$cloHelpMore,
"verbose|v+" => \$cloVerbose,
"list|l!" => \$cloList,
"project|p=s" => \$cloProject,
"device|d:s" => \$cloDevice,
"devtype|t:s" => \$cloDevType,
"runtime|r:s" => \$cloRuntime,
"output|o=s" => \$cloOutput,
"outputformat|O:s" => \$cloOutputFormat,
"source|S=s" => \$cloSource,
"compress|z:s" => \$cloCompress,
"xcodeconf|X=s" => \$cloXcodeConf,
"appversion|V=s" => \$cloAppVersion,
"appbuild|B=s" => \$cloAppBuild,
"sdk|k:s" => \$cloSDK,
"family|a=s" => \$cloFamily,
"osversion|e=s" => \$cloOSVersion,
"scheme|s=s" => \$cloScheme,
"config|c=s" => \$cloConfig,
"bundle|b=s" => \$cloBundle,
"devteam|m=s" => \$cloDevTeam,
"profile|i=s" => \$cloProfile,
) or quit;
final usage(defined $cloHelpMore)
if defined $cloHelp or defined $cloHelpMore;
$VERBOSITY = $cloVerbose if defined $cloVerbose;
ohno clr([_ERROR_COLOR], 'cannot control simulator tools: system utility "xcrun" not found')
unless 0 == system 'type -t xcrun 2>&1 > /dev/null';
ohno clr([_ERROR_COLOR], 'cannot control build tools: system utility "xcodebuild" not found')
unless 0 == system 'type -t xcodebuild 2>&1 > /dev/null';
my $row_width = $ROW_WIDTH_MIN;
if (defined $cloList)
{
# ======================================================================================================================
# CONFIGURATION LISTINGS
# ======================================================================================================================
# ------------------------------------------------------------------------------
# PARSE SDK/RUNTIME SETTINGS
# ------------------------------------------------------------------------------
my %device = get_devices($cloDevice || ".");
my %devtype = get_device_types($cloDevType || ".");
my %runtime = get_runtimes($cloRuntime || ".");
my %sdk = get_sdks($cloSDK || ".");
my $reduced_listing = any { defined } $cloDevice, $cloDevType, $cloRuntime, $cloSDK
, $cloProject
;
my $have_devices = keys %device > 0;
my $list_devices = (not $reduced_listing or defined $cloDevice);
my $have_devtypes = keys %devtype > 0;
my $list_devtypes = (not $reduced_listing or defined $cloDevType);
my $have_runtimes = keys %runtime > 0;
my $list_runtimes = (not $reduced_listing or defined $cloRuntime);
my $have_sdks = keys %sdk > 0;
my $list_sdks = (not $reduced_listing or defined $cloSDK);
# ------------------------------------------------------------------------------
# CALCULATE COLUMN WIDTHS
# ------------------------------------------------------------------------------
my $device_os_width = ($have_devices and $list_devices)
? max map { length } keys %device : 0;
my $device_name_width = ($have_devices and $list_devices)
? max map { map { length ${$_}[0] || 0 } @{$_} } values %device : 0;
my $device_udid_width = ($have_devices and $list_devices)
? max map { map { length ${$_}[1] || 0 } @{$_} } values %device : 0;
my $device_stat_width = ($have_devices and $list_devices)
? max map { map { length ${$_}[2] || 0 } @{$_} } values %device : 0;
my $devtype_name_width = ($have_devtypes and $list_devtypes)
? max map { length } values %devtype : 0;
my $devtype_spec_width = ($have_devtypes and $list_devtypes)
? max map { length } keys %devtype : 0;
my $runtime_os_width = ($have_runtimes and $list_runtimes)
? max map { length ${$_}[0] || 0 } values %runtime : 0;
my $runtime_build_width = ($have_runtimes and $list_runtimes)
? max map { length ${$_}[1] || 0 } values %runtime : 0;
my $runtime_spec_width = ($have_runtimes and $list_runtimes)
? max map { length } keys %runtime : 0;
my $sdk_name_width = ($have_sdks and $list_sdks)
? max map { length } keys %sdk : 0;
my $sdk_ident_width = ($have_sdks and $list_sdks)
? max map { map { length ${$_}[0] || 0 } @{$_} } values %sdk : 0;
my $sdk_version_width = ($have_sdks and $list_sdks)
? max map { map { length ${$_}[1] || 0 } @{$_} } values %sdk : 0;
my @col_width =
(
max($device_os_width, $runtime_os_width, $sdk_name_width),
max($device_name_width, $devtype_name_width, $runtime_build_width, $sdk_ident_width + $sdk_version_width),
max($device_udid_width, $devtype_spec_width, $runtime_spec_width),
max($device_stat_width),
);
$row_width = max($ROW_WIDTH_MIN,
(length _TAB) +
(@col_width * length _COL_SEP) +
(sum @col_width));
# ------------------------------------------------------------------------------
# LIST AVAILABLE SIMULATOR DEVICES
# ------------------------------------------------------------------------------
if ($list_devices)
{
sinfo header_line $row_width, "DEVICES", "icyan";