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

Feature Request: Overwrite an existent build phase script #138

Open
9t96 opened this issue Jul 3, 2023 · 2 comments
Open

Feature Request: Overwrite an existent build phase script #138

9t96 opened this issue Jul 3, 2023 · 2 comments

Comments

@9t96
Copy link

9t96 commented Jul 3, 2023

As the title says. Is there a function or a workaround to overwrite an existant build phase script?

As far as is know is not posible with this package to remove an existant build phase, so as an alternative i want to overwrite some of the script for already added build phases.

Thanks in advance :)

@9t96 9t96 changed the title Overwrite an existe build phase script Overwrite an existent build phase script Jul 3, 2023
@breautek
Copy link
Contributor

breautek commented Jul 4, 2023

After parsing the pbx file, the entire file is represented as a large JSON structure.

So if you want to modify/manipulate it, you can traverse the data structure to find the build phase you're looking for. Once you have the build phase object, should be able to reference the id for other API calls. (If there is any, I'm not too familiar with the API myself)

If you want to simply remove it, it does seem there is no delete counterpart of

pbxProject.prototype.addBuildPhase = function(filePathsArray, buildPhaseType, comment, target, optionsOrFolderType, subfolderPath) {

But likewise, as a stopgap, the data structure could be directly manipulated, but you'll have to clean all the references of the build phase from the data structure. I think you can reference the addBuildPhase API to see where these references occurs. I think a PR would be welcome for a deleteBuildPhase API.

@9t96
Copy link
Author

9t96 commented Jul 4, 2023

Well, this is how i solved. I delete the build phase with unwanted script and then add new build phase with wanted script. I think could be improved but is doing the job for now..

var fs = require('fs');
const xcodeProjPath = 'platforms/ios/T-Play.xcodeproj';

module.exports = function (ctx) {
console.log("Build phase sentry");
const projectPath = xcodeProjPath + '/project.pbxproj';
const myProj = xcode.project(projectPath);
myProj.parse(function(err) {
    let keyToReplace = '';
    var buildPhases = myProj.hash.project.objects['PBXShellScriptBuildPhase'];
    for (var key in buildPhases) {
        //Find build phase by name
        if (buildPhases[key].name?.includes('strip unused archs')) {
            keyToReplace = key;
            delete myProj.hash.project.objects['PBXShellScriptBuildPhase'][keyToReplace];
            fs.writeFileSync(projectPath, myProj.writeSync());
        }
    } 


    var options = { shellPath: '/bin/sh', shellScript: '' };
    //Read the new script from file
    fs.readFile('./hooks/buildPhaseScript.sh','utf8', function(err, data){
        if (err) {
            console.error(err);
            return;
        }
        // Display the file content
        options.shellScript = data;
        myProj.addBuildPhase([], 'PBXShellScriptBuildPhase', 'Sentry strip unused archs', myProj.getFirstTarget().uuid, options);
        fs.writeFileSync(projectPath, myProj.writeSync());
    });
});
}

@breautek breautek changed the title Overwrite an existent build phase script Feature Request: Overwrite an existent build phase script Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants