-
Notifications
You must be signed in to change notification settings - Fork 143
Support links in using file directive (implements #1328) #3681
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 all commits
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package scala.build | ||
|
||
import java.io.File | ||
import coursier.cache.FileCache | ||
import coursier.util.{Artifact, Task} | ||
|
||
import scala.build.CollectionOps.* | ||
import scala.build.EitherCps.{either, value} | ||
|
@@ -209,7 +210,8 @@ object CrossSources { | |
.flatMap(_.options) | ||
.flatMap(_.internal.extraSourceFiles) | ||
.distinct | ||
val inputsElemFromDirectives: Seq[SingleFile] = | ||
|
||
val inputsElemFromDirectives: Seq[SingleElement] = | ||
value(resolveInputsFromSources(sourcesFromDirectives, inputs.enableMarkdown)) | ||
val preprocessedSourcesFromDirectives: Seq[PreprocessedSource] = | ||
value(preprocessSources(inputsElemFromDirectives.pipe(elements => | ||
|
@@ -403,7 +405,39 @@ object CrossSources { | |
fromInputs ++ fromSources ++ fromSourcesWithRequirements | ||
} | ||
|
||
private def resolveInputsFromSources(sources: Seq[Positioned[os.Path]], enableMarkdown: Boolean) = | ||
// TODO: reuse existing one? e.g. scala.cli.commands.shared.SharedOptions.coursierCache | ||
lazy val fileCache: FileCache[coursier.util.Task] = FileCache() | ||
|
||
private def downloadFile(pUri: Positioned[java.net.URI]) = | ||
import scala.build.options.ScalaVersionUtil.fileWithTtl0 | ||
val artifact = Artifact(pUri.value.toString).withChanging(true) | ||
fileCache.fileWithTtl0(artifact) | ||
.left | ||
.map(err => | ||
new MalformedDirectiveError(err.describe, pUri.positions) | ||
) // TODO: better error type | ||
Comment on lines
+417
to
+418
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. just a new error class would do, I think |
||
.map(f => os.read.bytes(os.Path(f, Os.pwd))).map(content => | ||
Seq(Virtual(pUri.value.toString, content)) | ||
) | ||
Comment on lines
+411
to
+421
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. This is very similar to |
||
|
||
type CodeFile = os.Path | java.net.URI | ||
|
||
private def resolveInputsFromSources( | ||
sources: Seq[Positioned[CodeFile]], | ||
enableMarkdown: Boolean | ||
) = | ||
val links = sources.collect { | ||
case Positioned(pos, value: java.net.URI) => Positioned(pos, value) | ||
} | ||
val paths = sources.collect { | ||
case Positioned(pos, value: os.Path) => Positioned(pos, value) | ||
} | ||
|
||
(resolveInputsFromPath(paths, enableMarkdown) ++ links.map(downloadFile)).sequence | ||
.left.map(CompositeBuildException(_)) | ||
.map(_.flatten) | ||
|
||
private def resolveInputsFromPath(sources: Seq[Positioned[os.Path]], enableMarkdown: Boolean) = | ||
sources.map { source => | ||
val sourcePath = source.value | ||
lazy val dir = sourcePath / os.up | ||
|
@@ -424,9 +458,7 @@ object CrossSources { | |
else s"$sourcePath: not found path defined in using directive." | ||
Left(new MalformedDirectiveError(msg, source.positions)) | ||
} | ||
}.sequence | ||
.left.map(CompositeBuildException(_)) | ||
.map(_.flatten) | ||
} | ||
|
||
/** Filters out the sources from the input sequence based on the provided 'exclude' patterns. The | ||
* exclude patterns can be absolute paths, relative paths, or glob patterns. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I think it's accurate that
SharedOptions.coursierCache
should be used.