Skip to content

Commit 77abfdc

Browse files
mralephloic-sharma
authored andcommitted
Correctly propagate verbosity to subtasks in flutter.gradle (flutter#117897)
* Correctly propagate verbosity to subtasks in flutter.gradle * Add test * Revert accidental changes * Fix copyright year * Fix imports
1 parent eb09e0f commit 77abfdc

File tree

2 files changed

+67
-15
lines changed

2 files changed

+67
-15
lines changed

packages/flutter_tools/gradle/flutter.gradle

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -618,29 +618,20 @@ class FlutterPlugin implements Plugin<Project> {
618618
}
619619

620620
private Boolean shouldSplitPerAbi() {
621-
if (project.hasProperty('split-per-abi')) {
622-
return project.property('split-per-abi').toBoolean()
623-
}
624-
return false;
621+
return project.findProperty('split-per-abi')?.toBoolean() ?: false;
625622
}
626623

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

631628
private Boolean isVerbose() {
632-
if (project.hasProperty('verbose')) {
633-
return project.property('verbose').toBoolean()
634-
}
635-
return false
629+
return project.findProperty('verbose')?.toBoolean() ?: false;
636630
}
637631

638632
/** Whether to build the debug app in "fast-start" mode. */
639633
private Boolean isFastStart() {
640-
if (project.hasProperty("fast-start")) {
641-
return project.property("fast-start").toBoolean()
642-
}
643-
return false
634+
return project.findProperty("fast-start")?.toBoolean() ?: false;
644635
}
645636

646637
private static Boolean isBuiltAsApp(Project project) {
@@ -877,15 +868,21 @@ class FlutterPlugin implements Plugin<Project> {
877868
}
878869
String variantBuildMode = buildModeFor(variant.buildType)
879870
String taskName = toCamelCase(["compile", FLUTTER_BUILD_PREFIX, variant.name])
871+
// Be careful when configuring task below, Groovy has bizarre
872+
// scoping rules: writing `verbose isVerbose()` means calling
873+
// `isVerbose` on the task itself - which would return `verbose`
874+
// original value. You either need to hoist the value
875+
// into a separate variable `verbose verboseValue` or prefix with
876+
// `this` (`verbose this.isVerbose()`).
880877
FlutterTask compileTask = project.tasks.create(name: taskName, type: FlutterTask) {
881878
flutterRoot this.flutterRoot
882879
flutterExecutable this.flutterExecutable
883880
buildMode variantBuildMode
884881
localEngine this.localEngine
885882
localEngineSrcPath this.localEngineSrcPath
886883
targetPath getFlutterTarget()
887-
verbose isVerbose()
888-
fastStart isFastStart()
884+
verbose this.isVerbose()
885+
fastStart this.isFastStart()
889886
fileSystemRoots fileSystemRootsValue
890887
fileSystemScheme fileSystemSchemeValue
891888
trackWidgetCreation trackWidgetCreationValue
@@ -1089,7 +1086,7 @@ abstract class BaseFlutterTask extends DefaultTask {
10891086
Boolean fastStart
10901087
@Input
10911088
String targetPath
1092-
@Optional @Internal
1089+
@Optional @Input
10931090
Boolean verbose
10941091
@Optional @Input
10951092
String[] fileSystemRoots
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_tools/src/base/file_system.dart';
6+
import 'package:flutter_tools/src/base/io.dart';
7+
8+
import '../src/common.dart';
9+
import 'test_utils.dart';
10+
11+
// Test that verbosity it propagated to Gradle tasks correctly.
12+
void main() {
13+
late Directory tempDir;
14+
late String flutterBin;
15+
late Directory exampleAppDir;
16+
17+
setUp(() async {
18+
tempDir = createResolvedTempDirectorySync('flutter_build_test.');
19+
flutterBin = fileSystem.path.join(
20+
getFlutterRoot(),
21+
'bin',
22+
'flutter',
23+
);
24+
exampleAppDir = tempDir.childDirectory('aaa').childDirectory('example');
25+
26+
processManager.runSync(<String>[
27+
flutterBin,
28+
...getLocalEngineArguments(),
29+
'create',
30+
'--template=plugin',
31+
'--platforms=android',
32+
'aaa',
33+
], workingDirectory: tempDir.path);
34+
});
35+
36+
tearDown(() async {
37+
tryToDelete(tempDir);
38+
});
39+
40+
test(
41+
'flutter build apk -v output should contain gen_snapshot command',
42+
() async {
43+
final ProcessResult result = processManager.runSync(<String>[
44+
flutterBin,
45+
...getLocalEngineArguments(),
46+
'build',
47+
'apk',
48+
'--target-platform=android-arm',
49+
'-v',
50+
], workingDirectory: exampleAppDir.path);
51+
expect(
52+
result.stdout, contains(RegExp(r'executing:\s+\S+gen_snapshot\s+')));
53+
},
54+
);
55+
}

0 commit comments

Comments
 (0)