这是indexloc提供的服务,不要输入任何密码
Skip to content

refactor depfile usage and update linux rule #42487

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 16 commits into from
Oct 18, 2019

Conversation

jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Oct 11, 2019

Description

  • Pulls the logic for depfile reading and writing into a single class. Uses it to make the linux unpack command smarter.

  • Updates BuildSystem to not consider missing inputs a fatal error, instead it will rerun as normal. This allows easier usage of depfiles for fairly dynamic rules.

  • Remove dead code from build bundle.

Fixes #42411
Fixes #42399
Fixes #42697
Fixes #42411
Fixes #42954

@fluttergithubbot fluttergithubbot added the tool Affects the "flutter" command-line tool. See also t: labels. label Oct 11, 2019
@codecov
Copy link

codecov bot commented Oct 11, 2019

Codecov Report

Merging #42487 into master will decrease coverage by 1.11%.
The diff coverage is 94.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #42487      +/-   ##
==========================================
- Coverage   60.75%   59.64%   -1.12%     
==========================================
  Files         194      195       +1     
  Lines       18885    18905      +20     
==========================================
- Hits        11474    11276     -198     
- Misses       7411     7629     +218
Flag Coverage Δ
#flutter_tool 59.64% <94.11%> (-1.12%) ⬇️
Impacted Files Coverage Δ
...s/flutter_tools/lib/src/commands/build_bundle.dart 36.53% <ø> (ø) ⬆️
...tter_tools/lib/src/build_system/targets/linux.dart 89.55% <100%> (+4.44%) ⬆️
...s/flutter_tools/lib/src/tester/flutter_tester.dart 72.44% <100%> (+0.28%) ⬆️
...utter_tools/lib/src/build_system/build_system.dart 89.28% <83.33%> (+0.19%) ⬆️
packages/flutter_tools/lib/src/bundle.dart 85.45% <88.88%> (+4.13%) ⬆️
...es/flutter_tools/lib/src/build_system/depfile.dart 93.75% <93.75%> (ø)
...ages/flutter_tools/lib/src/commands/build_web.dart 29.41% <0%> (-64.71%) ⬇️
packages/flutter_tools/lib/src/web/compile.dart 10.34% <0%> (-62.07%) ⬇️
packages/flutter_tools/lib/src/ios/simulators.dart 3.26% <0%> (-47.29%) ⬇️
packages/flutter_tools/lib/src/base/flags.dart 38.88% <0%> (-11.12%) ⬇️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 134ac42...d1f1be6. Read the comment docs.

if (assets == null) {
throwToolExit('Error building assets', exitCode: 1);
// Work around for flutter_tester placing kernel artifacts in odd places.
if (applicationKernelFilePath != null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

flutter_tester is currently the only use of this logic. In the long term, we should clean this up to use a tempDir or something similar.

Copy link
Member

Choose a reason for hiding this comment

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

Is there an issue open for this?

@jonahwilliams jonahwilliams marked this pull request as ready for review October 12, 2019 20:38
@jonahwilliams
Copy link
Contributor Author

This change will also allow us to output a depfile for dart2js, which should cut down on memory usage.

environment.projectDir.path,
'linux',
'flutter',
'ephemeral',
Copy link
Member

Choose a reason for hiding this comment

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

Can we stick

s.path.join(
environment.projectDir.path,
'linux',
'flutter',
'ephemeral')

into a local?

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 Depfile depfile = Depfile(inputs, outputs);
depfile.writeToFile(environment.buildDir.childFile('linux_engine_sources.d'));
Copy link
Member

Choose a reason for hiding this comment

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

Does it matter if the dep file is re-written on every build, even if nothing changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we don't stat/diff the bytes of the depfile at all, we only read the contents. Changing the order/rewriting shouldn't trigger rebuilds.

/// Parse the depfile contents from [file].
///
/// If the syntax is invalid, returns an empty [Depfile].
factory Depfile.parse(File file) {
Copy link
Member

Choose a reason for hiding this comment

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

This looks untested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's tested indirectly via integration tests, but I've added some unit tests to cover it

@jonahwilliams jonahwilliams requested review from jmagman, blasten, dnfield and zanderso and removed request for zanderso and dnfield October 15, 2019 17:00
@@ -772,9 +772,12 @@ class Node {
}
}

// If we depend on a file that doesnt exist on disk, kill the build.
// If we depend on a file that doesnt exist on disk, mark the build as
Copy link
Member

Choose a reason for hiding this comment

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

What happens if the user listed a file by accident, and the fix is to remove the file? How do they find out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The user here would be the tools team, so ideally we'd have a test to cover it. Long term, I think we should surface the reasons why targets are re-run.

Copy link
Member

Choose a reason for hiding this comment

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

Would it be useful to do a printTrace here with some diagnostic info?

Copy link

Choose a reason for hiding this comment

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

From the description, what is an example of a fairly dynamic rule where a required file doesn't exist at the moment of running the target?

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anything using a depfile, which will be lots of rules

if (missingInputs.isNotEmpty) {
throw MissingInputException(missingInputs, target.name);
_dirty = true;
invalidatedReasons.add(InvalidedReason.inputChanged);
Copy link

Choose a reason for hiding this comment

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

does inputChanged mean that a required file is missing? The comment on this file says: An input file has an updated hash..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added InvalidatedReason.inputMissing with a description

jonahwilliams added 2 commits October 16, 2019 14:04
final List<String> colonSeparated = contents.split(': ');
if (colonSeparated.length != 2) {
printError('Invalid depfile: ${file.path}');
return const Depfile(<File>[], <File>[]);
Copy link

Choose a reason for hiding this comment

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

In which instance returning an empty Depfile makes the build successful later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the case where (for some reason, human intervention) an invalid depfile is written or edited - we don't force the user to flutter clean, instead we allow a new one be written which hopefully doesn't have the same issue

// Expand escape sequences, so that '\ ', for example,ß becomes ' '
.map<String>((String path) => path.replaceAllMapped(_escapeExpr, (Match match) => match.group(1)).trim())
.where((String path) => path.isNotEmpty)
.toSet()
Copy link

@blasten blasten Oct 16, 2019

Choose a reason for hiding this comment

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

are there duplicated items in the list? If so, would you mind added a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also added a test case for this

Comment on lines +82 to +93
final String outputPath = fs.path.join(
outputPrefix,
fs.path.relative(input.path, from: basePath),
);
final File destinationFile = fs.file(outputPath);
if (!destinationFile.parent.existsSync()) {
destinationFile.parent.createSync(recursive: true);
}
final File inputFile = fs.file(input);
inputFile.copySync(destinationFile.path);
inputs.add(inputFile);
outputs.add(destinationFile);
Copy link

Choose a reason for hiding this comment

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

ditto

Comment on lines +64 to +77
if (fs.isFileSync(entityPath)) {
final String outputPath = fs.path.join(
outputPrefix,
fs.path.relative(entityPath, from: basePath),
);
final File destinationFile = fs.file(outputPath);
if (!destinationFile.parent.existsSync()) {
destinationFile.parent.createSync(recursive: true);
}
final File inputFile = fs.file(entityPath);
inputFile.copySync(destinationFile.path);
inputs.add(inputFile);
outputs.add(destinationFile);
continue;
Copy link

Choose a reason for hiding this comment

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

nit: this code might need some comments.

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 tried to add some more context here, PTAL

if (assets == null) {
throwToolExit('Error building assets', exitCode: 1);
// Work around for flutter_tester placing kernel artifacts in odd places.
if (applicationKernelFilePath != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there an issue open for this?

import '../../src/common.dart';
import '../../src/testbed.dart';

void main() {
Copy link
Member

Choose a reason for hiding this comment

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

Some negative tests here would be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added test cases for malformed file, duplicates, and whitespace

@jonahwilliams
Copy link
Contributor Author

Filled #42957 for the tester issue

// Put every file on right-hand side on the separate line
.replaceAllMapped(_separatorExpr, (Match match) => '${match.group(1)}\n')
.split('\n')
// Expand escape sequences, so that '\ ', for example,ß becomes ' '
Copy link

Choose a reason for hiding this comment

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

nit: is the ß intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

outputs.add(destinationFile);
continue;
}
// If ths artifact is the directory cpp_client_wrapper, recursively
Copy link

Choose a reason for hiding this comment

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

nit: typo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

D'oh

@jonahwilliams jonahwilliams merged commit f53b32e into flutter:master Oct 18, 2019
@jonahwilliams jonahwilliams deleted the match_unpack_directories branch October 18, 2019 00:42
@devorso
Copy link

devorso commented Oct 18, 2019

I have now this error:

> Compiler message:
/E:/flutter/.pub-cache/hosted/pub.dartlang.org/circular_profile_avatar-1.0.2/lib/circular_profile_avatar.dart:3:8: Error: Error when reading '/E:/flutter/.pub-cache/hosted/pub.dartlang.org/cached_network_image-1.1.2+1/lib/cached_network_image.dart': Le chemin d’accès spécifié est introuvable.

import 'package:cached_network_image/cached_network_image.dart';
^
/E:/flutter/.pub-cache/hosted/pub.dartlang.org/circular_profile_avatar-1.0.2/lib/circular_profile_avatar.dart:70:9: Error: Type 'PlaceholderWidgetBuilder' not found.
final PlaceholderWidgetBuilder placeHolder;
^^^^^^^^^^^^^^^^^^^^^^^^
/E:/flutter/.pub-cache/hosted/pub.dartlang.org/circular_profile_avatar-1.0.2/lib/circular_profile_avatar.dart:73:9: Error: Type 'LoadingErrorWidgetBuilder' not found.
final LoadingErrorWidgetBuilder errorWidget;
^^^^^^^^^^^^^^^^^^^^^^^^^
/E:/flutter/.pub-cache/hosted/pub.dartlang.org/circular_profile_avatar-1.0.2/lib/circular_profile_avatar.dart:76:9: Error: Type 'ImageWidgetBuilder' not found.
final ImageWidgetBuilder imageBuilder;
^^^^^^^^^^^^^^^^^^
/E:/flutter/.pub-cache/hosted/pub.dartlang.org/circular_profile_avatar-1.0.2/lib/circular_profile_avatar.dart:70:9: Error: 'PlaceholderWidgetBuilder' isn't a type.
final PlaceholderWidgetBuilder placeHolder;
^^^^^^^^^^^^^^^^^^^^^^^^
/E:/flutter/.pub-cache/hosted/pub.dartlang.org/circular_profile_avatar-1.0.2/lib/circular_profile_avatar.dart:73:9: Error: 'LoadingErrorWidgetBuilder' isn't a type.
final LoadingErrorWidgetBuilder errorWidget;
^^^^^^^^^^^^^^^^^^^^^^^^^
/E:/flutter/.pub-cache/hosted/pub.dartlang.org/circular_profile_avatar-1.0.2/lib/circular_profile_avatar.dart:76:9: Error: 'ImageWidgetBuilder' isn't a type.
final ImageWidgetBuilder imageBuilder;
^^^^^^^^^^^^^^^^^^
/E:/flutter/.pub-cache/hosted/pub.dartlang.org/circular_profile_avatar-1.0.2/lib/circular_profile_avatar.dart:140:20: Error: The method 'CachedNetworkImage' isn't defined for the class '_CircularProfileAvatarState'.

'_CircularProfileAvatarState' is from 'package:circular_profile_avatar/circular_profile_avatar.dart' ('/E:/flutter/.pub-cache/hosted/pub.dartlang.org/circular_profile_avatar-1.0.2/lib/circular_profile_avatar.dart').
Try correcting the name to the name of an existing method, or defining a method named 'CachedNetworkImage'.
child: CachedNetworkImage(
^^^^^^^^^^^^^^^^^^
Exception: Errors during snapshot creation: null
#0 KernelSnapshot.build (package:flutter_tools/src/build_system/targets/dart.dart:225:7)
#1 _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:526:25) #2 _BuildInstance.invokeTarget. (package:flutter_tools/src/build_system/build_system.dart:481:35) #3 new Future.sync (dart:async/future.dart:224:31) #4 AsyncMemoizer.runOnce (package:async/src/async_memoizer.dart:43:45) #5 _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:481:21) #6 BuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:419:36) #7 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:43:6) #8 BuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:400:28) #9 buildWithAssemble (package:flutter_tools/src/bundle.dart:122:48) #10 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:43:6) #11 buildWithAssemble (package:flutter_tools/src/bundle.dart:98:31) #12 BundleBuilder.build (package:flutter_tools/src/bundle.dart:75:11) #13 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:43:6) #14 BundleBuilder.build (package:flutter_tools/src/bundle.dart:52:21) #15 BuildBundleCommand.runCommand (package:flutter_tools/src/commands/build_bundle.dart:126:25) #16 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:43:6) #17 BuildBundleCommand.runCommand (package:flutter_tools/src/commands/build_bundle.dart:97:42) #18 FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:557:18) #19 _asyncThenWrapperHelper. (dart:async-patch/async_patch.dart:71:64) #20 _rootRunUnary (dart:async/zone.dart:1132:38) #21 _CustomZone.runUnary (dart:async/zone.dart:1029:19) #22 _FutureListener.handleValue (dart:async/future_impl.dart:137:18) #23 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45) #24 Future._propagateToListeners (dart:async/future_impl.dart:707:32) #25 Future._completeWithValue (dart:async/future_impl.dart:522:5) #26 Future._asyncComplete. (dart:async/future_impl.dart:552:7) #27 _rootRun (dart:async/zone.dart:1124:13) #28 _CustomZone.run (dart:async/zone.dart:1021:19) #29 _CustomZone.runGuarded (dart:async/zone.dart:923:7) #30 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963:23) #31 _microtaskLoop (dart:async/schedule_microtask.dart:41:21) #32 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5) #33 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:116:13) #34 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:173:5)
Failed to build bundle.

FAILURE: Build failed with an exception.

Where:
Script 'E:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 794

What went wrong:
Execution failed for task ':app:compileFlutterBuildDebugArm64'.

Process 'command 'E:\flutter\bin\flutter.bat'' finished with non-zero exit value 1

Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Get more help at https://help.gradle.org

BUILD FAILED in 15s
Finished with error: Gradle task assembleDebug failed with exit code 1

Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Nov 26, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 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
7 participants