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
586b15cb
Unverified
Commit
586b15cb
authored
May 19, 2022
by
Christopher Fujino
Committed by
GitHub
May 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] Upgrade only from flutter update-packages (#103924)
parent
aa35c85e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
8 deletions
+66
-8
update_packages.dart
packages/flutter_tools/lib/src/commands/update_packages.dart
+24
-8
update_packages_test.dart
...ls/test/commands.shard/hermetic/update_packages_test.dart
+42
-0
No files found.
packages/flutter_tools/lib/src/commands/update_packages.dart
View file @
586b15cb
...
@@ -382,9 +382,9 @@ class UpdatePackagesCommand extends FlutterCommand {
...
@@ -382,9 +382,9 @@ class UpdatePackagesCommand extends FlutterCommand {
final
File
fakePackage
=
_pubspecFor
(
tempDir
);
final
File
fakePackage
=
_pubspecFor
(
tempDir
);
fakePackage
.
createSync
();
fakePackage
.
createSync
();
fakePackage
.
writeAsStringSync
(
fakePackage
.
writeAsStringSync
(
_
generateFakePubspec
(
generateFakePubspec
(
dependencies
,
dependencies
,
useAnyVersion
:
doUpgrade
,
doUpgrade
:
doUpgrade
,
),
),
);
);
// Create a synthetic flutter SDK so that transitive flutter SDK
// Create a synthetic flutter SDK so that transitive flutter SDK
...
@@ -1321,8 +1321,22 @@ class PubspecDependency extends PubspecLine {
...
@@ -1321,8 +1321,22 @@ class PubspecDependency extends PubspecLine {
/// This generates the entry for this dependency for the pubspec.yaml for the
/// 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.
/// fake package that we'll use to get the version numbers figured out.
void
describeForFakePubspec
(
StringBuffer
dependencies
,
StringBuffer
overrides
,
{
bool
useAnyVersion
=
true
})
{
///
final
String
versionToUse
=
useAnyVersion
||
version
.
isEmpty
?
'any'
:
version
;
/// When called with [doUpgrade] as [true], the version constrains will be set
/// to >= whatever the previous version was. If [doUpgrade] is [false], then
/// the previous version is used again as an exact pin.
void
describeForFakePubspec
(
StringBuffer
dependencies
,
StringBuffer
overrides
,
{
bool
doUpgrade
=
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
(
doUpgrade
)
{
// Must wrap in quotes for Yaml parsing
versionToUse
=
"'>=
$version
'"
;
}
else
{
versionToUse
=
version
;
}
switch
(
kind
)
{
switch
(
kind
)
{
case
DependencyKind
.
unknown
:
case
DependencyKind
.
unknown
:
case
DependencyKind
.
overridden
:
case
DependencyKind
.
overridden
:
...
@@ -1362,6 +1376,7 @@ class PubspecDependency extends PubspecLine {
...
@@ -1362,6 +1376,7 @@ class PubspecDependency extends PubspecLine {
dependencies
.
writeln
(
'
$name
:'
);
dependencies
.
writeln
(
'
$name
:'
);
dependencies
.
writeln
(
lockLine
);
dependencies
.
writeln
(
lockLine
);
}
}
break
;
}
}
}
}
...
@@ -1379,13 +1394,14 @@ File _pubspecFor(Directory directory) {
...
@@ -1379,13 +1394,14 @@ File _pubspecFor(Directory directory) {
/// Generates the source of a fake pubspec.yaml file given a list of
/// Generates the source of a fake pubspec.yaml file given a list of
/// dependencies.
/// dependencies.
String
_generateFakePubspec
(
@visibleForTesting
String
generateFakePubspec
(
Iterable
<
PubspecDependency
>
dependencies
,
{
Iterable
<
PubspecDependency
>
dependencies
,
{
bool
useAnyVersion
=
false
bool
doUpgrade
=
false
})
{
})
{
final
StringBuffer
result
=
StringBuffer
();
final
StringBuffer
result
=
StringBuffer
();
final
StringBuffer
overrides
=
StringBuffer
();
final
StringBuffer
overrides
=
StringBuffer
();
final
bool
verbose
=
useAnyVersion
;
final
bool
verbose
=
doUpgrade
;
result
.
writeln
(
'name: flutter_update_packages'
);
result
.
writeln
(
'name: flutter_update_packages'
);
result
.
writeln
(
'environment:'
);
result
.
writeln
(
'environment:'
);
result
.
writeln
(
" sdk: '>=2.10.0 <3.0.0'"
);
result
.
writeln
(
" sdk: '>=2.10.0 <3.0.0'"
);
...
@@ -1415,7 +1431,7 @@ String _generateFakePubspec(
...
@@ -1415,7 +1431,7 @@ String _generateFakePubspec(
}
}
for
(
final
PubspecDependency
dependency
in
dependencies
)
{
for
(
final
PubspecDependency
dependency
in
dependencies
)
{
if
(!
dependency
.
pointsToSdk
)
{
if
(!
dependency
.
pointsToSdk
)
{
dependency
.
describeForFakePubspec
(
result
,
overrides
,
useAnyVersion:
useAnyVersion
);
dependency
.
describeForFakePubspec
(
result
,
overrides
,
doUpgrade:
doUpgrade
);
}
}
}
}
result
.
write
(
overrides
.
toString
());
result
.
write
(
overrides
.
toString
());
...
...
packages/flutter_tools/test/commands.shard/hermetic/update_packages_test.dart
View file @
586b15cb
...
@@ -12,6 +12,7 @@ import 'package:flutter_tools/src/commands/update_packages.dart';
...
@@ -12,6 +12,7 @@ import 'package:flutter_tools/src/commands/update_packages.dart';
import
'package:flutter_tools/src/dart/pub.dart'
;
import
'package:flutter_tools/src/dart/pub.dart'
;
import
'package:meta/meta.dart'
;
import
'package:meta/meta.dart'
;
import
'package:test/fake.dart'
;
import
'package:test/fake.dart'
;
import
'package:yaml/yaml.dart'
;
import
'../../src/common.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/context.dart'
;
...
@@ -173,6 +174,47 @@ void main() {
...
@@ -173,6 +174,47 @@ void main() {
),
),
});
});
});
});
group
(
'generateFakePubspec'
,
()
{
const
String
prevVersion
=
'1.2.0'
;
testUsingContext
(
'constrains package versions to >= previous version if doUpgrade: true'
,
()
{
final
String
pubspecSource
=
generateFakePubspec
(
<
PubspecDependency
>[
PubspecDependency
(
' foo:
$prevVersion
'
,
'foo'
,
''
,
version:
prevVersion
,
sourcePath:
'/path/to/pubspec.yaml'
,
kind:
DependencyKind
.
normal
,
isTransitive:
false
,
),
],
doUpgrade:
true
,
);
final
YamlMap
pubspec
=
loadYaml
(
pubspecSource
)
as
YamlMap
;
expect
((
pubspec
[
'dependencies'
]
as
YamlMap
)[
'foo'
],
'>=
$prevVersion
'
);
});
testUsingContext
(
'uses previous package versions doUpgrade: false'
,
()
{
final
String
pubspecSource
=
generateFakePubspec
(
<
PubspecDependency
>[
PubspecDependency
(
' foo:
$prevVersion
'
,
'foo'
,
''
,
version:
prevVersion
,
sourcePath:
'/path/to/pubspec.yaml'
,
kind:
DependencyKind
.
normal
,
isTransitive:
false
,
),
],
doUpgrade:
false
,
);
final
YamlMap
pubspec
=
loadYaml
(
pubspecSource
)
as
YamlMap
;
expect
((
pubspec
[
'dependencies'
]
as
YamlMap
)[
'foo'
],
prevVersion
);
});
});
}
}
class
FakePub
extends
Fake
implements
Pub
{
class
FakePub
extends
Fake
implements
Pub
{
...
...
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