Skip to content

feat: Support .xcframework bundles #4907

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

Merged
merged 2 commits into from
Aug 12, 2019
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: 0 additions & 1 deletion lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ interface IPlatformData {
appDestinationDirectoryPath: string;
getBuildOutputPath(options: IBuildOutputOptions): string;
getValidBuildOutputData(buildOptions: IBuildOutputOptions): IValidBuildOutputData;
frameworkFilesExtensions: string[];
frameworkDirectoriesExtensions?: string[];
frameworkDirectoriesNames?: string[];
targetedOS?: string[];
Expand Down
1 change: 0 additions & 1 deletion lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
regexes: [new RegExp(`${constants.APP_FOLDER_NAME}-.*-(${Configurations.Debug}|${Configurations.Release})${constants.APK_EXTENSION_NAME}`, "i"), new RegExp(`${packageName}-.*-(${Configurations.Debug}|${Configurations.Release})${constants.APK_EXTENSION_NAME}`, "i")]
};
},
frameworkFilesExtensions: [".jar", ".dat", ".so"],
configurationFileName: constants.MANIFEST_FILE_NAME,
configurationFilePath: path.join(...configurationsDirectoryArr),
relativeToFrameworkConfigurationFilePath: path.join(constants.SRC_DIR, constants.MAIN_DIR, constants.MANIFEST_FILE_NAME),
Expand Down
50 changes: 38 additions & 12 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface INativeSourceCodeGroup {

const DevicePlatformSdkName = "iphoneos";
const SimulatorPlatformSdkName = "iphonesimulator";
const FRAMEWORK_EXTENSIONS = [".framework", ".xcframework"];

const getPlatformSdkName = (forDevice: boolean): string => forDevice ? DevicePlatformSdkName : SimulatorPlatformSdkName;
const getConfigurationName = (release: boolean): string => release ? Configurations.Release : Configurations.Debug;
Expand Down Expand Up @@ -88,8 +89,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
packageNames: [`${projectData.projectName}.app`, `${projectData.projectName}.zip`]
};
},
frameworkFilesExtensions: [".a", ".framework", ".bin"],
frameworkDirectoriesExtensions: [".framework"],
frameworkDirectoriesExtensions: FRAMEWORK_EXTENSIONS,
frameworkDirectoriesNames: ["Metadata", "metadataGenerator", "NativeScript", "internal"],
targetedOS: ['darwin'],
configurationFileName: constants.INFO_PLIST_FILE_NAME,
Expand Down Expand Up @@ -155,6 +155,9 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
this.replaceFileName("-Info.plist", projectRootFilePath, projectData);
}
this.replaceFileName("-Prefix.pch", projectRootFilePath, projectData);
if (this.$fs.exists(path.join(projectRootFilePath, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER + ".entitlements"))) {
this.replaceFileName(".entitlements", projectRootFilePath, projectData);
}

const xcschemeDirPath = path.join(this.getPlatformData(projectData).projectRoot, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER + IosProjectConstants.XcodeProjExtName, "xcshareddata/xcschemes");
const xcschemeFilePath = path.join(xcschemeDirPath, IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER + IosProjectConstants.XcodeSchemeExtName);
Expand Down Expand Up @@ -225,17 +228,38 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
return Promise.resolve();
}

private async isDynamicFramework(frameworkPath: string): Promise<boolean> {
const frameworkName = path.basename(frameworkPath, path.extname(frameworkPath));
const isDynamicFrameworkBundle = async (bundlePath: string) => {
const frameworkBinaryPath = path.join(bundlePath, frameworkName);

return _.includes((await this.$childProcess.spawnFromEvent("file", [frameworkBinaryPath], "close")).stdout, "dynamically linked");
};

if (path.extname(frameworkPath) === ".xcframework") {
let isDynamic = true;
const subDirs = this.$fs.readDirectory(frameworkPath).filter(entry => this.$fs.getFsStats(entry).isDirectory());
for (const subDir of subDirs) {
const singlePlatformFramework = path.join(subDir, frameworkName + ".framework");
if (this.$fs.exists(singlePlatformFramework)) {
isDynamic = await isDynamicFrameworkBundle(singlePlatformFramework);
break;
}
}

return isDynamic;
} else {
return await isDynamicFrameworkBundle(frameworkName);
}
}

private async addFramework(frameworkPath: string, projectData: IProjectData): Promise<void> {
if (!this.$hostInfo.isWindows) {
this.validateFramework(frameworkPath);

const project = this.createPbxProj(projectData);
const frameworkName = path.basename(frameworkPath, path.extname(frameworkPath));
const frameworkBinaryPath = path.join(frameworkPath, frameworkName);
const isDynamic = _.includes((await this.$childProcess.spawnFromEvent("file", [frameworkBinaryPath], "close")).stdout, "dynamically linked");
const frameworkAddOptions: IXcode.Options = { customFramework: true };

if (isDynamic) {
if (this.isDynamicFramework(frameworkPath)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing await?

frameworkAddOptions["embed"] = true;
}

Expand Down Expand Up @@ -577,8 +601,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
return target;
}

private getAllLibsForPluginWithFileExtension(pluginData: IPluginData, fileExtension: string): string[] {
const filterCallback = (fileName: string, pluginPlatformsFolderPath: string) => path.extname(fileName) === fileExtension;
private getAllLibsForPluginWithFileExtension(pluginData: IPluginData, fileExtension: string | string[]): string[] {
const fileExtensions = _.isArray(fileExtension) ? fileExtension : [fileExtension];
const filterCallback = (fileName: string, pluginPlatformsFolderPath: string) =>
fileExtensions.indexOf(path.extname(fileName)) !== -1;
return this.getAllNativeLibrariesForPlugin(pluginData, IOSProjectService.IOS_PLATFORM_NAME, filterCallback);
}

Expand All @@ -599,7 +625,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
const plistJson = this.$plistParser.parseFileSync(infoPlistPath);
const packageType = plistJson["CFBundlePackageType"];

if (packageType !== "FMWK") {
if (packageType !== "FMWK" && packageType !== "XFWK") {
this.$errors.failWithoutHelp("The bundle at %s does not appear to be a dynamic framework.", libraryPath);
}
}
Expand Down Expand Up @@ -679,7 +705,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
this.savePbxProj(project, projectData);
}
private async prepareFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData, projectData: IProjectData): Promise<void> {
for (const fileName of this.getAllLibsForPluginWithFileExtension(pluginData, ".framework")) {
for (const fileName of this.getAllLibsForPluginWithFileExtension(pluginData, FRAMEWORK_EXTENSIONS)) {
await this.addFramework(path.join(pluginPlatformsFolderPath, fileName), projectData);
}
}
Expand All @@ -700,7 +726,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ

private removeFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData, projectData: IProjectData): void {
const project = this.createPbxProj(projectData);
_.each(this.getAllLibsForPluginWithFileExtension(pluginData, ".framework"), fileName => {
_.each(this.getAllLibsForPluginWithFileExtension(pluginData, FRAMEWORK_EXTENSIONS), fileName => {
const relativeFrameworkPath = this.getLibSubpathRelativeToProjectPath(fileName, projectData);
project.removeFramework(relativeFrameworkPath, { customFramework: true, embed: true });
});
Expand Down
1 change: 0 additions & 1 deletion test/platform-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class PlatformData implements IPlatformData {
getBuildOutputPath = () => "";
getValidBuildOutputData = (buildOptions: IBuildOutputOptions) => ({ packageNames: [""] });
validPackageNamesForDevice: string[] = [];
frameworkFilesExtensions = [".jar", ".dat"];
appDestinationDirectoryPath = "";
relativeToFrameworkConfigurationFilePath = "";
fastLivesyncFileExtensions: string[] = [];
Expand Down
2 changes: 0 additions & 2 deletions test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ export class PlatformProjectServiceStub extends EventEmitter implements IPlatfor
projectRoot: "",
getBuildOutputPath: (buildConfig: IBuildConfig) => "",
getValidBuildOutputData: (buildOptions: IBuildOutputOptions) => ({ packageNames: [] }),
frameworkFilesExtensions: [],
appDestinationDirectoryPath: "",
relativeToFrameworkConfigurationFilePath: "",
fastLivesyncFileExtensions: []
Expand Down Expand Up @@ -486,7 +485,6 @@ export class NativeProjectDataStub extends EventEmitter implements IPlatformsDat
appDestinationDirectoryPath: "",
getBuildOutputPath: () => "",
getValidBuildOutputData: (buildOptions: IBuildOutputOptions) => ({ packageNames: [] }),
frameworkFilesExtensions: [],
relativeToFrameworkConfigurationFilePath: "",
fastLivesyncFileExtensions: []
};
Expand Down