Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion core/quality/adapter/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,41 @@ impl Scratch {
///
/// Returns an I/O error when the filesystem or process operation fails.
pub fn close(self) -> io::Result<()> {
self.dir.close()
remove_scratch(&self.dir.keep())
}
}

const SCRATCH_REMOVE_BACKOFF_MS: [u64; 6] = [10, 50, 100, 250, 500, 1000];

#[cfg(windows)]
const ERROR_SHARING_VIOLATION: i32 = 32;

fn held(err: &io::Error) -> bool {
#[cfg(windows)]
if err.raw_os_error() == Some(ERROR_SHARING_VIOLATION) {
return true;
}
err.kind() == io::ErrorKind::PermissionDenied
}

/// Removes a closed scratch tree, clearing read-only entries and retrying while entries are held.
fn remove_scratch(path: &Path) -> io::Result<()> {
let mut outcome = std::fs::remove_dir_all(path);
for delay in SCRATCH_REMOVE_BACKOFF_MS {
match &outcome {
Err(err) if held(err) => {}
_ => return outcome,
}
dx_process::make_writable(path);
outcome = std::fs::remove_dir_all(path);
if outcome.is_ok() {
return outcome;
}
std::thread::sleep(Duration::from_millis(delay));
}
outcome
}

fn ensure_no_symlink_prefix(root: &Path, path: &Path, rel: &Path) -> io::Result<()> {
let suffix = path.strip_prefix(root).map_err(|_| {
io::Error::new(
Expand Down Expand Up @@ -741,6 +772,20 @@ mod tests {
assert!(scratch.close().is_err(), "missing tree is an error");
}

#[cfg(unix)]
#[test]
fn close_removes_a_read_only_tree() {
use std::os::unix::fs::PermissionsExt as _;
let scratch = Scratch::create(&std::env::temp_dir()).expect("scratch");
let root = scratch.root().to_owned();
let locked = root.join("locked");
std::fs::create_dir(&locked).expect("locked dir");
std::fs::write(locked.join("file"), b"x").expect("file");
std::fs::set_permissions(&locked, std::fs::Permissions::from_mode(0o500)).expect("chmod");
scratch.close().expect("close clears read-only entries");
assert!(!root.exists(), "closed scratch is gone");
}

fn pair(key: &str, value: &str) -> (OsString, OsString) {
(OsString::from(key), OsString::from(value))
}
Expand Down
6 changes: 3 additions & 3 deletions core/quality/testdata/real_result_cases.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _cc_case(tool, capability, name, target, contains, absent, config = "cc_synt
"windows_arm64": True,
}

def _iac_dirty_case(tool, cls, package, target, contains, config = "default"):
def _iac_dirty_case(tool, cls, package, target, contains, config = "default", windows_x86_64 = True):
return {
"name": "real_result_%s_dirty" % tool,
"target": "//%s:%s" % (package, target),
Expand All @@ -51,7 +51,7 @@ def _iac_dirty_case(tool, cls, package, target, contains, config = "default"):
"absent": [],
"linux_arm64": True,
"macos_arm64": True,
"windows_x86_64": True,
"windows_x86_64": windows_x86_64,
}

def _ruff_tier_case(tier, name, contains, absent):
Expand Down Expand Up @@ -232,7 +232,7 @@ REAL_RESULT_CASES = [
"contains": ["core/quality/testdata/ocaml_owned/shadow.ml", "shadows"],
"absent": [],
},
_iac_dirty_case("ansible_lint", "ansible", "ansible/tests", "dirty", ["command-instead-of-shell"], "shared_standard"),
_iac_dirty_case("ansible_lint", "ansible", "ansible/tests", "dirty", ["command-instead-of-shell"], "shared_standard", windows_x86_64 = False),
_iac_dirty_case("bicep", "bicep", "bicep/tests", "dirty", ["no-unused-params", "BCP033"], "shared_standard"),
_iac_dirty_case("cfn_lint", "cloudformation", "cloudformation/tests", "dirty", ["E3002"]),
_iac_dirty_case("cmakelint", "cmake", "cmake/tests", "dirty", ["readability/mixedcase"], "shared_standard"),
Expand Down
1 change: 1 addition & 0 deletions julia/tests/fixtures/julia-app/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ julia_test(

julia_test(
name = "cli_test",
size = "medium",
srcs = ["cli_test.jl"],
data = [":readings"],
env = select({
Expand Down
12 changes: 6 additions & 6 deletions patches/rules_py/pep517_msvc.patch
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ diff -ru a/uv/private/pep517_whl/tools/build_helper.py b/uv/private/pep517_whl/t
# helper still runs there; bare tool names deliberately remain on PATH.
_absolutize_tool_paths(env)

+ if os.name == "nt" and len(sys.executable) >= 250:
+ # CreateProcess rejects a venv interpreter under the deep runfiles
+ # tree; run the short base interpreter against the venv packages.
+ env["PYTHONPATH"] = pathsep.join(entry for entry in sys.path if entry)
+ sys.executable = sys._base_executable
+ if msvc:
+ # setuptools finds cl.exe through PATH, INCLUDE and LIB from the
+ # toolchain, and only when it is told no Visual Studio is needed.
Expand All @@ -233,11 +238,6 @@ diff -ru a/uv/private/pep517_whl/tools/build_helper.py b/uv/private/pep517_whl/t
+ env["DISTUTILS_USE_SDK"] = "1"
+ env["MSSdk"] = "1"
+ _add_cargo_and_ant(env, tmpdir)
+ if len(sys.executable) >= 250:
+ # CreateProcess rejects a venv interpreter under the deep runfiles
+ # tree; run the short base interpreter against the venv packages.
+ env["PYTHONPATH"] = pathsep.join(entry for entry in sys.path if entry)
+ sys.executable = sys._base_executable
+ return env
+
cc_path = _resolve_compiler_path(env, "CC", "cc")
Expand Down Expand Up @@ -305,7 +305,7 @@ diff -ru a/uv/private/pep517_whl/tools/build_helper.py b/uv/private/pep517_whl/t

t = path.join(tmp_root, "worktree")
+ msvc_root = None
+ if opts.msvc:
+ if opts.msvc or os.name == "nt":
+ msvc_root = _msvc_worktree_root(opts.output)
+ shutil.rmtree(msvc_root, ignore_errors=True)
+ t = path.join(msvc_root, "w")
Expand Down
Loading