Skip to content

Commit 0783cea

Browse files
committed
feat(ios): pass a Swift Package authorization provider to xcodebuild
Private Swift Package registries need xcodebuild to be told which credential source to use, and the flag was not reachable through the CLI at all. NS_PACKAGE_AUTHORIZATION_PROVIDER supplies it. The provider describes how the machine stores its credentials rather than what is being built, so it reads from the environment instead of spending a command-line option on it.
1 parent 0f02a25 commit 0783cea

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

lib/services/ios/xcodebuild-args-service.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,19 @@ export class XcodebuildArgsService implements IXcodebuildArgsService {
180180
skipMacroValidation,
181181
];
182182

183+
// Selects how xcodebuild authenticates against private Swift Package
184+
// registries ("netrc" or "keychain"). It describes the machine's
185+
// credential setup rather than the build, so it is read from the
186+
// environment instead of a command-line option.
187+
const packageAuthorizationProvider =
188+
process.env.NS_PACKAGE_AUTHORIZATION_PROVIDER;
189+
if (packageAuthorizationProvider) {
190+
extraArgs.push(
191+
"-packageAuthorizationProvider",
192+
packageAuthorizationProvider,
193+
);
194+
}
195+
183196
const BUILD_SETTINGS_FILE_PATH = path.join(
184197
projectData.appResourcesDirectoryPath,
185198
platformData.normalizedPlatformName,

test/services/ios/xcodebuild-args-service.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ function getBuildLoggingArgs(logLevel: string): string[] {
8383

8484
describe("xcodebuildArgsService", () => {
8585
describe("getXcodeProjectArgs", () => {
86+
const originalAuthProvider = process.env.NS_PACKAGE_AUTHORIZATION_PROVIDER;
87+
88+
afterEach(() => {
89+
if (originalAuthProvider === undefined) {
90+
delete process.env.NS_PACKAGE_AUTHORIZATION_PROVIDER;
91+
} else {
92+
process.env.NS_PACKAGE_AUTHORIZATION_PROVIDER = originalAuthProvider;
93+
}
94+
});
95+
8696
it("should allow SWIFT_ENABLE_EXPLICIT_MODULES to be overridden from build.xcconfig", () => {
8797
const injector = createTestInjector({
8898
logLevel: "INFO",
@@ -119,6 +129,66 @@ describe("xcodebuildArgsService", () => {
119129

120130
assert.include(actualArgs, "DEVELOPMENT_TEAM=TEAM123");
121131
});
132+
133+
it("passes the package authorization provider from the environment", () => {
134+
process.env.NS_PACKAGE_AUTHORIZATION_PROVIDER = "netrc";
135+
const injector = createTestInjector({
136+
logLevel: "INFO",
137+
hasProjectWorkspace: false,
138+
});
139+
const xcodebuildArgsService: IXcodebuildArgsService = injector.resolve(
140+
"xcodebuildArgsService",
141+
);
142+
143+
const actualArgs = xcodebuildArgsService.getXcodeProjectArgs(
144+
<any>{ projectRoot, normalizedPlatformName },
145+
<any>{ projectName, appResourcesDirectoryPath },
146+
);
147+
148+
const index = actualArgs.indexOf("-packageAuthorizationProvider");
149+
assert.notStrictEqual(index, -1);
150+
assert.strictEqual(actualArgs[index + 1], "netrc");
151+
});
152+
153+
it("omits the package authorization provider when unset", () => {
154+
delete process.env.NS_PACKAGE_AUTHORIZATION_PROVIDER;
155+
const injector = createTestInjector({
156+
logLevel: "INFO",
157+
hasProjectWorkspace: false,
158+
});
159+
const xcodebuildArgsService: IXcodebuildArgsService = injector.resolve(
160+
"xcodebuildArgsService",
161+
);
162+
163+
const actualArgs = xcodebuildArgsService.getXcodeProjectArgs(
164+
<any>{ projectRoot, normalizedPlatformName },
165+
<any>{ projectName, appResourcesDirectoryPath },
166+
);
167+
168+
assert.notInclude(actualArgs, "-packageAuthorizationProvider");
169+
});
170+
171+
it("keeps the project path as the second argument", () => {
172+
process.env.NS_PACKAGE_AUTHORIZATION_PROVIDER = "keychain";
173+
const injector = createTestInjector({
174+
logLevel: "INFO",
175+
hasProjectWorkspace: false,
176+
});
177+
const xcodebuildArgsService: IXcodebuildArgsService = injector.resolve(
178+
"xcodebuildArgsService",
179+
);
180+
181+
const actualArgs = xcodebuildArgsService.getXcodeProjectArgs(
182+
<any>{ projectRoot, normalizedPlatformName },
183+
<any>{ projectName, appResourcesDirectoryPath },
184+
);
185+
186+
assert.strictEqual(actualArgs[0], "-project");
187+
assert.strictEqual(
188+
actualArgs[1],
189+
path.join(projectRoot, `${projectName}.xcodeproj`),
190+
);
191+
});
122192
});
123193

124194
describe("getBuildForSimulatorArgs", () => {

0 commit comments

Comments
 (0)