FR: Projucer should return non 0 exit code if command fails (especially --resave)

All these just return 0 no matter if they succeed or fail. :slightly_frowning_face:

        if (matchCommand ("help"))                     { showHelp();                            return 0; }
        if (matchCommand ("h"))                        { showHelp();                            return 0; }
        if (matchCommand ("resave"))                   { resaveProject (args, false);           return 0; }
        if (matchCommand ("resave-resources"))         { resaveProject (args, true);            return 0; }
        if (matchCommand ("get-version"))              { getVersion (args);                     return 0; }
        if (matchCommand ("set-version"))              { setVersion (args);                     return 0; }
        if (matchCommand ("bump-version"))             { bumpVersion (args);                    return 0; }
        if (matchCommand ("git-tag-version"))          { gitTag (args);                         return 0; }
        if (matchCommand ("buildmodule"))              { buildModules (args, false);            return 0; }
        if (matchCommand ("buildallmodules"))          { buildModules (args, true);             return 0; }
        if (matchCommand ("status"))                   { showStatus (args);                     return 0; }
        if (matchCommand ("trim-whitespace"))          { cleanWhitespace (args, false);         return 0; }
        if (matchCommand ("remove-tabs"))              { cleanWhitespace (args, true);          return 0; }
        if (matchCommand ("tidy-divider-comments"))    { tidyDividerComments (args);            return 0; }
        if (matchCommand ("fix-broken-include-paths")) { fixRelativeIncludePaths (args);        return 0; }
        if (matchCommand ("obfuscated-string-code"))   { generateObfuscatedStringCode (args);   return 0; }
        if (matchCommand ("encode-binary"))            { encodeBinary (args);                   return 0; }
        if (matchCommand ("trans"))                    { scanFoldersForTranslationFiles (args); return 0; }
        if (matchCommand ("trans-finish"))             { createFinishedTranslationFile (args);  return 0; }
        if (matchCommand ("set-global-search-path"))   { setGlobalPath (args);                  return 0; }
        if (matchCommand ("create-project-from-pip"))  { createProjectFromPIP (args);           return 0; }

Looking into this a bit more, Projucer actually does return error codes on errors (via exceptions, doesn’t need to be handled in the above code).

However, since Projucer is a GUI application and not a command line application, it doesn’t return its return code to the shell that ran it. (On windows at least)

Projucer.exe --resave doesnotexist.juce
Could not find file: doesnotexist.jucer
echo %errorlevel%

The return code is actually 1. Any idea how to get the Projucer to set %errorlevel%. Or is this just another sign to switch to CMake?

If you’re interested in modifying the Projucer source to achieve this, you can use JUCEApplication::setApplicationReturnValue().

1 Like

It’s already doing that.

        if (isRunningCommandLine)
            auto appReturnCode = performCommandLine (ArgumentList ("Projucer", commandLine));

            if (appReturnCode != commandLineNotPerformed)
                setApplicationReturnValue (appReturnCode);

            isRunningCommandLine = false;

Ah, I see what you’re saying now. The functions that actually invoke the command operations (like resaveProject()) need to return a result so that the lambda that is passed to ConsoleApplication::invokeCatchingFailures() can return an appropriate value, rather than indiscriminately returning 0 as it currently does.

In the case of resaveProject(), it calls LoadedProject::save() which would also need to be modified to return its result.

I agree that this FR would be nice to have, at least for any of the command-line operations that involve writing to files.