Unverified Commit 3c80cc7e authored by Reid Baker's avatar Reid Baker Committed by GitHub

Do not use project in do last (#139325)

- Use copy task that branches for 8.3 and above to avoid using project.exec in a dolast block. 

part 1/n for flutter/flutter/issues/138523 

This PR does not test the 8.3 branch but instead builds the ability to write a branching gradle test. 
After fixing this project.exec action there I discovered a second that needs to be removed or migrated in order for the build to work. 

Related reading https://docs.gradle.org/8.0/userguide/configuration_cache.html#config_cache:requirements
https://docs.gradle.org/current/javadoc/org/gradle/process/ExecOperations.html (not used but considered) 
https://docs.gradle.org/8.2/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:fileMode
parent 8791b0ea
......@@ -14,15 +14,37 @@ import 'package:flutter_devicelab/framework/utils.dart';
import 'package:path/path.dart' as path;
final String gradlew = Platform.isWindows ? 'gradlew.bat' : 'gradlew';
final String gradlewExecutable = Platform.isWindows ? '.\\$gradlew' : './$gradlew';
final String gradlewExecutable =
Platform.isWindows ? '.\\$gradlew' : './$gradlew';
final String fileReadWriteMode = Platform.isWindows ? 'rw-rw-rw-' : 'rw-r--r--';
final String platformLineSep = Platform.isWindows ? '\r\n': '\n';
final String platformLineSep = Platform.isWindows ? '\r\n' : '\n';
/// Combines several TaskFunctions with trivial success value into one.
TaskFunction combine(List<TaskFunction> tasks) {
return () async {
for (final TaskFunction task in tasks) {
final TaskResult result = await task();
if (result.failed) {
return result;
}
}
return TaskResult.success(null);
};
}
/// Tests that the Flutter module project template works and supports
/// adding Flutter to an existing Android app.
Future<void> main() async {
await task(() async {
class ModuleTest {
ModuleTest(
this.buildTarget, {
this.gradleVersion = '7.6.3',
});
final String buildTarget;
final String gradleVersion;
Future<TaskResult> call() async {
section('Running: $buildTarget');
section('Find Java');
final String? javaHome = await findJavaHome();
......@@ -253,11 +275,25 @@ exitCode: $exitCode
hostApp,
);
copy(
File(path.join(projectDir.path, '.android', 'gradle', 'wrapper', 'gradle-wrapper.jar')),
File(path.join(projectDir.path, '.android', 'gradle', 'wrapper',
'gradle-wrapper.jar')),
Directory(path.join(hostApp.path, 'gradle', 'wrapper')),
);
final File analyticsOutputFile = File(path.join(tempDir.path, 'analytics.log'));
// Modify gradle version to passed in version.
// This is somehow the wrong file.
final File gradleWrapperProperties = File(path.join(
hostApp.path, 'gradle', 'wrapper', 'gradle-wrapper.properties'));
String propertyContent = await gradleWrapperProperties.readAsString();
propertyContent = propertyContent.replaceFirst(
'REPLACEME',
gradleVersion,
);
section(propertyContent);
await gradleWrapperProperties.writeAsString(propertyContent, flush: true);
final File analyticsOutputFile =
File(path.join(tempDir.path, 'analytics.log'));
section('Build debug host APK');
......@@ -442,5 +478,12 @@ exitCode: $exitCode
} finally {
rmTree(tempDir);
}
});
}
}
Future<void> main() async {
await task(combine(<TaskFunction>[
// ignore: avoid_redundant_argument_values
ModuleTest('module-gradle-7.6', gradleVersion: '7.6.3').call,
]));
}
......@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-REPLACEME-all.zip
......@@ -1094,15 +1094,6 @@ class FlutterPlugin implements Plugin<Project> {
deferredComponents deferredComponentsValue
validateDeferredComponents validateDeferredComponentsValue
isAndroidLibrary isAndroidLibraryValue
doLast {
project.exec {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine('cmd', '/c', "attrib -r ${assetsDirectory}/* /s")
} else {
commandLine('chmod', '-R', 'u+w', assetsDirectory)
}
}
}
}
File libJar = project.file("${project.buildDir}/$INTERMEDIATES_DIR/flutter/${variant.name}/libs.jar")
Task packFlutterAppAotTask = project.tasks.create(name: "packLibs${FLUTTER_BUILD_PREFIX}${variant.name.capitalize()}", type: Jar) {
......@@ -1129,6 +1120,22 @@ class FlutterPlugin implements Plugin<Project> {
) {
dependsOn compileTask
with compileTask.assets
def currentGradleVersion = project.getGradle().getGradleVersion()
// See https://docs.gradle.org/current/javadoc/org/gradle/api/file/ConfigurableFilePermissions.html
// See https://github.com/flutter/flutter/pull/50047
if (compareVersionStrings(currentGradleVersion, '8.3') >= 0 ) {
filePermissions {
user {
read = true
write = true
}
}
} else {
// See https://docs.gradle.org/8.2/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:fileMode
// See https://github.com/flutter/flutter/pull/50047
fileMode 0644
}
if (isUsedAsSubproject) {
dependsOn packageAssets
dependsOn cleanPackageAssets
......@@ -1272,6 +1279,28 @@ class FlutterPlugin implements Plugin<Project> {
configurePlugins()
detectLowCompileSdkVersionOrNdkVersion()
}
// compareTo implementation of version strings in the format of ints and periods
// Requires non null objects.
static int compareVersionStrings(String firstString, String secondString) {
List firstVersion = firstString.tokenize('.')
List secondVersion = secondString.tokenize('.')
def commonIndices = Math.min(firstVersion.size(), secondVersion.size())
for (int i = 0; i < commonIndices; i++) {
def firstAtIndex = firstVersion[i].toInteger()
def secondAtIndex = secondVersion[i].toInteger()
if (firstAtIndex != secondAtIndex) {
// <=> in groovy delegates to compareTo
return firstAtIndex <=> secondAtIndex
}
}
// If we got this far then all the common indices are identical, so whichever version is longer must be more recent
return firstVersion.size() <=> secondVersion.size()
}
}
class AppLinkSettings {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment