Skip to content

Commit d3fca85

Browse files
authored
[ports] Enable use of "::" to escape options separator (#21710)
1 parent 1df9c19 commit d3fca85

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ See docs/process.md for more on how version tagging works.
4444
- TypeScript definitions for Wasm exports, runtime exports, and embind bindings
4545
can now be generated with `--emit-tsd`. The option `--embind-emit-tsd` has been
4646
deprecated, use `--emit-tsd` instead.
47+
- ports changes:
48+
- Fixed transitive link dependencies (#21602)
49+
- Enable use of options in ports dependencies (#21629)
50+
- Enable use of `::` to escape option separator (#21710)
4751

4852
3.1.56 - 03/14/24
4953
-----------------

test/other/ports/external.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
OPTIONS = {
1414
'value1': 'Value for define TEST_VALUE_1',
1515
'value2': 'Value for define TEST_VALUE_2',
16-
'dependency': 'A dependency'
16+
'value3': 'String value',
17+
'dependency': 'A dependency',
1718
}
1819

1920
# user options (from --use-port)
2021
opts: Dict[str, Optional[str]] = {
2122
'value1': None,
2223
'value2': None,
24+
'value3': "v3",
2325
'dependency': None
2426
}
2527

@@ -57,6 +59,7 @@ def process_args(ports):
5759
args.append(f'-DTEST_VALUE_2={opts["value2"]}')
5860
if opts['dependency']:
5961
args.append(f'-DTEST_DEPENDENCY_{opts["dependency"].upper()}')
62+
args.append(f'-DTEST_VALUE_3="{opts["value3"]}"')
6063
return args
6164

6265

test/other/test_external_ports.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
int main() {
2626
assert(my_port_fn(99) == 99); // check that we can call a function from my_port.h
27-
printf("value1=%d&value2=%d\n", TEST_VALUE_1, TEST_VALUE_2);
27+
printf("value1=%d&value2=%d&value3=%s\n", TEST_VALUE_1, TEST_VALUE_2, TEST_VALUE_3);
2828

2929
// external port declares deps = ['sdl2_image:formats=jpg'] as a dependency
3030
// this makes sure that the dependency + options gets processed properly

test/test_other.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,11 +2463,13 @@ def test_external_ports(self):
24632463
self.skipTest("test doesn't work with frozen cache")
24642464
external_port_path = test_file("other/ports/external.py")
24652465
# testing no option
2466-
self.do_runf('other/test_external_ports.c', 'value1=0&value2=0\n', emcc_args=[f'--use-port={external_port_path}'])
2466+
self.do_runf('other/test_external_ports.c', 'value1=0&value2=0&value3=v3\n', emcc_args=[f'--use-port={external_port_path}'])
24672467
# testing 1 option
2468-
self.do_runf('other/test_external_ports.c', 'value1=12&value2=0\n', emcc_args=[f'--use-port={external_port_path}:value1=12'])
2468+
self.do_runf('other/test_external_ports.c', 'value1=12&value2=0&value3=v3\n', emcc_args=[f'--use-port={external_port_path}:value1=12'])
24692469
# testing 2 options
2470-
self.do_runf('other/test_external_ports.c', 'value1=12&value2=36\n', emcc_args=[f'--use-port={external_port_path}:value1=12:value2=36'])
2470+
self.do_runf('other/test_external_ports.c', 'value1=12&value2=36&value3=v3\n', emcc_args=[f'--use-port={external_port_path}:value1=12:value2=36'])
2471+
# testing ':' escape
2472+
self.do_runf('other/test_external_ports.c', 'value1=12&value2=36&value3=v:3\n', emcc_args=[f'--use-port={external_port_path}:value1=12:value3=v::3:value2=36'])
24712473
# testing dependency
24722474
self.do_runf('other/test_external_ports.c', 'mpg123=45\n', emcc_args=[f'--use-port={external_port_path}:dependency=mpg123'])
24732475
# testing invalid dependency
@@ -2481,6 +2483,7 @@ def test_external_ports(self):
24812483
Options:
24822484
* value1: Value for define TEST_VALUE_1
24832485
* value2: Value for define TEST_VALUE_2
2486+
* value3: String value
24842487
* dependency: A dependency
24852488
More info: https://emscripten.org
24862489
''', stdout)

tools/ports/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ def handle_port_options(name, options, error_handler):
437437
error_handler(f'no options available for port `{name}`')
438438
else:
439439
options_dict = {}
440-
for name_value in options.split(':'):
440+
for name_value in options.replace('::', '\0').split(':'):
441+
name_value = name_value.replace('\0', ':')
441442
nv = name_value.split('=', 1)
442443
if len(nv) != 2:
443444
error_handler(f'`{name_value}` is missing a value')

tools/ports/contrib/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ calls the handler function with these (valid) options. If you detect an error
3737
with a value, you should use the error handler provided to report the
3838
failure.
3939

40+
Since emscripten uses `:` as the option separator, `::` is the escape syntax
41+
(ex: `--use-port=name:opt1=abc::def`)
42+
4043
> ### Note
4144
> If the options influence the way the library produced by the port is built,
4245
> you must ensure that the library name accounts for these options. Check

0 commit comments

Comments
 (0)