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

relax requirements for recognizing valid scala hashbang lines - fix for #13670 #13671

Merged
merged 1 commit into from Oct 4, 2021
Merged

relax requirements for recognizing valid scala hashbang lines - fix for #13670 #13671

merged 1 commit into from Oct 4, 2021

Conversation

philwalk
Copy link
Contributor

@philwalk philwalk commented Oct 3, 2021

This PR changes the current strict requirement that a hashbang line MUST end with "scala" in order to be recognized as a valid scala script.

The problem will only manifested if the script filename extension is neither .scala nor .sc, and the hashbang line has characters following "scala".

For example, if the hashbang line also provides a -classpath argument following "scala", the script name is not recognized as a valid script, and the REPL is entered.

Example:
A valid scala script named finder with these contents:

#!/usr/bin/env scala -classpath "/opt/lib/find.jar"
import foo.bar
def main(args: Array[String]): Unit =
  bar.finder(args)

Rather than executing the script, the current behavior is to enter the REPL.

The proposed fix is to consider a file to be a valid scala script if the first line of the file has these features:

  1. the line starts with "#!"
  2. the line contains the string "scala"

Although a workaround is to rename the file (e.g., to finder.sc rather than finder), this is restricive, because it prevents scala scripts from from shadowing command line tools written in other languages.

This regression was introduced after scala3-3.0.2.

@philwalk philwalk changed the title relax requirements for recognizing of a valid scala hashbang line - fix for #13670 relax requirements for recognizing valid scala hashbang lines - fix for #13670 Oct 3, 2021
Copy link
Member

@BarkingBad BarkingBad left a comment

Choose a reason for hiding this comment

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

Looks good to me

@BarkingBad BarkingBad merged commit a19f5dc into scala:master Oct 4, 2021
@philwalk philwalk deleted the fix-13670-relax-scala-hashbang-recognizer branch October 4, 2021 13:38
@philwalk
Copy link
Contributor Author

philwalk commented Oct 4, 2021

Do we know if this fix will be included in the scala3-3.1.0 release? I'm not surprised that it didn't make it into RC3, although I notice that neither did #13618, which merged 1 week ago.

@BarkingBad BarkingBad linked an issue Oct 4, 2021 that may be closed by this pull request
@BarkingBad
Copy link
Member

I guess it will be available from 3.1.1. If you want to set up this runner easily, you can use coursier to install it using cs install scala3 command. The coursier descriptor uses latest.release tag, so it should use the nightlies.

@BarkingBad
Copy link
Member

Maybe we could backport it to 3.1.0, but it would require us to backport all the changes to MainGenericRunner since it has changed a lot recently.

@philwalk
Copy link
Contributor Author

philwalk commented Oct 4, 2021

Maybe we could backport it to 3.1.0, but it would require us to backport all the changes to MainGenericRunner since it has changed a lot recently.

My concern is that scripting in scala3-3.1.0-RC3 is largely unusable. My manual testing of more than 500 scripts suggest that between a large percent of them (upt to 25%) are now failing due to one or more of these regressions, compared to scala-3.0.2.

@BarkingBad
Copy link
Member

I understand your problem. The 3.1.1-RC1 is scheduled to be released in 3 weeks. I know it's not fulfilling your requests, but backporting or introducing 3.1.0-RC4 would bring much more overhead.

@Kordyjan
Copy link
Contributor

Kordyjan commented Oct 4, 2021

@philwalk to clarify: once we release RC-1 for any version X, all PRs merged after that will end up in version X + 1. This means that anything merged after 7th September will be released in 3.1.1 and first available for testing in 3.1.1-RC1. Rarely, we are doing exceptions and backporting selected PRs to the version that already has a release candidate and then releasing further RCs.

If this issue indeed is a regression introduced between 3.0.2 and 3.1.0-RC1 we can consider backporting this fix. On the other hand, it would require releasing RC4. Moreover, 3.1.1-RC1 is just around the corner so I cannot tell if it is worth it.

@anatoliykmetyuk @smarter WDYT?

@philwalk
Copy link
Contributor Author

philwalk commented Oct 4, 2021 via email

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.

check for recognizing a valid scala hashbang line is too strict
3 participants