f4b41f0902
When parsing `--define` or `-D` arguments don't split the the value by
commas.
This is consistent with how dart2js handles `-D`, but inconsistent with
how VM handles it.
Example:
void main() {
print(const String.fromEnvironment("FOO"));
}
When compiled with `dart compile js -DFOO="a, b"` and run, dart2js
prints
a, b
VM prints (when compiled to exe)
a
Between these two, I think dart2js' behavior is more common, so we
follow dart2js.
Also update compile_benchmark to avoid splitting a single argument "a b"
into "a" and "b" when parsing the arguments and then splicing them back
before calling `dart2wasm`.
Also update the test runner and ddc batch mode argument parser to handle
splitting quoted arguments in `// dart2jsOption = ...` and the same
options for ddc and dart2wasm, by moving dart2js's `splitLine` to a new
library and reusing it in the test runner and ddc.
Fixes https://github.com/flutter/flutter/issues/164873.
See also https://github.com/dart-lang/sdk/issues/60341 for relevant
future work.
Change-Id: Idbdf69072fa212c8e4a390990577eb5a57b49e8a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415280
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
97 lines
2.5 KiB
Dart
97 lines
2.5 KiB
Dart
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import "package:expect/expect.dart";
|
|
import "package:shell_arg_splitter/shell_arg_splitter.dart";
|
|
|
|
void main() {
|
|
Expect.listEquals(["foo", "bar"], splitLine("foo bar"));
|
|
Expect.listEquals(["foo", "bar"], splitLine("foo bar", windows: true));
|
|
|
|
Expect.listEquals(["foo bar"], splitLine(r"foo\ bar"));
|
|
Expect.listEquals(["foo\\", "bar"], splitLine(r"foo\ bar", windows: true));
|
|
|
|
Expect.listEquals(["foo'", '"bar'], splitLine(r"""foo\' \"bar"""));
|
|
Expect.listEquals([
|
|
"foo\\'",
|
|
'"bar',
|
|
], splitLine(r"""foo\' \"bar""", windows: true));
|
|
|
|
Expect.listEquals(["foo'", '"bar'], splitLine(r"""foo"'" '"'bar"""));
|
|
Expect.throws(
|
|
() => splitLine(r"""foo"'" '"'bar""", windows: true),
|
|
(e) => e is FormatException,
|
|
);
|
|
Expect.listEquals([
|
|
"foo'",
|
|
"''bar",
|
|
], splitLine(r"""foo"'" '"'bar" """, windows: true));
|
|
|
|
Expect.listEquals(
|
|
["foo", "bar"],
|
|
splitLine(
|
|
"'f''o''o' "
|
|
'"b""a""r"',
|
|
),
|
|
);
|
|
// TODO(johnniwinther): This is not actual Windows behavior: "b""a" is
|
|
// interpreted as b"a but "b""a""r" is interpreted as b"ar.
|
|
Expect.listEquals(
|
|
["'f''o''o'", "bar"],
|
|
splitLine(
|
|
"'f''o''o' "
|
|
'"b""a""r"',
|
|
windows: true,
|
|
),
|
|
);
|
|
|
|
Expect.listEquals([
|
|
"\n",
|
|
"\r",
|
|
"\t",
|
|
"\b",
|
|
"\f",
|
|
"\v",
|
|
"\\",
|
|
"a",
|
|
"Z",
|
|
"-",
|
|
'"',
|
|
"'",
|
|
], splitLine(r"""\n \r \t \b \f \v \\ \a \Z \- \" \'"""));
|
|
Expect.listEquals([
|
|
"\\n",
|
|
"\\r",
|
|
"\\t",
|
|
"\\b",
|
|
"\\f",
|
|
"\\v",
|
|
"\\",
|
|
"\\a",
|
|
"\\Z",
|
|
"\\-",
|
|
'"',
|
|
"\\'",
|
|
], splitLine(r"""\n \r \t \b \f \v \\ \a \Z \- \" \'""", windows: true));
|
|
Expect.listEquals([
|
|
"C:Users\foo\bar\baz.dart",
|
|
], splitLine(r"C:\Users\foo\bar\baz.dart"));
|
|
Expect.listEquals([
|
|
r"C:\Users\foo\bar\baz.dart",
|
|
], splitLine(r"C:\Users\foo\bar\baz.dart", windows: true));
|
|
|
|
Expect.listEquals([
|
|
"C:Users\foo\bar\name with spaces.dart",
|
|
], splitLine(r'"C:\Users\foo\bar\name with spaces.dart"'));
|
|
Expect.listEquals([
|
|
r"C:\Users\foo\bar\name with spaces.dart",
|
|
], splitLine(r'"C:\Users\foo\bar\name with spaces.dart"', windows: true));
|
|
|
|
Expect.throws(() => splitLine(r"\"), (e) => e is FormatException);
|
|
Expect.throws(
|
|
() => splitLine(r"\", windows: true),
|
|
(e) => e is FormatException,
|
|
);
|
|
}
|