Skip to content

Commit

Permalink
fix(ios): append TitaniumKit.xcframework if module is created with sd…
Browse files Browse the repository at this point in the history
…k < 9.2.0 (#12160)

Fixes TIMOB-28159
  • Loading branch information
build authored Oct 5, 2020
1 parent 655a487 commit 1912296
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions iphone/cli/commands/_buildModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const appc = require('node-appc'),
path = require('path'),
temp = require('temp'),
util = require('util'),
xcodeParser = require('xcode/lib/parser/pbxproj'),
__ = appc.i18n(__dirname).__,
series = appc.async.series,
xcode = require('xcode');
Expand Down Expand Up @@ -117,6 +118,20 @@ iOSModuleBuilder.prototype.detectMacOSTarget = function detectMacOSTarget() {
return isMacOSEnabled;
};

iOSModuleBuilder.prototype.generateXcodeUuid = function generateXcodeUuid(xcodeProject) {
// normally we would want truly unique ids, but we want predictability so that we
// can detect when the project has changed and if we need to rebuild the app
if (!this.xcodeUuidIndex) {
this.xcodeUuidIndex = 1;
}
const id = appc.string.lpad(this.xcodeUuidIndex++, 24, '0');
if (xcodeProject && xcodeProject.allUuids().indexOf(id) >= 0) {
return this.generateXcodeUuid(xcodeProject);
} else {
return id;
}
};

iOSModuleBuilder.prototype.run = function run(logger, config, cli, finished) {
Builder.prototype.run.apply(this, arguments);

Expand Down Expand Up @@ -237,6 +252,60 @@ iOSModuleBuilder.prototype.processLicense = function processLicense() {
};

iOSModuleBuilder.prototype.processTiXcconfig = function processTiXcconfig(next) {
const srcFile = path.join(this.projectDir, this.moduleName + '.xcodeproj', 'project.pbxproj');
const xcodeProject = xcode.project(path.join(this.projectDir, this.moduleName + '.xcodeproj', 'project.pbxproj'));
const contents = fs.readFileSync(srcFile).toString();
const appName = this.moduleIdAsIdentifier;

if (this.isFramework && !contents.includes('TitaniumKit.xcframework')) {
this.logger.warn(`Module created with sdk < 9.2.0, need to add TitaniumKit.xcframework. The ${this.moduleName}.xcodeproj has been updated.`);

xcodeProject.hash = xcodeParser.parse(contents);
const xobjs = xcodeProject.hash.project.objects,
projectUuid = xcodeProject.hash.project.rootObject,
pbxProject = xobjs.PBXProject[projectUuid],
mainTargetUuid = pbxProject.targets.filter(function (t) { return t.comment.replace(/^"/, '').replace(/"$/, '') === appName; })[0].value,
mainGroupChildren = xobjs.PBXGroup[pbxProject.mainGroup].children,
buildPhases = xobjs.PBXNativeTarget[mainTargetUuid].buildPhases,
frameworksGroup = xobjs.PBXGroup[mainGroupChildren.filter(function (child) { return child.comment === 'Frameworks'; })[0].value],
// we lazily find the frameworks and embed frameworks uuids by working our way backwards so we don't have to compare comments
frameworksBuildPhase = xobjs.PBXFrameworksBuildPhase[
buildPhases.filter(phase => xobjs.PBXFrameworksBuildPhase[phase.value])[0].value
],
frameworkFileRefUuid = this.generateXcodeUuid(xcodeProject),
frameworkBuildFileUuid = this.generateXcodeUuid(xcodeProject);

xobjs.PBXFileReference[frameworkFileRefUuid] = {
isa: 'PBXFileReference',
lastKnownFileType: 'wrapper.xcframework',
name: '"TitaniumKit.xcframework"',
path: '"$(TITANIUM_SDK)/iphone/Frameworks/TitaniumKit.xcframework"',
sourceTree: '"<absolute>"'
};
xobjs.PBXFileReference[frameworkFileRefUuid + '_comment'] = 'TitaniumKit.xcframework';

xobjs.PBXBuildFile[frameworkBuildFileUuid] = {
isa: 'PBXBuildFile',
fileRef: frameworkFileRefUuid,
fileRef_comment: 'TitaniumKit.xcframework'
};
xobjs.PBXBuildFile[frameworkBuildFileUuid + '_comment'] = 'TitaniumKit.xcframework in Frameworks';

frameworksBuildPhase.files.push({
value: frameworkBuildFileUuid,
comment: xobjs.PBXBuildFile[frameworkBuildFileUuid + '_comment']
});

frameworksGroup.children.push({
value: frameworkFileRefUuid,
comment: 'TitaniumKit.xcframework'
});

const updatedContent = xcodeProject.writeSync();

fs.writeFileSync(srcFile, updatedContent);
}

const re = /^(\S+)\s*=\s*(.*)$/,
bindingReg = /\$\(([^$]+)\)/g;

Expand Down

0 comments on commit 1912296

Please sign in to comment.