[flutter_tools] disable source maps by default for release builds, enable for run and with command line arg (#67331)
Disables source map production by default for build web. For web builds performed as a part of flutter run --release, enable the source maps, or allow force enabling with --source-maps command line flag. fixes #67328
This commit is contained in:
parent
3a00c4e73c
commit
aa90dbe7f4
@ -39,6 +39,9 @@ const String kCspMode = 'cspMode';
|
|||||||
/// The caching strategy to use for service worker generation.
|
/// The caching strategy to use for service worker generation.
|
||||||
const String kServiceWorkerStrategy = 'ServiceWorkerStratgey';
|
const String kServiceWorkerStrategy = 'ServiceWorkerStratgey';
|
||||||
|
|
||||||
|
/// Whether the dart2js build should output source maps.
|
||||||
|
const String kSourceMapsEnabled = 'SourceMaps';
|
||||||
|
|
||||||
/// The caching strategy for the generated service worker.
|
/// The caching strategy for the generated service worker.
|
||||||
enum ServiceWorkerStrategy {
|
enum ServiceWorkerStrategy {
|
||||||
/// Download the app shell eagerly and all other assets lazily.
|
/// Download the app shell eagerly and all other assets lazily.
|
||||||
@ -194,6 +197,7 @@ class Dart2JSTarget extends Target {
|
|||||||
@override
|
@override
|
||||||
Future<void> build(Environment environment) async {
|
Future<void> build(Environment environment) async {
|
||||||
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
|
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
|
||||||
|
final bool sourceMapsEnabled = environment.defines[kSourceMapsEnabled] == 'true';
|
||||||
|
|
||||||
final List<String> sharedCommandOptions = <String>[
|
final List<String> sharedCommandOptions = <String>[
|
||||||
globals.artifacts.getArtifactPath(Artifact.engineDartBinary),
|
globals.artifacts.getArtifactPath(Artifact.engineDartBinary),
|
||||||
@ -207,6 +211,8 @@ class Dart2JSTarget extends Target {
|
|||||||
'-Ddart.vm.product=true',
|
'-Ddart.vm.product=true',
|
||||||
for (final String dartDefine in decodeDartDefines(environment.defines, kDartDefines))
|
for (final String dartDefine in decodeDartDefines(environment.defines, kDartDefines))
|
||||||
'-D$dartDefine',
|
'-D$dartDefine',
|
||||||
|
if (!sourceMapsEnabled)
|
||||||
|
'--no-source-maps',
|
||||||
];
|
];
|
||||||
|
|
||||||
// Run the dart2js compilation in two stages, so that icon tree shaking can
|
// Run the dart2js compilation in two stages, so that icon tree shaking can
|
||||||
@ -227,7 +233,7 @@ class Dart2JSTarget extends Target {
|
|||||||
final File outputJSFile = environment.buildDir.childFile('main.dart.js');
|
final File outputJSFile = environment.buildDir.childFile('main.dart.js');
|
||||||
final bool csp = environment.defines[kCspMode] == 'true';
|
final bool csp = environment.defines[kCspMode] == 'true';
|
||||||
|
|
||||||
final ProcessResult javaScriptResult = await globals.processManager.run(<String>[
|
final ProcessResult javaScriptResult = await environment.processManager.run(<String>[
|
||||||
...sharedCommandOptions,
|
...sharedCommandOptions,
|
||||||
if (dart2jsOptimization != null) '-$dart2jsOptimization' else '-O4',
|
if (dart2jsOptimization != null) '-$dart2jsOptimization' else '-O4',
|
||||||
if (buildMode == BuildMode.profile) '--no-minify',
|
if (buildMode == BuildMode.profile) '--no-minify',
|
||||||
|
@ -37,6 +37,13 @@ class BuildWebCommand extends BuildSubCommand {
|
|||||||
help: 'Disable dynamic generation of code in the generated output. '
|
help: 'Disable dynamic generation of code in the generated output. '
|
||||||
'This is necessary to satisfy CSP restrictions (see http://www.w3.org/TR/CSP/).'
|
'This is necessary to satisfy CSP restrictions (see http://www.w3.org/TR/CSP/).'
|
||||||
);
|
);
|
||||||
|
argParser.addFlag(
|
||||||
|
'source-maps',
|
||||||
|
defaultsTo: false,
|
||||||
|
help: 'Whether to generate a sourcemap file. These can be used by browsers '
|
||||||
|
'To view and debug the original source code of a compiled and minified Dart '
|
||||||
|
'application. Defaults to false (no sourcemaps produced).'
|
||||||
|
);
|
||||||
argParser.addOption('pwa-strategy',
|
argParser.addOption('pwa-strategy',
|
||||||
defaultsTo: kOfflineFirst,
|
defaultsTo: kOfflineFirst,
|
||||||
help:
|
help:
|
||||||
@ -88,6 +95,7 @@ class BuildWebCommand extends BuildSubCommand {
|
|||||||
boolArg('web-initialize-platform'),
|
boolArg('web-initialize-platform'),
|
||||||
boolArg('csp'),
|
boolArg('csp'),
|
||||||
stringArg('pwa-strategy'),
|
stringArg('pwa-strategy'),
|
||||||
|
boolArg('source-maps')
|
||||||
);
|
);
|
||||||
return FlutterCommandResult.success();
|
return FlutterCommandResult.success();
|
||||||
}
|
}
|
||||||
|
@ -531,6 +531,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
|
|||||||
debuggingOptions.initializePlatform,
|
debuggingOptions.initializePlatform,
|
||||||
false,
|
false,
|
||||||
kNoneWorker,
|
kNoneWorker,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await device.device.startApp(
|
await device.device.startApp(
|
||||||
@ -601,6 +602,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
|
|||||||
debuggingOptions.initializePlatform,
|
debuggingOptions.initializePlatform,
|
||||||
false,
|
false,
|
||||||
kNoneWorker,
|
kNoneWorker,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
} on ToolExit {
|
} on ToolExit {
|
||||||
return OperationResult(1, 'Failed to recompile application.');
|
return OperationResult(1, 'Failed to recompile application.');
|
||||||
|
@ -29,19 +29,25 @@ Future<void> buildWeb(
|
|||||||
bool initializePlatform,
|
bool initializePlatform,
|
||||||
bool csp,
|
bool csp,
|
||||||
String serviceWorkerStrategy,
|
String serviceWorkerStrategy,
|
||||||
|
bool sourceMaps,
|
||||||
) async {
|
) async {
|
||||||
if (!flutterProject.web.existsSync()) {
|
if (!flutterProject.web.existsSync()) {
|
||||||
throwToolExit('Missing index.html.');
|
throwToolExit('Missing index.html.');
|
||||||
}
|
}
|
||||||
final bool hasWebPlugins = (await findPlugins(flutterProject))
|
final bool hasWebPlugins = (await findPlugins(flutterProject))
|
||||||
.any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey));
|
.any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey));
|
||||||
|
final Directory outputDirectory = globals.fs.directory(getWebBuildDirectory());
|
||||||
|
if (outputDirectory.existsSync()) {
|
||||||
|
outputDirectory.deleteSync(recursive: true);
|
||||||
|
outputDirectory.createSync(recursive: true);
|
||||||
|
}
|
||||||
await injectPlugins(flutterProject, checkProjects: true);
|
await injectPlugins(flutterProject, checkProjects: true);
|
||||||
final Status status = globals.logger.startProgress('Compiling $target for the Web...', timeout: null);
|
final Status status = globals.logger.startProgress('Compiling $target for the Web...', timeout: null);
|
||||||
final Stopwatch sw = Stopwatch()..start();
|
final Stopwatch sw = Stopwatch()..start();
|
||||||
try {
|
try {
|
||||||
final BuildResult result = await globals.buildSystem.build(const WebServiceWorker(), Environment(
|
final BuildResult result = await globals.buildSystem.build(const WebServiceWorker(), Environment(
|
||||||
projectDir: globals.fs.currentDirectory,
|
projectDir: globals.fs.currentDirectory,
|
||||||
outputDir: globals.fs.directory(getWebBuildDirectory()),
|
outputDir: outputDirectory,
|
||||||
buildDir: flutterProject.directory
|
buildDir: flutterProject.directory
|
||||||
.childDirectory('.dart_tool')
|
.childDirectory('.dart_tool')
|
||||||
.childDirectory('flutter_build'),
|
.childDirectory('flutter_build'),
|
||||||
@ -53,6 +59,7 @@ Future<void> buildWeb(
|
|||||||
kDartDefines: encodeDartDefines(buildInfo.dartDefines),
|
kDartDefines: encodeDartDefines(buildInfo.dartDefines),
|
||||||
kCspMode: csp.toString(),
|
kCspMode: csp.toString(),
|
||||||
kIconTreeShakerFlag: buildInfo.treeShakeIcons.toString(),
|
kIconTreeShakerFlag: buildInfo.treeShakeIcons.toString(),
|
||||||
|
kSourceMapsEnabled: sourceMaps.toString(),
|
||||||
if (serviceWorkerStrategy != null)
|
if (serviceWorkerStrategy != null)
|
||||||
kServiceWorkerStrategy: serviceWorkerStrategy,
|
kServiceWorkerStrategy: serviceWorkerStrategy,
|
||||||
if (buildInfo.extraFrontEndOptions?.isNotEmpty ?? false)
|
if (buildInfo.extraFrontEndOptions?.isNotEmpty ?? false)
|
||||||
|
@ -57,6 +57,7 @@ void main() {
|
|||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
|
true,
|
||||||
), throwsToolExit());
|
), throwsToolExit());
|
||||||
}, overrides: <Type, Generator>{
|
}, overrides: <Type, Generator>{
|
||||||
Platform: () => fakePlatform,
|
Platform: () => fakePlatform,
|
||||||
|
@ -305,6 +305,7 @@ void main() {
|
|||||||
command: <String>[
|
command: <String>[
|
||||||
...kDart2jsLinuxArgs,
|
...kDart2jsLinuxArgs,
|
||||||
'-Ddart.vm.profile=true',
|
'-Ddart.vm.profile=true',
|
||||||
|
'--no-source-maps',
|
||||||
'-o',
|
'-o',
|
||||||
environment.buildDir.childFile('app.dill').absolute.path,
|
environment.buildDir.childFile('app.dill').absolute.path,
|
||||||
'--packages=.packages',
|
'--packages=.packages',
|
||||||
@ -316,6 +317,7 @@ void main() {
|
|||||||
command: <String>[
|
command: <String>[
|
||||||
...kDart2jsLinuxArgs,
|
...kDart2jsLinuxArgs,
|
||||||
'-Ddart.vm.profile=true',
|
'-Ddart.vm.profile=true',
|
||||||
|
'--no-source-maps',
|
||||||
'-O4',
|
'-O4',
|
||||||
'--no-minify',
|
'--no-minify',
|
||||||
'--csp',
|
'--csp',
|
||||||
@ -339,6 +341,7 @@ void main() {
|
|||||||
...kDart2jsLinuxArgs,
|
...kDart2jsLinuxArgs,
|
||||||
'--enable-experiment=non-nullable',
|
'--enable-experiment=non-nullable',
|
||||||
'-Ddart.vm.profile=true',
|
'-Ddart.vm.profile=true',
|
||||||
|
'--no-source-maps',
|
||||||
'-o',
|
'-o',
|
||||||
environment.buildDir.childFile('app.dill').absolute.path,
|
environment.buildDir.childFile('app.dill').absolute.path,
|
||||||
'--packages=.packages',
|
'--packages=.packages',
|
||||||
@ -351,6 +354,7 @@ void main() {
|
|||||||
...kDart2jsLinuxArgs,
|
...kDart2jsLinuxArgs,
|
||||||
'--enable-experiment=non-nullable',
|
'--enable-experiment=non-nullable',
|
||||||
'-Ddart.vm.profile=true',
|
'-Ddart.vm.profile=true',
|
||||||
|
'--no-source-maps',
|
||||||
'-O4',
|
'-O4',
|
||||||
'--no-minify',
|
'--no-minify',
|
||||||
'-o',
|
'-o',
|
||||||
@ -370,6 +374,7 @@ void main() {
|
|||||||
command: <String>[
|
command: <String>[
|
||||||
...kDart2jsLinuxArgs,
|
...kDart2jsLinuxArgs,
|
||||||
'-Ddart.vm.profile=true',
|
'-Ddart.vm.profile=true',
|
||||||
|
'--no-source-maps',
|
||||||
'-o',
|
'-o',
|
||||||
environment.buildDir.childFile('app.dill').absolute.path,
|
environment.buildDir.childFile('app.dill').absolute.path,
|
||||||
'--packages=.packages',
|
'--packages=.packages',
|
||||||
@ -381,6 +386,7 @@ void main() {
|
|||||||
command: <String>[
|
command: <String>[
|
||||||
...kDart2jsLinuxArgs,
|
...kDart2jsLinuxArgs,
|
||||||
'-Ddart.vm.profile=true',
|
'-Ddart.vm.profile=true',
|
||||||
|
'--no-source-maps',
|
||||||
'-O4',
|
'-O4',
|
||||||
'--no-minify',
|
'--no-minify',
|
||||||
'-o',
|
'-o',
|
||||||
@ -400,6 +406,7 @@ void main() {
|
|||||||
command: <String>[
|
command: <String>[
|
||||||
...kDart2jsLinuxArgs,
|
...kDart2jsLinuxArgs,
|
||||||
'-Ddart.vm.product=true',
|
'-Ddart.vm.product=true',
|
||||||
|
'--no-source-maps',
|
||||||
'-o',
|
'-o',
|
||||||
environment.buildDir.childFile('app.dill').absolute.path,
|
environment.buildDir.childFile('app.dill').absolute.path,
|
||||||
'--packages=.packages',
|
'--packages=.packages',
|
||||||
@ -411,6 +418,7 @@ void main() {
|
|||||||
command: <String>[
|
command: <String>[
|
||||||
...kDart2jsLinuxArgs,
|
...kDart2jsLinuxArgs,
|
||||||
'-Ddart.vm.product=true',
|
'-Ddart.vm.product=true',
|
||||||
|
'--no-source-maps',
|
||||||
'-O4',
|
'-O4',
|
||||||
'-o',
|
'-o',
|
||||||
environment.buildDir.childFile('main.dart.js').absolute.path,
|
environment.buildDir.childFile('main.dart.js').absolute.path,
|
||||||
@ -430,6 +438,7 @@ void main() {
|
|||||||
command: <String>[
|
command: <String>[
|
||||||
...kDart2jsLinuxArgs,
|
...kDart2jsLinuxArgs,
|
||||||
'-Ddart.vm.product=true',
|
'-Ddart.vm.product=true',
|
||||||
|
'--no-source-maps',
|
||||||
'-o',
|
'-o',
|
||||||
environment.buildDir.childFile('app.dill').absolute.path,
|
environment.buildDir.childFile('app.dill').absolute.path,
|
||||||
'--packages=.packages',
|
'--packages=.packages',
|
||||||
@ -441,6 +450,7 @@ void main() {
|
|||||||
command: <String>[
|
command: <String>[
|
||||||
...kDart2jsLinuxArgs,
|
...kDart2jsLinuxArgs,
|
||||||
'-Ddart.vm.product=true',
|
'-Ddart.vm.product=true',
|
||||||
|
'--no-source-maps',
|
||||||
'-O3',
|
'-O3',
|
||||||
'-o',
|
'-o',
|
||||||
environment.buildDir.childFile('main.dart.js').absolute.path,
|
environment.buildDir.childFile('main.dart.js').absolute.path,
|
||||||
@ -481,6 +491,7 @@ void main() {
|
|||||||
'-Ddart.vm.product=true',
|
'-Ddart.vm.product=true',
|
||||||
'-DFOO=bar',
|
'-DFOO=bar',
|
||||||
'-DBAZ=qux',
|
'-DBAZ=qux',
|
||||||
|
'--no-source-maps',
|
||||||
'-o',
|
'-o',
|
||||||
environment.buildDir.childFile('app.dill').absolute.path,
|
environment.buildDir.childFile('app.dill').absolute.path,
|
||||||
'--packages=.packages',
|
'--packages=.packages',
|
||||||
@ -494,6 +505,7 @@ void main() {
|
|||||||
'-Ddart.vm.product=true',
|
'-Ddart.vm.product=true',
|
||||||
'-DFOO=bar',
|
'-DFOO=bar',
|
||||||
'-DBAZ=qux',
|
'-DBAZ=qux',
|
||||||
|
'--no-source-maps',
|
||||||
'-O4',
|
'-O4',
|
||||||
'-o',
|
'-o',
|
||||||
environment.buildDir.childFile('main.dart.js').absolute.path,
|
environment.buildDir.childFile('main.dart.js').absolute.path,
|
||||||
@ -506,6 +518,37 @@ void main() {
|
|||||||
ProcessManager: () => processManager,
|
ProcessManager: () => processManager,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
test('Dart2JSTarget can enable source maps', () => testbed.run(() async {
|
||||||
|
environment.defines[kBuildMode] = 'release';
|
||||||
|
environment.defines[kSourceMapsEnabled] = 'true';
|
||||||
|
processManager.addCommand(FakeCommand(
|
||||||
|
command: <String>[
|
||||||
|
...kDart2jsLinuxArgs,
|
||||||
|
'-Ddart.vm.product=true',
|
||||||
|
'-o',
|
||||||
|
environment.buildDir.childFile('app.dill').absolute.path,
|
||||||
|
'--packages=.packages',
|
||||||
|
'--cfe-only',
|
||||||
|
environment.buildDir.childFile('main.dart').absolute.path,
|
||||||
|
]
|
||||||
|
));
|
||||||
|
processManager.addCommand(FakeCommand(
|
||||||
|
command: <String>[
|
||||||
|
...kDart2jsLinuxArgs,
|
||||||
|
'-Ddart.vm.product=true',
|
||||||
|
'-O4',
|
||||||
|
'-o',
|
||||||
|
environment.buildDir.childFile('main.dart.js').absolute.path,
|
||||||
|
environment.buildDir.childFile('app.dill').absolute.path,
|
||||||
|
]
|
||||||
|
));
|
||||||
|
|
||||||
|
await const Dart2JSTarget().build(environment);
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
ProcessManager: () => processManager,
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
test('Dart2JSTarget calls dart2js with Dart defines in profile mode', () => testbed.run(() async {
|
test('Dart2JSTarget calls dart2js with Dart defines in profile mode', () => testbed.run(() async {
|
||||||
environment.defines[kBuildMode] = 'profile';
|
environment.defines[kBuildMode] = 'profile';
|
||||||
environment.defines[kDartDefines] = 'FOO=bar,BAZ=qux';
|
environment.defines[kDartDefines] = 'FOO=bar,BAZ=qux';
|
||||||
@ -515,6 +558,7 @@ void main() {
|
|||||||
'-Ddart.vm.profile=true',
|
'-Ddart.vm.profile=true',
|
||||||
'-DFOO=bar',
|
'-DFOO=bar',
|
||||||
'-DBAZ=qux',
|
'-DBAZ=qux',
|
||||||
|
'--no-source-maps',
|
||||||
'-o',
|
'-o',
|
||||||
environment.buildDir.childFile('app.dill').absolute.path,
|
environment.buildDir.childFile('app.dill').absolute.path,
|
||||||
'--packages=.packages',
|
'--packages=.packages',
|
||||||
@ -528,6 +572,7 @@ void main() {
|
|||||||
'-Ddart.vm.profile=true',
|
'-Ddart.vm.profile=true',
|
||||||
'-DFOO=bar',
|
'-DFOO=bar',
|
||||||
'-DBAZ=qux',
|
'-DBAZ=qux',
|
||||||
|
'--no-source-maps',
|
||||||
'-O4',
|
'-O4',
|
||||||
'--no-minify',
|
'--no-minify',
|
||||||
'-o',
|
'-o',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user