processing
processing copied to clipboard
Export via processing-java is broken and has inconsistent design
Description
Hello and thank you for a nice application.
I'm creating a project where I want to be able to export Processing sketch using a build scripts in a consistent way (not via the GUI).
Howevre using the processing-java cli is very inconsistent and randomly fails silently. The code could need a good cleanup.
Expected Behavior
Current Behavior
GUI (works fine)
Opening a sketch inside of the GUI, and then doing File -> Export Application works fine:
The export is placed in sub-directories in the sketch directory:
CLI
Absolute paths required
Now trying the same thing in the CLI is far from straightforward. First of all, when running processing-java the cwd seems to be the same directory as the executable, not the directory I am standing in (which is normal behavior for any other command).
This mean referencing relative directories will not work (The directory exists).
Examples are using git bash on Windows. (Note cmd.exe has been tested, that is not the issue with these bugs).
$ processing-java --sketch=examples/flames --export # It does exist
examples\flames does not exist.
Instead I must use the absolute path for the command to find the sketch dir.
Export fails silently
$ processing-java --sketch=$(pwd)/examples/flames/ --export
Except when doing this, there is no output at all. Nothing gets created, and there are no errors.
(I managed to get the above command working fine with the exact same command previously, but now I cannot reproduce this).
Help text
$ processing-java --help
Command line edition for Processing 0264 (Java Mode)
--help Show this help text. Congratulations.
--sketch=<name> Specify the sketch folder (required)
--output=<name> Specify the output folder (optional and
cannot be the same as the sketch folder.)
--force The sketch will not build if the output
folder already exists, because the contents
will be replaced. This option erases the
folder first. Use with extreme caution!
--build Preprocess and compile a sketch into .class files.
--run Preprocess, compile, and run a sketch.
--present Preprocess, compile, and run a sketch in presentation mode.
--export Export an application.
--no-java Do not embed Java. Use at your own risk!
--platform Specify the platform (export to application only).
Should be one of 'windows', 'macosx', or 'linux'.
The --build, --run, --present, or --export must be the final parameter
passed to Processing. Arguments passed following one of those four will
be passed through to the sketch itself, and therefore available to the
sketch via the 'args' field. To pass options understood by PApplet.main(),
write a custom main() method so that the preprocessor does not add one.
https://github.com/processing/processing/wiki/Command-Line
Iconsistency using --export, --platform and --output
The help text above might look helpful at a glance.
However what it does not say is that if you specify an output directory using --output=<path>, it will export only for a single platform as specified using --platform.
When only specifying --export, it will export all platforms in separate directories.
I did not find this out until I looked at the code:
https://github.com/processing/processing/blob/0abee5af6ad3b11cf2b73bb794b8a97c157c4762/java/src/processing/mode/java/Commander.java#L291-L301
--export is doing something similar to what is done when exporting via the GUI menu:
https://github.com/processing/processing/blob/f65616ae74b97ffc1762380141b7dbfe9cca4693/java/src/processing/mode/java/JavaEditor.java#L943-L948
Error that is incorrect
When running --export (and it happens to work sometimes?), or using the gui to export. Versions for both Windows and Linux are created fine.
However when attempting to output the linux version it fails with an exception, which is not very helpful. The reason is that --no-java needs to be specified for that platform, which JavaMode.handleExportApplication seems to handle internally.
$ processing-java --sketch=$(pwd)/examples/flames/ --platform=linux --output=$(pwd)/bla --export
Exception in thread "main" java.lang.RuntimeException: Not yet implemented on Windows
at processing.app.Util.copyDirNative(Util.java:270)
at processing.mode.java.JavaBuild.exportApplication(JavaBuild.java:848)
at processing.mode.java.Commander.<init>(Commander.java:299)
at processing.mode.java.Commander.main(Commander.java:86)
$ processing-java --sketch=$(pwd)/examples/flames/ --platform=linux --output=$(pwd)/bla --no-java --export
The output folder already exists. Use --force to remove it.
$ processing-java --sketch=$(pwd)/examples/flames/ --platform=linux --output=$(pwd)/bla --no-java --force --export
Finished.
$ ls bla/
data/ flames* lib/ source/
Only a subset of the platforms are a choice
As seen in the help above only windows, linux and macosx are valid choices. However when exporting via the GUI, versions for multiple versions including 32/64 bit and ARM versions:
$ ls -1 examples/flames/
application.linux32/
application.linux64/
application.linux-arm64/
application.linux-armv6hf/
application.windows32/
application.windows64/
These are note possible to choose.
Steps to Reproduce
See above
Your Environment
- Processing version: 3.3.7
- Operating System and OS version: Windows 10
- Other information: Tested on 2 PC:s
Possible Causes / Solutions
The solution is most likely to clean up and rewrite the command line parsing code to be more robust. And make the choices more consistent to match with what the GUI is able to export.
Both the GUI and the cli using --export (without --output) uses this function. But something is slightly different, so only the GUI works:
https://github.com/processing/processing/blob/90522aa75fc85c4fcec84165c689d279167fa7ce/java/src/processing/mode/java/JavaMode.java#L237-L240
- Make the help be much clearer
- Rewrite the entire command line parser (Maybe use a lib? I'm no Java developer, but a quick google for a lib https://commons.apache.org/proper/commons-cli/)
- Make the cli do the exact same thing that makes things work via the GUI.
- Allow relative paths when running the cli.
- Give full control to export/build all the types of targets, and control all the involved parameters
- Give friendly error messages if the build fails
- Do not exit the program silently without exporting anything, give an error if something is wrong
If I had more time I would probably fix this myself. But I'm not a Java programmer or am familiar with this code base. So for now I will find a quickfix for my issue. I just thought it would be good to open an issue on my thoughts.
Doesn't work on ubuntu-14 either :cry:
Update: Nor Arch-Linux.
Can confirm all the issues. The inconsistencies with the CLI's --export argument made me switch to a proper IDE with a custom Ant script that is supposed to handle everything for me.
Its even worse in linux, only exports to linux, current running arch and platform,
@cjdg it actually depends on what you chose in the GUI, the platform command line param is useless. At least on Windows.
i change them on the gui and still doesnt work, using linux...
That only proves even more inconsistencies. BTW, @cjdg when you changed them did you click Export or Cancel?
I export them,
Still experiencing this today. The export application works create from the GUI but using processing-java CLI it doesn't create the same folders even with the --platform flag.
Tried with:
$ processing-java --sketch=$(pwd)/sketch-name --output=$(pwd)/outputs --force --export --platform linux
It outputs: Finished. but doesn't create the same output as the GUI. Seems to just copy the folder and place it in another output directory..
I'm currently trying about the same thing, and I'm also having a bit of trouble.
I'm trying to get a Processing sketch built using Ubuntu 20.04.2 LTS (in GitHub Actions) and, while I can get it to export to Linux, I can't get it to make a Windows version. (I don't need an apple version)
processing-java --sketch=<sketchPath> --export crashes: Error: Process completed with exit code 1. (no more info than this)
processing-java --sketch=<sketchPath> --output=<sketchPath>/artifacts/export/noargs --export exports a Linux build
processing-java --sketch=<sketchPath> --output=<sketchPath>/artifacts/export/linux --export --platform=linux exports a Linux build
processing-java --sketch=<sketchPath> --output=<sketchPath>/artifacts/export/windows --export --platform=windows also exports a Linux Build...
I also tried these with a space instead of an = between platform and the platform. None gave me a Windows version. They either crashed or gave me another Linux version.
Intent:
To export for multiple platforms from github actions
Setup in actions:
- Downloaded Processing 4.0b1 in ROOT DIR.
- Unzipped and ran
install.shin the downloaded and expanded Processing dir. sketchbookdir was created in ROOT location, withlibrariesfolder in it along with other dirs. (/home/runner/work/sketchbook/libraries)- Installed necessary libraries.
- Invoked export command:
/root/processing-4.0b1/processing-java --sketch=/root/testsketch/ --force --output=/root/testsketch/application.windows --platform='windows' --export: result: no error , but ofc need to fix somethings later (Not a big issue for now)/root/processing-4.0b1/processing-java --sketch=/root/testsketch/ --force --output=/root/testsketch/application.linux --platform='linux' --export: result: no error, but have not tested if it can run./root/processing-4.0b1/processing-java --sketch=/root/testsketch/ --force --output=/root/testsketch/application.macosx --platform='macosx' --export: result : error exporting (I'm aware that macos exports dont; work properly and need a manual fix sometimes - but that can be dealt with later):
java.io.FileNotFoundException: /root/processing-4.0b1/modes/java/application/mac-app-stub (No such file or directory)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
at processing.app.Util.copyFile(Util.java:129)
at processing.mode.java.JavaBuild.exportApplication(JavaBuild.java:695)
at processing.mode.java.Commander.<init>(Commander.java:262)
at processing.mode.java.Commander.main(Commander.java:394)
NOTE: Latest Processing 40b7 and earlier 3.5.3 versions are also not suitable for other reasons. Planning to stick with version 4.0b1.
Any solutions?