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 #525: Spuriously duplicate options #536

Merged
merged 8 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/build/src/main/scala/scala/build/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ object Build {

val crossSources0 = crossSources.withVirtualDir(inputs0, scope, baseOptions)

val sources = value(crossSources0.scopedSources(baseOptions))
.sources(scope, baseOptions)
val scopedSources = value(crossSources0.scopedSources(baseOptions))
val sources = scopedSources.sources(scope, baseOptions)

val generatedSources = sources.generateSources(inputs0.generatedSrcRoot(scope))
val buildOptions = sources.buildOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ final case class CrossSources(
.flatMap(_.withPlatform(platform.value).toSeq)
.map(_.scopedValue(defaultScope)),
buildOptions
.filter(!_.requirements.isEmpty)
.flatMap(_.withScalaVersion(retainedScalaVersion).toSeq)
.flatMap(_.withPlatform(platform.value).toSeq)
.map(_.scopedValue(defaultScope))
Expand Down
4 changes: 2 additions & 2 deletions modules/build/src/main/scala/scala/build/bsp/BspImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ final class BspImpl(
if (verbosity >= 3)
pprint.stderr.log(scopedSources)

val sourcesMain = scopedSources.sources(Scope.Main, buildOptions)
val sourcesTest = scopedSources.sources(Scope.Test, buildOptions)
val sourcesMain = scopedSources.sources(Scope.Main, crossSources.sharedOptions(buildOptions))
val sourcesTest = scopedSources.sources(Scope.Test, crossSources.sharedOptions(buildOptions))

if (verbosity >= 3)
pprint.stderr.log(sourcesMain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ final case class HasBuildRequirements[+T](
}
def scopedValue(defaultScope: Scope): HasScope[T] =
HasScope(requirements.scope.map(_.scope).getOrElse(defaultScope), value)
def map[U](f: T => U): HasBuildRequirements[U] =
copy(value = f(value))
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ final case class HasScope[+T](
def valueForInheriting(currentScope: Scope): Option[T] =
if (currentScope.allScopes.contains(scope)) Some(value)
else None
def map[U](f: T => U): HasScope[U] =
copy(value = f(value))
}
26 changes: 26 additions & 0 deletions modules/build/src/test/scala/scala/build/tests/BuildTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -775,4 +775,30 @@ class BuildTests extends munit.FunSuite {
assert(maybeBuild.toOption.get.options.scalaNativeOptions.linkingOptions.isEmpty)
}
}

// Issue #525
test("scalac options not spuriously duplicating") {
val inputs = TestInputs(
os.rel / "foo.scala" ->
"""// using scala "2.13"
|// using options "-deprecation", "-feature", "-Xmaxwarns", "1"
|// using option "-Xdisable-assertions"
|
|def foo = "bar"
|""".stripMargin
)

val buildOptions: BuildOptions = defaultOptions.copy(
internal = defaultOptions.internal.copy(
keepDiagnostics = true
)
)

inputs.withBuild(buildOptions, buildThreads, bloopConfig) { (_, _, maybeBuild) =>
val expectedOptions =
Seq("-deprecation", "-feature", "-Xmaxwarns", "1", "-Xdisable-assertions")
val scalacOptions = maybeBuild.toOption.get.options.scalaOptions.scalacOptions
expect(scalacOptions == expectedOptions)
}
}
}
28 changes: 14 additions & 14 deletions modules/build/src/test/scala/scala/build/tests/SourcesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SourcesTests extends munit.FunSuite {
TestLogger()
).orThrow
val scopedSources = crossSources.scopedSources(BuildOptions()).orThrow
val sources = scopedSources.sources(Scope.Main, BuildOptions())
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(BuildOptions()))

expect(sources.buildOptions.classPathOptions.extraDependencies.map(_.value) == expectedDeps)
expect(sources.paths.isEmpty)
Expand Down Expand Up @@ -78,7 +78,7 @@ class SourcesTests extends munit.FunSuite {
TestLogger()
).orThrow
val scopedSources = crossSources.scopedSources(BuildOptions()).orThrow
val sources = scopedSources.sources(Scope.Main, BuildOptions())
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(BuildOptions()))

expect(sources.buildOptions.classPathOptions.extraDependencies.map(
_.value
Expand Down Expand Up @@ -111,7 +111,7 @@ class SourcesTests extends munit.FunSuite {
TestLogger()
).orThrow
val scopedSources = crossSources.scopedSources(BuildOptions()).orThrow
val sources = scopedSources.sources(Scope.Main, BuildOptions())
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(BuildOptions()))

expect(sources.buildOptions.classPathOptions.extraDependencies.map(_.value) == expectedDeps)
expect(sources.paths.isEmpty)
Expand Down Expand Up @@ -140,7 +140,7 @@ class SourcesTests extends munit.FunSuite {
TestLogger()
).orThrow
val scopedSources = crossSources.scopedSources(BuildOptions()).orThrow
val sources = scopedSources.sources(Scope.Main, BuildOptions())
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(BuildOptions()))

expect(sources.buildOptions.classPathOptions.extraDependencies.map(_.value) == expectedDeps)
expect(sources.paths.isEmpty)
Expand Down Expand Up @@ -169,7 +169,7 @@ class SourcesTests extends munit.FunSuite {
TestLogger()
).orThrow
val scopedSources = crossSources.scopedSources(BuildOptions()).orThrow
val sources = scopedSources.sources(Scope.Main, BuildOptions())
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(BuildOptions()))

expect(sources.buildOptions.classPathOptions.extraDependencies.map(_.value).isEmpty)
expect(sources.paths.isEmpty)
Expand Down Expand Up @@ -203,7 +203,7 @@ class SourcesTests extends munit.FunSuite {
TestLogger()
).orThrow
val scopedSources = crossSources.scopedSources(BuildOptions()).orThrow
val sources = scopedSources.sources(Scope.Main, BuildOptions())
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(BuildOptions()))

expect(sources.buildOptions.classPathOptions.extraDependencies.map(_.value) == expectedDeps)
expect(sources.paths.length == 1)
Expand Down Expand Up @@ -236,7 +236,7 @@ class SourcesTests extends munit.FunSuite {
TestLogger()
).orThrow
val scopedSources = crossSources.scopedSources(BuildOptions()).orThrow
val sources = scopedSources.sources(Scope.Main, BuildOptions())
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(BuildOptions()))

expect(sources.buildOptions.classPathOptions.extraDependencies.map(_.value) == expectedDeps)
expect(sources.paths.isEmpty)
Expand Down Expand Up @@ -299,7 +299,7 @@ class SourcesTests extends munit.FunSuite {
TestLogger()
).orThrow
val scopedSources = crossSources.scopedSources(BuildOptions()).orThrow
val sources = scopedSources.sources(Scope.Main, BuildOptions())
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(BuildOptions()))

val parsedCodes: Seq[String] = sources.inMemory.map(_._3)

Expand Down Expand Up @@ -331,7 +331,7 @@ class SourcesTests extends munit.FunSuite {
TestLogger()
).orThrow
val scopedSources = crossSources.scopedSources(BuildOptions()).orThrow
val sources = scopedSources.sources(Scope.Main, BuildOptions())
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(BuildOptions()))

expect(sources.buildOptions.classPathOptions.extraDependencies.map(_.value) == expectedDeps)
expect(sources.paths.isEmpty)
Expand Down Expand Up @@ -364,7 +364,7 @@ class SourcesTests extends munit.FunSuite {
TestLogger()
).orThrow
val scopedSources = crossSources.scopedSources(BuildOptions()).orThrow
val sources = scopedSources.sources(Scope.Main, BuildOptions())
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(BuildOptions()))

expect(sources.buildOptions.classPathOptions.extraDependencies.map(_.value) == expectedDeps)
expect(sources.paths.isEmpty)
Expand All @@ -388,8 +388,8 @@ class SourcesTests extends munit.FunSuite {
TestLogger()
).orThrow
val scopedSources = crossSources.scopedSources(BuildOptions()).orThrow
val sources = scopedSources.sources(Scope.Main, BuildOptions())
val javaOpts = sources.buildOptions.javaOptions.javaOpts.sortBy(_.toString())
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(BuildOptions()))
val javaOpts = sources.buildOptions.javaOptions.javaOpts.sortBy(_.toString())

expect(
javaOpts(0).value == "-Dfoo1",
Expand Down Expand Up @@ -419,8 +419,8 @@ class SourcesTests extends munit.FunSuite {
TestLogger()
).orThrow
val scopedSources = crossSources.scopedSources(BuildOptions()).orThrow
val sources = scopedSources.sources(Scope.Main, BuildOptions())
val jsOptions = sources.buildOptions.scalaJsOptions
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(BuildOptions()))
val jsOptions = sources.buildOptions.scalaJsOptions
expect(
jsOptions.version == Some("1.8.0"),
jsOptions.mode == Some("mode"),
Expand Down
2 changes: 1 addition & 1 deletion modules/cli/src/main/scala/scala/cli/commands/Export.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Export extends ScalaCommand[ExportOptions] {
)
}
val scopedSources = value(crossSources.scopedSources(buildOptions))
val sources = scopedSources.sources(Scope.Main, buildOptions)
val sources = scopedSources.sources(Scope.Main, crossSources.sharedOptions(buildOptions))

if (verbosity >= 3)
pprint.stderr.log(sources)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object SetupIde extends ScalaCommand[SetupIdeOptions] {
}

value(crossSources.scopedSources(options))
.sources(Scope.Main, options)
.sources(Scope.Main, crossSources.sharedOptions(options))
.buildOptions
}

Expand Down