-
Notifications
You must be signed in to change notification settings - Fork 5
Support distribution of RPL patterns #108
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
Open
jellllly420
wants to merge
1
commit into
RPL-Toolchain:master
Choose a base branch
from
jellllly420:feat/publish
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| [package] | ||
| name = "rpl_config" | ||
| version.workspace = true | ||
| description.workspace = true | ||
| repository.workspace = true | ||
| license.workspace = true | ||
| keywords.workspace = true | ||
| edition.workspace = true | ||
|
|
||
| [dependencies] | ||
| cargo_metadata = "0.15.4" | ||
| serde.workspace = true | ||
| serde_json.workspace = true | ||
| toml.workspace = true | ||
| thiserror.workspace = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| use std::path::{Path, PathBuf}; | ||
|
|
||
| use serde::Deserialize; | ||
|
|
||
| mod patterns; | ||
| mod run; | ||
| mod util; | ||
|
|
||
| #[derive(Debug, thiserror::Error)] | ||
| pub enum ConfigError { | ||
| #[error("failed to read {path}: {source}")] | ||
| Io { path: PathBuf, source: Box<std::io::Error> }, | ||
| #[error("failed to parse {path}: {source}")] | ||
| Toml { | ||
| path: PathBuf, | ||
| source: Box<toml::de::Error>, | ||
| }, | ||
| #[error("cargo metadata failed: {0}")] | ||
| CargoMetadata(#[from] Box<cargo_metadata::Error>), | ||
| #[error("rpl.toml not found at {path}")] | ||
| ConfigNotFound { path: PathBuf }, | ||
| #[error("rpl.toml defines no pattern groups")] | ||
| NoGroups, | ||
| #[error("duplicate pattern group name `{name}`")] | ||
| DuplicateGroup { name: String }, | ||
| #[error("unknown pattern group `{name}`")] | ||
| UnknownGroup { name: String }, | ||
| #[error("invalid remote group reference `{spec}`; expected `crate::group`")] | ||
| InvalidRemoteGroup { spec: String }, | ||
| #[error("crate `{crate_name}` not found in cargo metadata")] | ||
| CrateNotFound { crate_name: String }, | ||
| #[error("multiple crates named `{crate_name}` found; disambiguation not supported")] | ||
| AmbiguousCrate { crate_name: String }, | ||
| #[error("crate `{crate_name}` does not publish RPL metadata")] | ||
| MissingRplMetadata { crate_name: String }, | ||
| #[error("crate `{crate_name}` has invalid RPL metadata: {error}")] | ||
| InvalidRplMetadata { crate_name: String, error: String }, | ||
| #[error("crate `{crate_name}` does not define RPL group `{group}`")] | ||
| MissingRemoteGroup { crate_name: String, group: String }, | ||
| #[error("pattern group name cannot be empty")] | ||
| EmptyGroupName, | ||
| #[error("pattern path is not valid unicode: {path}")] | ||
| NonUnicodePath { path: PathBuf }, | ||
| #[error("pattern paths cannot be joined for environment variable: {source}")] | ||
| InvalidPatternPathList { source: Box<std::env::JoinPathsError> }, | ||
| } | ||
|
|
||
| #[derive(Debug, Deserialize)] | ||
| struct RplConfig { | ||
| run: Option<run::RunConfig>, | ||
| patterns: Option<patterns::PatternsConfig>, | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct Config { | ||
| pub patterns_env: Option<String>, | ||
| pub inline_mir: Option<bool>, | ||
| } | ||
|
|
||
| pub fn load_config(manifest_path: Option<&Path>, selected_groups: &[String]) -> Result<Config, ConfigError> { | ||
| let base_dir = util::resolve_base_dir(manifest_path)?; | ||
| let config_path = base_dir.join("rpl.toml"); | ||
| let config = if config_path.exists() { | ||
| Some(util::read_config(&config_path)?) | ||
| } else { | ||
| None | ||
| }; | ||
| let inline_mir = run::load_inline_mir(config.as_ref()); | ||
| let patterns_env = patterns::load_patterns_env(manifest_path, selected_groups, config.as_ref())?; | ||
| Ok(Config { | ||
| patterns_env, | ||
| inline_mir, | ||
| }) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.