Skip to content

Commit

Permalink
Remove dependency on is_executable
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Feb 23, 2025
1 parent 8e02736 commit 3df8c10
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 25 deletions.
5 changes: 0 additions & 5 deletions .deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ build.allow-build-scripts = [
{ name = "rustix" }, # via tar
{ name = "serde_json" },
{ name = "serde" },
{ name = "winapi-i686-pc-windows-gnu" }, # via is_executable
{ name = "winapi-x86_64-pc-windows-gnu" }, # via is_executable
{ name = "winapi" }, # via is_executable
{ name = "windows_aarch64_gnullvm" },
{ name = "windows_aarch64_msvc" },
{ name = "windows_i686_gnu" },
Expand All @@ -39,8 +36,6 @@ build.allow-build-scripts = [
build.bypass = [
{ name = "autocfg", allow-globs = ["tests/wrap_ignored"] }, # via fs-err
# Import libraries are necessary because raw-dylib (requires 1.71+ for x86, 1.65+ for others) is not available on MSRV of them.
{ name = "winapi-i686-pc-windows-gnu", allow-globs = ["lib/*.a"] }, # via is_executable
{ name = "winapi-x86_64-pc-windows-gnu", allow-globs = ["lib/*.a"] }, # via is_executable
{ name = "windows_aarch64_gnullvm", allow-globs = ["lib/*.a"] },
{ name = "windows_aarch64_msvc", allow-globs = ["lib/*.lib"] },
{ name = "windows_i686_gnu", allow-globs = ["lib/*.a"] },
Expand Down
1 change: 0 additions & 1 deletion .github/.cspell/project-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ rustfilt
rustix
TESTNAME
trybuild
winapi
xargo
Xdemangler
xtask
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ cargo-config2 = "0.1.31"
duct = "0.13.1"
fs-err = "3"
glob = "0.3"
is_executable = "1"
lcov2cobertura = "1.0.1"
lexopt = "0.3"
opener = { version = "0.7", default-features = false }
Expand Down
64 changes: 46 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,19 +701,34 @@ fn object_files(cx: &Context) -> Result<Vec<OsString>> {
.into_iter()
.filter_entry(move |e| {
let p = e.path();
// Refs: https://github.com/rust-lang/cargo/blob/0.85.0/src/cargo/core/compiler/layout.rs.
if p.is_dir() {
if p.file_name()
.is_some_and(|f| f == "incremental" || f == ".fingerprint" || f == "out")
{
if p.file_name().is_some_and(|f| {
f == "incremental"
|| f == ".fingerprint"
|| if cx.args.cov.include_build_script {
f == "out"
} else {
f == "build"
}
}) {
// Ignore incremental compilation related files and output from build scripts.
return false;
}
} else if let Some(stem) = p.file_stem() {
let stem = stem.to_string_lossy();
if stem == "build-script-build" || stem.starts_with("build_script_build-") {
let p = p.parent().unwrap();
if p.parent().unwrap().file_name().unwrap() == "build" {
if cx.args.cov.include_build_script {
} else if cx.args.cov.include_build_script {
if let (Some(stem), Some(p)) = (p.file_stem(), p.parent()) {
fn in_build_dir(p: &Path) -> bool {
let Some(p) = p.parent() else { return false };
let Some(f) = p.file_name() else { return false };
f == "build"
}
if in_build_dir(p) {
if stem == "build-script-build"
|| stem
.to_str()
.unwrap_or_default()
.starts_with("build_script_build-")
{
let dir = p.file_name().unwrap().to_string_lossy();
if !cx.build_script_re.is_match(&dir) {
return false;
Expand All @@ -730,18 +745,31 @@ fn object_files(cx: &Context) -> Result<Vec<OsString>> {
}
fn is_object(cx: &Context, f: &Path) -> bool {
let ext = f.extension().unwrap_or_default();
// is_executable::is_executable doesn't work well on WSL.
// https://github.com/taiki-e/cargo-llvm-cov/issues/316
// https://github.com/taiki-e/cargo-llvm-cov/issues/342
if ext == "d" || ext == "rmeta" {
// We check extension instead of using is_executable crate because it always return true on WSL:
// - https://github.com/taiki-e/cargo-llvm-cov/issues/316
// - https://github.com/taiki-e/cargo-llvm-cov/issues/342
if ext == "d" || ext == "rlib" || ext == "rmeta" || f.ends_with(".cargo-lock") {
return false;
}
if cx.ws.target_for_config.triple().contains("-windows")
&& (ext.eq_ignore_ascii_case("exe") || ext.eq_ignore_ascii_case("dll"))
{
return true;
#[allow(clippy::disallowed_methods)] // std::fs is okay here since we ignore error contents
let Ok(metadata) = std::fs::metadata(f) else {
return false;
};
if !metadata.is_file() {
return false;
}
if cx.ws.target_for_config.triple().contains("-windows") {
ext.eq_ignore_ascii_case("exe") || ext.eq_ignore_ascii_case("dll")
} else {
#[cfg(unix)]
{
// This is useless on WSL, but check for others just in case.
use std::os::unix::fs::PermissionsExt as _;
metadata.permissions().mode() & 0o111 != 0
}
#[cfg(not(unix))]
true
}
is_executable::is_executable(f)
}

let re = pkg_hash_re(&cx.ws)?;
Expand Down

0 comments on commit 3df8c10

Please sign in to comment.