Skip to content

Minor path handling cleanups. NFC. #15018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2021
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
29 changes: 15 additions & 14 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

logger = logging.getLogger('emcc')

# endings = dot + a suffix, safe to test by filename.endswith(endings)
# endings = dot + a suffix, compare against result of shared.suffix()
C_ENDINGS = ('.c', '.i')
CXX_ENDINGS = ('.cpp', '.cxx', '.cc', '.c++', '.CPP', '.CXX', '.C', '.CC', '.C++', '.ii')
OBJC_ENDINGS = ('.m', '.mi')
Expand Down Expand Up @@ -753,7 +753,7 @@ def emsdk_ldflags(user_args):
library_paths = [
shared.Cache.get_lib_dir(absolute=True)
]
ldflags = ['-L' + l for l in library_paths]
ldflags = [f'-L{l}' for l in library_paths]

if '-nostdlib' in user_args:
return ldflags
Expand Down Expand Up @@ -1775,7 +1775,7 @@ def default_setting(name, new_default):
state.forced_stdlibs.append('libfetch')
settings.JS_LIBRARIES.append((0, 'library_fetch.js'))
if settings.USE_PTHREADS:
settings.FETCH_WORKER_FILE = unsuffixed(os.path.basename(target)) + '.fetch.js'
settings.FETCH_WORKER_FILE = unsuffixed_basename(target) + '.fetch.js'

if settings.DEMANGLE_SUPPORT:
settings.EXPORTED_FUNCTIONS += ['___cxa_demangle']
Expand Down Expand Up @@ -1894,7 +1894,7 @@ def default_setting(name, new_default):
building.user_requested_exports.add('_emscripten_current_thread_process_queued_calls')

# set location of worker.js
settings.PTHREAD_WORKER_FILE = unsuffixed(os.path.basename(target)) + '.worker.js'
settings.PTHREAD_WORKER_FILE = unsuffixed_basename(target) + '.worker.js'
else:
settings.JS_LIBRARIES.append((0, 'library_pthread_stub.js'))

Expand Down Expand Up @@ -2090,7 +2090,7 @@ def check_memory_setting(setting):
settings.MEM_INIT_IN_WASM = True

# wasm side modules have suffix .wasm
if settings.SIDE_MODULE and target.endswith('.js'):
if settings.SIDE_MODULE and shared.suffix(target) == '.js':
diagnostics.warning('emcc', 'output suffix .js requested, but wasm side modules are just wasm files; emitting only a .wasm, no .js')

sanitize = set()
Expand Down Expand Up @@ -2350,10 +2350,11 @@ def get_language_mode(args):
def use_cxx(src):
if 'c++' in language_mode or run_via_emxx:
return True
suffix = shared.suffix(src)
# Next consider the filename
if src.endswith(C_ENDINGS + OBJC_ENDINGS):
if suffix in C_ENDINGS + OBJC_ENDINGS:
return False
if src.endswith(CXX_ENDINGS):
if suffix in CXX_ENDINGS:
return True
# Finally fall back to the default
if settings.DEFAULT_TO_CXX:
Expand Down Expand Up @@ -2393,7 +2394,7 @@ def get_clang_command_asm(src_file):
if state.mode == Mode.PCH:
headers = [header for _, header in input_files]
for header in headers:
if not header.endswith(HEADER_ENDINGS):
if not shared.suffix(header) in HEADER_ENDINGS:
exit_with_error(f'cannot mix precompiled headers with non-header inputs: {headers} : {header}')
cmd = get_clang_command(header)
if options.output_file:
Expand Down Expand Up @@ -2423,7 +2424,7 @@ def get_object_filename(input_file):
return in_temp(unsuffixed(uniquename(input_file)) + options.default_object_extension)

def compile_source_file(i, input_file):
logger.debug('compiling source file: ' + input_file)
logger.debug(f'compiling source file: {input_file}')
output_file = get_object_filename(input_file)
if state.mode not in (Mode.COMPILE_ONLY, Mode.PREPROCESS_ONLY):
linker_inputs.append((i, output_file))
Expand Down Expand Up @@ -2452,10 +2453,10 @@ def compile_source_file(i, input_file):
if file_suffix in SOURCE_ENDINGS + ASSEMBLY_ENDINGS or (state.has_dash_c and file_suffix == '.bc'):
compile_source_file(i, input_file)
elif file_suffix in DYNAMICLIB_ENDINGS:
logger.debug('using shared library: ' + input_file)
logger.debug(f'using shared library: {input_file}')
linker_inputs.append((i, input_file))
elif building.is_ar(input_file):
logger.debug('using static library: ' + input_file)
logger.debug(f'using static library: {input_file}')
ensure_archive_index(input_file)
linker_inputs.append((i, input_file))
elif language_mode:
Expand All @@ -2464,7 +2465,7 @@ def compile_source_file(i, input_file):
exit_with_error('-E or -x required when input is from standard input')
else:
# Default to assuming the inputs are object files and pass them to the linker
logger.debug('using object file: ' + input_file)
logger.debug(f'using object file: {input_file}')
linker_inputs.append((i, input_file))

return linker_inputs
Expand Down Expand Up @@ -2586,7 +2587,7 @@ def phase_source_transforms(options, target):
file_args.append('--use-preload-plugins')
if not settings.ENVIRONMENT_MAY_BE_NODE:
file_args.append('--no-node')
file_code = shared.check_call([shared.FILE_PACKAGER, unsuffixed(target) + '.data'] + file_args, stdout=PIPE).stdout
file_code = shared.check_call([shared.FILE_PACKAGER, shared.replace_suffix(target, '.data')] + file_args, stdout=PIPE).stdout
options.pre_js = js_manipulation.add_files_pre_js(options.pre_js, file_code)

# Apply pre and postjs files
Expand Down Expand Up @@ -3529,7 +3530,7 @@ def generate_worker_js(target, js_target, target_basename):

# compiler output goes in .worker.js file
else:
move_file(js_target, unsuffixed(js_target) + '.worker.js')
move_file(js_target, shared.replace_suffix(js_target, '.worker.js'))
worker_target_basename = target_basename + '.worker'
proxy_worker_filename = (settings.PROXY_TO_WORKER_FILENAME or worker_target_basename) + '.js'

Expand Down
4 changes: 2 additions & 2 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,8 +1048,8 @@ def _build_and_run(self, filename, expected_output, args=[], output_nicerizer=No
engines += self.wasm_engines
if self.get_setting('WASM2C') and not EMTEST_LACKS_NATIVE_CLANG:
# compile the c file to a native executable.
c = shared.unsuffixed(js_file) + '.wasm.c'
executable = shared.unsuffixed(js_file) + '.exe'
c = shared.replace_suffix(js_file, '.wasm.c')
executable = shared.replace_suffix(js_file, '.exe')
cmd = [shared.CLANG_CC, c, '-o', executable] + clang_native.get_clang_native_args()
self.run_process(cmd, env=clang_native.get_clang_native_env())
# we can now run the executable directly, without an engine, which
Expand Down
4 changes: 2 additions & 2 deletions tests/jsrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def make_command(filename, engine, args=[]):
# if no engine is needed, indicated by None, then there is a native executable
# provided which we can just run
if engine[0] is None:
executable = shared.unsuffixed(os.path.abspath(filename)) + '.exe'
executable = shared.replace_suffix(os.path.abspath(filename), '.exe')
return [executable] + args
if type(engine) is not list:
engine = [engine]
Expand All @@ -44,7 +44,7 @@ def make_command(filename, engine, args=[]):
command_flags += ['run']
if is_wasmer or is_wasmtime:
# in a wasm runtime, run the wasm, not the js
filename = shared.unsuffixed(filename) + '.wasm'
filename = shared.replace_suffix(filename, '.wasm')
# Separates engine flags from script flags
flag_separator = ['--'] if is_d8 or is_jsc else []
return engine + command_flags + [filename] + shell_option_flags + flag_separator + args
Expand Down
4 changes: 2 additions & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ def test_emscripten_get_now(self):

def test_emscripten_get_compiler_setting(self):
src = test_file('core/emscripten_get_compiler_setting.c')
output = shared.unsuffixed(src) + '.out'
output = shared.replace_suffix(src, '.out')
# with assertions, a nice message is shown
self.set_setting('ASSERTIONS')
self.do_runf(src, 'You must build with -s RETAIN_COMPILER_SETTINGS=1', assert_returncode=NON_ZERO)
Expand Down Expand Up @@ -3532,7 +3532,7 @@ def dylink_testf(self, main, side=None, expected=None, force_c=False, main_emcc_
# Same as dylink_test but takes source code as filenames on disc.
old_args = self.emcc_args.copy()
if not expected:
outfile = shared.unsuffixed(main) + '.out'
outfile = shared.replace_suffix(main, '.out')
expected = read_file(outfile)
if not side:
side, ext = os.path.splitext(main)
Expand Down
6 changes: 3 additions & 3 deletions tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def scan_archive_group(group):
def get_command_with_possible_response_file(cmd):
# 8k is a bit of an arbitrary limit, but a reasonable one
# for max command line size before we use a response file
if len(' '.join(cmd)) <= 8192:
if len(shared.shlex_join(cmd)) <= 8192:
return cmd

logger.debug('using response file for %s' % cmd[0])
Expand Down Expand Up @@ -813,7 +813,7 @@ def move_to_safe_7bit_ascii_filename(filename):
# Specify input file relative to the temp directory to avoid specifying non-7-bit-ASCII path names.
args += ['--js', move_to_safe_7bit_ascii_filename(filename)]
cmd = closure_cmd + args + user_args
logger.debug('closure compiler: ' + ' '.join(cmd))
logger.debug(f'closure compiler: {shared.shlex_join(cmd)}')

# Closure compiler does not work if any of the input files contain characters outside the
# 7-bit ASCII range. Therefore make sure the command line we pass does not contain any such
Expand Down Expand Up @@ -847,7 +847,7 @@ def move_to_safe_7bit_ascii_filename(filename):
logger.error(proc.stderr) # print list of errors (possibly long wall of text if input was minified)

# Exit and print final hint to get clearer output
msg = 'closure compiler failed (rc: %d): %s' % (proc.returncode, shared.shlex_join(cmd))
msg = f'closure compiler failed (rc: {proc.returncode}): {shared.shlex_join(cmd)}'
if not pretty:
msg += ' the error message may be clearer with -g1 and EMCC_DEBUG=2 set'
exit_with_error(msg)
Expand Down