Skip to content
Merged
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
1 change: 1 addition & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ injector.require("iOSProvisionService", "./services/ios-provision-service");
injector.require("xcconfigService", "./services/xcconfig-service");
injector.require("iOSSigningService", "./services/ios/ios-signing-service");
injector.require("spmService", "./services/ios/spm-service");
injector.require("spmPbxprojService", "./services/ios/spm-pbxproj-service");
injector.require(
"xcodebuildArgsService",
"./services/ios/xcodebuild-args-service",
Expand Down
37 changes: 36 additions & 1 deletion lib/definitions/ios.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,42 @@ declare global {
): Promise<string>;
}

type IosSPMPackage = IosSPMPackageDefinition & { targets?: string[] };
interface IosSPMPackageBase {
name: string;
/** Swift product names to link from the package. */
libs: string[];
/**
* Optional: if the project has additional targets (widgets, watch apps,
* extensions...) list their names here to link the package with them too.
*/
targets?: string[];
}

/** A package resolved from a git remote at a version, range, branch or revision. */
interface IosRemoteSPMPackage extends IosSPMPackageBase {
repositoryURL: string;
version: string;
}

/** A package resolved from a directory on disk. */
interface IosLocalSPMPackage extends IosSPMPackageBase {
path: string;
}

type IosSPMPackage = IosRemoteSPMPackage | IosLocalSPMPackage;

/** One package linked into one target of the Xcode project. */
interface IosSPMPackageAssignment {
targetName: string;
package: IosSPMPackage;
}

interface ISPMPbxprojService {
addPackages(
projectRoot: string,
assignments: IosSPMPackageAssignment[],
): boolean;
}

interface ISPMService {
applySPMPackages(
Expand Down
31 changes: 15 additions & 16 deletions lib/services/ios-watch-app-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
import { IPlatformData } from "../definitions/platform";
import { IFileSystem } from "../common/declarations";
import { injector } from "../common/yok";
import { MobileProject } from "@nstudio/trapezedev-project";
import { Minimatch } from "minimatch";

const sourceExtensions = [
Expand Down Expand Up @@ -77,6 +76,7 @@ export class IOSWatchAppService implements IIOSWatchAppService {
protected $xcode: IXcode,
private $iOSNativeTargetService: IIOSNativeTargetService,
private $logger: ILogger,
private $spmPbxprojService: ISPMPbxprojService,
) {}

private addResourceFile(
Expand Down Expand Up @@ -1416,20 +1416,8 @@ export class IOSWatchAppService implements IIOSWatchAppService {
`Applying ${watchSPMPackages.length} SPM package(s) to targets:${targetNames}`,
);

const project = new MobileProject(platformData.projectRoot, {
ios: {
path: ".",
},
enableAndroid: false,
});
await project.load();

if (!project.ios) {
this.$logger.debug("No iOS project found via trapeze");
return;
}

// Add SPM packages to each watch target
const assignments: IosSPMPackageAssignment[] = [];
for (const pkg of watchSPMPackages) {
if ("path" in pkg) {
pkg.path = path.resolve(basedir, pkg.path);
Expand All @@ -1439,11 +1427,22 @@ export class IOSWatchAppService implements IIOSWatchAppService {
`Adding SPM package ${JSON.stringify(pkg)} to targets ${targetNames}`,
);
for (const targetName of targetNames) {
project.ios.addSPMPackage(targetName, pkg);
assignments.push({ targetName, package: pkg });
}
}

await project.commit();
if (
!this.$spmPbxprojService.addPackages(
platformData.projectRoot,
assignments,
)
) {
this.$logger.debug(
`No SPM packages were applied to targets ${targetNames}`,
);
return;
}

this.$logger.debug(
`Successfully applied SPM packages to targets ${targetNames}`,
);
Expand Down
Loading