-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathxcode.js
834 lines (772 loc) · 26.9 KB
/
xcode.js
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
/**
* Detects Xcode installs and their iOS SDKs.
*
* @module xcode
*
* @copyright
* Copyright (c) 2014-2018 by Appcelerator, Inc. All Rights Reserved.
*
* Copyright (c) 2010-2014 Digital Bazaar, Inc.
* {@link https://github.com/digitalbazaar/forge}
*
* @license
* Licensed under the terms of the Apache Public License.
* Please see the LICENSE included with this distribution for details.
*/
const
appc = require('node-appc'),
async = require('async'),
env = require('./env'),
hash = require('./utilities').hash,
magik = require('./utilities').magik,
fs = require('fs'),
path = require('path'),
readPlist = require('./utilities').readPlist,
simctl = require('./simctl'),
__ = appc.i18n(__dirname).__;
var cache,
detecting = {},
waiting = [];
/**
* A lookup table of valid iOS Simulator -> Watch Simulator pairings.
*
* This table MUST be maintained!
*
* The actual device pairing is done by the CoreSimulator private framework.
* I have no idea how it determines what iOS Simulators are compatible with
* what Watch Simulator. It's a mystery!
*/
const simulatorDevicePairCompatibility = {
'>=6.2 <7.0': { // Xcode 6.2, 6.3, 6.4
'>=8.2 <9.0': { // iOS 8.2, 8.3, 8.4
'1.x': true // watchOS 1.0
}
},
'7.x': { // Xcode 7.x
'>=8.2 <9.0': { // iOS 8.2, 8.3, 8.4
'1.x': true // watchOS 1.0
},
'>=9.0 <=9.2': { // iOS 9.0, 9.1, 9.2
'>=2.0 <=2.1': true // watchOS 2.0, 2.1
},
'>=9.3 <10': { // iOS 9.3
'2.2': true // watchOS 2.2
}
},
'8.x': { // Xcode 8.x
'>=9.0 <=9.2': { // iOS 9.0, 9.1, 9.2
'>=2.0 <=2.1': true // watchOS 2.0, 2.1
},
'>=9.3 <10': { // iOS 9.x
'2.2': true, // watchOS 2.2
'3.x': true // watchOS 3.x
},
'10.x': { // iOS 10.x
'2.2': true, // watchOS 2.2
'3.x': true // watchOS 3.x
}
},
'9.x': { // Xcode 9.x
'>=9.0 <=9.2': { // iOS 9.0, 9.1, 9.2
'>=2.0 <=2.1': true // watchOS 2.0, 2.1
},
'>=9.3 <10': { // iOS 9.x
'2.2': true, // watchOS 2.2
'3.x': true // watchOS 3.x
},
'10.x': { // iOS 10.x
'2.2': true, // watchOS 2.2
'3.x': true // watchOS 3.x
},
'11.x': { // iOS 11.x
'>=3.2 <4.0': true, // watchOS 3.2
'4.x': true // watchOS 4.x
}
},
'10.x <10.3': { // Xcode 10.0-10.2.1
'8.x': {}, // iOS 8.x
'>=9.0 <=9.2': { // iOS 9.0, 9.1, 9.2
'>=2.0 <=2.1': true // watchOS 2.0, 2.1
},
'>=9.3 <10': { // iOS 9.x
'2.2': true, // watchOS 2.2
'3.x': true // watchOS 3.x
},
'>=10.0 <=10.2': { // iOS 10.0, 10.1, 10.2
'2.2': true, // watchOS 2.2
'3.x': true // watchOS 3.x
},
'>=10.3 <11': { // iOS 10.3
'3.x': true // watchOS 3.x
},
'11.x': { // iOS 11.x
'>=3.2 <4.0': true, // watchOS 3.2
'4.x': true // watchOS 4.x
},
'12.x': { // iOS 12.x
'>=3.2 <4.0': true, // watchOS 3.2
'4.x': true, // watchOS 4.x
'5.x': true // watchOS 5.x
}
},
'>=10.3 <11': {
'>=10.3 <11': { // iOS 10.3
'3.x': true // watchOS 3.x
},
'11.x': { // iOS 11.x
'>=3.2 <4.0': true, // watchOS 3.2
'4.x': true // watchOS 4.x
},
'12.x': { // iOS 12.x
'4.x': true, // watchOS 4.x
'5.x': true // watchOS 5.x
}
},
'11.x': { // Xcode 11.x
'>=10.3 <11': { // iOS 10.3
'2.2': true, // watchOS 2.2
'3.x': true // watchOS 3.x
},
'11.x': { // iOS 11.x
'>=3.2 <4.0': true, // watchOS 3.2
'4.x': true // watchOS 4.x
},
'12.x': { // iOS 12.x
'4.x': true, // watchOS 4.x
'5.x': true, // watchOS 5.x
'6.x': true // watchOS 6.x
},
'13.x': { // iOS 13.x
'4.x': true, // watchOS 4.x
'5.x': true, // watchOS 5.x
'6.x': true // watchOS 6.x
}
},
'12.x': { // Xcode 12.x
'>=10.3 <11': { // iOS 10.x
'2.2': true, // watchOS 2.2
'3.x': true // watchOS 3.x
},
'11.x': { // iOS 11.x
'>=3.2 <4.0': true, // watchOS 3.2
'4.x': true // watchOS 4.x
},
'12.x': { // iOS 12.x
'4.x': true, // watchOS 4.x
'5.x': true, // watchOS 5.x
'6.x': true, // watchOS 6.x
'7.x': true // watchOS 7.x
},
'13.x': { // iOS 13.x
'4.x': true, // watchOS 4.x
'5.x': true, // watchOS 5.x
'6.x': true, // watchOS 6.x
'7.x': true // watchOS 7.x
},
'14.x': { // iOS 14.x
'4.x': true, // watchOS 4.x
'5.x': true, // watchOS 5.x
'6.x': true, // watchOS 6.x
'7.x': true // watchOS 7.x
}
},
'13.x': { // Xcode 13.x
'>=10.3 <11': { // iOS 10.x
'2.2': true, // watchOS 2.2
'3.x': true // watchOS 3.x
},
'11.x': { // iOS 11.x
'>=3.2 <4.0': true, // watchOS 3.2
'4.x': true // watchOS 4.x
},
'12.x': { // iOS 12.x
'4.x': true, // watchOS 4.x
'5.x': true, // watchOS 5.x
'6.x': true, // watchOS 6.x
'7.x': true, // watchOS 7.x
'8.x': true // watchOS 8.x
},
'13.x': { // iOS 13.x
'4.x': true, // watchOS 4.x
'5.x': true, // watchOS 5.x
'6.x': true, // watchOS 6.x
'7.x': true, // watchOS 7.x
'8.x': true // watchOS 8.x
},
'14.x': { // iOS 14.x
'4.x': true, // watchOS 4.x
'5.x': true, // watchOS 5.x
'6.x': true, // watchOS 6.x
'7.x': true, // watchOS 7.x
'8.x': true // watchOS 8.x
},
'15.x': {
'4.x': true, // watchOS 4.x
'5.x': true, // watchOS 5.x
'6.x': true, // watchOS 6.x
'7.x': true, // watchOS 7.x
'8.x': true // watchOS 8.x
}
},
'14.x': { // Xcode 14.x
'12.x': { // iOS 12.x
'7.x': true, // watchOS 7.x
'8.x': true, // watchOS 8.x
'9.x': true // watchOS 9.x
},
'13.x': { // iOS 13.x
'7.x': true, // watchOS 7.x
'8.x': true, // watchOS 8.x
'9.x': true // watchOS 9.x
},
'14.x': { // iOS 14.x
'7.x': true, // watchOS 7.x
'8.x': true, // watchOS 8.x
'9.x': true // watchOS 9.x
},
'15.x': {
'7.x': true, // watchOS 7.x
'8.x': true, // watchOS 8.x
'9.x': true // watchOS 9.x
},
'16.x': {
'7.x': true, // watchOS 7.x
'8.x': true, // watchOS 8.x
'9.x': true // watchOS 9.x
}
},
'15.x': { // Xcode 15.x
'13.x': { // iOS 13.x
'7.x': true, // watchOS 7.x
'8.x': true, // watchOS 8.x
'9.x': true, // watchOS 9.x
'10.x': true // watchOS 10.x
},
'14.x': { // iOS 14.x
'7.x': true, // watchOS 7.x
'8.x': true, // watchOS 8.x
'9.x': true, // watchOS 9.x
'10.x': true // watchOS 10.x
},
'15.x': {
'7.x': true, // watchOS 7.x
'8.x': true, // watchOS 8.x
'9.x': true, // watchOS 9.x
'10.x': true // watchOS 10.x
},
'16.x': {
'7.x': true, // watchOS 7.x
'8.x': true, // watchOS 8.x
'9.x': true, // watchOS 9.x
'10.x': true // watchOS 10.x
},
'17.x': {
'7.x': true, // watchOS 7.x
'8.x': true, // watchOS 8.x
'9.x': true, // watchOS 9.x
'10.x': true // watchOS 10.x
}
},
'16.x': { // Xcode 16.x
'15.x': { // iOS 15.x
'8.x': true, // watchOS 8.x
'9.x': true, // watchOS 9.x
'10.x': true, // watchOS 10.x
'11.x': true, // watchOS 11.x
},
'16.x': { // iOS 16.x
'8.x': true, // watchOS 8.x
'9.x': true, // watchOS 9.x
'10.x': true, // watchOS 10.x
'11.x': true, // watchOS 11.x
},
'17.x': { // iOS 18.x
'8.x': true, // watchOS 8.x
'9.x': true, // watchOS 9.x
'10.x': true, // watchOS 10.x
'11.x': true, // watchOS 11.x
},
'18.x': { // iOS 18.x
'8.x': true, // watchOS 8.x
'9.x': true, // watchOS 9.x
'10.x': true, // watchOS 10.x
'11.x': true, // watchOS 11.x
}
}
};
/**
* Detects Xcode installations.
*
* @param {Object} [options] - An object containing various settings.
* @param {Boolean} [options.bypassCache=false] - When true, re-detects all Xcode installations.
* @param {String|Array<String>} [options.searchPath] - One or more path to scan for Xcode installations.
* @param {String} [options.minTVosVersion] - The minimum AppleTV SDK to detect.
* @param {String} [options.minIosVersion] - The minimum iOS SDK to detect.
* @param {String} [options.minWatchosVersion] - The minimum WatchOS SDK to detect.
* @param {String} [options.sqlite] - Path to the <code>sqlite</code> executable (most likely named sqlite3)
* @param {String} [options.supportedVersions] - A string with a version number or range to check if an Xcode install is supported.
* @param {Function} [callback(err, results)] - A function to call with the Xcode information.
*
* @emits module:xcode#detected
* @emits module:xcode#error
*
* @returns {Handle}
*/
exports.detect = function detect(options, callback) {
var hopt = hash(JSON.stringify(options));
if (detecting[hopt]) {
waiting.push(callback);
return detecting[hopt];
}
return detecting[hopt] = magik(options, callback, function (emitter, options, callback) {
waiting.push(callback);
function fireCallbacks(err, result) {
delete detecting[hopt];
var w;
while (w = waiting.shift()) {
w(err, result);
}
}
if (cache && !options.bypassCache) {
emitter.emit('detected', cache);
return fireCallbacks(null, cache);
}
function findSimRuntimes(dir) {
var runtimes = {};
// regex to extract the version from the runtime name
var runtimeNameRegExp = /\s(\d+(?:\.\d+(?:\.\d+)?)?)$/;
fs.existsSync(dir) && fs.readdirSync(dir).forEach(function (name) {
var x = path.join(dir, name, 'Contents', 'Info.plist');
var plist = readPlist(path.join(dir, name, 'Contents', 'Info.plist'));
if (plist) {
var runtime = runtimes[plist.CFBundleIdentifier] = {
name: plist.CFBundleName,
version: null
};
var m = plist.CFBundleName.match(runtimeNameRegExp);
if (m) {
runtime.version = m[1];
}
plist = readPlist(path.join(dir, name, 'Contents', 'Resources', 'profile.plist'));
if (plist) {
if (!runtime.version || plist.defaultVersionString.startsWith(runtime.version)) {
runtime.version = plist.defaultVersionString;
}
}
}
});
return runtimes;
}
function findSDKs(dir, nameRegExp, minVersion) {
var vers = [];
fs.existsSync(dir) && fs.readdirSync(dir).forEach(function (name) {
var file = path.join(dir, name);
if (!fs.existsSync(file) || !fs.statSync(file).isDirectory()) return;
var m = name.match(nameRegExp);
if (m && (!minVersion || appc.version.gte(m[1], minVersion))) {
var ver = m[1];
file = path.join(file, 'System', 'Library', 'CoreServices', 'SystemVersion.plist');
if (fs.existsSync(file)) {
var p = new appc.plist(file);
if (p.ProductVersion) {
ver = p.ProductVersion;
}
}
vers.push(ver);
}
});
return vers.sort().reverse();
}
function findSims(dir, sdkRegExp, simRuntimeRegExp, minVer, xcodeVer) {
var vers = findSDKs(dir, sdkRegExp),
simRuntimesDir = '/Library/Developer/CoreSimulator/Profiles/Runtimes';
// for Xcode >=6.2 <7.0, the simulators are in a global directory
if (fs.existsSync(simRuntimesDir) && (!xcodeVer || appc.version.gte(xcodeVer, '6.2'))) {
fs.readdirSync(simRuntimesDir).forEach(function (name) {
var file = path.join(simRuntimesDir, name);
if (!fs.existsSync(file) || !fs.statSync(file).isDirectory()) return;
var m = name.match(simRuntimeRegExp);
if (m && (!minVer || appc.version.gte(m[1], minVer))) {
var ver = m[1];
file = path.join(file, 'Contents', 'Resources', 'RuntimeRoot', 'System', 'Library', 'CoreServices', 'SystemVersion.plist');
if (fs.existsSync(file)) {
var p = new appc.plist(file);
if (p.ProductVersion) {
ver = p.ProductVersion;
}
}
if (vers.indexOf(ver) === -1) {
vers.push(ver);
}
}
});
}
return vers.sort().reverse();
}
var searchPaths = {
'/Applications': 1,
'~/Applications': 1
},
results = {
selectedXcode: null,
xcode: {},
iosSDKtoXcode: {},
issues: []
},
selectedXcodePath = null,
globalSimRuntimes = findSimRuntimes('/Library/Developer/CoreSimulator/Profiles/Runtimes'),
xcodes = [];
async.series([
// build the list of searchPaths
function detectOSXenv(next) {
env.detect(options, function (err, env) {
(Array.isArray(options.searchPath) ? options.searchPath : [ options.searchPath ]).forEach(function (p) {
p && (searchPaths[p] = 1);
});
// resolve each of the paths
Object.keys(searchPaths).forEach(function (p) {
delete searchPaths[p];
searchPaths[appc.fs.resolvePath(p)] = 1;
});
if (err || !env.executables.xcodeSelect) {
return next();
}
appc.subprocess.run(env.executables.xcodeSelect, '--print-path', function (code, out, err) {
if (!err) {
searchPaths[selectedXcodePath = out.trim()] = 1;
}
next();
});
});
},
function findXcodes(next) {
// scan all searchPaths for Xcode installs
Object.keys(searchPaths).forEach(function (p) {
if (fs.existsSync(p) && fs.statSync(p).isDirectory()) {
// is this directory an Xcode dev dir?
if (/\/Contents\/Developer\/?$/.test(p) && fs.existsSync(path.join(p, 'usr', 'bin', 'xcodebuild')) && xcodes.indexOf(p) === -1) {
xcodes.push(p)
} else {
// is it the Xcode dir?
var devDir = path.join(p, 'Contents', 'Developer');
if (fs.existsSync(path.join(devDir, 'usr', 'bin', 'xcodebuild')) && xcodes.indexOf(devDir) === -1) {
xcodes.push(devDir);
} else {
// possibly a parent folder, scan for Xcodes
fs.readdirSync(p).forEach(function (name) {
var dir = path.join(p, name, 'Contents', 'Developer');
if (xcodes.indexOf(dir) === -1 && fs.existsSync(path.join(dir, 'usr', 'bin', 'xcodebuild'))) {
xcodes.push(dir);
}
});
}
}
}
});
next();
},
function loadXcodeInfo(next) {
async.eachSeries(xcodes, function (dir, cb) {
var p = new appc.plist(path.join(path.dirname(dir), 'version.plist')),
version = p.CFBundleShortVersionString,
selected = dir == selectedXcodePath,
supported = options.supportedVersions ? appc.version.satisfies(version, options.supportedVersions, true) : true,
id = version + ':' + p.ProductBuildVersion,
f;
if (results.xcode[id] && !selected && dir > results.xcode[id].path) {
return cb();
}
var watchos = null;
if (appc.version.gte(version, '7.0')) {
watchos = {
sdks: findSDKs(path.join(dir, 'Platforms', 'WatchOS.platform', 'Developer', 'SDKs'), /^WatchOS(.+)\.sdk$/, options.minWatchosVersion),
sims: []
};
} else if (appc.version.gte(version, '6.2')) {
watchos = {
sdks: ['1.0'],
sims: ['1.0']
};
}
var tvos = {
sdks: findSDKs(path.join(dir, 'Platforms', 'AppleTVOS.platform', 'Developer', 'SDKs'), /^AppleTVOS(.+)\.sdk$/, options.minTVosVersion),
sims: [] // nobody cares
};
var xc = results.xcode[id] = {
xcodeapp: dir.replace(/\/Contents\/Developer\/?$/, ''),
path: dir,
selected: selected,
version: version,
build: p.ProductBuildVersion,
supported: supported,
eulaAccepted: false,
sdks: findSDKs(path.join(dir, 'Platforms', 'iPhoneOS.platform', 'Developer', 'SDKs'), /^iPhoneOS(.+)\.sdk$/, options.minIosVersion),
sims: [],
simDeviceTypes: {},
simRuntimes: {},
simDevicePairs: {},
watchos: watchos,
tvos: tvos,
teams: {},
executables: {
xcodebuild: fs.existsSync(f = path.join(dir, 'usr', 'bin', 'xcodebuild')) ? f : null,
clang: fs.existsSync(f = path.join(dir, 'Toolchains', 'XcodeDefault.xctoolchain', 'usr', 'bin', 'clang')) ? f : null,
clang_xx: fs.existsSync(f = path.join(dir, 'Toolchains', 'XcodeDefault.xctoolchain', 'usr', 'bin', 'clang++')) ? f : null,
libtool: fs.existsSync(f = path.join(dir, 'Toolchains', 'XcodeDefault.xctoolchain', 'usr', 'bin', 'libtool')) ? f : null,
lipo: fs.existsSync(f = path.join(dir, 'Toolchains', 'XcodeDefault.xctoolchain', 'usr', 'bin', 'lipo')) ? f : null,
otool: fs.existsSync(f = path.join(dir, 'Toolchains', 'XcodeDefault.xctoolchain', 'usr', 'bin', 'otool')) ? f : null,
pngcrush: fs.existsSync(f = path.join(dir, 'Platforms', 'iPhoneOS.platform', 'Developer', 'usr', 'bin', 'pngcrush')) ? f : null,
simulator: null,
watchsimulator: null,
simctl: fs.existsSync(f = path.join(dir, 'usr', 'bin', 'simctl')) ? f : null
}
};
Object.keys(simulatorDevicePairCompatibility).some(function (xcodeRange) {
if (appc.version.satisfies(xc.version, xcodeRange)) {
xc.simDevicePairs = simulatorDevicePairCompatibility[xcodeRange];
// use the device pair compatibility to see if the simruntime is supported by
// this Xcode as there isn't a way to programmatically do it
Object.keys(globalSimRuntimes).forEach(function (runtime) {
Object.keys(xc.simDevicePairs).forEach(function (iosRange) {
if (/iOS/.test(runtime) && appc.version.satisfies(globalSimRuntimes[runtime].version, iosRange)) {
xc.simRuntimes[runtime] = globalSimRuntimes[runtime];
} else if (/watchOS/.test(runtime)) {
// scan all iOS versions
Object.keys(xc.simDevicePairs[iosRange]).forEach(function (watchosRange) {
if (appc.version.satisfies(globalSimRuntimes[runtime].version, watchosRange)) {
xc.simRuntimes[runtime] = globalSimRuntimes[runtime];
}
});
}
});
});
return true;
}
});
var deviceTypesPaths = [
path.join(xc.path, 'Platforms', 'iPhoneSimulator.platform', 'Developer', 'Library', 'CoreSimulator', 'Profiles'),
path.join(xc.path, 'Platforms', 'WatchSimulator.platform', 'Developer', 'Library', 'CoreSimulator', 'Profiles'),
// Xcode 9 moved CoreSimulator into the "OS" directory instead of the "Simulator" directory
path.join(xc.path, 'Platforms', 'iPhoneOS.platform', 'Developer', 'Library', 'CoreSimulator', 'Profiles'),
path.join(xc.path, 'Platforms', 'WatchOS.platform', 'Developer', 'Library', 'CoreSimulator', 'Profiles'),
// Xcode 11 moved CoreSimulator into the "Library/Developer" directory instead of the "Developer/Library" directory
path.join(xc.path, 'Platforms', 'iPhoneOS.platform', 'Library', 'Developer', 'CoreSimulator', 'Profiles'),
path.join(xc.path, 'Platforms', 'WatchOS.platform', 'Library', 'Developer', 'CoreSimulator', 'Profiles')
];
deviceTypesPaths.forEach(function (deviceTypePath) {
// read in the device types
var deviceTypesDir = path.join(deviceTypePath, 'DeviceTypes');
fs.existsSync(deviceTypesDir) && fs.readdirSync(deviceTypesDir).forEach(function (name) {
var plist = readPlist(path.join(deviceTypesDir, name, 'Contents', 'Info.plist')),
devId = plist && plist.CFBundleIdentifier;
if (plist) {
var deviceType = xc.simDeviceTypes[devId] = {
name: plist.CFBundleName,
model: 'unknown',
supportsWatch: false
};
plist = readPlist(path.join(deviceTypesDir, name, 'Contents', 'Resources', 'profile.plist'));
if (plist) {
deviceType.model = plist.modelIdentifier;
}
plist = readPlist(path.join(deviceTypesDir, name, 'Contents', 'Resources', 'capabilities.plist'));
if (plist) {
deviceType.supportsWatch = !!plist.capabilities['watch-companion'];
}
}
});
simctl.listDevices({ simctl: xc.executables.simctl }, function (err, info) {
if (err) {
return next(err);
}
// Map the platform and version from CoreSimulator string like:
// - com.apple.CoreSimulator.SimRuntime.iOS-17-0
// - com.apple.CoreSimulator.SimRuntime.watchOS-10-0
for (const key of Object.keys(info.devices)) {
const [_, platform, rawVersion] = key.match(/\.SimRuntime\.(.*?)\-(.*)$/);
const version = rawVersion.replace(/-/g, '.');
const mapping = {
name: `${platform} ${version}`,
version
}
appc.util.mix(xc.simRuntimes, { [key]: mapping });
}
});
});
['Simulator', 'iOS Simulator'].some(function (name) {
var p = path.join(dir, 'Applications', name + '.app', 'Contents', 'MacOS', name);
if (fs.existsSync(p)) {
xc.executables.simulator = p;
return true;
}
});
if (appc.version.gte(xc.version, 9)) {
xc.executables.watchsimulator = xc.executables.simulator;
} else {
var watchsim = path.join(dir, 'Applications', 'Simulator (Watch).app', 'Contents', 'MacOS', 'Simulator (Watch)');
if (fs.existsSync(watchsim)) {
xc.executables.watchsimulator = watchsim;
}
}
// determine the compatible sims
simctl.list({ simctl: xc.executables.simctl }, function (err, info) {
if (err) {
return next(err);
}
var rtRegExp = /(iOS|watchOS)-(.+)$/;
Object.keys(info.devices).forEach(function (rt) {
var m = rt.match(rtRegExp);
if (m) {
var dest = m[1] === 'iOS' ? xc.sims : xc.watchos.sims;
var ver = m[2].replace(/-/g, '.');
if (dest.indexOf(ver) === -1) {
dest.push(ver);
}
}
});
xc.sims.sort();
xc.watchos.sims.sort();
selected && (results.selectedXcode = xc);
if (supported === false) {
results.issues.push({
id: 'IOS_XCODE_TOO_OLD',
type: 'warning',
message: __('Xcode %s is too old and is no longer supported.', '__' + version + '__') + '\n' +
__('The minimum supported Xcode version is Xcode %s.', appc.version.parseMin(options.supportedVersions)),
xcodeVer: version,
minSupportedVer: appc.version.parseMin(options.supportedVersions)
});
} else if (supported === 'maybe') {
results.issues.push({
id: 'IOS_XCODE_TOO_NEW',
type: 'warning',
message: __('Xcode %s may or may not work as expected.', '__' + version + '__') + '\n' +
__('The maximum supported Xcode version is Xcode %s.', appc.version.parseMax(options.supportedVersions, true)),
xcodeVer: version,
maxSupportedVer: appc.version.parseMax(options.supportedVersions, true)
});
}
appc.subprocess.run(xc.executables.xcodebuild, [ '-checkFirstLaunchStatus' ], function (code, out, err) {
xc.eulaAccepted = (code === 0);
cb();
});
});
}, next);
},
function findTeams(next) {
appc.subprocess.findExecutable([options.sqlite, '/usr/bin/sqlite3', '/usr/bin/sqlite', 'sqlite3', 'sqlite'], function (err, sqlite) {
if (err) {
results.issues.push({
id: 'IOS_SQLITE_EXECUTABLE_NOT_FOUND',
type: 'error',
message: __("Unable to find the 'sqlite' or 'sqlite3' executable.")
});
return next();
}
async.each(Object.keys(results.xcode), function (id, cb) {
var xc = results.xcode[id],
dbFile = appc.fs.resolvePath('~/Library/Developer/Xcode/DeveloperPortal ' + xc.version + '.db');
if (!fs.existsSync(dbFile)) {
return cb();
}
appc.subprocess.run(sqlite, [dbFile, '-separator', '|||', 'SELECT ZNAME, ZSTATUS, ZTEAMID, ZTYPE FROM ZTEAM'], function (code, out, err) {
if (!code) {
out.trim().split('\n').forEach(function (line) {
var cols = line.trim().split('|||');
if (cols.length === 4) {
xc.teams[cols[2]] = {
name: cols[0],
status: cols[1] || 'unknown',
type: cols[3]
};
}
});
}
cb();
});
}, next);
});
}
], function () {
if (Object.keys(results.xcode).length) {
var validXcodes = 0,
xcodeIds = Object.keys(results.xcode),
sdkCounter = 0,
simCounter = 0,
eulaNotAccepted = [];
xcodeIds.forEach(function (xcodeId) {
const xc = results.xcode[xcodeId];
xc.sdks.forEach(function (iosVersion) {
if (xc.selected || !results.iosSDKtoXcode[iosVersion]) {
results.iosSDKtoXcode[iosVersion] = xcodeId;
}
});
if (xc.supported) {
// we're counting maybe's as valid
validXcodes++;
}
if (xc.sdks) {
sdkCounter += xc.sdks.length;
}
if (xc.sims) {
simCounter += xc.sims.length;
}
if (!xc.eulaAccepted) {
eulaNotAccepted.push(xc);
}
});
if (eulaNotAccepted.length) {
var message;
if (xcodeIds.length === 1) {
message = __('Xcode EULA has not been accepted.') + '\n' +
__('Launch Xcode and accept the license.');
} else {
message = __('Multiple Xcode versions have not had their EULA accepted:') + '\n' +
eulaNotAccepted.map(function (xc) {
return ' ' + xc.version + ' (' + xc.xcodeapp + ')';
}).join('\n') + '\n' +
__('Launch each Xcode and accept the license.');
}
results.issues.push({
id: 'IOS_XCODE_EULA_NOT_ACCEPTED',
type: 'warning',
message: message
});
}
if (options.supportedVersions && !validXcodes) {
results.issues.push({
id: 'IOS_NO_SUPPORTED_XCODE_FOUND',
type: 'warning',
message: __('There are no supported Xcode installations found.')
});
}
if (!sdkCounter) {
results.issues.push({
id: 'IOS_NO_IOS_SDKS',
type: 'error',
message: __('There are no iOS SDKs found') + '\n' +
__('Launch Xcode and download the mobile support packages.')
});
}
if (!sdkCounter) {
results.issues.push({
id: 'IOS_NO_IOS_SIMS',
type: 'error',
message: __('There are no iOS Simulators found') + '\n' +
__('You can install them from the Xcode Preferences > Downloads tab.')
});
}
} else {
results.issues.push({
id: 'IOS_XCODE_NOT_INSTALLED',
type: 'error',
message: __('No Xcode installations found.') + '\n' +
__('You can download it from the %s or from %s.', '__App Store__', '__https://developer.apple.com/xcode/__')
});
}
cache = results;
emitter.emit('detected', results);
return fireCallbacks(null, results);
});
});
};