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

implement scalac script in Scala #15212

Merged
merged 3 commits into from May 20, 2022

Conversation

bishabosha
Copy link
Member

@bishabosha bishabosha commented May 18, 2022

fixes #15173
fixes #15221

@bishabosha bishabosha added this to the 3.2.0-RC1 milestone May 18, 2022
@bishabosha

This comment was marked as outdated.

@bishabosha bishabosha closed this May 18, 2022
@bishabosha bishabosha reopened this May 18, 2022
@bishabosha bishabosha added the needs-minor-release This PR cannot be merged until the next minor release label May 18, 2022
@bishabosha bishabosha marked this pull request as ready for review May 18, 2022 14:22
@bishabosha bishabosha requested a review from michelou May 18, 2022 14:26
@bishabosha
Copy link
Member Author

bishabosha commented May 18, 2022

@michelou also tagging you here for when this is merged

@bishabosha bishabosha changed the title add MainGenericCompiler implement scalac script in Scala May 18, 2022
@bishabosha
Copy link
Member Author

tested in project/scripts/winCmdTests and project/scripts/bootstrappedOnlyCmdTests

@bishabosha bishabosha assigned sjrd and unassigned Kordyjan May 19, 2022
@bishabosha bishabosha requested a review from sjrd May 19, 2022 07:46
dist/bin/scalac Show resolved Hide resolved
dist/bin/scalac Outdated Show resolved Hide resolved
compiler/src/dotty/tools/MainGenericCompiler.scala Outdated Show resolved Hide resolved
compiler/src/dotty/tools/MainGenericCompiler.scala Outdated Show resolved Hide resolved
compiler/src/dotty/tools/MainGenericCompiler.scala Outdated Show resolved Hide resolved
compiler/src/dotty/tools/MainGenericCompiler.scala Outdated Show resolved Hide resolved
addScala "$1"
shift
;;
-classpath*)
Copy link
Member

Choose a reason for hiding this comment

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

Same confusion here. This did not use to be special in the old script. Why is it special now?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is copied from the Scala script, I think there was the same Cygwin bug there

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's related to cygwin; the code and comments appear to be inherited from the scala2 version of the script.

Comment on lines +77 to +90
"-Dscala.usejavacp=true" \
"-Dscala.home=$PROG_HOME" \
Copy link
Member

Choose a reason for hiding this comment

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

Are these things that the cs runner would be able to pass to MainGenericRunner?

Copy link
Member Author

Choose a reason for hiding this comment

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

CS can configure properties, but probably does not have a magic variable for the launch directory (-Dscala.home was copied from the Scala script for use in programs), I don't think it should be supported in CS because the directory structure is not equivalent

Copy link
Contributor

@philwalk philwalk May 19, 2022

Choose a reason for hiding this comment

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

Some scripts will fail if -Dscala.home=$PROG_HOME isn't defined.
And there is no simple alternative to figuring out the path to the current runtime scala.
Different scripts can specify different versions of scala via the hashbang line, so environment variables can't be relied on. See #13758
It might not matter for non-script code, although it can be useful there as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've had a look and we can check if the property coursier.mainJar is set, which will be the path of the coursier launcher script - we can then use that to set scala.home to the parent directory. - problem here is that using the native script then scala is at s"${sys.props("scala.home")}/bin/scala", but for coursier it is s"${sys.props("scala.home")}/scala" (we could go one directory above to preserve /bin but I think this won't work on a custom Coursier install dir. [edit: I checked and for windows the default it also in some /bin directory])

Copy link
Member Author

Choose a reason for hiding this comment

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

Idea from @sjrd it could likely be much more useful to provide properties that have the classpath of the scala compiler and scala standard libraries, that can be provided as arguments to the java command, this is more uniform than a fragile directory structure that depends on the package manager.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this suggestion, it would then be possible to find the first scala3-library*.jar in the classpath, and two directories up would be scala.home.

@bishabosha bishabosha force-pushed the main-generic-compiler branch 3 times, most recently from a8a2bc8 to 98d5f9d Compare May 19, 2022 15:30
@bishabosha bishabosha requested a review from sjrd May 19, 2022 16:06
@bishabosha bishabosha force-pushed the main-generic-compiler branch 2 times, most recently from 3b1413b to 37bcdb3 Compare May 19, 2022 18:46
@bishabosha

This comment was marked as outdated.

@bishabosha bishabosha force-pushed the main-generic-compiler branch 2 times, most recently from 646cf10 to 7e05e4e Compare May 19, 2022 20:53
@bishabosha
Copy link
Member Author

bishabosha commented May 19, 2022

@philwalk I've added again a minimal version of the changes to run the shebang scripts on macOS - but I would need advice on if this is a problem for testing unglobClasspath.sc

Edit: moved to #15241

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

I don't know about the changes with #!/usr/bin/env -S bin/scala, but otherwise LGTM.


// won't compile unless the hashbang line sets classpath
import org.jline.terminal.Terminal
import org.jsoup.Jsoup
Copy link
Member Author

Choose a reason for hiding this comment

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

for clarification: jline is included in the compiler toolchain by dist/bin/common, so the -classpath 'dist/target/pack/lib/*' is not necessary. However Jsoup is in the lib directory, making the import break without it.

@bishabosha
Copy link
Member Author

bishabosha commented May 20, 2022

I will open a new PR with the shebang changes (Edit: see #15241)

@bishabosha bishabosha merged commit 83b90d8 into scala:main May 20, 2022
@bishabosha bishabosha deleted the main-generic-compiler branch May 20, 2022 10:26
@philwalk
Copy link
Contributor

Looks good

@bishabosha bishabosha added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label May 23, 2022
@bishabosha
Copy link
Member Author

do you think we can backport this to the 3.1.3 branch? - It would be good to get this as soon as possible into Coursier's scalac script

@bishabosha bishabosha added backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" and removed backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. labels May 23, 2022
@smarter smarter added backport:done This PR was successfully backported. and removed backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" labels Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:scripting backport:done This PR was successfully backported. needs-minor-release This PR cannot be merged until the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BashScriptsTests seems to be broken on macOS Scalac command should delegate to a "generic runner"
5 participants