1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #2878 from tertsdiepraam/stdbuf-trouble

`stdbuf`: fix `cargo publish` problem
This commit is contained in:
Sylvestre Ledru 2022-01-16 23:23:35 +01:00 committed by GitHub
commit 4fc47aba61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 6 deletions

View file

@ -329,7 +329,7 @@ sort = { optional=true, version="0.0.9", package="uu_sort", path="src/uu/sor
split = { optional=true, version="0.0.9", package="uu_split", path="src/uu/split" }
stat = { optional=true, version="0.0.9", package="uu_stat", path="src/uu/stat" }
# Very ugly, uncomment when the issue #2876 is fixed
stdbuf = { optional=true, version="0.0.8", package="uu_stdbuf", path="src/uu/stdbuf" }
stdbuf = { optional=true, version="0.0.9", package="uu_stdbuf", path="src/uu/stdbuf" }
sum = { optional=true, version="0.0.9", package="uu_sum", path="src/uu/sum" }
sync = { optional=true, version="0.0.9", package="uu_sync", path="src/uu/sync" }
tac = { optional=true, version="0.0.9", package="uu_tac", path="src/uu/tac" }

View file

@ -28,15 +28,30 @@ fn main() {
// - cargo run
// - cross run
// - cargo install --git
// - cargo publish --dry-run
let mut name = target_dir.file_name().unwrap().to_string_lossy();
while name != "target" && !name.starts_with("cargo-install") {
target_dir = target_dir.parent().unwrap();
name = target_dir.file_name().unwrap().to_string_lossy();
}
let mut libstdbuf = target_dir.to_path_buf();
libstdbuf.push(env::var("PROFILE").unwrap());
libstdbuf.push("deps");
libstdbuf.push(format!("liblibstdbuf{}", platform::DYLIB_EXT));
let mut dir = target_dir.to_path_buf();
dir.push(env::var("PROFILE").unwrap());
dir.push("deps");
let mut path = None;
fs::copy(libstdbuf, Path::new(&out_dir).join("libstdbuf.so")).unwrap();
// When running cargo publish, cargo appends hashes to the filenames of the compiled artifacts.
// Therefore, it won't work to just get liblibstdbuf.so. Instead, we look for files with the
// glob pattern "liblibstdbuf*.so" (i.e. starts with liblibstdbuf and ends with the extension).
for entry in fs::read_dir(dir).unwrap().flatten() {
let name = entry.file_name();
let name = name.to_string_lossy();
if name.starts_with("liblibstdbuf") && name.ends_with(platform::DYLIB_EXT) {
path = Some(entry.path());
}
}
fs::copy(
path.expect("liblibstdbuf was not found"),
Path::new(&out_dir).join("libstdbuf.so"),
)
.unwrap();
}