diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-16 01:19:38 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-16 01:19:38 +0800 |
| commit | 32c3af83920071d570972e33a6383cfa88c663a8 (patch) | |
| tree | 2c76caae27154ba774e94a3b227d9442ceda0173 /mingling_cli | |
| parent | e287b5090919fffa162918a8b78c50b59f790970 (diff) | |
chore: move lint registry to OUT_DIR
Update registry generation to write to cargo's OUT_DIR and
include it via env! instead of a static project-relative path.
Diffstat (limited to 'mingling_cli')
| -rw-r--r-- | mingling_cli/.gitignore | 2 | ||||
| -rw-r--r-- | mingling_cli/pre/lint_registry.rs | 8 | ||||
| -rw-r--r-- | mingling_cli/src/linter/registry.rs | 5 |
3 files changed, 9 insertions, 6 deletions
diff --git a/mingling_cli/.gitignore b/mingling_cli/.gitignore index 6a6d575..8b13789 100644 --- a/mingling_cli/.gitignore +++ b/mingling_cli/.gitignore @@ -1 +1 @@ -registry.json + diff --git a/mingling_cli/pre/lint_registry.rs b/mingling_cli/pre/lint_registry.rs index e69592b..5bfd3fe 100644 --- a/mingling_cli/pre/lint_registry.rs +++ b/mingling_cli/pre/lint_registry.rs @@ -1,4 +1,4 @@ -use std::{fs, io::Error}; +use std::{fs, io::Error, path::Path}; use just_template::{Template, tmpl}; @@ -67,7 +67,8 @@ pub fn gen_mod_file() -> Result<(), Error> { /// Generate lint metadata registry /// /// Parses each `.rs` file in `src/lints/` (excluding mod.rs and _init.rs), -/// extracts doc-comment metadata, and writes the result as JSON. +/// extracts doc-comment metadata, and writes the result as `registry.json` +/// in the cargo `OUT_DIR`. pub fn gen_lint_registry() -> Result<(), Error> { let root = std::env::current_dir()?; let lints_dir = root.join("src").join("lints"); @@ -102,7 +103,8 @@ pub fn gen_lint_registry() -> Result<(), Error> { }); let json = serde_json::json!({ "lints": lints }); - let out_path = root.join("registry.json"); + let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR is not set"); + let out_path = Path::new(&out_dir).join("registry.json"); fs::write(&out_path, serde_json::to_string_pretty(&json).unwrap())?; Ok(()) } diff --git a/mingling_cli/src/linter/registry.rs b/mingling_cli/src/linter/registry.rs index 79f3225..b9f82fa 100644 --- a/mingling_cli/src/linter/registry.rs +++ b/mingling_cli/src/linter/registry.rs @@ -26,8 +26,9 @@ pub struct LintMetadata { #[program_setup] pub fn lint_registry_setup(p: &mut Program<ThisProgram>) { p.with_resource(ResLintRegistry::lazy_init(|| { - let registry: ResLintRegistry = serde_json::from_str(include_str!("../../registry.json")) - .expect("failed to parse embedded registry.json"); + let registry: ResLintRegistry = + serde_json::from_str(include_str!(concat!(env!("OUT_DIR"), "/registry.json"))) + .expect("failed to parse embedded registry.json"); registry })); } |
