Rename Justfile::first → Justfile::default (#1741)

This commit is contained in:
Casey Rodarmor 2023-11-22 10:33:55 -08:00 committed by GitHub
parent ab16c0493f
commit 09a39055ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 11 deletions

View File

@ -88,7 +88,7 @@ impl<'src> Analyzer<'src> {
let root = paths.get(root).unwrap(); let root = paths.get(root).unwrap();
Ok(Justfile { Ok(Justfile {
first: recipes default: recipes
.values() .values()
.filter(|recipe| recipe.name.path == root) .filter(|recipe| recipe.name.path == root)
.fold(None, |accumulator, next| match accumulator { .fold(None, |accumulator, next| match accumulator {

View File

@ -8,20 +8,19 @@ impl Compiler {
loader: &'src Loader, loader: &'src Loader,
root: &Path, root: &Path,
) -> RunResult<'src, Compilation<'src>> { ) -> RunResult<'src, Compilation<'src>> {
let mut srcs: HashMap<PathBuf, &str> = HashMap::new();
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 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, &current)?; let (relative, src) = loader.load(root, &current)?;
paths.insert(current.clone(), 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)?;
paths.insert(current.clone(), relative.into());
srcs.insert(current.clone(), src); srcs.insert(current.clone(), src);
for item in &mut ast.items { for item in &mut ast.items {
@ -31,15 +30,11 @@ impl Compiler {
message: "The !include directive is currently unstable.".into(), message: "The !include directive is currently unstable.".into(),
}); });
} }
let include = current.parent().unwrap().join(relative).lexiclean(); let include = current.parent().unwrap().join(relative).lexiclean();
if srcs.contains_key(&include) { if srcs.contains_key(&include) {
return Err(Error::CircularInclude { current, include }); return Err(Error::CircularInclude { current, include });
} }
*absolute = Some(include.clone()); *absolute = Some(include.clone());
stack.push(include); stack.push(include);
} }
} }

View File

@ -4,8 +4,8 @@ use {super::*, serde::Serialize};
pub(crate) struct Justfile<'src> { pub(crate) struct Justfile<'src> {
pub(crate) aliases: Table<'src, Alias<'src>>, pub(crate) aliases: Table<'src, Alias<'src>>,
pub(crate) assignments: Table<'src, Assignment<'src>>, pub(crate) assignments: Table<'src, Assignment<'src>>,
#[serde(serialize_with = "keyed::serialize_option")] #[serde(rename = "first", serialize_with = "keyed::serialize_option")]
pub(crate) first: Option<Rc<Recipe<'src>>>, pub(crate) default: Option<Rc<Recipe<'src>>>,
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>,
@ -190,7 +190,7 @@ impl<'src> Justfile<'src> {
let argvec: Vec<&str> = if !arguments.is_empty() { let argvec: Vec<&str> = if !arguments.is_empty() {
arguments.iter().map(String::as_str).collect() arguments.iter().map(String::as_str).collect()
} else if let Some(recipe) = &self.first { } else if let Some(recipe) = &self.default {
let min_arguments = recipe.min_arguments(); let min_arguments = recipe.min_arguments();
if min_arguments > 0 { if min_arguments > 0 {
return Err(Error::DefaultRecipeRequiresArguments { return Err(Error::DefaultRecipeRequiresArguments {