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

Add launcher options allowing to override the default Scala version #2860

Conversation

Gedochao
Copy link
Contributor

@Gedochao Gedochao commented Apr 17, 2024

Relevant to #2838

This PR adds 2 new launcher options: --cli-default-scala-version & --cli-predefined-repository

--cli-default-scala-version allows to override the default Scala version (which can then be overridden with -S):

scala-cli --cli-default-scala-version 3.4.2-RC1 version --offline
# Scala CLI version: 1.2.3-SNAPSHOT
# Scala version (default): 3.4.2-RC1
scala-cli --cli-default-scala-version 3.4.2-RC1 run -e 'println(dotty.tools.dotc.config.Properties.simpleVersionString)' --with-compiler
# Compiling project (Scala 3.4.2-RC1, JVM (17))
# Compiled project (Scala 3.4.2-RC1, JVM (17))
# 3.4.2-RC1
scala-cli --cli-default-scala-version 3.4.2-RC1 run -e 'println(dotty.tools.dotc.config.Properties.simpleVersionString)' --with-compiler -S lts
# Compiling project (Scala 3.3.3, JVM (17))
# Compiled project (Scala 3.3.3, JVM (17))
# 3.3.3

--cli-predefined-repository is an equivalent to the existing --repo option for building sub-commands, but can be passed as a launcher option. This i.e. allows to pass a local repository containing compiler artifacts.

cs fetch --cache local-repo org.scala-lang:scala3-compiler_3:3.4.2-RC1
# local-repo/https/repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3/3.4.1-RC1/scala3-compiler_3-3.4.1-RC1.jar
# local-repo/https/repo1.maven.org/maven2/org/scala-lang/scala3-interfaces/3.4.1-RC1/scala3-interfaces-3.4.1-RC1.jar
# local-repo/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.4.1-RC1/scala3-library_3-3.4.1-RC1.jar
# local-repo/https/repo1.maven.org/maven2/org/scala-lang/tasty-core_3/3.4.1-RC1/tasty-core_3-3.4.1-RC1.jar
# local-repo/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-asm/9.6.0-scala-1/scala-asm-9.6.0-scala-1.jar
# local-repo/https/repo1.maven.org/maven2/org/scala-sbt/compiler-interface/1.9.6/compiler-interface-1.9.6.jar
# local-repo/https/repo1.maven.org/maven2/org/jline/jline-reader/3.19.0/jline-reader-3.19.0.jar
# local-repo/https/repo1.maven.org/maven2/org/jline/jline-terminal/3.19.0/jline-terminal-3.19.0.jar
# local-repo/https/repo1.maven.org/maven2/org/jline/jline-terminal-jna/3.19.0/jline-terminal-jna-3.19.0.jar
# local-repo/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar
# local-repo/https/repo1.maven.org/maven2/org/scala-sbt/util-interface/1.9.8/util-interface-1.9.8.jar
# local-repo/https/repo1.maven.org/maven2/net/java/dev/jna/jna/5.3.1/jna-5.3.1.jar
scala-cli --cli-default-scala-version 3.4.2-RC1 --cli-predefined-repository file:///Users/pchabelski/IdeaProjects/scala-cli-tests/demo/local-repo/https/repo1.maven.org/maven2 run simple.sc --with-compiler --offline --power
# 3.4.2-RC1

@Gedochao Gedochao force-pushed the feature/override-default-scala-launcher-option branch 3 times, most recently from 227da37 to 0664cf0 Compare April 17, 2024 13:20
@Gedochao
Copy link
Contributor Author

cc @bishabosha

@bishabosha
Copy link
Contributor

bishabosha commented Apr 17, 2024

nice, Is it necessary to add another test to assert it fails if --cli-default-scala-version is provided twice?

@Gedochao Gedochao force-pushed the feature/override-default-scala-launcher-option branch from 0664cf0 to 4f08f0e Compare April 18, 2024 08:52
@Gedochao
Copy link
Contributor Author

Is it necessary to add another test to assert it fails if --cli-default-scala-version is provided twice?

@bishabosha that's guaranteed by case-app, but I added a test as a sanity check

@Gedochao Gedochao force-pushed the feature/override-default-scala-launcher-option branch 2 times, most recently from f8af5c1 to 861b894 Compare April 19, 2024 08:29
@Gedochao Gedochao added the SIP-46 All the issues related to SIP-46 to turn Scala CLI into the official scala runner command. label Apr 19, 2024
@Gedochao Gedochao changed the title Add a launcher option allowing to override the default Scala version Add launcher options allowing to override the default Scala version Apr 19, 2024
@Gedochao Gedochao marked this pull request as ready for review April 19, 2024 11:11
Copy link
Collaborator

@kasiaMarek kasiaMarek left a comment

Choose a reason for hiding this comment

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

Generally looks good, but there are two places, where this doesn't seem to be propagated and I don't know if that is on purpose:

  1. scala version used for export,
  2. when scala version is downgraded for ammonite it's check against defaultScalaVersion not the override default

@Gedochao
Copy link
Contributor Author

Gedochao commented Apr 19, 2024

Generally looks good, but there are two places, where this doesn't seem to be propagated and I don't know if that is on purpose:

  1. scala version used for export,
  2. when scala version is downgraded for ammonite it's check against defaultScalaVersion not the override default

@kasiaMarek nice catch, let me fix those

@Gedochao Gedochao force-pushed the feature/override-default-scala-launcher-option branch from 861b894 to d5427b0 Compare April 23, 2024 09:59
@Gedochao
Copy link
Contributor Author

Changes:

  • export --sbt, --mill and --json should now respect the launcher override for the default Scala version
  • ammonite repl should now respect the launcher override when downgrading the default Scala version

@Gedochao Gedochao force-pushed the feature/override-default-scala-launcher-option branch from 1f07e78 to d5a0190 Compare April 23, 2024 11:17
@Gedochao Gedochao merged commit 3afca5f into VirtusLab:main Apr 23, 2024
75 checks passed
@Gedochao Gedochao deleted the feature/override-default-scala-launcher-option branch April 23, 2024 12:36
@bishabosha
Copy link
Contributor

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SIP-46 All the issues related to SIP-46 to turn Scala CLI into the official scala runner command.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants