Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export DEVELOPER_DIR instead of invoking xcode-select to set the active Xcode version #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions __tests__/xcode-selector.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import fs from "fs";
import child from "child_process";
import * as core from "@actions/core";
import { XcodeSelector } from "../src/xcode-selector";
import * as xcodeUtils from "../src/xcode-utils";

jest.mock("child_process");

const fakeGetXcodeVersionInfoResult: xcodeUtils.XcodeVersion[] = [
{ version: "10.3.0", buildNumber: "", path: "/Applications/Xcode_10.3.app", releaseType: "GM", stable: true },
{ version: "12.0.0", buildNumber: "", path: "/Applications/Xcode_12_beta.app", releaseType: "Beta", stable: false },
Expand Down Expand Up @@ -83,7 +80,6 @@ describe("XcodeSelector", () => {
describe("setVersion", () => {
let coreExportVariableSpy: jest.SpyInstance;
let fsExistsSpy: jest.SpyInstance;
let fsSpawnSpy: jest.SpyInstance;
const xcodeVersion: xcodeUtils.XcodeVersion = {
version: "11.4",
buildNumber: "12A7300",
Expand All @@ -95,7 +91,6 @@ describe("XcodeSelector", () => {
beforeEach(() => {
coreExportVariableSpy = jest.spyOn(core, "exportVariable");
fsExistsSpy = jest.spyOn(fs, "existsSync");
fsSpawnSpy = jest.spyOn(child, "spawnSync");
});

afterEach(() => {
Expand All @@ -107,7 +102,8 @@ describe("XcodeSelector", () => {
fsExistsSpy.mockImplementation(() => true);
const sel = new XcodeSelector();
sel.setVersion(xcodeVersion);
expect(fsSpawnSpy).toHaveBeenCalledWith("sudo", ["xcode-select", "-s", "/Applications/Xcode_11.4.app"]);
expect(coreExportVariableSpy).toHaveBeenCalledTimes(2)
expect(coreExportVariableSpy).toHaveBeenCalledWith("DEVELOPER_DIR", "/Applications/Xcode_11.4.app/Contents/Developer");
expect(coreExportVariableSpy).toHaveBeenCalledWith("MD_APPLE_SDK_ROOT", "/Applications/Xcode_11.4.app");
});

Expand Down
17 changes: 6 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.XcodeSelector = void 0;
const child = __importStar(__nccwpck_require__(2081));
const core = __importStar(__nccwpck_require__(2186));
const fs = __importStar(__nccwpck_require__(7147));
const semver = __importStar(__nccwpck_require__(1383));
Expand Down Expand Up @@ -134,7 +133,7 @@ class XcodeSelector {
if (!fs.existsSync(xcodeVersion.path)) {
throw new Error(`Invalid version: Directory '${xcodeVersion.path}' doesn't exist`);
}
child.spawnSync("sudo", ["xcode-select", "-s", xcodeVersion.path]);
core.exportVariable("DEVELOPER_DIR", (0, xcode_utils_1.developerDirPath)(xcodeVersion));
// set "MD_APPLE_SDK_ROOT" environment variable to specify Xcode for Mono and Xamarin
core.exportVariable("MD_APPLE_SDK_ROOT", xcodeVersion.path);
}
Expand Down Expand Up @@ -173,7 +172,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getXcodeVersionInfo = exports.getXcodeReleaseType = exports.getInstalledXcodeApps = exports.parsePlistFile = void 0;
exports.developerDirPath = exports.getXcodeVersionInfo = exports.getXcodeReleaseType = exports.getInstalledXcodeApps = exports.parsePlistFile = void 0;
const path = __importStar(__nccwpck_require__(1017));
const fs = __importStar(__nccwpck_require__(7147));
const core = __importStar(__nccwpck_require__(2186));
Expand Down Expand Up @@ -231,6 +230,10 @@ const getXcodeVersionInfo = (xcodeRootPath) => {
};
};
exports.getXcodeVersionInfo = getXcodeVersionInfo;
const developerDirPath = (xcodeVersion) => {
return path.join(xcodeVersion.path, "Contents", "Developer");
};
exports.developerDirPath = developerDirPath;


/***/ }),
Expand Down Expand Up @@ -14276,14 +14279,6 @@ module.exports = require("assert");

/***/ }),

/***/ 2081:
/***/ ((module) => {

"use strict";
module.exports = require("child_process");

/***/ }),

/***/ 6113:
/***/ ((module) => {

Expand Down
11 changes: 7 additions & 4 deletions src/xcode-selector.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import * as child from "child_process";
import * as core from "@actions/core";
import * as fs from "fs";
import * as semver from "semver";
import { getInstalledXcodeApps, getXcodeVersionInfo, XcodeVersion } from "./xcode-utils";
import {
developerDirPath,
getInstalledXcodeApps,
getXcodeVersionInfo,
XcodeVersion,
} from "./xcode-utils";

export class XcodeSelector {
public getAllVersions(): XcodeVersion[] {
Expand Down Expand Up @@ -47,8 +51,7 @@ export class XcodeSelector {
if (!fs.existsSync(xcodeVersion.path)) {
throw new Error(`Invalid version: Directory '${xcodeVersion.path}' doesn't exist`);
}

child.spawnSync("sudo", ["xcode-select", "-s", xcodeVersion.path]);
core.exportVariable("DEVELOPER_DIR", developerDirPath(xcodeVersion));

// set "MD_APPLE_SDK_ROOT" environment variable to specify Xcode for Mono and Xamarin
core.exportVariable("MD_APPLE_SDK_ROOT", xcodeVersion.path);
Expand Down
4 changes: 4 additions & 0 deletions src/xcode-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ export const getXcodeVersionInfo = (xcodeRootPath: string): XcodeVersion | null
path: xcodeRootPath,
} as XcodeVersion;
};

export const developerDirPath = (xcodeVersion: XcodeVersion): string => {
return path.join(xcodeVersion.path, "Contents", "Developer");
};