Skip to content

[flutter_tools] remove globals from compilers - #59184

Merged
jonahwilliams merged 14 commits into
flutter:masterfrom
jonahwilliams:resident_runner_dependencies
Jun 18, 2020
Merged

jonahwilliams merged 14 commits into
flutter:masterfrom
jonahwilliams:resident_runner_dependencies

Conversation

@jonahwilliams

@jonahwilliams jonahwilliams commented Jun 10, 2020 •

Copy link
Copy Markdown
Contributor

Description

Refactors KernelCompiler and ResidentCompiler to no longer use globals (except as a fallback for g3 migration). Improves the compilation error when running flutter test on a package without a flutter_test dependency.

Fixes #59510

}


class _TestArtifacts implements Artifacts {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I got tired of mocking Artifacts when I don't actually care about the contents. This should trivially generate unique-ish artifact paths for testing

this.pid = 1,
Future<int> exitCode,
Stream<List<int>> stdin,
IOSink stdin,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this type was wrong and the case is bogus

// Override the filesystem scheme so that the frontend_server can find
// the generated entrypoint code.
fileSystemScheme: 'org-dartlang-app',
compilerMessageConsumer:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@annagrin I need to remove this because it prevents regular compiler errors from showing up on the web

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I need to understand this better. I added this to communicate compiler errors to the debugger during evaluation, so something might break there...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is only printing trace messages, how is the debugger using printed messages?

@annagrin annagrin Jun 16, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For expression evaluation, the debugger does not need messages printed to the console, but instead is handing them specially, depending on the context (watch window, hover over, expression evaluation box, conditional compilation all need their own error handling). Not sure how the debugger is getting the error messages though, will find it out and update.

I tried the change and figured out that if we suppress the compilation messages in compile.dart :

Future<CompilerOutput> _compileExpressionToJs(_CompileExpressionToJsRequest request) async {
    _stdoutHandler.reset(suppressCompilerMessages: **false**, expectSources: false);

then we get the desired effect - the error messages are still propagating to the debugger but the printing is gone.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ahh, awesome - I will make that change!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Figured out how debugger gets compilation errors:

return ExpressionCompilationResult(

So as long as the generator writes them to the file, the debugger should get them:

https://github.com/dart-lang/sdk/blob/ecc7a2110667284d792946775f471f4a7f409afb/pkg/frontend_server/lib/frontend_server.dart#L964

And the errors table is filled by:

https://github.com/dart-lang/sdk/blob/ecc7a2110667284d792946775f471f4a7f409afb/pkg/frontend_server/lib/frontend_server.dart#L360

This a bit too complicated, may need revisiting and simplification...

@goderbauer goderbauer added the tool Affects the "flutter" command-line tool. See also t: labels. label Jun 10, 2020
}
}

void _reportCompilerMessage(String message, {bool emphasis, TerminalColor color}) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rather than printing this message after a bunch of compilation failures, the new test compiler checks for a dependency before compiling and exits early. This gives a much clearer instruction on how to resolve the error too

<<stderr>>
<<skip until matching line>>
Failed to load test harness\. +Are you missing a dependency on flutter_test\? No newline at end of file
Error: cannot run without a dependency on "package:flutter_test". Ensure the following lines are present in your pubspec.yaml:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

By checking the package config we know definitely there is a missing dependency. Added instructions on how to fix

@jmagman jmagman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: CompilerMessageConsumer typedef is unused, remove.
LGTM

@zanderso zanderso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm w/ question.

@@ -68,10 +76,6 @@ void main() {
verifyNoMoreInteractions(mockFrontendServerStdIn);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can any of these use testWithoutContext?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, fixed

verify(residentCompiler.shutdown()).called(1);
}));

test('Reports an error when there is no dependency on flutter_test', () => testbed.run(() async {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not until these tests are re-written.

Comment thread packages/flutter_tools/lib/src/commands/daemon.dart
@jonahwilliams
jonahwilliams requested a review from annagrin June 17, 2020 15:29
@jonahwilliams
jonahwilliams merged commit 447e3d3 into flutter:master Jun 18, 2020
@jonahwilliams
jonahwilliams deleted the resident_runner_dependencies branch June 18, 2020 17:33
@fluttergithubbot fluttergithubbot added the c: contributor-productivity Team-specific productivity, code health, technical debt. label Jun 18, 2020
@jonahwilliams

Copy link
Copy Markdown
Contributor Author

Fixes #59510

zljj0818 pushed a commit to zljj0818/flutter that referenced this pull request Jun 22, 2020
Refactors KernelCompiler and ResidentCompiler to no longer use globals (except as a fallback for g3 migration). Improves the compilation error when running flutter test on a package without a flutter_test dependency.

Updates machine mode to output trace text to stderr
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
Refactors KernelCompiler and ResidentCompiler to no longer use globals (except as a fallback for g3 migration). Improves the compilation error when running flutter test on a package without a flutter_test dependency.

Updates machine mode to output trace text to stderr
@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

c: contributor-productivity Team-specific productivity, code health, technical debt. tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dart SDK error hidden as warning by flutter tool

7 participants