[llvm] [lit] Implement builtin umask (PR #94621)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 6 08:31:32 PDT 2024
https://github.com/jayfoad updated https://github.com/llvm/llvm-project/pull/94621
>From 2c7bab227cf1ca0dd68c79579833ebdb98e7fea2 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Thu, 6 Jun 2024 14:55:37 +0100
Subject: [PATCH 1/2] [lit] Implement builtin umask
This allows a few more tests to use lit's internal shell.
---
.../ELF/X86/mirror-permissions-unix.test | 1 -
.../ELF/mirror-permissions-unix.test | 1 -
.../tools/llvm-objcopy/ELF/respect-umask.test | 1 -
llvm/utils/lit/lit/TestRunner.py | 19 +++++++++++++++++--
4 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/llvm/test/tools/llvm-dwarfutil/ELF/X86/mirror-permissions-unix.test b/llvm/test/tools/llvm-dwarfutil/ELF/X86/mirror-permissions-unix.test
index a95d1c0aafa21..fdcba4dcd666b 100644
--- a/llvm/test/tools/llvm-dwarfutil/ELF/X86/mirror-permissions-unix.test
+++ b/llvm/test/tools/llvm-dwarfutil/ELF/X86/mirror-permissions-unix.test
@@ -3,7 +3,6 @@
## Setting the umask to 0 ensures deterministic permissions across
## test environments.
# UNSUPPORTED: system-windows
-# REQUIRES: shell
# RUN: touch %t
# RUN: chmod 0777 %t
diff --git a/llvm/test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test b/llvm/test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test
index 8f4993f4f3d29..66a481a2230d1 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test
@@ -6,7 +6,6 @@
## Setting the umask to 0 ensures deterministic permissions across
## test environments.
# UNSUPPORTED: system-windows
-# REQUIRES: shell
# RUN: touch %t
# RUN: chmod 0777 %t
diff --git a/llvm/test/tools/llvm-objcopy/ELF/respect-umask.test b/llvm/test/tools/llvm-objcopy/ELF/respect-umask.test
index 376e33a217819..f4d3099056168 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/respect-umask.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/respect-umask.test
@@ -4,7 +4,6 @@
## Windows has no umask so this test makes no sense, nor would
## it work because there is no umask(1) in a Windows environment
# UNSUPPORTED: system-windows
-# REQUIRES: shell
# RUN: rm -f %t
# RUN: touch %t
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index da7fa86fd3917..d2627728eb09e 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -87,10 +87,11 @@ class ShellEnvironment(object):
we maintain a dir stack for pushd/popd.
"""
- def __init__(self, cwd, env):
+ def __init__(self, cwd, env, umask=-1):
self.cwd = cwd
self.env = dict(env)
self.dirStack = []
+ self.umask = umask
def change_dir(self, newdir):
if os.path.isabs(newdir):
@@ -565,6 +566,18 @@ class SHFILEOPSTRUCTW(Structure):
return ShellCommandResult(cmd, "", stderr.getvalue(), exitCode, False)
+def executeBuiltinUmask(cmd, shenv):
+ """executeBuiltinUmask - Change the current umask."""
+ if len(cmd.args) != 2:
+ raise InternalShellError(cmd, "'umask' supports only one argument")
+ try:
+ # Update the umask in the parent environment.
+ shenv.umask = int(cmd.args[1], 8)
+ except ValueError as err:
+ raise InternalShellError(cmd, "Error: 'umask': %s" % str(err))
+ return ShellCommandResult(cmd, "", "", 0, False)
+
+
def executeBuiltinColon(cmd, cmd_shenv):
"""executeBuiltinColon - Discard arguments and exit with status 0."""
return ShellCommandResult(cmd, "", "", 0, False)
@@ -719,6 +732,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
"popd": executeBuiltinPopd,
"pushd": executeBuiltinPushd,
"rm": executeBuiltinRm,
+ "umask": executeBuiltinUmask,
":": executeBuiltinColon,
}
# To avoid deadlock, we use a single stderr stream for piped
@@ -740,7 +754,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
# env FOO=1 llc < %s | env BAR=2 llvm-mc | FileCheck %s
# env FOO=1 %{another_env_plus_cmd} | FileCheck %s
if cmd_shenv is shenv:
- cmd_shenv = ShellEnvironment(shenv.cwd, shenv.env)
+ cmd_shenv = ShellEnvironment(shenv.cwd, shenv.env, shenv.umask)
args = updateEnv(cmd_shenv, args)
if not args:
raise InternalShellError(j, "Error: 'env' requires a" " subcommand")
@@ -884,6 +898,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
close_fds=kUseCloseFDs,
universal_newlines=True,
errors="replace",
+ umask=cmd_shenv.umask,
)
)
proc_not_counts.append(not_count)
>From 3e649aa23ef6f88c04bec1735eb563390eb166f9 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Thu, 6 Jun 2024 16:31:01 +0100
Subject: [PATCH 2/2] Update Windows umask explanation
---
llvm/test/tools/llvm-objcopy/ELF/respect-umask.test | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/test/tools/llvm-objcopy/ELF/respect-umask.test b/llvm/test/tools/llvm-objcopy/ELF/respect-umask.test
index f4d3099056168..02e9b93f5376f 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/respect-umask.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/respect-umask.test
@@ -1,8 +1,7 @@
## This tests that the umask is respected when
## assigning permissions of output files.
-## Windows has no umask so this test makes no sense, nor would
-## it work because there is no umask(1) in a Windows environment
+## Windows has no umask so this test makes no sense.
# UNSUPPORTED: system-windows
# RUN: rm -f %t
More information about the llvm-commits
mailing list