From fb8932b837a2fe63dd5370e5b05a26f930db6f50 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Sat, 19 Oct 2024 08:24:33 -0600 Subject: [PATCH] Move IS_ROOT definition to framework Signed-off-by: Mats Wichmann --- SCons/CacheDirTests.py | 8 +------- SCons/Node/FSTests.py | 8 +------- SCons/Variables/PathVariableTests.py | 8 +------- test/Install/Install.py | 5 +---- test/VariantDir/errors.py | 5 +---- testing/framework/TestCmd.py | 4 ++++ 6 files changed, 9 insertions(+), 29 deletions(-) diff --git a/SCons/CacheDirTests.py b/SCons/CacheDirTests.py index 7b6c5aa27..3fbab4e24 100644 --- a/SCons/CacheDirTests.py +++ b/SCons/CacheDirTests.py @@ -28,18 +28,12 @@ import tempfile import stat -from TestCmd import TestCmd, IS_WINDOWS +from TestCmd import TestCmd, IS_WINDOWS, IS_ROOT import SCons.CacheDir built_it = None -try: - IS_ROOT = os.geteuid() == 0 -except AttributeError: - IS_ROOT = False - - class Action: def __call__(self, targets, sources, env, **kw) -> int: global built_it diff --git a/SCons/Node/FSTests.py b/SCons/Node/FSTests.py index 14a2b5691..83ceef28c 100644 --- a/SCons/Node/FSTests.py +++ b/SCons/Node/FSTests.py @@ -31,7 +31,7 @@ import stat from typing import Optional -from TestCmd import TestCmd, IS_WINDOWS +from TestCmd import TestCmd, IS_WINDOWS, IS_ROOT import SCons.Errors import SCons.Node.FS @@ -44,12 +44,6 @@ scanner_count = 0 -try: - IS_ROOT = os.geteuid() == 0 -except AttributeError: - IS_ROOT = False - - class Scanner: def __init__(self, node=None) -> None: global scanner_count diff --git a/SCons/Variables/PathVariableTests.py b/SCons/Variables/PathVariableTests.py index 87d6bdffa..b093053d7 100644 --- a/SCons/Variables/PathVariableTests.py +++ b/SCons/Variables/PathVariableTests.py @@ -28,13 +28,7 @@ import SCons.Variables import TestCmd -from TestCmd import IS_WINDOWS - -try: - IS_ROOT = os.geteuid() == 0 -except AttributeError: - IS_ROOT = False - +from TestCmd import IS_WINDOWS, IS_ROOT class PathVariableTestCase(unittest.TestCase): def test_PathVariable(self) -> None: diff --git a/test/Install/Install.py b/test/Install/Install.py index 8df927644..802b10dae 100644 --- a/test/Install/Install.py +++ b/test/Install/Install.py @@ -31,6 +31,7 @@ import time import TestSCons +from TestCmd import IS_ROOT test = TestSCons.TestSCons() @@ -132,10 +133,6 @@ def my_install(dest, source, env): test.write(['work', 'f1.in'], "f1.in again again\n") # This test is not designed to work if running as root -try: - IS_ROOT = os.geteuid() == 0 -except AttributeError: - IS_ROOT = False if not IS_ROOT: os.chmod(test.workpath('work', 'export'), 0o555) with open(f1_out, 'rb'): diff --git a/test/VariantDir/errors.py b/test/VariantDir/errors.py index 531beea77..1ff3be3c4 100644 --- a/test/VariantDir/errors.py +++ b/test/VariantDir/errors.py @@ -33,13 +33,10 @@ import stat import sys import TestSCons +from TestCmd import IS_ROOT test = TestSCons.TestSCons() -try: - IS_ROOT = os.geteuid() == 0 -except AttributeError: - IS_ROOT = False if IS_ROOT: test.skip_test('SConscript permissions meaningless when running as root; skipping test.\n') diff --git a/testing/framework/TestCmd.py b/testing/framework/TestCmd.py index 240aa6c35..243745d02 100644 --- a/testing/framework/TestCmd.py +++ b/testing/framework/TestCmd.py @@ -329,6 +329,10 @@ IS_MACOS = sys.platform == 'darwin' IS_64_BIT = sys.maxsize > 2**32 IS_PYPY = hasattr(sys, 'pypy_translation_info') +try: + IS_ROOT = os.geteuid() == 0 +except AttributeError: + IS_ROOT = False NEED_HELPER = os.environ.get('SCONS_NO_DIRECT_SCRIPT') # sentinel for cases where None won't do