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 817005b
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ jobs:
files-folder: build
files-folder-filter: msix
file-digest: SHA256
- if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
# - if: ${{ failure() }}
# uses: mxschmitt/action-tmate@v3
- uses: softprops/action-gh-release@v2
with:
prerelease: true
Expand Down
2 changes: 1 addition & 1 deletion codchi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codchi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "codchi"
build = "build/main.rs"
version = "0.2.3"
version = "0.2.4"
edition = "2021"
rust-version = "1.80.0"
resolver = "2"
Expand Down
2 changes: 1 addition & 1 deletion codchi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ let
'';

CODCHI_WSL_VERSION_MIN = "2.0.14";
CODCHI_WSL_VERSION_MAX = "2.2.4";
CODCHI_WSL_VERSION_MAX = "2.3.24";

};
linux = rec {
Expand Down
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
8 changes: 8 additions & 0 deletions codchi/src/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ tail -f "{log_file}"
fn delete_container(&self) -> Result<()> {
lxd::container::delete(&machine_name(&self.config.name), true)
}

fn create_exec_cmd(&self, cmd: &[&str]) -> super::LinuxCommandBuilder {
let args = [&vec![consts::user::DEFAULT_NAME], cmd].concat();
let cmd = self.cmd().raw("su", &args);

cmd.with_cwd(consts::user::DEFAULT_HOME.clone())
.with_user(LinuxUser::Root)
}
}

#[derive(Debug, Clone)]
Expand Down
18 changes: 6 additions & 12 deletions codchi/src/platform/machine.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::{platform::HostImpl, Host, LinuxCommandTarget, LinuxUser, NixDriver};
use super::{
platform::HostImpl, Host, LinuxCommandBuilder, LinuxCommandTarget, LinuxUser, NixDriver,
};
use crate::{
cli::CODCHI_DRIVER_MODULE,
config::{EnvSecret, FlakeLocation, MachineConfig},
Expand Down Expand Up @@ -28,6 +30,8 @@ pub trait MachineDriver: Sized {

/// Delete container
fn delete_container(&self) -> Result<()>;

fn create_exec_cmd(&self, cmd: &[&str]) -> LinuxCommandBuilder;
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -400,18 +404,8 @@ 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"]),
};

hide_progress();

cmd.with_cwd(consts::user::DEFAULT_HOME.clone())
.with_user(LinuxUser::Default)
self.create_exec_cmd(&cmd.iter().map(|str| str.as_str()).collect_vec())
.exec()?;
Ok(())
}
Expand Down
10 changes: 10 additions & 0 deletions codchi/src/platform/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ tail -f "{log_file}"
.wait_ok()?;
Ok(())
}

fn create_exec_cmd(&self, cmd: &[&str]) -> super::LinuxCommandBuilder {
let cmd = match cmd.split_first() {
Some((cmd, args)) => self.cmd().run(cmd, args),
None => self.cmd().run("bash", &["-l"]),
};

cmd.with_cwd(consts::user::DEFAULT_HOME.clone())
.with_user(LinuxUser::Default)
}
}

#[derive(Debug, Clone)]
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 817005b

Please sign in to comment.