New mill.api.opt API for configuration data containing paths#6129
New mill.api.opt API for configuration data containing paths#6129lefou wants to merge 85 commits intocom-lihaoyi:mainfrom
mill.api.opt API for configuration data containing paths#6129Conversation
9f178f7 to
84c9c7e
Compare
1651aab to
8c6d4dd
Compare
|
Merged in latest changes from |
Opt, Opts and OptMap
Opt, Opts and OptMapmill.api.opt API for configuration data containing paths
|
Going to move the binary breaking refactoring into it's own PR to get this API into Mill. I'm still interested into feedback, though. |
|
Overall not really convinced that this is a viable alternative to the symlink+relative-path approach prototyped in the other PR. This PR adds special handling for option lists, and some limited data structures related to them, but it doesn't really handle all the other places where paths may be embedded in various data structures, text blobs, or This PR is also opt-in, v.s. the other approach which is on-by-default for OS-Lib via global configuration, which means it would be much easier for users to forget and get it wrong. And in general seems to be solving a much narrower slice of the problem that I'm not convinced is enough to get us to the goal of reproducible builds |
Add new API classes with the purpose to represent configuration data that may contain paths. All paths, even when embedded in options or text, are represented as
os.Pathtype and can be therefore handled in a type-safe manner. In case, paths need to be to relocated, no guessing or vagueString.replacelogic is needed. For example, PR #6031 contains a path mapping mechanism, with which allOpts would be automatically covered, too. That means if aOptsor it's companion types are used forjavacOptions,scalacOptionsand other configuration tasks, embedded paths are no longer an issue for relocatable Mill caches or remote caching in general.In contrast to the initial proposal of this idea (#6057) the main classes are named
Opt/Opts, notArg/Args, since we already have amill.api.Argsclass used for other purposes.New API classes
Optis a holder of configuration data.Optcan be constructed from one or multipleStrings oros.Paths. When rendered as string, all parts will be concatenated.Optsis a Seq-like container to be used instead ofSeq[String].OptMapis a type alias toMap[String, Opt]to provide some convenience to be used instead ofMap[String, String].Both container types,
OptsandOptMapcan be easily converted to a String-based container with.toStringSeqor.toStringMap.OptGroupis a group ofOpts that are tightly coupled, and should never be split. This is useful to model semantically bound CLI args with multi-arity like--file <file>or-classpath jar2:jar2:...:jarN. It can help to communicate intent and eases post-processing of multi-part opts.JSON serialization
The JSON structure is more complex than the previous
Seq[String]equivalent, because it needs to support options, option groups and multi-parts options, which may itself consist of many strings and paths.A rather complex
OptsJSON serialization may look like this:Since the JSON serialization for paths re-use the respective upickle-serializers, the root path mapping of PR #6031 may also work here (Resulting is paths like
$MILL_OUT/task/to/jar.dest/out.jar).YAML convenience
In addition, the json reader supports reading of flat json arrays, which means, that all
Seq[String]can easily be read asOpts. This was done to make working withOptsas convenient asSeq[String]not only in Scala code but also inYAMLconfiguration code.This means,
build.millYAML frontmatter andbuild.mill.yamldon't need any changes.Although the full encoding is also supported but seldomly required.
Realistic example
In POC PR #6800, you can see a refactoring of Mill to use the new
mill.api.optAPI in all relevant tasks likejavacOptions,scalacOptions,forkArgs,forkEnvand some more.Caveats / Feedback wanted
In this current POC, we need to add
import mill.api.opt.*. I'm looking for ideas, how to improve this and make it a single import.Related issues and discussions
out/folder contents (more) reproducible and filesystem layout agnostic #3660 - Tracker issuePull request: #6129