Skip to content
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
5 changes: 3 additions & 2 deletions emar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

import sys

from tools import shared, building
from tools import shared


#
# Main run() function
#
def run():
return shared.run_process([shared.LLVM_AR] + building.get_command_with_possible_response_file(sys.argv[1:]), stdin=sys.stdin, check=False).returncode
cmd = [shared.LLVM_AR] + sys.argv[1:]
return shared.run_process(cmd, stdin=sys.stdin, check=False).returncode
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does seem natural to use building.get_command_with_possible_response_file - if I were refactoring this I would want to do that. maybe a comment here why it can't work, or why it isn't necessary? (I still don't understand why not)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we know that the command line here (by definition) does not need a response file.. also doing that alone would be broken because sys.argv here might already have response file.. so it only makes sense if you have somehow already opened and expanded any incoming response file, which we don't do by default (at least not prior to #13954)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you mean that if it worked to call this script with those args, then the number of args is reasonable anyhow? Sgtm.



if __name__ == '__main__':
Expand Down
10 changes: 10 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from tools.shared import unsuffixed, unsuffixed_basename, WINDOWS, safe_copy
from tools.shared import run_process, read_and_preprocess, exit_with_error, DEBUG
from tools.shared import do_replace
from tools.response_file import substitute_response_files
from tools.minimal_runtime_shell import generate_minimal_runtime_html
import tools.line_endings
from tools import js_manipulation
Expand Down Expand Up @@ -926,6 +927,12 @@ def run(args):

# Handle some global flags

# read response files very early on
try:
args = substitute_response_files(args)
except IOError as e:
exit_with_error(e)

if '--help' in args:
# Documentation for emcc and its options must be updated in:
# site/source/docs/tools_reference/emcc.rst
Expand Down Expand Up @@ -2757,6 +2764,9 @@ def consume_arg_file():
diagnostics.warning('legacy-settings', '--remove-duplicates is deprecated as it is no longer needed. If you cannot link without it, file a bug with a testcase')
elif check_flag('--jcache'):
logger.error('jcache is no longer supported')
elif check_arg('--cache'):
config.CACHE = os.path.normpath(consume_arg())
shared.reconfigure_cache()
elif check_flag('--clear-cache'):
logger.info('clearing cache as requested by --clear-cache')
shared.Cache.erase()
Expand Down
5 changes: 0 additions & 5 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -7464,11 +7464,6 @@ def test_emar_duplicate_inputs(self):
create_file('file1', ' ')
self.run_process([EMAR, 'cr', 'file1.a', 'file1', 'file1'])

# It seems our response file parsing, which is currently just shlex.split(), is
# not up to the task on windows. This wasn't a problem that became apparent until
# after https://github.com/emscripten-core/emscripten/pull/13954 which
# broke this test because we starting parsing incoming response files in emar.py.
@no_windows('https://github.com/emscripten-core/emscripten/pull/13954')
def test_emar_response_file(self):
# Test that special character such as single quotes in filenames survive being
# sent via response file
Expand Down
16 changes: 2 additions & 14 deletions tests/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,7 @@ def test_emcc_cache_flag(self, use_response_files):
# The cache directory must contain a sysroot
self.assertTrue(os.path.exists(os.path.join(cache_dir_name, 'sysroot')))

@parameterized({
'': [False],
'response_files': [True]
})
def test_emconfig(self, use_response_files):
def test_emconfig(self):
restore_and_set_up()

fd, custom_config_filename = tempfile.mkstemp(prefix='.emscripten_config_')
Expand All @@ -541,18 +537,10 @@ def test_emconfig(self, use_response_files):

temp_dir = tempfile.mkdtemp(prefix='emscripten_temp_')

args = ['--em-config', custom_config_filename]
if use_response_files:
rsp = response_file.create_response_file(args, shared.TEMP_DIR)
args = ['@' + rsp]

with utils.chdir(temp_dir):
self.run_process([EMCC] + args + MINIMAL_HELLO_WORLD + ['-O2'])
self.run_process([EMCC, '--em-config', custom_config_filename] + MINIMAL_HELLO_WORLD + ['-O2'])
result = self.run_js('a.out.js')

if use_response_files:
os.remove(rsp)

self.assertContained('hello, world!', result)

# Clean up created temp files.
Expand Down
59 changes: 19 additions & 40 deletions tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import sys
import logging
from .utils import path_from_root, exit_with_error, __rootpath__, which
from .response_file import substitute_response_files

logger = logging.getLogger('shared')

Expand Down Expand Up @@ -240,46 +239,26 @@ def generate_config(path, first_time=False):
emsdk_embedded_config = os.path.join(emsdk_root, '.emscripten')
user_home_config = os.path.expanduser('~/.emscripten')

# read response files very early on so that all subsequent code that accesses
# sys.argv will see the expanded content.
try:
sys.argv = substitute_response_files(sys.argv)
except IOError as e:
exit_with_error(e)


def consume_argv(name):
value = None
while name in sys.argv:
i = sys.argv.index(name)
if len(sys.argv) <= i + 1:
exit_with_error(name + ' must be followed by a filename')
value = sys.argv.pop(i + 1)
del sys.argv[i]
return value


EM_CONFIG = consume_argv('--em-config')
if not EM_CONFIG:
if 'EM_CONFIG' in os.environ:
EM_CONFIG = os.environ['EM_CONFIG']
elif os.path.exists(embedded_config):
EM_CONFIG = embedded_config
elif os.path.exists(emsdk_embedded_config):
EM_CONFIG = emsdk_embedded_config
elif os.path.exists(user_home_config):
EM_CONFIG = user_home_config
if '--em-config' in sys.argv:
i = sys.argv.index('--em-config')
if len(sys.argv) <= i + 1:
exit_with_error('--em-config must be followed by a filename')
EM_CONFIG = sys.argv.pop(i + 1)
del sys.argv[i]
elif 'EM_CONFIG' in os.environ:
EM_CONFIG = os.environ['EM_CONFIG']
elif os.path.exists(embedded_config):
EM_CONFIG = embedded_config
elif os.path.exists(emsdk_embedded_config):
EM_CONFIG = emsdk_embedded_config
elif os.path.exists(user_home_config):
EM_CONFIG = user_home_config
else:
if root_is_writable():
generate_config(embedded_config, first_time=True)
else:
if root_is_writable():
generate_config(embedded_config, first_time=True)
else:
generate_config(user_home_config, first_time=True)
sys.exit(0)

argv_cache = consume_argv('--cache')
if argv_cache:
CACHE = os.path.abspath(os.path.expanduser(argv_cache))
os.environ['EM_CACHE'] = CACHE
generate_config(user_home_config, first_time=True)
sys.exit(0)

# We used to support inline EM_CONFIG.
if '\n' in EM_CONFIG:
Expand Down
5 changes: 5 additions & 0 deletions tools/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@ def asmjs_mangle(name):
return name


def reconfigure_cache():
global Cache
Cache = cache.Cache(config.CACHE)


class JS:
emscripten_license = '''\
/**
Expand Down