diff --git a/__tests__/xcode-selector.test.ts b/__tests__/xcode-selector.test.ts index 9f56328..2ba0340 100644 --- a/__tests__/xcode-selector.test.ts +++ b/__tests__/xcode-selector.test.ts @@ -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 }, @@ -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", @@ -95,7 +91,6 @@ describe("XcodeSelector", () => { beforeEach(() => { coreExportVariableSpy = jest.spyOn(core, "exportVariable"); fsExistsSpy = jest.spyOn(fs, "existsSync"); - fsSpawnSpy = jest.spyOn(child, "spawnSync"); }); afterEach(() => { @@ -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"); }); diff --git a/dist/index.js b/dist/index.js index 3a35059..4ea91fd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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)); @@ -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); } @@ -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)); @@ -231,6 +230,10 @@ const getXcodeVersionInfo = (xcodeRootPath) => { }; }; exports.getXcodeVersionInfo = getXcodeVersionInfo; +const developerDirPath = (xcodeVersion) => { + return path.join(xcodeVersion.path, "Contents", "Developer"); +}; +exports.developerDirPath = developerDirPath; /***/ }), @@ -14276,14 +14279,6 @@ module.exports = require("assert"); /***/ }), -/***/ 2081: -/***/ ((module) => { - -"use strict"; -module.exports = require("child_process"); - -/***/ }), - /***/ 6113: /***/ ((module) => { diff --git a/src/xcode-selector.ts b/src/xcode-selector.ts index a615ae5..77fac15 100644 --- a/src/xcode-selector.ts +++ b/src/xcode-selector.ts @@ -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[] { @@ -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); diff --git a/src/xcode-utils.ts b/src/xcode-utils.ts index b2a415b..f9791c2 100644 --- a/src/xcode-utils.ts +++ b/src/xcode-utils.ts @@ -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"); +};