Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
fb28ee28
Unverified
Commit
fb28ee28
authored
Nov 10, 2020
by
Jonah Williams
Committed by
GitHub
Nov 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] reland: cache pub invocations (#70180)
Disabled caching of pub invocations on flutter drive.
parent
191d0aa4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
302 additions
and
1 deletion
+302
-1
drive.dart
packages/flutter_tools/lib/src/commands/drive.dart
+3
-0
pub.dart
packages/flutter_tools/lib/src/dart/pub.dart
+28
-1
flutter_command.dart
packages/flutter_tools/lib/src/runner/flutter_command.dart
+4
-0
pub_get_test.dart
...s/flutter_tools/test/general.shard/dart/pub_get_test.dart
+266
-0
throwing_pub.dart
packages/flutter_tools/test/src/throwing_pub.dart
+1
-0
No files found.
packages/flutter_tools/lib/src/commands/drive.dart
View file @
fb28ee28
...
...
@@ -154,6 +154,9 @@ class DriveCommand extends RunCommandBase {
@override
bool
get
startPausedDefault
=>
true
;
@override
bool
get
cachePubGet
=>
false
;
@override
Future
<
void
>
validateCommand
()
async
{
if
(
userIdentifier
!=
null
)
{
...
...
packages/flutter_tools/lib/src/dart/pub.dart
View file @
fb28ee28
...
...
@@ -94,6 +94,7 @@ abstract class Pub {
bool
offline
=
false
,
bool
generateSyntheticPackage
=
false
,
String
flutterRootOverride
,
bool
checkUpToDate
=
false
,
});
/// Runs pub in 'batch' mode.
...
...
@@ -118,7 +119,6 @@ abstract class Pub {
bool
showTraceForErrors
,
});
/// Runs pub in 'interactive' mode.
///
/// directly piping the stdin stream of this process to that of pub, and the
...
...
@@ -164,12 +164,38 @@ class _DefaultPub implements Pub {
bool
offline
=
false
,
bool
generateSyntheticPackage
=
false
,
String
flutterRootOverride
,
bool
checkUpToDate
=
false
,
})
async
{
directory
??=
_fileSystem
.
currentDirectory
.
path
;
final
File
packageConfigFile
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
directory
,
'.dart_tool'
,
'package_config.json'
));
final
Directory
generatedDirectory
=
_fileSystem
.
directory
(
_fileSystem
.
path
.
join
(
directory
,
'.dart_tool'
,
'flutter_gen'
));
final
File
lastVersion
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
directory
,
'.dart_tool'
,
'version'
));
final
File
currentVersion
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
Cache
.
flutterRoot
,
'version'
));
final
File
pubspecYaml
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
directory
,
'pubspec.yaml'
));
final
File
pubLockFile
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
directory
,
'pubspec.lock'
)
);
// If the pubspec.yaml is older than the package config file and the last
// flutter version used is the same as the current version skip pub get.
// This will incorrectly skip pub on the master branch if dependencies
// are being added/removed from the flutter framework packages, but this
// can be worked around by manually running pub.
if
(
checkUpToDate
&&
packageConfigFile
.
existsSync
()
&&
pubLockFile
.
existsSync
()
&&
pubspecYaml
.
lastModifiedSync
().
isBefore
(
pubLockFile
.
lastModifiedSync
())
&&
pubspecYaml
.
lastModifiedSync
().
isBefore
(
packageConfigFile
.
lastModifiedSync
())
&&
lastVersion
.
existsSync
()
&&
lastVersion
.
readAsStringSync
()
==
currentVersion
.
readAsStringSync
())
{
_logger
.
printTrace
(
'Skipping pub get: version match.'
);
return
;
}
final
String
command
=
upgrade
?
'upgrade'
:
'get'
;
final
Status
status
=
_logger
.
startProgress
(
...
...
@@ -207,6 +233,7 @@ class _DefaultPub implements Pub {
if
(!
packageConfigFile
.
existsSync
())
{
throwToolExit
(
'
$directory
: pub did not create .dart_tools/package_config.json file.'
);
}
lastVersion
.
writeAsStringSync
(
currentVersion
.
readAsStringSync
());
await
_updatePackageConfig
(
packageConfigFile
,
generatedDirectory
,
...
...
packages/flutter_tools/lib/src/runner/flutter_command.dart
View file @
fb28ee28
...
...
@@ -467,6 +467,9 @@ abstract class FlutterCommand extends Command<void> {
);
}
/// Whether it is safe for this command to use a cached pub invocation.
bool
get
cachePubGet
=>
true
;
Duration
get
deviceDiscoveryTimeout
{
if
(
_deviceDiscoveryTimeout
==
null
&&
argResults
.
options
.
contains
(
FlutterOptions
.
kDeviceTimeout
)
...
...
@@ -1057,6 +1060,7 @@ abstract class FlutterCommand extends Command<void> {
await
pub
.
get
(
context:
PubContext
.
getVerifyContext
(
name
),
generateSyntheticPackage:
project
.
manifest
.
generateSyntheticPackage
,
checkUpToDate:
cachePubGet
,
);
await
project
.
regeneratePlatformSpecificTooling
();
}
...
...
packages/flutter_tools/test/general.shard/dart/pub_get_test.dart
View file @
fb28ee28
...
...
@@ -30,6 +30,269 @@ void main() {
MockDirectory
.
findCache
=
false
;
});
testWithoutContext
(
'checkUpToDate skips pub get if the package config is newer than the pubspec '
'and the current framework version is the same as the last version'
,
()
async
{
final
FakeProcessManager
processManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[]);
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
fileSystem
.
file
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
file
(
'pubspec.lock'
).
createSync
();
fileSystem
.
file
(
'.dart_tool/package_config.json'
).
createSync
(
recursive:
true
);
fileSystem
.
file
(
'.dart_tool/version'
).
writeAsStringSync
(
'a'
);
fileSystem
.
file
(
'version'
).
writeAsStringSync
(
'a'
);
final
Pub
pub
=
Pub
(
fileSystem:
fileSystem
,
logger:
logger
,
processManager:
processManager
,
usage:
MockUsage
(),
platform:
FakePlatform
(
environment:
const
<
String
,
String
>{},
),
botDetector:
const
BotDetectorAlwaysNo
(),
);
await
pub
.
get
(
context:
PubContext
.
pubGet
,
checkUpToDate:
true
,
);
expect
(
logger
.
traceText
,
contains
(
'Skipping pub get: version match.'
));
});
testWithoutContext
(
'checkUpToDate does not skip pub get if the package config is newer than the pubspec '
'but the current framework version is not the same as the last version'
,
()
async
{
final
FakeProcessManager
processManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[
const
FakeCommand
(
command:
<
String
>[
'bin/cache/dart-sdk/bin/pub'
,
'--verbosity=warning'
,
'get'
,
'--no-precompile'
,
])
]);
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
fileSystem
.
file
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
file
(
'pubspec.lock'
).
createSync
();
fileSystem
.
file
(
'.dart_tool/package_config.json'
).
createSync
(
recursive:
true
);
fileSystem
.
file
(
'.dart_tool/version'
).
writeAsStringSync
(
'a'
);
fileSystem
.
file
(
'version'
).
writeAsStringSync
(
'b'
);
final
Pub
pub
=
Pub
(
fileSystem:
fileSystem
,
logger:
logger
,
processManager:
processManager
,
usage:
MockUsage
(),
platform:
FakePlatform
(
environment:
const
<
String
,
String
>{},
),
botDetector:
const
BotDetectorAlwaysNo
(),
);
await
pub
.
get
(
context:
PubContext
.
pubGet
,
checkUpToDate:
true
,
);
expect
(
processManager
.
hasRemainingExpectations
,
false
);
expect
(
fileSystem
.
file
(
'.dart_tool/version'
).
readAsStringSync
(),
'b'
);
});
testWithoutContext
(
'checkUpToDate does not skip pub get if the package config is newer than the pubspec '
'but the current framework version does not exist yet'
,
()
async
{
final
FakeProcessManager
processManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[
const
FakeCommand
(
command:
<
String
>[
'bin/cache/dart-sdk/bin/pub'
,
'--verbosity=warning'
,
'get'
,
'--no-precompile'
,
])
]);
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
fileSystem
.
file
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
file
(
'pubspec.lock'
).
createSync
();
fileSystem
.
file
(
'.dart_tool/package_config.json'
).
createSync
(
recursive:
true
);
fileSystem
.
file
(
'version'
).
writeAsStringSync
(
'b'
);
final
Pub
pub
=
Pub
(
fileSystem:
fileSystem
,
logger:
logger
,
processManager:
processManager
,
usage:
MockUsage
(),
platform:
FakePlatform
(
environment:
const
<
String
,
String
>{},
),
botDetector:
const
BotDetectorAlwaysNo
(),
);
await
pub
.
get
(
context:
PubContext
.
pubGet
,
checkUpToDate:
true
,
);
expect
(
processManager
.
hasRemainingExpectations
,
false
);
expect
(
fileSystem
.
file
(
'.dart_tool/version'
).
readAsStringSync
(),
'b'
);
});
testWithoutContext
(
'checkUpToDate does not skip pub get if the package config does not exist'
,
()
async
{
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
FakeProcessManager
processManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[
FakeCommand
(
command:
const
<
String
>[
'bin/cache/dart-sdk/bin/pub'
,
'--verbosity=warning'
,
'get'
,
'--no-precompile'
,
],
onRun:
()
{
fileSystem
.
file
(
'.dart_tool/package_config.json'
).
createSync
(
recursive:
true
);
})
]);
final
BufferLogger
logger
=
BufferLogger
.
test
();
fileSystem
.
file
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
file
(
'pubspec.lock'
).
createSync
();
fileSystem
.
file
(
'version'
).
writeAsStringSync
(
'b'
);
final
Pub
pub
=
Pub
(
fileSystem:
fileSystem
,
logger:
logger
,
processManager:
processManager
,
usage:
MockUsage
(),
platform:
FakePlatform
(
environment:
const
<
String
,
String
>{},
),
botDetector:
const
BotDetectorAlwaysNo
(),
);
await
pub
.
get
(
context:
PubContext
.
pubGet
,
checkUpToDate:
true
,
);
expect
(
processManager
.
hasRemainingExpectations
,
false
);
expect
(
fileSystem
.
file
(
'.dart_tool/version'
).
readAsStringSync
(),
'b'
);
});
testWithoutContext
(
'checkUpToDate does not skip pub get if the pubspec.lock does not exist'
,
()
async
{
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
final
FakeProcessManager
processManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[
const
FakeCommand
(
command:
<
String
>[
'bin/cache/dart-sdk/bin/pub'
,
'--verbosity=warning'
,
'get'
,
'--no-precompile'
,
]),
]);
final
BufferLogger
logger
=
BufferLogger
.
test
();
fileSystem
.
file
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
file
(
'version'
).
writeAsStringSync
(
'b'
);
fileSystem
.
file
(
'.dart_tool/package_config.json'
).
createSync
(
recursive:
true
);
fileSystem
.
file
(
'.dart_tool/version'
).
writeAsStringSync
(
'b'
);
final
Pub
pub
=
Pub
(
fileSystem:
fileSystem
,
logger:
logger
,
processManager:
processManager
,
usage:
MockUsage
(),
platform:
FakePlatform
(
environment:
const
<
String
,
String
>{},
),
botDetector:
const
BotDetectorAlwaysNo
(),
);
await
pub
.
get
(
context:
PubContext
.
pubGet
,
checkUpToDate:
true
,
);
expect
(
processManager
.
hasRemainingExpectations
,
false
);
expect
(
fileSystem
.
file
(
'.dart_tool/version'
).
readAsStringSync
(),
'b'
);
});
testWithoutContext
(
'checkUpToDate does not skip pub get if the package config is older that the pubspec'
,
()
async
{
final
FakeProcessManager
processManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[
const
FakeCommand
(
command:
<
String
>[
'bin/cache/dart-sdk/bin/pub'
,
'--verbosity=warning'
,
'get'
,
'--no-precompile'
,
])
]);
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
fileSystem
.
file
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
file
(
'pubspec.lock'
).
createSync
();
fileSystem
.
file
(
'.dart_tool/package_config.json'
)
..
createSync
(
recursive:
true
)
..
setLastModifiedSync
(
DateTime
(
1991
));
fileSystem
.
file
(
'version'
).
writeAsStringSync
(
'b'
);
final
Pub
pub
=
Pub
(
fileSystem:
fileSystem
,
logger:
logger
,
processManager:
processManager
,
usage:
MockUsage
(),
platform:
FakePlatform
(
environment:
const
<
String
,
String
>{},
),
botDetector:
const
BotDetectorAlwaysNo
(),
);
await
pub
.
get
(
context:
PubContext
.
pubGet
,
checkUpToDate:
true
,
);
expect
(
processManager
.
hasRemainingExpectations
,
false
);
expect
(
fileSystem
.
file
(
'.dart_tool/version'
).
readAsStringSync
(),
'b'
);
});
testWithoutContext
(
'checkUpToDate does not skip pub get if the pubspec.lock is older that the pubspec'
,
()
async
{
final
FakeProcessManager
processManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[
const
FakeCommand
(
command:
<
String
>[
'bin/cache/dart-sdk/bin/pub'
,
'--verbosity=warning'
,
'get'
,
'--no-precompile'
,
])
]);
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
MemoryFileSystem
fileSystem
=
MemoryFileSystem
.
test
();
fileSystem
.
file
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
file
(
'pubspec.lock'
)
..
createSync
()
..
setLastModifiedSync
(
DateTime
(
1991
));
fileSystem
.
file
(
'.dart_tool/package_config.json'
)
.
createSync
(
recursive:
true
);
fileSystem
.
file
(
'version'
).
writeAsStringSync
(
'b'
);
fileSystem
.
file
(
'.dart_tool/version'
).
writeAsStringSync
(
'b'
);
final
Pub
pub
=
Pub
(
fileSystem:
fileSystem
,
logger:
logger
,
processManager:
processManager
,
usage:
MockUsage
(),
platform:
FakePlatform
(
environment:
const
<
String
,
String
>{},
),
botDetector:
const
BotDetectorAlwaysNo
(),
);
await
pub
.
get
(
context:
PubContext
.
pubGet
,
checkUpToDate:
true
,
);
expect
(
processManager
.
hasRemainingExpectations
,
false
);
expect
(
fileSystem
.
file
(
'.dart_tool/version'
).
readAsStringSync
(),
'b'
);
});
testWithoutContext
(
'pub get 69'
,
()
async
{
String
error
;
...
...
@@ -209,6 +472,7 @@ void main() {
}
),
);
fileSystem
.
file
(
'version'
).
createSync
();
fileSystem
.
file
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
file
(
'.dart_tool/package_config.json'
)
..
createSync
(
recursive:
true
)
...
...
@@ -237,6 +501,7 @@ void main() {
}
),
);
fileSystem
.
file
(
'version'
).
createSync
();
fileSystem
.
file
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
file
(
'.dart_tool/package_config.json'
)
..
createSync
(
recursive:
true
)
...
...
@@ -377,6 +642,7 @@ void main() {
botDetector:
const
BotDetectorAlwaysNo
()
);
fileSystem
.
file
(
'version'
).
createSync
();
// the good scenario: .packages is old, pub updates the file.
fileSystem
.
file
(
'.dart_tool/package_config.json'
)
..
createSync
(
recursive:
true
)
...
...
packages/flutter_tools/test/src/throwing_pub.dart
View file @
fb28ee28
...
...
@@ -30,6 +30,7 @@ class ThrowingPub implements Pub {
bool
skipPubspecYamlCheck
=
false
,
bool
generateSyntheticPackage
=
false
,
String
flutterRootOverride
,
bool
checkUpToDate
=
false
,
})
{
throw
UnsupportedError
(
'Attempted to invoke pub during test.'
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment