[flutter_tools] switch dart defines to base64 to avoid windows control characters (#75027)

= gets escaped into %3D which seems to be tripping up cmake on windows since % is a control character. Switch to base64 encoding, since this does not have % nor , in the output character set.

This change is not trivially cherry pickable, and isn't tested on windows aside from my local, manual tests due to the planned CI work not being complete yet.

Fixes #75017
Fixes #74705
This commit is contained in:
Jonah Williams
2021-02-02 09:10:48 -08:00
committed by GitHub
parent aebf548436
commit 44d5950d27
17 changed files with 149 additions and 88 deletions

View File

@@ -368,10 +368,10 @@ ERROR: No file or variants found for asset: images/a_dot_burr.jpeg
expect(configLines, containsAll(<String>[
'file(TO_CMAKE_PATH "$_kTestFlutterRoot" FLUTTER_ROOT)',
'file(TO_CMAKE_PATH "${fileSystem.currentDirectory.path}" PROJECT_DIR)',
' "DART_DEFINES=foo.bar%3D2,fizz.far%3D3"',
' "DART_DEFINES=Zm9vLmJhcj0y,Zml6ei5mYXI9Mw=="',
' "DART_OBFUSCATION=true"',
' "EXTRA_FRONT_END_OPTIONS=--enable-experiment%3Dnon-nullable"',
' "EXTRA_GEN_SNAPSHOT_OPTIONS=--enable-experiment%3Dnon-nullable"',
' "EXTRA_FRONT_END_OPTIONS=--enable-experiment=non-nullable"',
' "EXTRA_GEN_SNAPSHOT_OPTIONS=--enable-experiment=non-nullable"',
' "SPLIT_DEBUG_INFO=foo/"',
' "TRACK_WIDGET_CREATION=true"',
' "TREE_SHAKE_ICONS=true"',

View File

@@ -257,16 +257,21 @@ void main() {
.readAsLinesSync();
expect(contents, containsAll(<String>[
'DART_DEFINES=foo.bar%3D2,fizz.far%3D3',
'FLUTTER_APPLICATION_PATH=/',
'FLUTTER_TARGET=lib/other.dart',
'FLUTTER_BUILD_DIR=build',
'FLUTTER_BUILD_NAME=1.0.0',
'FLUTTER_BUILD_NUMBER=1',
'EXCLUDED_ARCHS=arm64',
'DART_DEFINES=Zm9vLmJhcj0y,Zml6ei5mYXI9Mw==',
'DART_OBFUSCATION=true',
'EXTRA_FRONT_END_OPTIONS=--enable-experiment%3Dnon-nullable',
'EXTRA_GEN_SNAPSHOT_OPTIONS=--enable-experiment%3Dnon-nullable',
'EXTRA_FRONT_END_OPTIONS=--enable-experiment=non-nullable',
'EXTRA_GEN_SNAPSHOT_OPTIONS=--enable-experiment=non-nullable',
'SPLIT_DEBUG_INFO=foo/',
'TRACK_WIDGET_CREATION=true',
'TREE_SHAKE_ICONS=true',
'FLUTTER_TARGET=lib/other.dart',
'BUNDLE_SKSL_PATH=foo/bar.sksl.json',
'EXCLUDED_ARCHS=arm64',
'PACKAGE_CONFIG=/.dart_tool/package_config.json'
]));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,

View File

@@ -317,10 +317,10 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier
expect(configLines, containsAll(<String>[
r'file(TO_CMAKE_PATH "C:\\flutter" FLUTTER_ROOT)',
r'file(TO_CMAKE_PATH "C:\\" PROJECT_DIR)',
r' "DART_DEFINES=foo%3Da,bar%3Db"',
r' "DART_DEFINES=Zm9vPWE=,YmFyPWI="',
r' "DART_OBFUSCATION=true"',
r' "EXTRA_FRONT_END_OPTIONS=--enable-experiment%3Dnon-nullable"',
r' "EXTRA_GEN_SNAPSHOT_OPTIONS=--enable-experiment%3Dnon-nullable"',
r' "EXTRA_FRONT_END_OPTIONS=--enable-experiment=non-nullable"',
r' "EXTRA_GEN_SNAPSHOT_OPTIONS=--enable-experiment=non-nullable"',
r' "SPLIT_DEBUG_INFO=C:\\foo\\"',
r' "TRACK_WIDGET_CREATION=true"',
r' "TREE_SHAKE_ICONS=true"',

View File

@@ -237,6 +237,7 @@ void main() {
'-q',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Pdart-obfuscation=false',
'-Ptrack-widget-creation=true',
'-Ptree-shake-icons=true',
'assembleRelease',
@@ -265,8 +266,9 @@ void main() {
'-q',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'-Pdart-obfuscation=false',
'-Psplit-debug-info=${tempDir.path}',
'-Ptrack-widget-creation=true',
'-Ptree-shake-icons=true',
'assembleRelease',
],
@@ -297,8 +299,9 @@ void main() {
'-q',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Ptrack-widget-creation=true',
'-Pdart-obfuscation=false',
'-Pextra-front-end-options=foo,bar',
'-Ptrack-widget-creation=true',
'-Ptree-shake-icons=true',
'assembleRelease',
],
@@ -329,6 +332,7 @@ void main() {
'-q',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Pdart-obfuscation=false',
'-Ptrack-widget-creation=true',
'-Ptree-shake-icons=true',
'assembleRelease',
@@ -353,6 +357,7 @@ void main() {
'-q',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Pdart-obfuscation=false',
'-Ptrack-widget-creation=true',
'-Ptree-shake-icons=true',
'assembleRelease',
@@ -422,6 +427,7 @@ void main() {
'-q',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Pdart-obfuscation=false',
'-Ptrack-widget-creation=true',
'-Ptree-shake-icons=true',
'assembleRelease',
@@ -481,6 +487,7 @@ void main() {
'-q',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}',
'-Pdart-obfuscation=false',
'-Ptrack-widget-creation=true',
'-Ptree-shake-icons=true',
'assembleRelease',

View File

@@ -916,7 +916,9 @@ plugin2=${plugin2.path}
'-Pis-plugin=true',
'-PbuildNumber=1.0',
'-q',
'-Pfont-subset=true',
'-Pdart-obfuscation=false',
'-Ptrack-widget-creation=false',
'-Ptree-shake-icons=true',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'assembleAarRelease',
],
@@ -931,7 +933,9 @@ plugin2=${plugin2.path}
'-Pis-plugin=true',
'-PbuildNumber=1.0',
'-q',
'-Pfont-subset=true',
'-Pdart-obfuscation=false',
'-Ptrack-widget-creation=false',
'-Ptree-shake-icons=true',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'assembleAarRelease',
],
@@ -2103,7 +2107,9 @@ plugin1=${plugin1.path}
'--no-daemon',
'-Ptarget-platform=android-arm,android-arm64,android-x64',
'-Ptarget=lib/main.dart',
'-Pdart-obfuscation=false',
'-Ptrack-widget-creation=false',
'-Ptree-shake-icons=false',
'assembleRelease'
],
));

View File

@@ -115,40 +115,67 @@ void main() {
expect(buildInfo.toEnvironmentConfig(), <String, String>{
'TREE_SHAKE_ICONS': 'true',
'TRACK_WIDGET_CREATION': 'true',
'DART_DEFINES': 'foo%3D2,bar%3D2',
'DART_DEFINES': 'Zm9vPTI=,YmFyPTI=',
'DART_OBFUSCATION': 'true',
'SPLIT_DEBUG_INFO': 'foo/',
'EXTRA_FRONT_END_OPTIONS': '--enable-experiment%3Dnon-nullable,bar',
'EXTRA_GEN_SNAPSHOT_OPTIONS': '--enable-experiment%3Dnon-nullable,fizz',
'EXTRA_FRONT_END_OPTIONS': '--enable-experiment=non-nullable,bar',
'EXTRA_GEN_SNAPSHOT_OPTIONS': '--enable-experiment=non-nullable,fizz',
'BUNDLE_SKSL_PATH': 'foo/bar/baz.sksl.json',
'PACKAGE_CONFIG': 'foo/.packages',
'CODE_SIZE_DIRECTORY': 'foo/code-size',
});
});
testWithoutContext('encodeDartDefines encodes define values with URI encode compnents', () {
expect(encodeDartDefines(<String>['"hello"']), '%22hello%22');
expect(encodeDartDefines(<String>['https://www.google.com']), 'https%3A%2F%2Fwww.google.com');
expect(encodeDartDefines(<String>['2,3,4', '5']), '2%2C3%2C4,5');
expect(encodeDartDefines(<String>['true', 'false', 'flase']), 'true,false,flase');
expect(encodeDartDefines(<String>['1232,456', '2']), '1232%2C456,2');
testWithoutContext('toGradleConfig encoding of standard values', () {
const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '',
treeShakeIcons: true,
trackWidgetCreation: true,
dartDefines: <String>['foo=2', 'bar=2'],
dartObfuscation: true,
splitDebugInfoPath: 'foo/',
extraFrontEndOptions: <String>['--enable-experiment=non-nullable', 'bar'],
extraGenSnapshotOptions: <String>['--enable-experiment=non-nullable', 'fizz'],
bundleSkSLPath: 'foo/bar/baz.sksl.json',
packagesPath: 'foo/.packages',
codeSizeDirectory: 'foo/code-size',
);
expect(buildInfo.toGradleConfig(), <String>[
'-Pdart-defines=Zm9vPTI=,YmFyPTI=',
'-Pdart-obfuscation=true',
'-Pextra-front-end-options=--enable-experiment=non-nullable,bar',
'-Pextra-gen-snapshot-options=--enable-experiment=non-nullable,fizz',
'-Psplit-debug-info=foo/',
'-Ptrack-widget-creation=true',
'-Ptree-shake-icons=true',
'-Pbundle-sksl-path=foo/bar/baz.sksl.json',
'-Pcode-size-directory=foo/code-size'
]);
});
testWithoutContext('decodeDartDefines decodes URI encoded dart defines', () {
testWithoutContext('encodeDartDefines encodes define values with base64 encoded compnents', () {
expect(encodeDartDefines(<String>['"hello"']), 'ImhlbGxvIg==');
expect(encodeDartDefines(<String>['https://www.google.com']), 'aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbQ==');
expect(encodeDartDefines(<String>['2,3,4', '5']), 'MiwzLDQ=,NQ==');
expect(encodeDartDefines(<String>['true', 'false', 'flase']), 'dHJ1ZQ==,ZmFsc2U=,Zmxhc2U=');
expect(encodeDartDefines(<String>['1232,456', '2']), 'MTIzMiw0NTY=,Mg==');
});
testWithoutContext('decodeDartDefines decodes base64 encoded dart defines', () {
expect(decodeDartDefines(<String, String>{
kDartDefines: '%22hello%22'
kDartDefines: 'ImhlbGxvIg=='
}, kDartDefines), <String>['"hello"']);
expect(decodeDartDefines(<String, String>{
kDartDefines: 'https%3A%2F%2Fwww.google.com'
kDartDefines: 'aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbQ=='
}, kDartDefines), <String>['https://www.google.com']);
expect(decodeDartDefines(<String, String>{
kDartDefines: '2%2C3%2C4,5'
kDartDefines: 'MiwzLDQ=,NQ=='
}, kDartDefines), <String>['2,3,4', '5']);
expect(decodeDartDefines(<String, String>{
kDartDefines: 'true,false,flase'
kDartDefines: 'dHJ1ZQ==,ZmFsc2U=,Zmxhc2U='
}, kDartDefines), <String>['true', 'false', 'flase']);
expect(decodeDartDefines(<String, String>{
kDartDefines: '1232%2C456,2'
kDartDefines: 'MTIzMiw0NTY=,Mg=='
}, kDartDefines), <String>['1232,456', '2']);
});
}

View File

@@ -481,7 +481,7 @@ void main() {
test('Dart2JSTarget calls dart2js with Dart defines in release mode', () => testbed.run(() async {
environment.defines[kBuildMode] = 'release';
environment.defines[kDartDefines] = 'FOO=bar,BAZ=qux';
environment.defines[kDartDefines] = encodeDartDefines(<String>['FOO=bar', 'BAZ=qux']);
processManager.addCommand(FakeCommand(
command: <String>[
...kDart2jsLinuxArgs,
@@ -548,7 +548,7 @@ void main() {
test('Dart2JSTarget calls dart2js with Dart defines in profile mode', () => testbed.run(() async {
environment.defines[kBuildMode] = 'profile';
environment.defines[kDartDefines] = 'FOO=bar,BAZ=qux';
environment.defines[kDartDefines] = encodeDartDefines(<String>['FOO=bar', 'BAZ=qux']);
processManager.addCommand(FakeCommand(
command: <String>[
...kDart2jsLinuxArgs,