Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flutter_tools] Remove globals/mocks from GradleUtils #76020

Merged
merged 5 commits into from
Feb 17, 2021

Conversation

jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented Feb 14, 2021

Refactor GradleUtils into a mostly global free class.

  • Remove gradle environment, and instead make gradle pass the JAVA_PATH (I'm not sure if we actually need to do this, still investigating).
  • make copyDirectory a stand alone apart from FileSystemUtils, since it is stateless and has no dependencies. This allows tests to avoid injects/mocking this class, it only requires a memory file system.
  • make FileSystemUtils.copyDirectorySync delegate to copyDirectory, to avoid a large diff/breaking change
  • Do not conditionally set execute bit on gradle, instead just always set it. Doesn't seem to be any harm, and simplifies the code.

Remove tests that tested a mock of GradleUtils against itself.


@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Feb 14, 2021
@google-cla google-cla bot added the cla: yes label Feb 14, 2021
/// Gets the Gradle executable path and prepares the Gradle project.
/// This is the `gradlew` or `gradlew.bat` script in the `android/` directory.
String getExecutable(FlutterProject project) {
final Directory androidDir = project.android.hostAppGradleRoot;
gradleUtils.injectGradleWrapperIfNeeded(androidDir);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is sus. Basically, what this did is re-grabbed the global GradleUtils - the tests used this to test getExecutable against a mocked out injectgradleWrapperIfNeeded. I removed this functionality

@jonahwilliams jonahwilliams changed the title [flutter_tools] reduce scope of gradle utils [flutter_tools] Remove globals/mocks from GradleUtils Feb 16, 2021
@jonahwilliams jonahwilliams marked this pull request as ready for review February 16, 2021 21:59
}
// Don't log analytics for downstream Flutter commands.
// e.g. `flutter build bundle`.
environment['FLUTTER_SUPPRESS_ANALYTICS'] = 'true';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't care about this anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we specifically don't want it actually - this is a holdover from each build requiring N flutter commands

Comment on lines -123 to -148
const int _kExecPermissionMask = 0x49; // a+x

/// Returns [true] if [executable] has all executable flag set.
bool _hasAllExecutableFlagSet(File executable) {
final FileStat stat = executable.statSync();
assert(stat.type != FileSystemEntityType.notFound);
globals.printTrace('${executable.path} mode: ${stat.mode} ${stat.modeString()}.');
return stat.mode & _kExecPermissionMask == _kExecPermissionMask;
}

/// Returns [true] if [executable] has any executable flag set.
bool _hasAnyExecutableFlagSet(File executable) {
final FileStat stat = executable.statSync();
assert(stat.type != FileSystemEntityType.notFound);
globals.printTrace('${executable.path} mode: ${stat.mode} ${stat.modeString()}.');
return stat.mode & _kExecPermissionMask != 0;
}

/// Gives execute permission to [executable] if it doesn't have it already.
void _giveExecutePermissionIfNeeded(File executable) {
if (!_hasAllExecutableFlagSet(executable)) {
globals.printTrace('Trying to give execute permission to ${executable.path}.');
globals.os.makeExecutable(executable);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context at #46748. \cc @blasten

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also set the executable bit in create.dart, but that has a separate method for doing so. I can handle that cleanup in a separate PR

@@ -65,34 +65,12 @@ class FileSystemUtils {
bool shouldCopyFile(File srcFile, File destFile),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make FileSystemUtils.copyDirectorySync delegate to copyDirectory, to avoid a large diff/breaking change

I don't mind reviewing large diffs to migrate existing FileSystemUtils.copyDirectorySync usages to just copyDirectory. What breaking changes are you concerned about (ono is this used in g3?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, just mostly dreading fixing the tests that mock it, but there weren't too many.

@jonahwilliams
Copy link
Member Author

All usage of createDirectorySync removed

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jonahwilliams
Copy link
Member Author

Build is green - landing.

@jonahwilliams jonahwilliams merged commit 93e7d34 into flutter:master Feb 17, 2021
@jonahwilliams jonahwilliams deleted the gradle_cleanup_3333 branch February 17, 2021 22:27

for (final FileSystemEntity entity in srcDir.listSync()) {
final String newPath = destDir.fileSystem.path.join(destDir.path, entity.basename);
if (entity is Link) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of a link falling through to the exception: #35170

@jonahwilliams
Copy link
Member Author

Part of #76264

@jonahwilliams
Copy link
Member Author

I mean #71511

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants