List included recipes in load order (#1745)
This commit is contained in:
parent
2cff91cee2
commit
92bae080ab
@ -9,15 +9,17 @@ pub(crate) struct Analyzer<'src> {
|
|||||||
|
|
||||||
impl<'src> Analyzer<'src> {
|
impl<'src> Analyzer<'src> {
|
||||||
pub(crate) fn analyze(
|
pub(crate) fn analyze(
|
||||||
|
loaded: Vec<PathBuf>,
|
||||||
paths: &HashMap<PathBuf, PathBuf>,
|
paths: &HashMap<PathBuf, PathBuf>,
|
||||||
asts: &HashMap<PathBuf, Ast<'src>>,
|
asts: &HashMap<PathBuf, Ast<'src>>,
|
||||||
root: &Path,
|
root: &Path,
|
||||||
) -> CompileResult<'src, Justfile<'src>> {
|
) -> CompileResult<'src, Justfile<'src>> {
|
||||||
Analyzer::default().justfile(paths, asts, root)
|
Analyzer::default().justfile(loaded, paths, asts, root)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn justfile(
|
fn justfile(
|
||||||
mut self,
|
mut self,
|
||||||
|
loaded: Vec<PathBuf>,
|
||||||
paths: &HashMap<PathBuf, PathBuf>,
|
paths: &HashMap<PathBuf, PathBuf>,
|
||||||
asts: &HashMap<PathBuf, Ast<'src>>,
|
asts: &HashMap<PathBuf, Ast<'src>>,
|
||||||
root: &Path,
|
root: &Path,
|
||||||
@ -101,6 +103,7 @@ impl<'src> Analyzer<'src> {
|
|||||||
}),
|
}),
|
||||||
aliases,
|
aliases,
|
||||||
assignments: self.assignments,
|
assignments: self.assignments,
|
||||||
|
loaded,
|
||||||
recipes,
|
recipes,
|
||||||
settings,
|
settings,
|
||||||
warnings,
|
warnings,
|
||||||
|
@ -11,12 +11,14 @@ impl Compiler {
|
|||||||
let mut asts: HashMap<PathBuf, Ast> = HashMap::new();
|
let mut asts: HashMap<PathBuf, Ast> = HashMap::new();
|
||||||
let mut paths: HashMap<PathBuf, PathBuf> = HashMap::new();
|
let mut paths: HashMap<PathBuf, PathBuf> = HashMap::new();
|
||||||
let mut srcs: HashMap<PathBuf, &str> = HashMap::new();
|
let mut srcs: HashMap<PathBuf, &str> = HashMap::new();
|
||||||
|
let mut loaded = Vec::new();
|
||||||
|
|
||||||
let mut stack: Vec<PathBuf> = Vec::new();
|
let mut stack: Vec<PathBuf> = Vec::new();
|
||||||
stack.push(root.into());
|
stack.push(root.into());
|
||||||
|
|
||||||
while let Some(current) = stack.pop() {
|
while let Some(current) = stack.pop() {
|
||||||
let (relative, src) = loader.load(root, ¤t)?;
|
let (relative, src) = loader.load(root, ¤t)?;
|
||||||
|
loaded.push(relative.into());
|
||||||
let tokens = Lexer::lex(relative, src)?;
|
let tokens = Lexer::lex(relative, src)?;
|
||||||
let mut ast = Parser::parse(&tokens)?;
|
let mut ast = Parser::parse(&tokens)?;
|
||||||
|
|
||||||
@ -42,7 +44,7 @@ impl Compiler {
|
|||||||
asts.insert(current.clone(), ast.clone());
|
asts.insert(current.clone(), ast.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
let justfile = Analyzer::analyze(&paths, &asts, root)?;
|
let justfile = Analyzer::analyze(loaded, &paths, &asts, root)?;
|
||||||
|
|
||||||
Ok(Compilation {
|
Ok(Compilation {
|
||||||
asts,
|
asts,
|
||||||
@ -61,7 +63,7 @@ impl Compiler {
|
|||||||
asts.insert(root.clone(), ast);
|
asts.insert(root.clone(), ast);
|
||||||
let mut paths: HashMap<PathBuf, PathBuf> = HashMap::new();
|
let mut paths: HashMap<PathBuf, PathBuf> = HashMap::new();
|
||||||
paths.insert(root.clone(), root.clone());
|
paths.insert(root.clone(), root.clone());
|
||||||
Analyzer::analyze(&paths, &asts, &root)
|
Analyzer::analyze(Vec::new(), &paths, &asts, &root)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ pub(crate) struct Justfile<'src> {
|
|||||||
pub(crate) assignments: Table<'src, Assignment<'src>>,
|
pub(crate) assignments: Table<'src, Assignment<'src>>,
|
||||||
#[serde(rename = "first", serialize_with = "keyed::serialize_option")]
|
#[serde(rename = "first", serialize_with = "keyed::serialize_option")]
|
||||||
pub(crate) default: Option<Rc<Recipe<'src>>>,
|
pub(crate) default: Option<Rc<Recipe<'src>>>,
|
||||||
|
#[serde(skip)]
|
||||||
|
pub(crate) loaded: Vec<PathBuf>,
|
||||||
pub(crate) recipes: Table<'src, Rc<Recipe<'src>>>,
|
pub(crate) recipes: Table<'src, Rc<Recipe<'src>>>,
|
||||||
pub(crate) settings: Settings<'src>,
|
pub(crate) settings: Settings<'src>,
|
||||||
pub(crate) warnings: Vec<Warning>,
|
pub(crate) warnings: Vec<Warning>,
|
||||||
@ -365,7 +367,16 @@ impl<'src> Justfile<'src> {
|
|||||||
.collect::<Vec<&Recipe<Dependency>>>();
|
.collect::<Vec<&Recipe<Dependency>>>();
|
||||||
|
|
||||||
if source_order {
|
if source_order {
|
||||||
recipes.sort_by_key(|recipe| recipe.name.offset);
|
recipes.sort_by_key(|recipe| {
|
||||||
|
(
|
||||||
|
self
|
||||||
|
.loaded
|
||||||
|
.iter()
|
||||||
|
.position(|path| path == recipe.name.path)
|
||||||
|
.unwrap(),
|
||||||
|
recipe.name.offset,
|
||||||
|
)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
recipes
|
recipes
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
clippy::enum_glob_use,
|
clippy::enum_glob_use,
|
||||||
clippy::let_underscore_untyped,
|
clippy::let_underscore_untyped,
|
||||||
clippy::needless_pass_by_value,
|
clippy::needless_pass_by_value,
|
||||||
|
clippy::similar_names,
|
||||||
clippy::too_many_lines,
|
clippy::too_many_lines,
|
||||||
clippy::unnecessary_wraps,
|
clippy::unnecessary_wraps,
|
||||||
clippy::wildcard_imports
|
clippy::wildcard_imports
|
||||||
|
@ -68,7 +68,7 @@ pub(crate) fn analysis_error(
|
|||||||
let mut paths: HashMap<PathBuf, PathBuf> = HashMap::new();
|
let mut paths: HashMap<PathBuf, PathBuf> = HashMap::new();
|
||||||
paths.insert("justfile".into(), "justfile".into());
|
paths.insert("justfile".into(), "justfile".into());
|
||||||
|
|
||||||
match Analyzer::analyze(&paths, &asts, &root) {
|
match Analyzer::analyze(Vec::new(), &paths, &asts, &root) {
|
||||||
Ok(_) => panic!("Analysis unexpectedly succeeded"),
|
Ok(_) => panic!("Analysis unexpectedly succeeded"),
|
||||||
Err(have) => {
|
Err(have) => {
|
||||||
let want = CompileError {
|
let want = CompileError {
|
||||||
|
@ -120,3 +120,25 @@ fn include_recipes_are_not_default() {
|
|||||||
.stderr("error: Justfile contains no default recipe.\n")
|
.stderr("error: Justfile contains no default recipe.\n")
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn listed_recipes_in_includes_are_in_load_order() {
|
||||||
|
Test::new()
|
||||||
|
.justfile(
|
||||||
|
"
|
||||||
|
!include ./include.justfile
|
||||||
|
foo:
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.write("include.justfile", "bar:")
|
||||||
|
.args(["--list", "--unstable", "--unsorted"])
|
||||||
|
.test_round_trip(false)
|
||||||
|
.stdout(
|
||||||
|
"
|
||||||
|
Available recipes:
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user