Skip to content

[flutter_tools] Make flutter git upstream configurable #61513

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

Merged
merged 2 commits into from
Jul 24, 2020

Conversation

TooYoungTooSimp
Copy link
Contributor

@TooYoungTooSimp TooYoungTooSimp commented Jul 15, 2020

Description

Make flutter git upstream configurable from environment variable.

Used FLUTTER_GIT_URL to control _flutterGit value.

Related Issues

#61286

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

@fluttergithubbot
Copy link
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@fluttergithubbot fluttergithubbot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jul 15, 2020
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@TooYoungTooSimp
Copy link
Contributor Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@TooYoungTooSimp
Copy link
Contributor Author

Sorry for making many wrong commits at beginning. Please use rebase merge to hide them. 😢

@christopherfujino
Copy link
Contributor

Sorry for making many wrong commits at beginning. Please use rebase merge to hide them.

No prob, we default to squash and merge, so each PR becomes one commit on master :)

@@ -24,7 +24,7 @@ enum Channel {
}

/// The flutter GitHub repository.
const String _flutterGit = 'https://github.com/flutter/flutter.git';
final String _flutterGit = globals.platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git';
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a good solution. One thing though, is that if the user has a typo in this env variable (or if it the remote is down), we should explicitly show the override value in any error message. If you check line 654 of this file, we throw an error if a command we run does not return a 0 exit code. Even though this error includes the complete command that failed, unfortunately, if FLUTTER_GIT_URL env variable is wrong, we won't hit an error until line 257, which tries to run the command git fetch $_versionCheckRemote $branch, which doesn't include the upstream URL in it. Probably the better version would be to add a catch around 262, and IF we have an explicit FLUTTER_GIT_URL override set in the environment, globals.printError('Warning: the Flutter git upstream was overriden by the environment variable FLUTTER_GIT_URL = ${globals.platform.environment['FLUTTER_GIT_URL']}'); (something like that, I didn't test it).

Also, this change should have unit tests in the file: https://github.com/flutter/flutter/blob/master/packages/flutter_tools/test/general.shard/version_test.dart. Using the testUsingContext() function, you can provide a FakePlatform and ProcessManager overrides (if you search the codebase for FakePlatform, you'll find a lot of examples) where you set the environment variable and then expect that you are getting the correct git commands to the mockProcessManager, specifically the one setting the upstream.

Let me know if you you run into any obstacles!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have finished print warning and unit test. But test running failed unexpected. Sorry for troubling but I have a problem now.

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.

Thanks for your contribution! This needs a test in order to be merged. How about something like this in version_test.dart?

  testUsingContext('determine uses overridden git url', () {
    final MockProcessUtils processUtils = MockProcessUtils();
    when(processUtils.runSync(
      <String>['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
      workingDirectory: anyNamed('workingDirectory'),
      environment: anyNamed('environment'),
    )).thenReturn(RunResult(ProcessResult(108, 0, 'master', ''), <String>['git', 'fetch']));
    when(processUtils.runSync(
      <String>['git', 'fetch', 'https://githubmirror.com/flutter.git', '--tags'],
      workingDirectory: anyNamed('workingDirectory'),
      environment: anyNamed('environment'),
    )).thenReturn(RunResult(ProcessResult(109, 0, '', ''), <String>['git', 'fetch']));
    when(processUtils.runSync(
      <String>['git', 'tag', '--contains', 'HEAD'],
      workingDirectory: anyNamed('workingDirectory'),
      environment: anyNamed('environment'),
    )).thenReturn(
        RunResult(ProcessResult(110, 0, '', ''),
          <String>['git', 'tag', '--contains', 'HEAD'],
        ));
    when(processUtils.runSync(
      <String>['git', 'describe', '--match', '*.*.*-*.*.pre', '--first-parent', '--long', '--tags'],
      workingDirectory: anyNamed('workingDirectory'),
      environment: anyNamed('environment'),
    )).thenReturn(RunResult(ProcessResult(111, 0, 'v0.1.2-3-1234abcd', ''), <String>['git', 'describe']));

    GitTagVersion.determine(processUtils, workingDirectory: '.', fetchTags: true);

    verify(processUtils.runSync(
      <String>['git', 'fetch', 'https://githubmirror.com/flutter.git', '--tags'],
      workingDirectory: anyNamed('workingDirectory'),
      environment: anyNamed('environment'),
    ));
  }, overrides: <Type, Generator>{
    Platform: () => FakePlatform(environment: <String, String>{
      'FLUTTER_GIT_URL': 'https://githubmirror.com/flutter.git',
    }),
  });

Those tests are kind of hard to write, sorry about that. I'd be happy to push the test to your fork, if you'd like!

#61286 (comment)

Except flutter-build, all other test passed.
To be honest, I don't know what is it and other prs have this problem too.

flutter-build is our post-submit CI system, and at the moment it's failing, but this has nothing to do with your PR. Once this is in good shape, we'll handle merging your PR once it goes green!

@@ -24,7 +24,7 @@ enum Channel {
}

/// The flutter GitHub repository.
const String _flutterGit = 'https://github.com/flutter/flutter.git';
final String _flutterGit = globals.platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git';
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately this isn't really testable since it can't be changed after the first time it's set. I wrote a unit test for this that passed on its own, but failed when run with the entire test suite because it always returned https://github.com/flutter/flutter.git because a previous test had initialized it.

How about:

String get _flutterGit => globals.platform.environment['FLUTTER_GIT_URL'] ??
    'https://github.com/flutter/flutter.git';

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch

@TooYoungTooSimp
Copy link
Contributor Author

Really great. Thanks for all of your kindly helps. I'll work on them right now.
// Learned a lot this time 😃

@TooYoungTooSimp
Copy link
Contributor Author

I got trouble writing tests...sorry.
After I copied the test from @jmagman and pushed to my branch.
Some CI tests failed.
Which result is

[test/general.shard/version_test.dart:main]:  NoSuchMethodError: The getter 'stdout' was called on null.
Receiver: null
Tried calling: stdout[test/general.shard/version_test.dart:main]:  #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      _runGit (package:flutter_tools/src/version.dart:676:5)
#2      GitTagVersion.determine (package:flutter_tools/src/version.dart:760:9)
#3      main.<anonymous closure> (org-dartlang-app:///test/general.shard/version_test.dart:640:19)
#4      testUsingContext.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (org-dartlang-app:///test/src/context.dart:151:42)
#5      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:29)

And so on, but I believe these should be enough.
detailed CI status

So basically, I need your help. 😢

@TooYoungTooSimp TooYoungTooSimp force-pushed the TooYoungTooSimp-patch-1 branch 2 times, most recently from 60412f1 to 1376aa9 Compare July 18, 2020 11:48
@TooYoungTooSimp TooYoungTooSimp force-pushed the TooYoungTooSimp-patch-1 branch from e0ffece to f98cfcb Compare July 18, 2020 14:15
@TooYoungTooSimp TooYoungTooSimp changed the title Make flutter git upstream configurable [flutter_tools] Make flutter git upstream configurable Jul 18, 2020
@TooYoungTooSimp
Copy link
Contributor Author

Finally I managed to pass CI with tests.
So I would like to request you to review my pr again now.
@christopherfujino @jmagman

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.

Other than the one spacing nit, this LGTM. I'll approve and merge once that gets fixed, assuming @christopherfujino doesn't have any more suggestions.

@christopherfujino
Copy link
Contributor

LGTM once you make @jmagman 's spacing change

Co-authored-by: Jenn Magder <magder@google.com>
@TooYoungTooSimp
Copy link
Contributor Author

The space problem fixed. Thanks.

@TooYoungTooSimp TooYoungTooSimp requested a review from jmagman July 21, 2020 01:39
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

@jmagman jmagman merged commit 7779a14 into flutter:master Jul 24, 2020
Pragya007 pushed a commit to Pragya007/flutter that referenced this pull request Aug 11, 2020
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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.

5 participants