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] [dap] Add support for passing env variables to spawned processes #107415

Merged
merged 4 commits into from
Jul 12, 2022

Conversation

DanTup
Copy link
Contributor

@DanTup DanTup commented Jul 11, 2022

This wires up the env field that may be passed in the DAP's launch args to the Flutter processes. These may be set by the user (although for non-test that's less useful since they only apply to the tool and not the process running on the device), but also allows editors to add vars that may be used for analytics (such as PUB_ENVIRONMENT).

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jul 11, 2022
@@ -316,12 +316,13 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
}

@visibleForOverriding
Future<void> launchAsProcess(String executable, List<String> processArgs) async {
Future<void> launchAsProcess(String executable, List<String> processArgs, Map<String, String>? env) async {
Copy link
Member

Choose a reason for hiding this comment

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

nit. prefer named arguments with 3 or more

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
group('launchRequest', () {
test('runs "flutter run" with --machine', () async {
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(fileSystem: globals.fs, platform: globals.platform);
Copy link
Member

Choose a reason for hiding this comment

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

Does the MockFlutterDebugAdapter actually use the real filesystem? If so, these tests should be probably be under flutter_tools/test/integration.shard/dap/flutter_adapter_test.dart. If not, can we pass a memory file system and FakePlatform to them instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They don't use them, these ones are just simple unit tests. I've changed them to use MemoryFileSystem.test() and FakePlatform, but I made the platform match the real one so that the Windows bots will test with Windows paths etc.

(I haven't verified on Windows so if I didn't do this right the bots may fail, I'll check back on this later since I gotta be away for a little)

Copy link
Member

Choose a reason for hiding this comment

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

This does fail on windows:

00:48 +1256 ~3 -2: test\general.shard\dap\flutter_test_adapter_test.dart: flutter test adapter includes toolArgs [E]                                                                                   
  Expected: 'C:\\fake\\flutter\\bin\\flutter.bat'
    Actual: 'C:\\fake\\flutter/bin/flutter.bat'
     Which: is different.
            Expected: ... e\\flutter\\bin\\flu ...
              Actual: ... e\\flutter/bin/flutt ...
                                    ^
             Differ at offset 17
  
  package:test_api                                            expect
  test\general.shard\dap\flutter_test_adapter_test.dart 49:7  main.<fn>.<fn>

I think when constructing the MemoryFileSystem, you have to also specify the FileSystemStyle in the constructor

Copy link
Member

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

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

LGTM

@DanTup
Copy link
Contributor Author

DanTup commented Jul 11, 2022

@christopherfujino Windows framework_tests_widgets says it's an infra failure. Is there a way to re-run that one without re-running everything?

@christopherfujino
Copy link
Member

@christopherfujino Windows framework_tests_widgets says it's an infra failure. Is there a way to re-run that one without re-running everything?

Done

@DanTup
Copy link
Contributor Author

DanTup commented Jul 12, 2022

Thanks!

@DanTup DanTup merged commit 78d924a into flutter:master Jul 12, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Jul 12, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 12, 2022
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
…d processes (flutter#107415)

* [flutter_tools] [dap] Add support for passing env variables to spawned processes

* Use named args

* Use in-memory fs and FakePlatform

* Pass filesystem style to MemoryFileSystem
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