Skip to content

Commit 7b7d42c

Browse files
Fix exception when checking if xcproj is required
In case Cocoapods version is below 1.0.0 and Xcode version contains only two digits, we fail as semver cannot work with versions with two digits. Append zero to the version, to make it correct semver.
1 parent 8cc3a1a commit 7b7d42c

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

lib/helpers.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ export class Helpers {
2222
return this.hostInfo.isWindows ? this.cmdQuote(value) : this.bashQuote(value);
2323
}
2424

25+
public appendZeroesToVersion(version: string, requiredVersionLength: number): string {
26+
const zeroesToAppend = requiredVersionLength - version.split(".").length;
27+
for (let index = 0; index < zeroesToAppend; index++) {
28+
version += ".0";
29+
}
30+
31+
return version;
32+
}
33+
2534
private bashQuote(s: string): string {
2635
if (s[0] === "'" && s[s.length - 1] === "'") {
2736
return s;

lib/sys-info.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,10 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
313313
public getXcprojInfo(): Promise<NativeScriptDoctor.IXcprojInfo> {
314314
return this.getValueForProperty(() => this.xcprojInfoCache, async (): Promise<NativeScriptDoctor.IXcprojInfo> => {
315315
const cocoaPodsVersion = await this.getCocoaPodsVersion();
316-
const xcodeVersion = await this.getXcodeVersion();
316+
let xcodeVersion = await this.getXcodeVersion();
317+
if (xcodeVersion) {
318+
xcodeVersion = this.helpers.appendZeroesToVersion(xcodeVersion, 3);
319+
}
317320

318321
// CocoaPods with version lower than 1.0.0 don't support Xcode 7.3 yet
319322
// https://github.com/CocoaPods/CocoaPods/issues/2530#issuecomment-210470123

test/sys-info.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,16 @@ describe("SysInfo unit tests", () => {
333333
});
334334
});
335335

336+
describe("getXcprojInfo", () => {
337+
it("does not fail when cocoapods version is below 1.0.0 and Xcode version contains only two digits", async () => {
338+
childProcessResult.podVersion = { result: setStdOut("0.39.0") };
339+
childProcessResult.xCodeVersion = { result: setStdOut("Xcode 8.3") };
340+
sysInfo = mockSysInfo(childProcessResult, { isWindows: false, isDarwin: true, dotNetVersion });
341+
const result = await sysInfo.getXcprojInfo();
342+
assert.deepEqual(result, { shouldUseXcproj: true, xcprojAvailable: false });
343+
});
344+
});
345+
336346
const testData: ICLIOutputVersionTestCase[] = [
337347
{
338348
testedProperty: "nativeScriptCliVersion",

0 commit comments

Comments
 (0)