Skip to content

Commit

Permalink
fix things on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Mar 21, 2024
1 parent 7f7eb23 commit 9804f47
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
7 changes: 6 additions & 1 deletion crates/rattler/src/install/link_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ pub fn run_link_scripts<'a>(
shell,
&env,
) {
Ok(_) => {}
Ok(o) if o.status.success() => {}
Ok(o) => {
tracing::warn!("Error running post-link script. Status: {:?}", o.status);
tracing::warn!(" stdout: {}", String::from_utf8_lossy(&o.stdout));
tracing::warn!(" stderr: {}", String::from_utf8_lossy(&o.stderr));
}
Err(e) => {
tracing::error!("Error running post-link script: {:?}", e);
}
Expand Down
20 changes: 14 additions & 6 deletions crates/rattler_shell/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,28 @@ pub fn run_in_environment(

writeln!(shell_script.contents, "{}", host_activation.script)?;

match shell {
let tempfile = match shell {
ShellEnum::Bash(_) => {
writeln!(shell_script.contents, ". {}", args.join(" "))?;
tempfile::Builder::new().suffix(".sh").tempfile()?
}
ShellEnum::CmdExe(_) => {
writeln!(shell_script.contents, "@call {}", args.join(" "))?;
tempfile::Builder::new().suffix(".bat").tempfile()?
}
_ => unimplemented!("Unsupported shell: {:?}", shell),
}
};

let tempfile = tempfile::NamedTempFile::new()?;
std::fs::write(tempfile.path(), shell_script.contents)?;

Ok(Command::new(shell.executable())
.arg(tempfile.path())
.output()?)
match shell {
ShellEnum::Bash(_) => Ok(Command::new(shell.executable())
.arg(tempfile.path())
.output()?),
ShellEnum::CmdExe(_) => Ok(Command::new(shell.executable())
.arg("/c")
.arg(tempfile.path())
.output()?),
_ => unimplemented!("Unsupported shell: {:?}", shell),
}
}
Binary file modified test-data/link-scripts/link-scripts-0.1.0-h4616a5c_0.tar.bz2
Binary file not shown.
2 changes: 1 addition & 1 deletion test-data/link-scripts/recipe/post-link.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
echo. > %PREFIX%\i-was-post-linked
copy NUL %PREFIX%\i-was-post-linked

echo This is a post-link script that just ran for the recipe package. >> %PREFIX%\.messages.txt
21 changes: 15 additions & 6 deletions test-data/link-scripts/recipe/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@ outputs:
build:
noarch: generic
script:
- mkdir -p $PREFIX/bin
- mkdir -p $PREFIX/Scripts
- cp $RECIPE_DIR/post-link.sh $PREFIX/bin/.${PKG_NAME}-post-link.sh
- cp $RECIPE_DIR/pre-unlink.sh $PREFIX/bin/.${PKG_NAME}-pre-unlink.sh
# - cp $RECIPE_DIR/pre-link.bat $PREFIX/Scripts/.${PKG_NAME}-pre-link.bat
# - cp $RECIPE_DIR/post-link.bat $PREFIX/Scripts/.${PKG_NAME}-post-link.bat
- if: unix
then:
- mkdir -p $PREFIX/bin
- mkdir -p $PREFIX/Scripts
- cp $RECIPE_DIR/post-link.sh $PREFIX/bin/.${PKG_NAME}-post-link.sh
- cp $RECIPE_DIR/pre-unlink.sh $PREFIX/bin/.${PKG_NAME}-pre-unlink.sh
- cp $RECIPE_DIR/post-link.bat $PREFIX/Scripts/.${PKG_NAME}-post-link.bat
- cp $RECIPE_DIR/pre-unlink.bat $PREFIX/Scripts/.${PKG_NAME}-pre-unlink.bat
else:
- mkdir -p %PREFIX%\bin
- mkdir -p %PREFIX%\Scripts
- copy %RECIPE_DIR%\post-link.sh %PREFIX%\bin\.%PKG_NAME%-post-link.sh
- copy %RECIPE_DIR%\pre-unlink.sh %PREFIX%\bin\.%PKG_NAME%-pre-unlink.sh
- copy %RECIPE_DIR%\post-link.bat %PREFIX%\Scripts\.%PKG_NAME%-post-link.bat
- copy %RECIPE_DIR%\pre-unlink.bat %PREFIX%\Scripts\.%PKG_NAME%-pre-unlink.bat

0 comments on commit 9804f47

Please sign in to comment.