2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2019-02-13 15:48:03 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-05-05 01:37:44 +00:00
|
|
|
import 'package:flutter_tools/src/base/logger.dart';
|
2019-02-13 15:48:03 +00:00
|
|
|
import 'package:flutter_tools/src/build_info.dart';
|
|
|
|
|
2019-07-13 18:51:44 +00:00
|
|
|
import '../src/common.dart';
|
2019-02-13 15:48:03 +00:00
|
|
|
|
|
|
|
void main() {
|
2021-04-08 22:18:52 +00:00
|
|
|
late BufferLogger logger;
|
2020-05-05 01:37:44 +00:00
|
|
|
setUp(() {
|
|
|
|
logger = BufferLogger.test();
|
|
|
|
});
|
2019-02-13 15:48:03 +00:00
|
|
|
|
|
|
|
group('Validate build number', () {
|
2020-05-05 01:37:44 +00:00
|
|
|
testWithoutContext('CFBundleVersion for iOS', () async {
|
2021-04-08 22:18:52 +00:00
|
|
|
String? buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, 'xyz', logger);
|
2019-09-18 00:07:41 +00:00
|
|
|
expect(buildName, isNull);
|
2020-05-05 01:37:44 +00:00
|
|
|
buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '0.0.1', logger);
|
2019-07-31 23:18:09 +00:00
|
|
|
expect(buildName, '0.0.1');
|
2020-05-05 01:37:44 +00:00
|
|
|
buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '123.xyz', logger);
|
2019-02-13 15:48:03 +00:00
|
|
|
expect(buildName, '123');
|
2020-05-05 01:37:44 +00:00
|
|
|
buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '123.456.xyz', logger);
|
2019-02-13 15:48:03 +00:00
|
|
|
expect(buildName, '123.456');
|
|
|
|
});
|
|
|
|
|
2020-05-05 01:37:44 +00:00
|
|
|
testWithoutContext('versionCode for Android', () async {
|
2021-04-08 22:18:52 +00:00
|
|
|
String? buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, '123.abc+-', logger);
|
2019-02-13 15:48:03 +00:00
|
|
|
expect(buildName, '123');
|
2020-05-05 01:37:44 +00:00
|
|
|
buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, 'abc', logger);
|
2019-02-13 15:48:03 +00:00
|
|
|
expect(buildName, '1');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
group('Validate build name', () {
|
2020-05-05 01:37:44 +00:00
|
|
|
testWithoutContext('CFBundleShortVersionString for iOS', () async {
|
2021-04-08 22:18:52 +00:00
|
|
|
String? buildName = validatedBuildNameForPlatform(TargetPlatform.ios, 'xyz', logger);
|
2019-09-18 00:07:41 +00:00
|
|
|
expect(buildName, isNull);
|
2020-05-05 01:37:44 +00:00
|
|
|
buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '0.0.1', logger);
|
2019-07-31 23:18:09 +00:00
|
|
|
expect(buildName, '0.0.1');
|
2020-05-05 01:37:44 +00:00
|
|
|
|
|
|
|
buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '123.456.xyz', logger);
|
|
|
|
expect(logger.traceText, contains('Invalid build-name'));
|
2019-02-13 15:48:03 +00:00
|
|
|
expect(buildName, '123.456.0');
|
2020-05-05 01:37:44 +00:00
|
|
|
|
|
|
|
buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '123.xyz', logger);
|
2019-02-13 15:48:03 +00:00
|
|
|
expect(buildName, '123.0.0');
|
|
|
|
});
|
|
|
|
|
2020-05-05 01:37:44 +00:00
|
|
|
testWithoutContext('versionName for Android', () async {
|
2021-04-08 22:18:52 +00:00
|
|
|
String? buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, '123.abc+-', logger);
|
2019-02-13 15:48:03 +00:00
|
|
|
expect(buildName, '123.abc+-');
|
2020-05-05 01:37:44 +00:00
|
|
|
buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, 'abc+-', logger);
|
2019-02-13 15:48:03 +00:00
|
|
|
expect(buildName, 'abc+-');
|
|
|
|
});
|
2019-10-28 16:37:29 +00:00
|
|
|
|
2020-05-05 01:37:44 +00:00
|
|
|
testWithoutContext('build mode configuration is correct', () {
|
2019-10-28 16:37:29 +00:00
|
|
|
expect(BuildMode.debug.isRelease, false);
|
|
|
|
expect(BuildMode.debug.isPrecompiled, false);
|
|
|
|
expect(BuildMode.debug.isJit, true);
|
|
|
|
|
|
|
|
expect(BuildMode.profile.isRelease, false);
|
|
|
|
expect(BuildMode.profile.isPrecompiled, true);
|
|
|
|
expect(BuildMode.profile.isJit, false);
|
|
|
|
|
|
|
|
expect(BuildMode.release.isRelease, true);
|
|
|
|
expect(BuildMode.release.isPrecompiled, true);
|
|
|
|
expect(BuildMode.release.isJit, false);
|
|
|
|
|
|
|
|
expect(BuildMode.jitRelease.isRelease, true);
|
|
|
|
expect(BuildMode.jitRelease.isPrecompiled, false);
|
|
|
|
expect(BuildMode.jitRelease.isJit, true);
|
|
|
|
|
|
|
|
expect(BuildMode.fromName('debug'), BuildMode.debug);
|
|
|
|
expect(BuildMode.fromName('profile'), BuildMode.profile);
|
|
|
|
expect(BuildMode.fromName('jit_release'), BuildMode.jitRelease);
|
|
|
|
expect(BuildMode.fromName('release'), BuildMode.release);
|
2020-01-27 22:36:02 +00:00
|
|
|
expect(() => BuildMode.fromName('foo'), throwsArgumentError);
|
2019-10-28 16:37:29 +00:00
|
|
|
});
|
2019-02-13 15:48:03 +00:00
|
|
|
});
|
2020-02-06 01:45:24 +00:00
|
|
|
|
2020-05-05 01:37:44 +00:00
|
|
|
testWithoutContext('getNameForTargetPlatform on Darwin arches', () {
|
2020-02-06 01:45:24 +00:00
|
|
|
expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.arm64), 'ios-arm64');
|
|
|
|
expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.armv7), 'ios-armv7');
|
|
|
|
expect(getNameForTargetPlatform(TargetPlatform.ios, darwinArch: DarwinArch.x86_64), 'ios-x86_64');
|
|
|
|
expect(getNameForTargetPlatform(TargetPlatform.android), isNot(contains('ios')));
|
|
|
|
});
|
2020-02-12 03:43:43 +00:00
|
|
|
|
2020-05-05 01:37:44 +00:00
|
|
|
testWithoutContext('getIOSArchForName on Darwin arches', () {
|
2020-02-12 03:43:43 +00:00
|
|
|
expect(getIOSArchForName('armv7'), DarwinArch.armv7);
|
|
|
|
expect(getIOSArchForName('arm64'), DarwinArch.arm64);
|
|
|
|
expect(getIOSArchForName('arm64e'), DarwinArch.arm64);
|
|
|
|
expect(getIOSArchForName('x86_64'), DarwinArch.x86_64);
|
2020-03-06 18:22:12 +00:00
|
|
|
expect(() => getIOSArchForName('bogus'), throwsException);
|
2020-02-12 03:43:43 +00:00
|
|
|
});
|
2020-04-26 02:02:03 +00:00
|
|
|
|
2020-05-05 01:37:44 +00:00
|
|
|
testWithoutContext('toEnvironmentConfig encoding of standard values', () {
|
2020-04-26 02:02:03 +00:00
|
|
|
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'],
|
2020-06-09 18:15:52 +00:00
|
|
|
bundleSkSLPath: 'foo/bar/baz.sksl.json',
|
2020-06-25 19:52:14 +00:00
|
|
|
packagesPath: 'foo/.packages',
|
[flutter_tools] support code size tooling on iOS, linux, windows, macOS, and Android on Windows (#63610)
Adds support for size analysis on iOS, macOS, linux, and Windows - using an uncompressed directory based approach. The output format is not currently specified.
Adds support for size analysis on android on windows, switching to package:archive
Updates the console format to display as a tree, allowing longer paths. Increases the number of dart libraries shown (to avoid only ever printing the flutter/dart:ui libraries, which dominate the size)
2020-08-25 17:00:24 +00:00
|
|
|
codeSizeDirectory: 'foo/code-size',
|
2020-04-26 02:02:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
expect(buildInfo.toEnvironmentConfig(), <String, String>{
|
|
|
|
'TREE_SHAKE_ICONS': 'true',
|
|
|
|
'TRACK_WIDGET_CREATION': 'true',
|
2021-02-02 17:10:48 +00:00
|
|
|
'DART_DEFINES': 'Zm9vPTI=,YmFyPTI=',
|
2020-04-26 02:02:03 +00:00
|
|
|
'DART_OBFUSCATION': 'true',
|
|
|
|
'SPLIT_DEBUG_INFO': 'foo/',
|
2021-02-02 17:10:48 +00:00
|
|
|
'EXTRA_FRONT_END_OPTIONS': '--enable-experiment=non-nullable,bar',
|
|
|
|
'EXTRA_GEN_SNAPSHOT_OPTIONS': '--enable-experiment=non-nullable,fizz',
|
2020-06-09 18:15:52 +00:00
|
|
|
'BUNDLE_SKSL_PATH': 'foo/bar/baz.sksl.json',
|
2020-06-25 19:52:14 +00:00
|
|
|
'PACKAGE_CONFIG': 'foo/.packages',
|
[flutter_tools] support code size tooling on iOS, linux, windows, macOS, and Android on Windows (#63610)
Adds support for size analysis on iOS, macOS, linux, and Windows - using an uncompressed directory based approach. The output format is not currently specified.
Adds support for size analysis on android on windows, switching to package:archive
Updates the console format to display as a tree, allowing longer paths. Increases the number of dart libraries shown (to avoid only ever printing the flutter/dart:ui libraries, which dominate the size)
2020-08-25 17:00:24 +00:00
|
|
|
'CODE_SIZE_DIRECTORY': 'foo/code-size',
|
2020-04-26 02:02:03 +00:00
|
|
|
});
|
|
|
|
});
|
2020-05-27 17:11:04 +00:00
|
|
|
|
2021-02-02 17:10:48 +00:00
|
|
|
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('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==');
|
2020-05-27 17:11:04 +00:00
|
|
|
});
|
|
|
|
|
2021-02-02 17:10:48 +00:00
|
|
|
testWithoutContext('decodeDartDefines decodes base64 encoded dart defines', () {
|
2020-05-27 17:11:04 +00:00
|
|
|
expect(decodeDartDefines(<String, String>{
|
2021-02-02 17:10:48 +00:00
|
|
|
kDartDefines: 'ImhlbGxvIg=='
|
2020-06-04 04:02:07 +00:00
|
|
|
}, kDartDefines), <String>['"hello"']);
|
2020-05-27 17:11:04 +00:00
|
|
|
expect(decodeDartDefines(<String, String>{
|
2021-02-02 17:10:48 +00:00
|
|
|
kDartDefines: 'aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbQ=='
|
2020-06-04 04:02:07 +00:00
|
|
|
}, kDartDefines), <String>['https://www.google.com']);
|
2020-05-27 17:11:04 +00:00
|
|
|
expect(decodeDartDefines(<String, String>{
|
2021-02-02 17:10:48 +00:00
|
|
|
kDartDefines: 'MiwzLDQ=,NQ=='
|
2020-06-04 04:02:07 +00:00
|
|
|
}, kDartDefines), <String>['2,3,4', '5']);
|
2020-05-27 17:11:04 +00:00
|
|
|
expect(decodeDartDefines(<String, String>{
|
2021-02-02 17:10:48 +00:00
|
|
|
kDartDefines: 'dHJ1ZQ==,ZmFsc2U=,Zmxhc2U='
|
2020-06-04 04:02:07 +00:00
|
|
|
}, kDartDefines), <String>['true', 'false', 'flase']);
|
2020-05-27 17:11:04 +00:00
|
|
|
expect(decodeDartDefines(<String, String>{
|
2021-02-02 17:10:48 +00:00
|
|
|
kDartDefines: 'MTIzMiw0NTY=,Mg=='
|
2020-06-04 04:02:07 +00:00
|
|
|
}, kDartDefines), <String>['1232,456', '2']);
|
2020-05-27 17:11:04 +00:00
|
|
|
});
|
2019-02-13 15:48:03 +00:00
|
|
|
}
|