8000 fix(session min): fix weird subcommands and messages, copypasta from tasks by twitchyliquid64 · Pull Request #845 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions crates/mctx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,21 @@ impl Context {
)));
}
}
AddDepMode::SessionPackages => {
if let Some(h) = doc["session"].as_table_mut() {
did_edit |= upsert_toml_packages_list(h, "packages", &resolved);
} else {
doc.insert(
"session",
Item::Table(toml_edit::Table::from_iter([(
"packages",
Item::Value(Value::Array(Array::from_iter(resolved.iter()))),
)])),
);
did_edit = true;
}
println!("Added [{}] to session.packages", resolved.join(","));
}
}

if did_edit {
Expand All @@ -1066,6 +1081,8 @@ pub enum AddDepMode {
RuntimePackages,
/// Add the specified packages to a task with a given name.
TaskPackages { name: String },
/// Add the specified packages to session.packages.
SessionPackages,
}

fn upsert_toml_packages_list<T: TableLike>(t: &mut T, key: &str, upsert: &[String]) -> bool {
Expand Down Expand Up @@ -1451,6 +1468,15 @@ mod tests {
ctx.add_deps(&graph, ["missingggggg"], AddDepMode::BuildPackages)
.is_err()
);

// Add a package to the session.
ctx.add_deps(&graph, ["uroot"], AddDepMode::SessionPackages)
.unwrap();
assert!(
String::from_utf8(std::fs::read(&mfile_path).unwrap())
.unwrap()
.contains("[session]\npackages = [\"uroot\"]")
);
}

#[test]
Expand Down
4 changes: 1 addition & 3 deletions crates/mctx/src/min_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,11 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
;;
*)
echo "Usage: min <subcommand>" >&2
echo "See CLAUDE.md at the project root for more detailed instructions." >&2
echo "" >&2
echo "Add packages: min add [--session|--build|--runtime|--task <taskname>] <packages>" >&2
echo "Add packages: min add [--session|--build|--runtime|--task] <packages>" >&2
Comment thread
twitchyliquid64 marked this conversation as resolved.
Resolved
echo "Search for packages: min search <query>" >&2
echo "Check minimal configuration: min check" >&2
echo "Run a task: min run <task name>" >&2
echo "Check minimal configuration: min check" >&2
echo "Try building a package (with potentially-stale dependencies): min patched-pkg <package name>" >&2
exit 1
;;
Expand Down
15 changes: 3 additions & 12 deletions crates/minimald/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ impl Env {
.unwrap(),
state_dir: args.state_base_dir.clone(),
working: args.cwd.clone(),
task_name: args.name.clone(),
has_packages: transitives.keys().copied().collect(),
ot: args.ot.clone(),
ctx,
Expand Down Expand Up @@ -497,8 +496,6 @@ struct SessionChannel {
/// The host directory the working directory.
working: DaemonAbsPath,

/// The environment name, used when adding task packages.
task_name: String,
/// Packages already materialized into the rootfs.
has_packages: HashSet<BuildSpecRef>,
ot: Option<OpTracker>,
Expand All @@ -519,7 +516,7 @@ impl SessionChannel {
/// Dispatches a single `method%data` request line.
async fn handle(&mut self, line: &str, stream: &mut UnixStream) {
let add_dep = match line.split_once('%') {
Some(("add-session", pkgs)) => match self.parse_pkgs_line(pkgs) {
Some(("add-transient", pkgs)) => match self.parse_pkgs_line(pkgs) {
Err(n) => {
let _ = writeln!(stream, "error: no such package '{n}'");
None
Expand Down Expand Up @@ -549,19 +546,14 @@ impl SessionChannel {
Some((AddDepMode::RuntimePackages, pkgs))
}
},
Some(("add-task", pkgs)) => match self.parse_pkgs_line(pkgs) {
Some(("add-session", pkgs)) => match self.parse_pkgs_line(pkgs) {
Err(n) => {
let _ = writeln!(stream, "error: no such package '{n}'");
None
}
Ok(pkgs) => {
self.install(&pkgs, stream).await;
Some((
AddDepMode::TaskPackages {
name: self.task_name.clone(),
},
pkgs,
))
Some((AddDepMode::SessionPackages, pkgs))
Comment thread
twitchyliquid64 marked this conversation as resolved.
Resolved
}
},
Some(("search", term)) => {
Expand Down Expand Up @@ -1027,7 +1019,6 @@ mod tests {
Utf8PathBuf::try_from(cwd.path().to_path_buf()).unwrap(),
)
.unwrap(),
task_name: "test-task".to_string(),
has_packages: HashSet::new(),
ot: None,
ctx,
Expand Down
10 changes: 3 additions & 7 deletions crates/minimald/src/env_min_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,13 @@ min_add() {

# If no flag provided, or first arg isn't a flag, default to --session
if [[ -z "$flag" || "$flag" != --* ]]; then
echo "No --flag provided, defaulting to adding package(s) for this session only"
flag="--session"
else
shift
fi

if [[ -z "$1" ]]; then
echo "Usage: min add [--session|--build|--runtime|--task] <packages>" >&2
echo "Usage: min add [--session|--build|--runtime] <packages>" >&2
Comment thread
twitchyliquid64 marked this conversation as resolved.
Resolved
return 1
fi

Expand All @@ -96,9 +95,8 @@ min_add() {
--session) prefix="add-session" ;;
--build) prefix="add-build" ;;
--runtime) prefix="add-runtime" ;;
--task) prefix="add-task" ;;
*)
echo "error: unknown flag '$flag'. Expected --session, --build, --runtime, or --task" >&2
echo "error: unknown flag '$flag'. Expected --session, --build, or --runtime" >&2
return 1
;;
esac
Expand Down Expand Up @@ -142,13 +140,11 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
;;
*)
echo "Usage: min <subcommand>" >&2
echo "See CLAUDE.md at the project root for more detailed instructions." >&2
echo "" >&2
echo "Add packages: min add [--session|--build|--runtime|--task <taskname>] <packages>" >&2
echo "Add packages: min add [--session|--build|--runtime] <packages>" >&2
echo "Search for packages: min search <query>" >&2
echo "Check minimal configuration: min check" >&2
echo "Run a task: min run <task name>" >&2
echo "Check minimal configuration: min check" >&2
echo "Try building a package (with potentially-stale dependencies): min patched-pkg <package name>" >&2
exit 1
;;
Expand Down
0