Skip to content

Commit

Permalink
Correctly propagate verbosity to subtasks in flutter.gradle (#117897)
Browse files Browse the repository at this point in the history
* Correctly propagate verbosity to subtasks in flutter.gradle

* Add test

* Revert accidental changes

* Fix copyright year

* Fix imports
  • Loading branch information
mraleph committed Jan 4, 2023
1 parent c53501d commit 025ce11
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 15 deletions.
27 changes: 12 additions & 15 deletions packages/flutter_tools/gradle/flutter.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -618,29 +618,20 @@ class FlutterPlugin implements Plugin<Project> {
}

private Boolean shouldSplitPerAbi() {
if (project.hasProperty('split-per-abi')) {
return project.property('split-per-abi').toBoolean()
}
return false;
return project.findProperty('split-per-abi')?.toBoolean() ?: false;
}

private Boolean useLocalEngine() {
return project.hasProperty('local-engine-repo')
}

private Boolean isVerbose() {
if (project.hasProperty('verbose')) {
return project.property('verbose').toBoolean()
}
return false
return project.findProperty('verbose')?.toBoolean() ?: false;
}

/** Whether to build the debug app in "fast-start" mode. */
private Boolean isFastStart() {
if (project.hasProperty("fast-start")) {
return project.property("fast-start").toBoolean()
}
return false
return project.findProperty("fast-start")?.toBoolean() ?: false;
}

private static Boolean isBuiltAsApp(Project project) {
Expand Down Expand Up @@ -877,15 +868,21 @@ class FlutterPlugin implements Plugin<Project> {
}
String variantBuildMode = buildModeFor(variant.buildType)
String taskName = toCamelCase(["compile", FLUTTER_BUILD_PREFIX, variant.name])
// Be careful when configuring task below, Groovy has bizarre
// scoping rules: writing `verbose isVerbose()` means calling
// `isVerbose` on the task itself - which would return `verbose`
// original value. You either need to hoist the value
// into a separate variable `verbose verboseValue` or prefix with
// `this` (`verbose this.isVerbose()`).
FlutterTask compileTask = project.tasks.create(name: taskName, type: FlutterTask) {
flutterRoot this.flutterRoot
flutterExecutable this.flutterExecutable
buildMode variantBuildMode
localEngine this.localEngine
localEngineSrcPath this.localEngineSrcPath
targetPath getFlutterTarget()
verbose isVerbose()
fastStart isFastStart()
verbose this.isVerbose()
fastStart this.isFastStart()
fileSystemRoots fileSystemRootsValue
fileSystemScheme fileSystemSchemeValue
trackWidgetCreation trackWidgetCreationValue
Expand Down Expand Up @@ -1089,7 +1086,7 @@ abstract class BaseFlutterTask extends DefaultTask {
Boolean fastStart
@Input
String targetPath
@Optional @Internal
@Optional @Input
Boolean verbose
@Optional @Input
String[] fileSystemRoots
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2014 The Flutter Authors. 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:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';

import '../src/common.dart';
import 'test_utils.dart';

// Test that verbosity it propagated to Gradle tasks correctly.
void main() {
late Directory tempDir;
late String flutterBin;
late Directory exampleAppDir;

setUp(() async {
tempDir = createResolvedTempDirectorySync('flutter_build_test.');
flutterBin = fileSystem.path.join(
getFlutterRoot(),
'bin',
'flutter',
);
exampleAppDir = tempDir.childDirectory('aaa').childDirectory('example');

processManager.runSync(<String>[
flutterBin,
...getLocalEngineArguments(),
'create',
'--template=plugin',
'--platforms=android',
'aaa',
], workingDirectory: tempDir.path);
});

tearDown(() async {
tryToDelete(tempDir);
});

test(
'flutter build apk -v output should contain gen_snapshot command',
() async {
final ProcessResult result = processManager.runSync(<String>[
flutterBin,
...getLocalEngineArguments(),
'build',
'apk',
'--target-platform=android-arm',
'-v',
], workingDirectory: exampleAppDir.path);
expect(
result.stdout, contains(RegExp(r'executing:\s+\S+gen_snapshot\s+')));
},
);
}

0 comments on commit 025ce11

Please sign in to comment.