-
Notifications
You must be signed in to change notification settings - Fork 144
Scalac preset option in directive #3615
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
5ae4b9c
3eeddf8
d61c509
fcf4301
06f5cd7
ec393ed
c8fea6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ package scala.build.preprocessing.directives | |
|
||
import scala.build.Positioned | ||
import scala.build.directives.* | ||
import scala.build.errors.BuildException | ||
import scala.build.errors.{BuildException, DirectiveErrors, InputsException} | ||
import scala.build.options.WithBuildRequirements.* | ||
import scala.build.options.{ | ||
BuildOptions, | ||
|
@@ -31,6 +31,9 @@ import scala.cli.commands.SpecificationLevel | |
|`//> using test.scalacOptions` _option1_ _option2_ … | ||
|`//> using test.options` _option1_ _option2_ … | ||
| | ||
|`//> using options` _option1_ _option2_ … | ||
| | ||
|`//> using options.preset` _suggested_ | _ci_ | _strict_ | ||
|""".stripMargin | ||
) | ||
@DirectiveDescription("Add Scala compiler options") | ||
|
@@ -44,12 +47,39 @@ final case class ScalacOptions( | |
@DirectiveName("test.options") | ||
@DirectiveName("test.scalacOption") | ||
@DirectiveName("test.scalacOptions") | ||
testOptions: List[Positioned[String]] = Nil | ||
testOptions: List[Positioned[String]] = Nil, | ||
@DirectiveName("option.preset") | ||
@DirectiveName("options.preset") | ||
presetOptions: Option[String] = None | ||
) extends HasBuildOptionsWithRequirements { | ||
def buildOptionsList: List[Either[BuildException, WithBuildRequirements[BuildOptions]]] = List( | ||
ScalacOptions.buildOptions(options).map(_.withEmptyRequirements), | ||
ScalacOptions.buildOptions(testOptions).map(_.withScopeRequirement(Scope.Test)) | ||
) | ||
def buildOptionsList: List[Either[BuildException, WithBuildRequirements[BuildOptions]]] = { | ||
val explicitScalacOptions = List( | ||
ScalacOptions.buildOptions(options).map(_.withEmptyRequirements), | ||
ScalacOptions.buildOptions(testOptions).map(_.withScopeRequirement(Scope.Test)) | ||
) | ||
|
||
presetOptions match { | ||
case None => explicitScalacOptions | ||
case Some("suggested") => | ||
val presetOptions = | ||
ScalacOptions.buildOptions(ScalacOptions.presetOptionsSuggested.map(Positioned.none)) | ||
explicitScalacOptions :+ presetOptions.map(_.withEmptyRequirements) | ||
case Some("ci") => | ||
val presetOptions = | ||
ScalacOptions.buildOptions(ScalacOptions.presetOptionsCI.map(Positioned.none)) | ||
explicitScalacOptions :+ presetOptions.map(_.withEmptyRequirements) | ||
case Some("strict") => | ||
val presetOptions = | ||
ScalacOptions.buildOptions(ScalacOptions.presetOptionsStrict.map(Positioned.none)) | ||
explicitScalacOptions :+ presetOptions.map(_.withEmptyRequirements) | ||
case Some(other) => | ||
List(Left( | ||
InputsException( | ||
s"Unknown preset options: $other. Available options are: suggested, ci, strict" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have an enumeration of the available presets somewhere, with tied option lists. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, where should this be defined. I was only making a quick draft just to see if I understood the requirement correctly. The issue seems to be really interesting as I tend to add some options manually and I never remember what should be used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added these options as enums |
||
) | ||
)) | ||
} | ||
} | ||
} | ||
|
||
object ScalacOptions { | ||
|
@@ -62,4 +92,9 @@ object ScalacOptions { | |
) | ||
) | ||
} | ||
|
||
// todo: this should be based on the scala version. This might not be the correct location | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup... might be annoying to keep up-to-date as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the 3 presets for a start are good I think (having There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I just wanted to add some ideas, I am also not fully clear what should they be, but added there just to make sure that we should handle multiple presets. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding what they should be, I believe the idea was to start with something like what https://github.com/typelevel/sbt-tpolecat has... We could also start a discussion for suggestions somewhere... A thread on https://contributors.scala-lang.org/, maybe... or just a discussion on this repo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about the duplicates yday, but I saw some test related to duplicate scalaC args are ignored or something like that. SO thought it can be ignored. I will try to handle them. How about getting the scalaVersion? We should have the sugested and other presets based on the scala versions right. I assumes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the command line args needs to be processed, then is it not possible to add the scalac options in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Gedochao Could you have a look at it when you get time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You can't. We don't know what's the final Scala version until
Yep, the presets can only be applied once the Scala version is finalised, which generally should be after (or within)
We do have handling for when there's duplicates introduced by the command line vs directives. If duplicates are explicitly added by the user in one context, we don't remove them and let the compiler handle it. |
||
def presetOptionsSuggested = List("-Xfatal-warnings", "-deprecation", "-unchecked") | ||
def presetOptionsCI = List("-Xfatal-warnings", "-deprecation", "-unchecked") | ||
def presetOptionsStrict = List("-Xfatal-warnings", "-deprecation", "-unchecked") | ||
} |
Uh oh!
There was an error while loading. Please reload this page.