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

fix support for top-level main methods in Scala 3 #1592

Merged
merged 14 commits into from
Apr 11, 2024
Merged

fix support for top-level main methods in Scala 3 #1592

merged 14 commits into from
Apr 11, 2024

Conversation

mberndt123
Copy link
Contributor

@mberndt123 mberndt123 commented Apr 5, 2024

app_mainclass is currently not escaped correctly. This leads to problems in Scala 3 when you define main as a function at the top level (as opposed to inside an object. In this case, the main class generated by the Scala compiler will contain $ symbols that need to be escaped.

The LauncherJarPlugin abuses mainClass to set the -jar foo.jar parameter instead of a main class, so this case needs to be treated specially (I find this an ugly hack but haven't found a cleaner solution).
The scripted-docker test failures seem to be unrelated to my changes as they also occur in other CI runs

@lightbend-cla-validator
Copy link

@lightbend-cla-validator
Copy link

Hi @mberndt123,

Thank you for your contribution! We really value the time you've taken to put this together.

We see that you have signed the Lightbend Contributors License Agreement before, however, the CLA has changed since you last signed it.
Please review the new CLA and sign it before we proceed with reviewing this pull request:

http://www.lightbend.com/contribute/cla

@lightbend-cla-validator
Copy link

@mberndt123 mberndt123 changed the title correctly escape app_mainclass variable fix support for top-level main methods in Scala 3 Apr 5, 2024
@lightbend-cla-validator
Copy link

@@ -129,4 +129,4 @@ java_cmd="$(get_java_cmd)"
# If a configuration file exist, read the contents to $opts
[ -f "$script_conf_file" ] && opts=$(loadConfigFile "$script_conf_file")

eval "exec $java_cmd $java_opts -classpath $app_classpath $opts $app_mainclass $app_commands $residual_args"
exec $java_cmd $java_opts -classpath $app_classpath $opts $app_mainclass $app_commands $residual_args
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why eval was used here. It breaks app_mainclass if it contains $ symbols, so I've removed it and it doesn't seem to break any tests, so… I guess it's fine?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if #1334 added a test but it seems like eval was added there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1334 added checkComplexResidual but never called it from the test file. If we fix that, hopefully we'll see why eval was added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've added that to the test file. Ironically, the tests still pass, and they fail if I put the eval back in. I think everything here is broken, both the way "residual args" are being handled and the test that is supposed to test them.

Copy link
Collaborator

@dwickern dwickern Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I'm not confident that those tests work. Digging into the blame, there's a lot of history for that line of code going back to #1334, #1303, #1095 and before.

If you call myProgram --param1 "value1 value2", does it correctly pass two arguments (args[0]="--param1", args[1]="value1 value2")?

Copy link
Contributor Author

@mberndt123 mberndt123 Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now fixed the tests and the escaping of residual args. I've also added tests for all kinds of nasty things that might confuse a shell script and they're all passed through correctly.

@lightbend-cla-validator
Copy link

@lightbend-cla-validator

Copy link
Collaborator

@dwickern dwickern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mberndt123
Copy link
Contributor Author

LGTM

Thanks @dwickern, is there anything else I need to do to get this merged?

@dwickern dwickern requested a review from muuki88 April 11, 2024 16:33
@muuki88 muuki88 merged commit cb29893 into sbt:master Apr 11, 2024
15 checks passed
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

Successfully merging this pull request may close these issues.

5 participants