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
8c5a70f3
Unverified
Commit
8c5a70f3
authored
Jun 15, 2023
by
Ian Hickson
Committed by
GitHub
Jun 15, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flutter update-packages --cherry-pick-package (#128917)
Fixes
https://github.com/flutter/flutter/issues/101525
parent
d3e771c8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
235 additions
and
49 deletions
+235
-49
update_packages.dart
packages/flutter_tools/lib/src/commands/update_packages.dart
+166
-49
update_packages_test.dart
...ls/test/commands.shard/hermetic/update_packages_test.dart
+69
-0
No files found.
packages/flutter_tools/lib/src/commands/update_packages.dart
View file @
8c5a70f3
...
...
@@ -51,6 +51,14 @@ class UpdatePackagesCommand extends FlutterCommand {
'This will actually modify the pubspec.yaml files in your checkout.'
,
negatable:
false
,
)
..
addOption
(
'cherry-pick-package'
,
help:
'Attempt to update only the specified package. The "-cherry-pick-version" version must be specified also.'
,
)
..
addOption
(
'cherry-pick-version'
,
help:
'Attempt to update the package to the specified version. The "--cherry-pick-package" option must be specified also.'
,
)
..
addFlag
(
'paths'
,
help:
'Finds paths in the dependency chain leading from package specified '
...
...
@@ -182,7 +190,8 @@ class UpdatePackagesCommand extends FlutterCommand {
final
bool
isVerifyOnly
=
boolArg
(
'verify-only'
);
final
bool
isConsumerOnly
=
boolArg
(
'consumer-only'
);
final
bool
offline
=
boolArg
(
'offline'
);
final
bool
doUpgrade
=
forceUpgrade
||
isPrintPaths
||
isPrintTransitiveClosure
;
final
String
?
cherryPickPackage
=
stringArg
(
'cherry-pick-package'
);
final
String
?
cherryPickVersion
=
stringArg
(
'cherry-pick-version'
);
if
(
boolArg
(
'crash'
))
{
throw
StateError
(
'test crash please ignore.'
);
...
...
@@ -194,6 +203,54 @@ class UpdatePackagesCommand extends FlutterCommand {
);
}
if
(
forceUpgrade
&&
cherryPickPackage
!=
null
)
{
throwToolExit
(
'--force-upgrade cannot be used with the --cherry-pick-package flag'
);
}
if
(
forceUpgrade
&&
isPrintPaths
)
{
throwToolExit
(
'--force-upgrade cannot be used with the --paths flag'
);
}
if
(
forceUpgrade
&&
isPrintTransitiveClosure
)
{
throwToolExit
(
'--force-upgrade cannot be used with the --transitive-closure flag'
);
}
if
(
cherryPickPackage
!=
null
&&
offline
)
{
throwToolExit
(
'--cherry-pick-package cannot be used with the --offline flag'
);
}
if
(
cherryPickPackage
!=
null
&&
cherryPickVersion
==
null
)
{
throwToolExit
(
'--cherry-pick-version is required when using --cherry-pick-package flag'
);
}
if
(
isPrintPaths
&&
(
stringArg
(
'from'
)
==
null
||
stringArg
(
'to'
)
==
null
))
{
throwToolExit
(
'The --from and --to flags are required when using the --paths flag'
);
}
if
(!
isPrintPaths
&&
(
stringArg
(
'from'
)
!=
null
||
stringArg
(
'to'
)
!=
null
))
{
throwToolExit
(
'The --from and --to flags are only allowed when using the --paths flag'
);
}
if
(
isPrintTransitiveClosure
&&
isPrintPaths
)
{
throwToolExit
(
'The --transitive-closure flag cannot be used with the --paths flag'
);
}
// "consumer" packages are those that constitute our public API (e.g. flutter, flutter_test, flutter_driver, flutter_localizations, integration_test).
if
(
isConsumerOnly
)
{
if
(!
isPrintTransitiveClosure
)
{
...
...
@@ -216,7 +273,7 @@ class UpdatePackagesCommand extends FlutterCommand {
return
FlutterCommandResult
.
success
();
}
if
(
do
Upgrade
)
{
if
(
force
Upgrade
)
{
// This feature attempts to collect all the packages used across all the
// pubspec.yamls in the repo (including via transitive dependencies), and
// find the latest version of each that can be used while keeping each
...
...
@@ -235,9 +292,38 @@ class UpdatePackagesCommand extends FlutterCommand {
explicitDependencies:
explicitDependencies
,
allDependencies:
allDependencies
,
specialDependencies:
specialDependencies
,
doUpgrade:
doUpgrade
,
printPaths:
forceUpgrade
||
isPrintPaths
||
isPrintTransitiveClosure
||
cherryPickPackage
!=
null
,
);
final
Iterable
<
PubspecDependency
>
baseDependencies
;
if
(
cherryPickPackage
!=
null
)
{
if
(!
allDependencies
.
containsKey
(
cherryPickPackage
))
{
throwToolExit
(
'Package "
$cherryPickPackage
" is not currently a dependency, and therefore cannot be upgraded.'
);
}
if
(
cherryPickVersion
!=
null
)
{
globals
.
printStatus
(
'Pinning package "
$cherryPickPackage
" to version "
$cherryPickVersion
"...'
);
}
else
{
globals
.
printStatus
(
'Upgrading package "
$cherryPickPackage
"...'
);
}
final
List
<
PubspecDependency
>
adjustedDependencies
=
<
PubspecDependency
>[];
for
(
final
String
package
in
allDependencies
.
keys
)
{
if
(
package
==
cherryPickPackage
)
{
assert
(
cherryPickVersion
!=
null
);
final
PubspecDependency
pubspec
=
allDependencies
[
cherryPickPackage
]!;
adjustedDependencies
.
add
(
pubspec
.
copyWith
(
version:
cherryPickVersion
));
}
else
{
adjustedDependencies
.
add
(
allDependencies
[
package
]!);
}
}
baseDependencies
=
adjustedDependencies
;
}
else
if
(
forceUpgrade
)
{
baseDependencies
=
explicitDependencies
.
values
;
}
else
{
baseDependencies
=
allDependencies
.
values
;
}
// Now that we have all the dependencies we care about, we are going to
// create a fake package and then run either "pub upgrade", if requested,
// followed by "pub get" on it. If upgrading, the pub tool will attempt to
...
...
@@ -246,12 +332,14 @@ class UpdatePackagesCommand extends FlutterCommand {
// attempt to download any necessary package versions to the pub cache to
// warm the cache.
final
PubDependencyTree
tree
=
PubDependencyTree
();
// object to collect results
await
_
generateFakePackage
(
await
_
pubGetAllDependencies
(
tempDir:
_syntheticPackageDir
,
dependencies:
doUpgrade
?
explicitDependencies
.
values
:
allDependencies
.
valu
es
,
dependencies:
baseDependenci
es
,
pubspecs:
pubspecs
,
tree:
tree
,
doUpgrade:
doUpgrade
,
doUpgrade:
forceUpgrade
,
isolateEnvironment:
forceUpgrade
||
isPrintPaths
||
isPrintTransitiveClosure
||
cherryPickPackage
!=
null
,
reportDependenciesToTree:
forceUpgrade
||
isPrintPaths
||
isPrintTransitiveClosure
||
cherryPickPackage
!=
null
,
);
// Only delete the synthetic package if it was done in a temp directory
...
...
@@ -259,18 +347,31 @@ class UpdatePackagesCommand extends FlutterCommand {
_syntheticPackageDir
.
deleteSync
(
recursive:
true
);
}
if
(
doUpgrade
)
{
final
bool
done
=
_upgrade
Pubspecs
(
if
(
forceUpgrade
||
isPrintTransitiveClosure
||
isPrintPaths
||
cherryPickPackage
!=
null
)
{
_process
Pubspecs
(
tree:
tree
,
pubspecs:
pubspecs
,
explicitDependencies:
explicitDependencies
,
specialDependencies:
specialDependencies
,
);
if
(
done
)
{
// Complete early if we were just printing data.
if
(
isPrintTransitiveClosure
)
{
tree
.
_dependencyTree
.
forEach
((
String
from
,
Set
<
String
>
to
)
{
globals
.
printStatus
(
'
$from
->
$to
'
);
});
return
FlutterCommandResult
.
success
();
}
if
(
isPrintPaths
)
{
showDependencyPaths
(
from:
stringArg
(
'from'
)!,
to:
stringArg
(
'to'
)!,
tree:
tree
);
return
FlutterCommandResult
.
success
();
}
globals
.
printStatus
(
'Updating workspace...'
);
_updatePubspecs
(
tree:
tree
,
pubspecs:
pubspecs
,
specialDependencies:
specialDependencies
,
);
}
await
_runPubGetOnPackages
(
packages
);
...
...
@@ -306,8 +407,9 @@ class UpdatePackagesCommand extends FlutterCommand {
// we need to run update-packages to recapture the transitive deps.
globals
.
printWarning
(
'Warning: pubspec in
${directory.path}
has updated or new dependencies. '
'Please run "flutter update-packages --force-upgrade" to update them correctly '
'(checksum
${pubspec.checksum.value}
!=
$checksum
).'
'Please run "flutter update-packages --force-upgrade" to update them correctly.'
// DO NOT PRINT THE CHECKSUM HERE.
// It causes people to ignore the requirement to actually run the script.
);
needsUpdate
=
true
;
}
else
{
...
...
@@ -331,11 +433,11 @@ class UpdatePackagesCommand extends FlutterCommand {
required
Set
<
String
>
specialDependencies
,
required
Map
<
String
,
PubspecDependency
>
explicitDependencies
,
required
Map
<
String
,
PubspecDependency
>
allDependencies
,
required
bool
doUpgrade
,
required
bool
printPaths
,
})
{
// Visit all the directories with pubspec.yamls we care about.
for
(
final
Directory
directory
in
packages
)
{
if
(
doUpgrade
)
{
if
(
printPaths
)
{
globals
.
printTrace
(
'Reading pubspec.yaml from:
${directory.path}
'
);
}
final
PubspecYaml
pubspec
=
PubspecYaml
(
directory
);
// this parses the pubspec.yaml
...
...
@@ -404,12 +506,14 @@ class UpdatePackagesCommand extends FlutterCommand {
}
}
Future
<
void
>
_
generateFakePackage
({
Future
<
void
>
_
pubGetAllDependencies
({
required
Directory
tempDir
,
required
Iterable
<
PubspecDependency
>
dependencies
,
required
List
<
PubspecYaml
>
pubspecs
,
required
PubDependencyTree
tree
,
required
bool
doUpgrade
,
required
bool
isolateEnvironment
,
required
bool
reportDependenciesToTree
,
})
async
{
Directory
?
temporaryFlutterSdk
;
final
Directory
syntheticPackageDir
=
tempDir
.
childDirectory
(
'synthetic_package'
);
...
...
@@ -421,9 +525,10 @@ class UpdatePackagesCommand extends FlutterCommand {
doUpgrade:
doUpgrade
,
),
);
// Create a synthetic flutter SDK so that transitive flutter SDK
// constraints are not affected by this upgrade.
if
(
doUpgrade
)
{
if
(
isolateEnvironment
)
{
// Create a synthetic flutter SDK so that transitive flutter SDK
// constraints are not affected by this upgrade.
temporaryFlutterSdk
=
createTemporaryFlutterSdk
(
globals
.
logger
,
globals
.
fs
,
...
...
@@ -433,8 +538,10 @@ class UpdatePackagesCommand extends FlutterCommand {
);
}
//
Next we r
un "pub get" on it in order to force the download of any
//
R
un "pub get" on it in order to force the download of any
// needed packages to the pub cache, upgrading if requested.
// TODO(ianh): If this fails, the tool exits silently.
// It can fail, e.g., if --cherry-pick-version is invalid.
await
pub
.
get
(
context:
PubContext
.
updatePackages
,
project:
FlutterProject
.
fromDirectory
(
syntheticPackageDir
),
...
...
@@ -444,9 +551,9 @@ class UpdatePackagesCommand extends FlutterCommand {
outputMode:
PubOutputMode
.
none
,
);
if
(
doUpgrad
e
)
{
//
If upgrading, we run "pub deps --style=compact" on the result. We
// pipe all the output to tree.fill(), which parses it so that it can
if
(
reportDependenciesToTre
e
)
{
//
Run "pub deps --style=compact" on the result.
//
We
pipe all the output to tree.fill(), which parses it so that it can
// create a graph of all the dependencies so that we can figure out the
// transitive dependencies later. It also remembers which version was
// selected for each package.
...
...
@@ -459,40 +566,29 @@ class UpdatePackagesCommand extends FlutterCommand {
}
}
bool
_upgrade
Pubspecs
({
void
_process
Pubspecs
({
required
PubDependencyTree
tree
,
required
List
<
PubspecYaml
>
pubspecs
,
required
Set
<
String
>
specialDependencies
,
required
Map
<
String
,
PubspecDependency
>
explicitDependencies
,
})
{
// The transitive dependency tree for the fake package does not contain
// dependencies between Flutter SDK packages and pub packages. We add them
// here.
for
(
final
PubspecYaml
pubspec
in
pubspecs
)
{
final
String
package
=
pubspec
.
name
;
specialDependencies
.
add
(
package
);
tree
.
_versions
[
package
]
=
pubspec
.
version
;
assert
(!
tree
.
_dependencyTree
.
containsKey
(
package
));
tree
.
_dependencyTree
[
package
]
=
<
String
>{};
for
(
final
PubspecDependency
dependency
in
pubspec
.
dependencies
)
{
if
(
dependency
.
kind
==
DependencyKind
.
normal
)
{
tree
.
_dependencyTree
[
package
]
??=
<
String
>{};
tree
.
_dependencyTree
[
package
]!.
add
(
dependency
.
name
);
}
}
}
}
if
(
boolArg
(
'transitive-closure'
))
{
tree
.
_dependencyTree
.
forEach
((
String
from
,
Set
<
String
>
to
)
{
globals
.
printStatus
(
'
$from
->
$to
'
);
});
return
true
;
}
if
(
boolArg
(
'paths'
))
{
showDependencyPaths
(
from:
stringArg
(
'from'
)!,
to:
stringArg
(
'to'
)!,
tree:
tree
);
return
true
;
}
bool
_updatePubspecs
({
required
PubDependencyTree
tree
,
required
List
<
PubspecYaml
>
pubspecs
,
required
Set
<
String
>
specialDependencies
,
})
{
// Now that we have collected all the data, we can apply our dependency
// versions to each pubspec.yaml that we collected. This mutates the
// pubspec.yaml files.
...
...
@@ -662,7 +758,6 @@ enum DependencyKind {
/// pubspec.yaml file.
const
String
kTransitiveMagicString
=
'# THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"'
;
/// This is the string output before a checksum of the packages used.
const
String
kDependencyChecksum
=
'# PUBSPEC CHECKSUM: '
;
...
...
@@ -1288,6 +1383,28 @@ class PubspecDependency extends PubspecLine {
static
const
String
_sdkPrefix
=
' sdk: '
;
static
const
String
_gitPrefix
=
' git:'
;
PubspecDependency
copyWith
({
String
?
line
,
String
?
name
,
String
?
suffix
,
bool
?
isTransitive
,
DependencyKind
?
kind
,
String
?
version
,
String
?
sourcePath
,
bool
?
isDevDependency
,
})
{
return
PubspecDependency
(
line
??
this
.
line
,
name
??
this
.
name
,
suffix
??
this
.
suffix
,
isTransitive:
isTransitive
??
this
.
isTransitive
,
kind:
kind
??
this
.
kind
,
version:
version
??
this
.
version
,
sourcePath:
sourcePath
??
this
.
sourcePath
,
isDevDependency:
isDevDependency
??
this
.
isDevDependency
,
);
}
/// Whether the dependency points to a package in the Flutter SDK.
///
/// There are two ways one can point to a Flutter package:
...
...
@@ -1353,16 +1470,16 @@ class PubspecDependency extends PubspecLine {
/// This generates the entry for this dependency for the pubspec.yaml for the
/// fake package that we'll use to get the version numbers figured out.
///
/// When called with [
do
Upgrade] as [true], the version constrains will be set
/// to >= whatever the previous version was. If [
do
Upgrade] is [false], then
/// When called with [
allow
Upgrade] as [true], the version constrains will be set
/// to >= whatever the previous version was. If [
allow
Upgrade] is [false], then
/// the previous version is used again as an exact pin.
void
describeForFakePubspec
(
StringBuffer
dependencies
,
StringBuffer
overrides
,
{
bool
do
Upgrade
=
true
})
{
void
describeForFakePubspec
(
StringBuffer
dependencies
,
StringBuffer
overrides
,
{
bool
allow
Upgrade
=
true
})
{
final
String
versionToUse
;
// This should only happen when manually adding new dependencies; otherwise
// versions should always be pinned exactly
if
(
version
.
isEmpty
||
version
==
'any'
)
{
versionToUse
=
'any'
;
}
else
if
(
do
Upgrade
)
{
}
else
if
(
allow
Upgrade
)
{
// Must wrap in quotes for Yaml parsing
versionToUse
=
"'>=
$version
'"
;
}
else
{
...
...
@@ -1445,7 +1562,7 @@ String generateFakePubspec(
// Don't add pinned dependency if it is not in the set of all transitive dependencies.
if
(!
allTransitive
.
contains
(
package
))
{
if
(
verbose
)
{
globals
.
printStatus
(
'
Skipping
$package
because it was not transitive
'
);
globals
.
printStatus
(
'
-
$package
:
$version
(skipped because it was not a transitive dependency)
'
);
}
return
;
}
...
...
@@ -1457,7 +1574,7 @@ String generateFakePubspec(
}
for
(
final
PubspecDependency
dependency
in
dependencies
)
{
if
(!
dependency
.
pointsToSdk
)
{
dependency
.
describeForFakePubspec
(
result
,
overrides
,
do
Upgrade:
doUpgrade
);
dependency
.
describeForFakePubspec
(
result
,
overrides
,
allow
Upgrade:
doUpgrade
);
}
}
result
.
write
(
overrides
.
toString
());
...
...
packages/flutter_tools/test/commands.shard/hermetic/update_packages_test.dart
View file @
8c5a70f3
...
...
@@ -197,6 +197,73 @@ void main() {
Logger:
()
=>
logger
,
});
testUsingContext
(
'--cherry-pick-package'
,
()
async
{
final
UpdatePackagesCommand
command
=
UpdatePackagesCommand
();
await
createTestCommandRunner
(
command
).
run
(<
String
>[
'update-packages'
,
'--cherry-pick-package=vector_math'
,
'--cherry-pick-version=2.0.9'
,
]);
expect
(
pub
.
pubGetDirectories
,
equals
(<
String
>[
'/.tmp_rand0/flutter_update_packages.rand0/synthetic_package'
,
'/flutter/examples'
,
'/flutter/packages/flutter'
,
]));
expect
(
pub
.
pubBatchDirectories
,
equals
(<
String
>[
'/.tmp_rand0/flutter_update_packages.rand0/synthetic_package'
,
]));
expect
(
pub
.
pubspecYamls
,
hasLength
(
3
));
final
String
output
=
pub
.
pubspecYamls
.
first
;
expect
(
output
,
isNotNull
);
expect
(
output
,
contains
(
'collection: 1.14.11
\n
'
));
expect
(
output
,
contains
(
'meta: 1.1.8
\n
'
));
expect
(
output
,
contains
(
'typed_data: 1.1.6
\n
'
));
expect
(
output
,
contains
(
'vector_math: 2.0.9
\n
'
));
expect
(
output
,
isNot
(
contains
(
'vector_math: 2.0.8'
)));
expect
(
output
,
isNot
(
contains
(
'vector_math: ">= 2.0.8"'
)));
expect
(
output
,
isNot
(
contains
(
"vector_math: '>= 2.0.8'"
)));
},
overrides:
<
Type
,
Generator
>{
Pub:
()
=>
pub
,
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
processManager
,
Cache:
()
=>
Cache
.
test
(
processManager:
processManager
,
),
Logger:
()
=>
logger
,
});
testUsingContext
(
'--force-upgrade'
,
()
async
{
final
UpdatePackagesCommand
command
=
UpdatePackagesCommand
();
await
createTestCommandRunner
(
command
).
run
(<
String
>[
'update-packages'
,
'--force-upgrade'
,
]);
expect
(
pub
.
pubGetDirectories
,
equals
(<
String
>[
'/.tmp_rand0/flutter_update_packages.rand0/synthetic_package'
,
'/flutter/examples'
,
'/flutter/packages/flutter'
,
]));
expect
(
pub
.
pubBatchDirectories
,
equals
(<
String
>[
'/.tmp_rand0/flutter_update_packages.rand0/synthetic_package'
,
]));
expect
(
pub
.
pubspecYamls
,
hasLength
(
3
));
final
String
output
=
pub
.
pubspecYamls
.
first
;
expect
(
output
,
isNotNull
);
expect
(
output
,
contains
(
"collection: '>= 1.14.11'
\n
"
));
expect
(
output
,
contains
(
"meta: '>= 1.1.8'
\n
"
));
expect
(
output
,
contains
(
"typed_data: '>= 1.1.6'
\n
"
));
expect
(
output
,
contains
(
"vector_math: '>= 2.0.8'
\n
"
));
expect
(
output
,
isNot
(
contains
(
'vector_math: 2.0.8'
)));
},
overrides:
<
Type
,
Generator
>{
Pub:
()
=>
pub
,
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
processManager
,
Cache:
()
=>
Cache
.
test
(
processManager:
processManager
,
),
Logger:
()
=>
logger
,
});
testUsingContext
(
'force updates packages --synthetic-package-path'
,
()
async
{
final
UpdatePackagesCommand
command
=
UpdatePackagesCommand
();
const
String
dir
=
'/path/to/synthetic/package'
;
...
...
@@ -272,6 +339,7 @@ class FakePub extends Fake implements Pub {
final
FileSystem
fileSystem
;
final
List
<
String
>
pubGetDirectories
=
<
String
>[];
final
List
<
String
>
pubBatchDirectories
=
<
String
>[];
final
List
<
String
>
pubspecYamls
=
<
String
>[];
@override
Future
<
void
>
get
({
...
...
@@ -287,6 +355,7 @@ class FakePub extends Fake implements Pub {
PubOutputMode
outputMode
=
PubOutputMode
.
all
,
})
async
{
pubGetDirectories
.
add
(
project
.
directory
.
path
);
pubspecYamls
.
add
(
project
.
directory
.
childFile
(
'pubspec.yaml'
).
readAsStringSync
());
project
.
directory
.
childFile
(
'pubspec.lock'
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
'''
...
...
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