Skip to content

Commit

Permalink
codchi exec bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
htngr committed Oct 17, 2024
1 parent dadf287 commit d1e3215
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
20 changes: 20 additions & 0 deletions codchi/src/platform/cmd/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ pub trait LinuxCommandTarget {
}
}

fn raw(&self, program: &str, args: &[&str]) -> LinuxCommandBuilder {
LinuxCommandBuilder {
driver: self.get_driver(),
program: Program::Raw {
program: program.to_string(),
args: args.iter().map(|arg| arg.to_string()).collect(),
},
user: None,
cwd: None,
env: HashMap::new(), // output: Output::Collect,
}
}

fn script(&self, script: String) -> LinuxCommandBuilder {
LinuxCommandBuilder {
driver: self.get_driver(),
Expand Down Expand Up @@ -66,6 +79,7 @@ pub struct LinuxCommandBuilder {
#[derive(Debug, Clone)]
pub enum Program {
Run { program: String, args: Vec<String> },
Raw { program: String, args: Vec<String> },
Script(String),
}

Expand Down Expand Up @@ -107,6 +121,12 @@ impl From<LinuxCommandBuilder> for Command {
cmd.arg("runin");
cmd.stdin(Stdio::piped());
}
Program::Raw { program, args } => {
cmd.arg(program);
for arg in args.iter() {
cmd.arg(arg);
}
}
};
cmd
}
Expand Down
14 changes: 7 additions & 7 deletions codchi/src/platform/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,17 +401,17 @@ git add flake.*
set_progress_status(format!("Starting {}...", self.config.name));
self.start()?;

let cmd = match cmd.split_first() {
Some((cmd, args)) => self
.cmd()
.run(cmd, &args.iter().map(|str| str.as_str()).collect_vec()),
None => self.cmd().run("bash", &["-l"]),
};
let args = [
vec![consts::user::DEFAULT_NAME],
cmd.iter().map(|str| str.as_str()).collect_vec(),
]
.concat();
let cmd = self.cmd().raw("su", &args);

hide_progress();

cmd.with_cwd(consts::user::DEFAULT_HOME.clone())
.with_user(LinuxUser::Default)
.with_user(LinuxUser::Root)
.exec()?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion tests/windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Describe "codchi.msix" {
{ codchi.exe -vv clone codchi https://github.com/aformatik/codchi nixosModules.codchi } | Should -Not -Throw
}
It "builds codchi inside codchi" {
{ codchi.exe exec -vv codchi bash -lc 'cd codchi/codchi && direnv allow && cargo run -- --version' } | Should -Not -Throw
{ codchi.exe exec -vv codchi bash -lc 'cd codchi/codchi && nix develop -c cargo run -- --version' } | Should -Not -Throw
}
}

0 comments on commit d1e3215

Please sign in to comment.