-
-
Notifications
You must be signed in to change notification settings - Fork 421
Improve Task.{Source,Sources} API
#5245
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
Conversation
Accept the following tpye: * `os.SubPath` - an sub-path resolved against `moduleDir` * `os.RelPath` - an relative path resolved against `moduleDir` * `os.Path` - an absolute path * `String` - a sub-path relative to `moduleDir`; the special string `"."` is treated as the `moduleDir`.
Task.{Source,Sources} APITask.{Source,Sources} API
| * [[Task.Computed]]s need to be invalidated and re-computed. | ||
| */ | ||
| inline def Sources(inline values: Result[os.Path]*)(implicit | ||
| inline def Sources(inline values: (os.Path | os.SubPath | os.RelPath | String)*)(implicit |
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.
This big union type looks pretty out of place. Could we use os.FilePath here? Maybe if we add a few more implicits upstream in OS-Lib to make the conversions from string work?
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.
Yeah. Once we use just os.FilePath, we can't profit from String to os.SubPath translation. We either want to support a more generic conversion for String to os.FilePath, which also means we want to handle absolute and relative paths, or find some other way to support conversion.
I committed some compromise acepting os.SubPath | os.FilePath to see if CI likes it.
By using `os.SubPath | os.FilePath`, which is redundant as `os.SubPath` is already a sub-type of `os.FilePath`, we allow implicit converstions from `String` to `os.SubPath`. The explicit `"."` is a test, too.
|
Isn't |
Yeah. Here's my comment from commit 5a28bbb
Also from #5245 (comment)
|
lihaoyi
left a comment
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.
Looks good to me!
Accept the following types (which are all sub-types of
os.FilePath):os.SubPath- an sub-path resolved againstmoduleDiros.RelPath- an relative path resolved againstmoduleDiros.Path- an absolute pathWe also want to accept well-formatted
Stringly-typed paths, by the use of the macro-based implicit conversion from os-lib. To make that work, we need to explicitly accept theos.SubPathtype. Thus we end up with aos.SubPath | os.FilePathsignature, which can be a bit confusing, but gives us compile-time validation instead of potential runtime errors when paths are given asString.