Skip to content

Commit b457c30

Browse files
authored
Be flexible regarding executable extensions. NFC (#25960)
In particular, on windows, when looking for llvm / binaryen / emscripten entry points allow them to end with the normal set of executable extensions. This allows folks use, for example, a clang.bat wrapper around clang and also allows us to start using `emcc.exe` over `emcc.bat` at some point. See #24858 The old `exe_suffix` helper still exists but is now moved to the test framework.
1 parent 4d02e3a commit b457c30

File tree

9 files changed

+47
-32
lines changed

9 files changed

+47
-32
lines changed

test/browser_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class FirefoxConfig:
243243
data_dir_flag = '-profile '
244244
default_flags = ('-new-instance', '-wait-for-browser')
245245
headless_flags = '-headless'
246-
executable_name = utils.exe_suffix('firefox')
246+
executable_name = common.exe_suffix('firefox')
247247

248248
@staticmethod
249249
def configure(data_dir):

test/common.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from tools.shared import DEBUG, EMCC, EMXX, get_canonical_temp_dir
3535
from tools.utils import (
3636
WINDOWS,
37+
exe_path_from_root,
3738
exit_with_error,
3839
path_from_root,
3940
read_binary,
@@ -77,13 +78,13 @@
7778
LAST_TEST = path_from_root('out/last_test.txt')
7879
PREVIOUS_TEST_RUN_RESULTS_FILE = path_from_root('out/previous_test_run_results.json')
7980

80-
WEBIDL_BINDER = utils.bat_suffix(path_from_root('tools/webidl_binder'))
81+
WEBIDL_BINDER = exe_path_from_root('tools/webidl_binder')
8182

82-
EMBUILDER = utils.bat_suffix(path_from_root('embuilder'))
83-
EMMAKE = utils.bat_suffix(path_from_root('emmake'))
84-
EMCMAKE = utils.bat_suffix(path_from_root('emcmake'))
85-
EMCONFIGURE = utils.bat_suffix(path_from_root('emconfigure'))
86-
EMRUN = utils.bat_suffix(utils.path_from_root('emrun'))
83+
EMBUILDER = exe_path_from_root('embuilder')
84+
EMMAKE = exe_path_from_root('emmake')
85+
EMCMAKE = exe_path_from_root('emcmake')
86+
EMCONFIGURE = exe_path_from_root('emconfigure')
87+
EMRUN = exe_path_from_root('emrun')
8788
WASM_DIS = os.path.join(building.get_binaryen_bin(), 'wasm-dis')
8889
LLVM_OBJDUMP = shared.llvm_tool_path('llvm-objdump')
8990
PYTHON = sys.executable
@@ -127,6 +128,10 @@ def copytree(src, dest):
127128
shutil.copytree(src, dest, dirs_exist_ok=True)
128129

129130

131+
def exe_suffix(cmd):
132+
return cmd + '.exe' if WINDOWS else cmd
133+
134+
130135
def compiler_for(filename, force_c=False):
131136
if utils.suffix(filename) in ('.cc', '.cxx', '.cpp') and not force_c:
132137
return EMXX

test/test_other.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
create_file,
4949
ensure_dir,
5050
env_modify,
51+
exe_path_from_root,
5152
make_executable,
5253
path_from_root,
5354
test_file,
@@ -118,13 +119,13 @@
118119
write_file,
119120
)
120121

121-
emmake = utils.bat_suffix(path_from_root('emmake'))
122-
emconfig = utils.bat_suffix(path_from_root('em-config'))
123-
emsize = utils.bat_suffix(path_from_root('emsize'))
124-
empath_split = utils.bat_suffix(path_from_root('empath-split'))
125-
emprofile = utils.bat_suffix(path_from_root('emprofile'))
126-
emstrip = utils.bat_suffix(path_from_root('emstrip'))
127-
emsymbolizer = utils.bat_suffix(path_from_root('emsymbolizer'))
122+
emmake = exe_path_from_root('emmake')
123+
emconfig = exe_path_from_root('em-config')
124+
emsize = exe_path_from_root('emsize')
125+
empath_split = exe_path_from_root('empath-split')
126+
emprofile = exe_path_from_root('emprofile')
127+
emstrip = exe_path_from_root('emstrip')
128+
emsymbolizer = exe_path_from_root('emsymbolizer')
128129

129130

130131
def is_bitcode(filename):

test/test_sanity.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
create_file,
2020
ensure_dir,
2121
env_modify,
22+
exe_suffix,
2223
make_executable,
2324
path_from_root,
2425
test_file,
@@ -101,7 +102,7 @@ def make_fake_clang(filename, version, targets='wasm32 - WebAssembly 32-bit'):
101102

102103
# Return a new PATH that has no directories that would contain the given tool.
103104
def path_without_tool(env_path, tool_bin):
104-
tool_bin = utils.exe_suffix(tool_bin)
105+
tool_bin = exe_suffix(tool_bin)
105106
python_path = os.path.normpath(os.path.dirname(sys.executable))
106107

107108
def ignore_path(p):
@@ -837,8 +838,7 @@ def test_bootstrap(self):
837838
self.assert_fail([EMCC, test_file('hello_world.c')], expected)
838839

839840
# Running bootstrap.py should fix that
840-
bootstrap = shared.bat_suffix(path_from_root('bootstrap'))
841-
self.run_process([bootstrap])
841+
self.run_process([utils.exe_path_from_root('bootstrap')])
842842

843843
# Now the compiler should work again
844844
self.run_process([EMCC, test_file('hello_world.c')])
@@ -857,4 +857,4 @@ def test_bootstrap_without_em_config(self):
857857
env['PATH'] = path_without_tool(env['PATH'], 'clang')
858858

859859
# Running bootstrap.py should not fail
860-
self.run_process([shared.bat_suffix(path_from_root('bootstrap'))], env=env)
860+
self.run_process([utils.exe_path_from_root('bootstrap')], env=env)

tools/building.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ def get_binaryen_feature_flags():
11891189

11901190

11911191
def get_binaryen_version(bindir):
1192-
opt = os.path.join(bindir, utils.exe_suffix('wasm-opt'))
1192+
opt = utils.find_exe(bindir, 'wasm-opt')
11931193
if not os.path.exists(opt):
11941194
exit_with_error('binaryen executable not found (%s). Please check your binaryen installation' % opt)
11951195
try:

tools/empath-split.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def parse_args():
9898
if args.preserve_manifest:
9999
args.verbose = True
100100
if not args.wasm_split:
101-
args.wasm_split = os.path.join(building.get_binaryen_bin(), utils.exe_suffix('wasm-split'))
101+
args.wasm_split = utils.find_exe(building.get_binaryen_bin(), 'wasm-split')
102102

103103
if '--manifest' in forwarded_args:
104104
parser.error('manifest file will be generated by this script and should not be given')

tools/maint/rebaseline_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def main():
7979
print('tree is not clean')
8080
return 1
8181

82-
subprocess.check_call([utils.bat_suffix(os.path.join('test', 'runner')), '--rebaseline', 'codesize'], cwd=root_dir)
82+
subprocess.check_call([utils.exe_path_from_root('test/runner'), '--rebaseline', 'codesize'], cwd=root_dir)
8383

8484
output = run(['git', 'status', '-uno', '--porcelain'])
8585
filenames = []

tools/shared.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
from . import cache, config, diagnostics, filelock, tempfiles, utils
4545
from .settings import settings
46-
from .utils import bat_suffix, exit_with_error, memoize, path_from_root, safe_ensure_dirs
46+
from .utils import exe_path_from_root, exit_with_error, memoize, path_from_root, safe_ensure_dirs
4747

4848
DEBUG_SAVE = DEBUG or int(os.environ.get('EMCC_DEBUG_SAVE', '0'))
4949
PRINT_SUBPROCS = int(os.getenv('EMCC_VERBOSE', '0'))
@@ -451,7 +451,7 @@ def llvm_tool_path_with_suffix(tool, suffix):
451451
if suffix:
452452
tool += '-' + suffix
453453
llvm_root = os.path.expanduser(config.LLVM_ROOT)
454-
return os.path.join(llvm_root, utils.exe_suffix(tool))
454+
return utils.find_exe(llvm_root, tool)
455455

456456

457457
# Some distributions ship with multiple llvm versions so they add
@@ -644,11 +644,11 @@ def init():
644644
LLVM_PROFDATA = llvm_tool_path('llvm-profdata')
645645
LLVM_COV = llvm_tool_path('llvm-cov')
646646

647-
EMCC = bat_suffix(path_from_root('emcc'))
648-
EMXX = bat_suffix(path_from_root('em++'))
649-
EMAR = bat_suffix(path_from_root('emar'))
650-
EMRANLIB = bat_suffix(path_from_root('emranlib'))
651-
FILE_PACKAGER = bat_suffix(path_from_root('tools/file_packager'))
647+
EMCC = exe_path_from_root('emcc')
648+
EMXX = exe_path_from_root('em++')
649+
EMAR = exe_path_from_root('emar')
650+
EMRANLIB = exe_path_from_root('emranlib')
651+
FILE_PACKAGER = exe_path_from_root('tools/file_packager')
652652
# Windows .dll suffix is not included in this list, since those are never
653653
# linked to directly on the command line.
654654
DYLIB_EXTENSIONS = ['.dylib', '.so']

tools/utils.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,26 @@ def path_from_root(*pathelems):
6565
return str(Path(__rootpath__, *pathelems))
6666

6767

68+
def exe_path_from_root(*pathelems):
69+
return find_exe(path_from_root(*pathelems))
70+
71+
6872
def suffix(name):
6973
"""Return the file extension"""
7074
return os.path.splitext(name)[1]
7175

7276

73-
def exe_suffix(cmd):
74-
return cmd + '.exe' if WINDOWS else cmd
77+
def find_exe(*pathelems):
78+
path = os.path.join(*pathelems)
7579

80+
if WINDOWS:
81+
# Should we use PATHEXT environment variable here?
82+
# For now, specify only enough extensions to find llvm / binaryen / emscripten executables.
83+
for ext in ['.exe', '.bat']:
84+
if os.path.isfile(path + ext):
85+
return path + ext
7686

77-
def bat_suffix(cmd):
78-
return cmd + '.bat' if WINDOWS else cmd
87+
return path
7988

8089

8190
def replace_suffix(filename, new_suffix):

0 commit comments

Comments
 (0)