Execute git in Post-Export Shell Command

I’m trying to execute git command in the post export shell command of Projucer (Mac).

'git -C %%1%% apply %%1%%/Patch/foo.patch'

Projucer fails export saying that the command exited with code 127 or 128. I’ve tried to run the exact same command in terminal and it executes without any issues. How can i apply a git patch to the project after export?

My actual problem is that i’ve customized a few Juce modules and Projucer overwrites my changes during export and i need to apply the patch everytime. I’d be happy to learn of any other ways to accomplish this.

I believe error code 127 is ‘command not found’. might be a path issue.

I’ve also tried with full path /usr/bin/git. No dice.

What exactly is your patch doing? I would be happy to help you find an alternative way once I know what you are trying to achieve.

The patch itself adds a parameter to the drawPopupMenuBackground method declaration of the look and feel system.

-    void drawPopupMenuBackground (Graphics&, int width, int height) override;
+    void drawPopupMenuBackground(Graphics& g, int width, int height, const Component& popup) override;

and correspondingly some

-    getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
+    getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight(), *this);

This change needs to be applied to 9 source files. It’s not complicated and a simple diff patch has been able to take care of this little detail. Applying the patch in a post export command would streamline the workflow for this part.

I use the component to find out the location of the popup and use that information when rendering the background. Actually, i’ve never understood why Juce doesn’t deliver this parameter, but haven’t had the time and energy to ask and request, as i’ve been quite happy with my solution and no one else seems to need it.

I’m also getting this same error on a Pre-Export Shell Command. I’m trying to run a nodejs script. I’ve tried running the command directly in quotes, and I’ve also tried wrapping the call into a shell script which is called fromm the pre-export command instead. Both fail with exit code 127. When I run either command or script in terminal, it works correctly. I’ve also tried including absolute paths instead of the dynamic path replacement. No dice.

@mjokipii Did you ever solve this?

@Cymatic No, unfortunately i did not.

@mjokipii I was able to solve my issue finally, perhaps what I learned will be of use to you. The first thing I noticed is that any time I tried to pass arguments to the command I was calling (whether inside quotes or not) I would get an early exit error. So I don’t think the export shell commands are designed to deal with passing arguments. This was true for both trying to call a command directly, or passing arguments into a shell script which called the command. Like you I was trying to pass JUCE’s path substitution string %%1%% into the command I was calling as an argument.

Step one was wrapping everything into a shell script instead of trying to call it directly from the Projucer property. So in your case you would create something like apply-patch.sh

#!/bin/sh
git -C %%1%% apply %%1%%/Patch/foo.patch

Now, of course the path replacement of %%1%% will only work in the Projucer property and not in the shell script, so we need a way to identify our locations. I chose to do this relative to where the shell script exists. For ease of explanation let’s say we just put the apply-patch.sh script in the root of the project where the .jucer file is.

In the Projucer’s export shell command:

"%%1%%/apply-patch.sh"

And inside of the shell script something like this:

SCRIPT_DIR=$(dirname "$0")
git -C $SCRIPT_DIR apply $SCRIPT_DIR/Patch/foo.patch

Since I was calling the nodejs binary that also failed unless I provided an absolute path like /usr/local/bin/node because it seems like env variables like $PATH are not getting exported when the Projucer invokes the export command; you might have to do the same with git, I’m not sure.

Putting aliases to the absolute paths for things like node or git in a .bash_profile or .bashrc file might get loaded and work with Projucer’s export commands, but I didn’t test it to found out, and since I had to hardcode a path to the binary I’m calling, I just decided to stick it directly in the shell script called by the Projucer.

I hope this helps.

@Cymatic That worked! It was all about the paths. Apparently the git command itself doesn’t require full path (/usr/bin/).

Thank you very much for your help!

1 Like