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
a0be9802
Unverified
Commit
a0be9802
authored
Jan 19, 2021
by
Jonah Williams
Committed by
GitHub
Jan 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] ensure pub get can run from partially valid state (#74249)
parent
7a413e71
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
5 deletions
+120
-5
packages.dart
packages/flutter_tools/lib/src/commands/packages.dart
+9
-2
plugins.dart
packages/flutter_tools/lib/src/plugins.dart
+2
-1
project.dart
packages/flutter_tools/lib/src/project.dart
+6
-0
pub_get_test.dart
...tter_tools/test/commands.shard/hermetic/pub_get_test.dart
+101
-0
migrate_test.dart
...es/flutter_tools/test/integration.shard/migrate_test.dart
+2
-2
No files found.
packages/flutter_tools/lib/src/commands/packages.dart
View file @
a0be9802
...
@@ -76,6 +76,8 @@ class PackagesGetCommand extends FlutterCommand {
...
@@ -76,6 +76,8 @@ class PackagesGetCommand extends FlutterCommand {
return
'
${runner.executableName}
pub
$name
[<target directory>]'
;
return
'
${runner.executableName}
pub
$name
[<target directory>]'
;
}
}
/// The pub packages usage values are incorrect since these are calculated/sent
/// before pub get completes. This needs to be performed after dependency resolution.
@override
@override
Future
<
Map
<
CustomDimensions
,
String
>>
get
usageValues
async
{
Future
<
Map
<
CustomDimensions
,
String
>>
get
usageValues
async
{
final
Map
<
CustomDimensions
,
String
>
usageValues
=
<
CustomDimensions
,
String
>{};
final
Map
<
CustomDimensions
,
String
>
usageValues
=
<
CustomDimensions
,
String
>{};
...
@@ -85,9 +87,14 @@ class PackagesGetCommand extends FlutterCommand {
...
@@ -85,9 +87,14 @@ class PackagesGetCommand extends FlutterCommand {
return
usageValues
;
return
usageValues
;
}
}
final
FlutterProject
rootProject
=
FlutterProject
.
fromPath
(
target
);
final
FlutterProject
rootProject
=
FlutterProject
.
fromPath
(
target
);
final
bool
hasPlugins
=
rootProject
.
flutterPluginsDependenciesFile
.
existsSync
();
// Do not send plugin analytics if pub has not run before.
final
bool
hasPlugins
=
rootProject
.
flutterPluginsDependenciesFile
.
existsSync
()
&&
rootProject
.
packagesFile
.
existsSync
()
&&
rootProject
.
packageConfigFile
.
existsSync
();
if
(
hasPlugins
)
{
if
(
hasPlugins
)
{
final
List
<
Plugin
>
plugins
=
await
findPlugins
(
rootProject
);
// Do not fail pub get if package config files are invalid before pub has
// had a chance to run.
final
List
<
Plugin
>
plugins
=
await
findPlugins
(
rootProject
,
throwOnError:
false
);
usageValues
[
CustomDimensions
.
commandPackagesNumberPlugins
]
=
plugins
.
length
.
toString
();
usageValues
[
CustomDimensions
.
commandPackagesNumberPlugins
]
=
plugins
.
length
.
toString
();
}
else
{
}
else
{
usageValues
[
CustomDimensions
.
commandPackagesNumberPlugins
]
=
'0'
;
usageValues
[
CustomDimensions
.
commandPackagesNumberPlugins
]
=
'0'
;
...
...
packages/flutter_tools/lib/src/plugins.dart
View file @
a0be9802
...
@@ -345,7 +345,7 @@ Plugin _pluginFromPackage(String name, Uri packageRoot) {
...
@@ -345,7 +345,7 @@ Plugin _pluginFromPackage(String name, Uri packageRoot) {
);
);
}
}
Future
<
List
<
Plugin
>>
findPlugins
(
FlutterProject
project
)
async
{
Future
<
List
<
Plugin
>>
findPlugins
(
FlutterProject
project
,
{
bool
throwOnError
=
true
}
)
async
{
final
List
<
Plugin
>
plugins
=
<
Plugin
>[];
final
List
<
Plugin
>
plugins
=
<
Plugin
>[];
final
String
packagesFile
=
globals
.
fs
.
path
.
join
(
final
String
packagesFile
=
globals
.
fs
.
path
.
join
(
project
.
directory
.
path
,
project
.
directory
.
path
,
...
@@ -354,6 +354,7 @@ Future<List<Plugin>> findPlugins(FlutterProject project) async {
...
@@ -354,6 +354,7 @@ Future<List<Plugin>> findPlugins(FlutterProject project) async {
final
PackageConfig
packageConfig
=
await
loadPackageConfigWithLogging
(
final
PackageConfig
packageConfig
=
await
loadPackageConfigWithLogging
(
globals
.
fs
.
file
(
packagesFile
),
globals
.
fs
.
file
(
packagesFile
),
logger:
globals
.
logger
,
logger:
globals
.
logger
,
throwOnError:
throwOnError
,
);
);
for
(
final
Package
package
in
packageConfig
.
packages
)
{
for
(
final
Package
package
in
packageConfig
.
packages
)
{
final
Uri
packageRoot
=
package
.
packageUriRoot
.
resolve
(
'..'
);
final
Uri
packageRoot
=
package
.
packageUriRoot
.
resolve
(
'..'
);
...
...
packages/flutter_tools/lib/src/project.dart
View file @
a0be9802
...
@@ -162,6 +162,12 @@ class FlutterProject {
...
@@ -162,6 +162,12 @@ class FlutterProject {
/// The `.packages` file of this project.
/// The `.packages` file of this project.
File
get
packagesFile
=>
directory
.
childFile
(
'.packages'
);
File
get
packagesFile
=>
directory
.
childFile
(
'.packages'
);
/// The `package_config.json` file of the project.
///
/// This is the replacement for .packages which contains language
/// version information.
File
get
packageConfigFile
=>
directory
.
childDirectory
(
'.dart_tool'
).
childFile
(
'package_config.json'
);
/// The `.metadata` file of this project.
/// The `.metadata` file of this project.
File
get
metadataFile
=>
directory
.
childFile
(
'.metadata'
);
File
get
metadataFile
=>
directory
.
childFile
(
'.metadata'
);
...
...
packages/flutter_tools/test/commands.shard/hermetic/pub_get_test.dart
0 → 100644
View file @
a0be9802
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:args/command_runner.dart'
;
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/commands/packages.dart'
;
import
'package:flutter_tools/src/dart/pub.dart'
;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:meta/meta.dart'
;
import
'package:test/fake.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
void
main
(
)
{
FileSystem
fileSystem
;
FakePub
pub
;
setUp
(()
{
Cache
.
disableLocking
();
fileSystem
=
MemoryFileSystem
.
test
();
pub
=
FakePub
(
fileSystem
);
});
tearDown
(()
{
Cache
.
enableLocking
();
});
testUsingContext
(
'pub get usage values are resilient to missing package config files before running "pub get"'
,
()
async
{
fileSystem
.
currentDirectory
.
childFile
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
currentDirectory
.
childFile
(
'.flutter-plugins'
).
createSync
();
fileSystem
.
currentDirectory
.
childFile
(
'.flutter-plugins-dependencies'
).
createSync
();
final
PackagesGetCommand
command
=
PackagesGetCommand
(
'get'
,
false
);
final
CommandRunner
<
void
>
commandRunner
=
createTestCommandRunner
(
command
);
await
commandRunner
.
run
(<
String
>[
'get'
]);
expect
(
await
command
.
usageValues
,
<
CustomDimensions
,
Object
>{
CustomDimensions
.
commandPackagesNumberPlugins
:
'0'
,
CustomDimensions
.
commandPackagesProjectModule
:
'false'
,
CustomDimensions
.
commandPackagesAndroidEmbeddingVersion
:
'v1'
});
},
overrides:
<
Type
,
Generator
>{
Pub:
()
=>
pub
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
FileSystem:
()
=>
fileSystem
,
});
testUsingContext
(
'pub get usage values are resilient to poorly formatted package config before "pub get"'
,
()
async
{
fileSystem
.
currentDirectory
.
childFile
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
currentDirectory
.
childFile
(
'.flutter-plugins'
).
createSync
();
fileSystem
.
currentDirectory
.
childFile
(
'.flutter-plugins-dependencies'
).
createSync
();
fileSystem
.
currentDirectory
.
childFile
(
'.packages'
).
writeAsBytesSync
(<
int
>[
0
]);
fileSystem
.
currentDirectory
.
childFile
(
'.dart_tool/package_config.json'
)
..
createSync
(
recursive:
true
)
..
writeAsBytesSync
(<
int
>[
0
]);
final
PackagesGetCommand
command
=
PackagesGetCommand
(
'get'
,
false
);
final
CommandRunner
<
void
>
commandRunner
=
createTestCommandRunner
(
command
);
await
commandRunner
.
run
(<
String
>[
'get'
]);
expect
(
await
command
.
usageValues
,
<
CustomDimensions
,
Object
>{
CustomDimensions
.
commandPackagesNumberPlugins
:
'0'
,
CustomDimensions
.
commandPackagesProjectModule
:
'false'
,
CustomDimensions
.
commandPackagesAndroidEmbeddingVersion
:
'v1'
});
},
overrides:
<
Type
,
Generator
>{
Pub:
()
=>
pub
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
FileSystem:
()
=>
fileSystem
,
});
}
class
FakePub
extends
Fake
implements
Pub
{
FakePub
(
this
.
fileSystem
);
final
FileSystem
fileSystem
;
@override
Future
<
void
>
get
({
@required
PubContext
context
,
String
directory
,
bool
skipIfAbsent
=
false
,
bool
upgrade
=
false
,
bool
offline
=
false
,
bool
generateSyntheticPackage
=
false
,
String
flutterRootOverride
,
bool
checkUpToDate
=
false
,
})
async
{
fileSystem
.
currentDirectory
.
childDirectory
(
'.dart_tool'
)
.
childFile
(
'package_config.json'
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
'{"configVersion":2,"packages":[]}'
);
}
}
packages/flutter_tools/test/integration.shard/migrate_test.dart
View file @
a0be9802
...
@@ -8,10 +8,10 @@ import 'package:flutter_tools/src/base/io.dart';
...
@@ -8,10 +8,10 @@ import 'package:flutter_tools/src/base/io.dart';
import
'../src/common.dart'
;
import
'../src/common.dart'
;
import
'test_utils.dart'
;
import
'test_utils.dart'
;
/// Verifies that `dart migrate` will run successfuly on the default `flutter create`
/// Verifies that `dart migrate` will run successful
l
y on the default `flutter create`
/// template.
/// template.
void
main
(
)
{
void
main
(
)
{
testWithoutContext
(
'dart migrate succeed
e
s on flutter create template'
,
()
async
{
testWithoutContext
(
'dart migrate succeeds on flutter create template'
,
()
async
{
final
String
flutterBin
=
fileSystem
.
path
.
join
(
getFlutterRoot
(),
'bin'
,
platform
.
isWindows
?
'flutter.bat'
:
'flutter'
);
final
String
flutterBin
=
fileSystem
.
path
.
join
(
getFlutterRoot
(),
'bin'
,
platform
.
isWindows
?
'flutter.bat'
:
'flutter'
);
final
String
dartBin
=
fileSystem
.
path
.
join
(
getFlutterRoot
(),
'bin'
,
platform
.
isWindows
?
'dart.bat'
:
'dart'
);
final
String
dartBin
=
fileSystem
.
path
.
join
(
getFlutterRoot
(),
'bin'
,
platform
.
isWindows
?
'dart.bat'
:
'dart'
);
...
...
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