feat: configuration of project sources#130
feat: configuration of project sources#130victor-linroth-sensmetry wants to merge 28 commits intomainfrom
Conversation
|
Is there a particular reason for expanding |
No particular reason, just the first thing that came to mind. Do you think that would be a better solution? |
It might be easier to test/mock, and be a bit easier to reuse elsewhere. You can simply have No very strong preference though, so don't bother if it's a lot of work to refactor. |
|
Everything looks good to me in principle, would be a good to have a proper code review from @andrius-puksta-sensmetry before merging though. |
Well, this was precisely the type of feedback I was looking for, so I'll definitely consider it.
It's still a draft so far. I want to add some quality of life command line stuff also. |
67ca989 to
4173804
Compare
4173804 to
a418bd2
Compare
a418bd2 to
bf73d16
Compare
bd2ad17 to
0fa5369
Compare
|
Currently The problem stem from the fact that reference of types in macros should be absolute but the absolute paths vary depending on if you are inside or outside the crate. E.g. it's One could try to add them as associated types to Another solution would be to refactor the crates so that they are always used outside of the crate where they are exported. Would essentially mean that all the project stuff goes into it's own crate (except for Edit: I think the appropriate course of action is to factor out the projects into their own crate, but this would be a pretty wide reaching change so best to do as a separate PR after this is merged. |
|
Unsure if |
|
Still left to make sure Windows paths are handled properly (don't think they are at the moment). Edit: Since the sources only have paths that are |
49299d9 to
7a835d1
Compare
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
| MemoryResolver::from(overrides), | ||
| standard_resolver( | ||
| cwd, | ||
| if local_env_path.is_dir() { |
There was a problem hiding this comment.
This is eating errors. Maybe we should add is_file() and is_dir() to wrapfs, but make them e.g. fn is_file() -> Result<bool, SomeError>? This is mostly a nice-to-have, so can be done later.
There was a problem hiding this comment.
What error? You can run sysand info on an IRI without having an env.
sysand/src/commands/add.rs
Outdated
| Ok(src_path) | ||
| } | ||
|
|
||
| fn relativize(path: &Utf8Path, root: &Utf8Path) -> Utf8PathBuf { |
There was a problem hiding this comment.
| fn relativize(path: &Utf8Path, root: &Utf8Path) -> Utf8PathBuf { | |
| /// Create a relative path from `root` to `path`. Both of them must either | |
| /// be absolute or otherwise start with the same prefix. | |
| fn relativize(path: &Utf8Path, root: &Utf8Path) -> Utf8PathBuf { |
There was a problem hiding this comment.
Also maybe return Option<Utf8PathBuf> so that caller can decide what to do in case relative path cannot be constructed.
There was a problem hiding this comment.
This function is useful (i.e. should be used, but currently isn't) in lots of places, so it should be moved to some utils file.
| // If prefixes (e.g. C: vs D: on Windows) differ, no relative path is possible. | ||
| if path.components().next() != root.components().next() { | ||
| return path.to_path_buf(); | ||
| } |
There was a problem hiding this comment.
Not sure what to do about Windows UNC vs non-UNC paths, as they always have different first components. Relevant here is that std's canonicalize returns UNC paths on Windows, but calling that on both inputs here would be kind of wasteful.
There was a problem hiding this comment.
Windows root-relative paths are also not handled correctly here.
There was a problem hiding this comment.
It may be a good idea after all to canonicalize both paths (or ensuring only canonical paths are given as args here) to avoid subtle bugs due to symlinks and Windows weirndess.
docs/src/config/dependencies.md
Outdated
|
|
||
| Sometimes you may wish to use a project that isn't resolvable through an | ||
| available index or you want to override the dependency resolution for other | ||
| reasons. In any case you can do this by adding the appropriate IRI and `Source` |
There was a problem hiding this comment.
| reasons. In any case you can do this by adding the appropriate IRI and `Source` | |
| reasons. You may also just want to give the usage a different identifier for readability. In any case you can do this by adding the appropriate IRI and `sources` |
There was a problem hiding this comment.
I'm not sure this is a great way of doing general aliasing, as then you may want to still want to go through regular dependency resolution. Maybe there's a way to add that as a separate feature in the future?
| file, but it is also possible to do through the command line interface with the | ||
| [`sysand add`](../commands/add.md) command. | ||
|
|
||
| ## Local projects |
There was a problem hiding this comment.
Maybe mention the exact CLI flag to use for each type here?
| the following entry to your `sysand.toml`. | ||
|
|
||
| ```toml | ||
| [[project]] |
There was a problem hiding this comment.
Maybe rename this to [[source]] to give us space to put the current project metadata here (if we ever decide to do this)?
There was a problem hiding this comment.
Yeah, I thought about that a too, but naming it something else breaks the symmetry with lockfile format. There is potentially more configurations we want to add here like e.g. aliasing (having multiple identifiers) and disabling checksums (in case the project is expected to change a lot like editable projects and sources pointing to git branches). I think having the lockfile and config mirror each other here would be nice.
| #[proc_macro_derive(ProjectRead)] | ||
| pub fn project_read_derive(input: TokenStream) -> TokenStream { |
There was a problem hiding this comment.
Add a doc comment describing what this derive generates (i.e. what the derived impl does given an example arg).
| #[proc_macro_derive(ProjectMut)] | ||
| pub fn project_mut_derive(input: TokenStream) -> TokenStream { |
There was a problem hiding this comment.
Description also needed here
| for r in root_iter { | ||
| if let Utf8Component::Normal(_) = r { | ||
| result.push(".."); | ||
| } | ||
| } |
There was a problem hiding this comment.
This is not always correct due to symlinks, unless both paths are already canonical.
There was a problem hiding this comment.
This will also return an empty path if path and base are the same.
There was a problem hiding this comment.
And the paths will use platform-dependent separator: \ on Windows and / everywhere? else. Is config.toml intended to be portable?
There was a problem hiding this comment.
This is not always correct due to symlinks, unless both paths are already canonical.
Guess it's easiest to just canonicalize them both.
This will also return an empty path if path and base are the same.
No it will be .? (Maybe some warning is appropriate here though since this doesn't make much sense for actual usage.)
And the paths will use platform-dependent separator: \ on Windows and / everywhere? else. Is config.toml intended to be portable?
I'm pretty sure all paths get transformed to Utf8UnixPaths before going into any file.
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Signed-off-by: victor.linroth.sensmetry <victor.linroth@sensmetry.com>
Main new features added by this PR:
sysand.toml(or given config). Allows for portable specification of local and remote sources.--editable,--path,--url-srcand--url-kparforsysand addthat automatically updates config file. These also get removed withsysand remove.In order to simplify implementing the above the
corelibrary was build out with the following changes:ProjectReadandProjectMutderive macros for easy enum composition of project structs.CachedProject<Local, Remote>struct for when theLocalproject is easier to access (e.g. on disk or in memory) vsRemote, but you still want.sources()to give the remote sources.CombinedResolversimplified usingderive(ProjectRead)andCachedProject.ProjectReference<Project>struct. When working withReadEnvironmentthe projects need to be clonable, but this might not always be a good idea, e.g. some project hold ownership of temp dirs.ProjectReferenceis basically andArcwrapper for a project to be used as a compatibility layer.AnyProjectstruct combining the different projects supported for source configuration. Should be extended to include Git projects in future.LocalSrcProjectandLocalKparProjectnow has optional nominal paths in addition to the regular path. This comes from the choice to have configured source always be relative to the project root but this not always being available everywhere. (Could perhaps be simplified if we added a Global Context).In addition there where some small changes that came about when experimenting with different solutions:
MemoryEnvcan now be used with a generic project.MemoryResolvercan be conveniently constructed from iterator/array/Vec.These ended up not being used here, but they could be useful at some later point so where left in.
Lastly, the
verbose/quietoptions were removed from the config. They were mostly placeholders to begin with and now that there are more real options present in the config they don't serve much of a purpose. Removing them also means that the logger can be initialized almost immediately on start, opening up the potential for logging more things, like e.g. the loading of the config files.