Skip to content
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

[iOS] Changes made by plugin hooks are rewritten due to project file caching #557

Open
3 tasks done
smishenk opened this issue May 12, 2021 · 0 comments
Open
3 tasks done

Comments

@smishenk
Copy link

Bug Report

Changes which are made in .xcodeproj by plugin in before_compile hook are rewritten by Сordova build scripts.

Problem

I have a project that uses BlackBerry Dynamics SDK for Cordova. To enable core BlackBerry features I have to add cordova-plugin-bbd-base plugin. This plugin adds some BlackBerry frameworks to .xcodeproj to build and link a project against within before_compile hook (I have no idea on why they've chosen exactly that hook). Unfortunately, if I use Cordova CLI commands like build or run , I get build and link errors, because Cordova scripts unintentionally re-write project configurations.

What is expected to happen?

Project builds successfully if I run one of this command:

cordova build ios --release --device
cordova run ios --release --device

What does actually happen?

Project build is failed because required BlackBerry frameworks wasn't added to project configuration.
Worth to mention: if I try to execute all build phases separately, like:

cordova prepare ios
cordova compile ios --release --device

Then I have no issues with project build

Information

I managed to find out what is the root cause of my issue by exploring Cordova build scripts. Just to be clear, I'm talking about scripts that are located within <project_dir>/platforms/ios/cordova/ after execution of cordova platform add ios command.
My problem is connected with projectFile.js module since it caches project files by project directory. In the same time, when I execute cordova build command, both prepare and compile phases are run in the same environment and share the same instance of projectFile module. Thus, project file is cached during prepare phase, then it is changed in before_compile hook (and Cordova scripts are unaware of it) and finally it is restored to 'cordova-scripts' version when compile phase processes build options and make final adjustments within project file here:

function writeCodeSignStyle (value) {
    const project = createProjectObject(projectPath, projectName);

    events.emit('verbose', `Set CODE_SIGN_STYLE Build Property to ${value}.`);
    project.xcode.updateBuildProperty('CODE_SIGN_STYLE', value);
    events.emit('verbose', `Set ProvisioningStyle Target Attribute to ${value}.`);
    project.xcode.addTargetAttribute('ProvisioningStyle', value);

    project.write();
}

if (buildOpts.provisioningProfile) {
    events.emit('verbose', 'ProvisioningProfile build option set, changing project settings to Manual.');
    writeCodeSignStyle('Manual');
} else if (buildOpts.automaticProvisioning) {
    events.emit('verbose', 'ProvisioningProfile build option NOT set, changing project settings to Automatic.');
    writeCodeSignStyle('Automatic');
}

When I execute prepare and compile phases separately, each phase gets correct and 'up-to-date' project file version and everything goes fine.
Though my case might be quite unique, I believe the problem itself is much wider. I've not found any limitations of actions which can be performed within hooks in documentation. So, xcodeproj modification on before_compile hook looks more or less OK. It seems more like a bug to me that project file is cached along all of the build phases, while any custom actions on hooks are allowed.

Version information

Cordova: 10.0.0,
Cordova Platforms: iOS,
Cordova Plugins: cordova-plugin-bbd-base,
Ionic Framework: 5.3.2,
Ionic CLI: 6.15.0,
Operating System: macOS 10.15.6,
XCode: 12.4

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant