Skip to content

Commit

Permalink
Parse command as shell-friendly string
Browse files Browse the repository at this point in the history
  • Loading branch information
runesoerensen committed Feb 5, 2025
1 parent c53acef commit ed3b93e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions buildpacks/dotnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ semver = "1.0"
serde = "1"
serde_json = "1"
sha2 = "0.10"
shell-words = "1.1.0"

[dev-dependencies]
libcnb-test = "0.26"
Expand Down
12 changes: 6 additions & 6 deletions buildpacks/dotnet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use libcnb::{buildpack_main, Buildpack, Env};
use libherokubuildpack::inventory;
use semver::{Version, VersionReq};
use sha2::Sha512;
use std::ffi::OsStr;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
Expand Down Expand Up @@ -199,12 +200,11 @@ impl Buildpack for DotnetBuildpack {
}

fn command_to_string(cmd: &Command) -> String {
let mut result = cmd.get_program().to_string_lossy().to_string();
for arg in cmd.get_args() {
result.push(' ');
result.push_str(&arg.to_string_lossy());
}
result
shell_words::join(
std::iter::once(cmd.get_program())
.chain(cmd.get_args())
.map(OsStr::to_string_lossy),
)
}

fn get_solution_to_publish(app_dir: &Path) -> Result<Solution, DotnetBuildpackError> {
Expand Down
2 changes: 1 addition & 1 deletion buildpacks/dotnet/tests/dotnet_publish_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn test_dotnet_publish_with_global_json_and_custom_verbosity_level() {
&formatdoc! {r#"
- Publish solution
- Using `Release` build configuration
- Running `dotnet publish /workspace/foo.csproj --runtime {rid} -p:PublishDir=bin/publish --verbosity normal`
- Running `dotnet publish /workspace/foo.csproj --runtime {rid} '-p:PublishDir=bin/publish' --verbosity normal`
MSBuild version 17.8.3+195e7f5a3 for .NET
Build started <PLACEHOLDER>.
Expand Down

0 comments on commit ed3b93e

Please sign in to comment.