[llvm] [lit] Implement builtin umask (PR #94621)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 6 07:00:44 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-debuginfo

Author: Jay Foad (jayfoad)

<details>
<summary>Changes</summary>

This allows a few more tests to use lit's internal shell.


---
Full diff: https://github.com/llvm/llvm-project/pull/94621.diff


4 Files Affected:

- (modified) llvm/test/tools/llvm-dwarfutil/ELF/X86/mirror-permissions-unix.test (-1) 
- (modified) llvm/test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test (-1) 
- (modified) llvm/test/tools/llvm-objcopy/ELF/respect-umask.test (-1) 
- (modified) llvm/utils/lit/lit/TestRunner.py (+17-2) 


``````````diff
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)

``````````

</details>


https://github.com/llvm/llvm-project/pull/94621


More information about the llvm-commits mailing list