Skip to content

Commit

Permalink
Ensure resource directories passed via a using directive aren't ign…
Browse files Browse the repository at this point in the history
…ored in `--watch` mode
  • Loading branch information
Gedochao committed Oct 4, 2024
1 parent b0e24a2 commit 130a955
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
19 changes: 16 additions & 3 deletions modules/build/src/main/scala/scala/build/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -687,24 +687,37 @@ object Build {
either {
val (crossSources: CrossSources, inputs0: Inputs) =
value(allInputs(inputs, options, logger))
val resourceDirectoriesFromDirectives = {
// resource directories passed via a command line option are registered as Input elements.
// however, those passed via a using directive are only passed via build options.
// TODO: refactor and clean this up
val resourceDirsFromCli =
inputs0.elements.flatMap { case rd: ResourceDirectory => Some(rd.path); case _ => None }
val latestResourceDirsFromBuildOptions: Seq[os.Path] =
crossSources.buildOptions.flatMap(_.value.classPathOptions.resourcesDir).distinct
latestResourceDirsFromBuildOptions
.filter(!resourceDirsFromCli.contains(_))
.map(ResourceDirectory(_))
}
val finalInputs = inputs0.add(resourceDirectoriesFromDirectives)
val sharedOptions = crossSources.sharedOptions(options)
val compiler: ScalaCompiler = value {
compilerMaker.create(
inputs0.workspace / Constants.workspaceDirName,
finalInputs.workspace / Constants.workspaceDirName,
classesDir0,
buildClient,
logger,
sharedOptions
)
}
val docCompilerOpt: Option[ScalaCompiler] = docCompilerMakerOpt.map(_.create(
inputs0.workspace / Constants.workspaceDirName,
finalInputs.workspace / Constants.workspaceDirName,
classesDir0,
buildClient,
logger,
sharedOptions
)).map(value)
(compiler, docCompilerOpt, crossSources, inputs0)
(compiler, docCompilerOpt, crossSources, finalInputs)
}

var res: Either[BuildException, Builds] = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,32 @@ trait RunWithWatchTestDefinitions { _: RunTestDefinitions =>
}
}
}

for {
useDirective <- Seq(false, true)
directive = if (useDirective) "//> using resourceDirs ./resources" else ""
resourceOptions = if (useDirective) Nil else Seq("--resource-dirs", "./src/proj/resources")
title = if (useDirective) "directive" else "command line"
} test(s"resources via $title with --watch") {
val expectedMessage1 = "Hello"
val expectedMessage2 = "world"
resourcesInputs(directive = directive, resourceContent = expectedMessage1)
.fromRoot { root =>
TestUtil.withProcessWatching(
os.proc(TestUtil.cli, "run", "src", "--watch", resourceOptions, extraOptions)
.spawn(cwd = root, stderr = os.Pipe)
) { (proc, timeout, ec) =>
val output1 = TestUtil.readLine(proc.stdout, ec, timeout)
expect(output1 == expectedMessage1)
proc.printStderrUntilRerun(timeout)(ec)
val Some((resourcePath, newResourceContent)) =
resourcesInputs(directive = directive, resourceContent = expectedMessage2)
.files
.find(_._1.toString.contains("resources"))
os.write.over(root / resourcePath, newResourceContent)
val output2 = TestUtil.readLine(proc.stdout, ec, timeout)
expect(output2 == expectedMessage2)
}
}
}
}

0 comments on commit 130a955

Please sign in to comment.