Skip to content
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

add argument to emrun for file dump_out directory #15801

Merged
merged 12 commits into from
Jan 11, 2022
Merged
10 changes: 6 additions & 4 deletions emrun.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -684,13 +684,12 @@ def do_POST(self):
# Binary file dump/upload handling. Requests to
# "stdio.html?file=filename" will write binary data to the given file.
data = self.rfile.read(int(self.headers['Content-Length']))
filename = query[len('file='):]
dump_out_directory = 'dump_out'
filename = unquote_u(query[len('file='):])
filename = os.path.join(emrun_options.dump_out_directory, os.path.normpath(filename))
try:
os.mkdir(dump_out_directory)
os.makedirs(os.path.dirname(filename))
except OSError:
pass
filename = os.path.join(dump_out_directory, os.path.normpath(filename))
with open(filename, 'wb') as fh:
fh.write(data)
logi('Wrote ' + str(len(data)) + ' bytes to file "' + filename + '".')
Expand Down Expand Up @@ -1571,6 +1570,9 @@ def run():
parser.add_argument('--private_browsing', action='store_true',
help='If specified, opens browser in private/incognito mode.')

parser.add_argument('--dump_out_directory', default='dump_out', type=str,
help='If specified, overrides the directory for dump files using emrun_file_dump method.')

parser.add_argument('serve', nargs='?', default='')

parser.add_argument('cmdlineparams', nargs='*')
Expand Down
7 changes: 6 additions & 1 deletion tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5330,12 +5330,17 @@ def test_emrun(self):

for args in [
args_base,
args_base + ['--private_browsing', '--port', '6941']
args_base + ['--private_browsing', '--port', '6941'],
args_base + ['--dump_out_directory', 'other dir/multiple', '--port', '6942']
]:
args += [self.in_dir('hello_world.html'), '--', '1', '2', '--3']
print(shared.shlex_join(args))
proc = self.run_process(args, check=False)
self.assertEqual(proc.returncode, 100)
dump_dir = 'other dir/multiple' if '--dump_out_directory' in args else 'dump_out'
self.assertExists(self.in_dir(f'{dump_dir}/test.dat'))
self.assertExists(self.in_dir(f'{dump_dir}/heap.dat'))
self.assertExists(self.in_dir(f'{dump_dir}/nested/with space.dat'))
stdout = read_file(self.in_dir('stdout.txt'))
stderr = read_file(self.in_dir('stderr.txt'))
self.assertContained('argc: 4', stdout)
Expand Down
1 change: 1 addition & 0 deletions tests/test_emrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ int main(int argc, char **argv) {
// Dump a file to local filesystem with emrun.
EM_ASM(emrun_file_dump("test.dat", HEAPU8.subarray(0, 128)););
EM_ASM(emrun_file_dump("heap.dat", HEAPU8));
EM_ASM(emrun_file_dump("nested/with space.dat", HEAPU8.subarray(128, 256)););

if (argc <= 1)
exit(1);
Expand Down