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
ddfcda73
Unverified
Commit
ddfcda73
authored
Aug 31, 2022
by
Gary Qian
Committed by
GitHub
Aug 31, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track platform in MigratePlaformConfig and enforce metadata file being provided (#110540)
parent
0508a1de
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
29 deletions
+61
-29
flutter_project_metadata.dart
packages/flutter_tools/lib/src/flutter_project_metadata.dart
+46
-25
migrate_config_test.dart
...ter_tools/test/integration.shard/migrate_config_test.dart
+15
-4
No files found.
packages/flutter_tools/lib/src/flutter_project_metadata.dart
View file @
ddfcda73
...
...
@@ -72,22 +72,21 @@ FlutterProjectType? stringToProjectType(String value) {
/// A wrapper around the `.metadata` file.
class
FlutterProjectMetadata
{
/// Creates a MigrateConfig by parsing an existing .migrate_config yaml file.
FlutterProjectMetadata
(
File
file
,
Logger
logger
)
:
_metadataFile
=
file
,
_logger
=
logger
,
FlutterProjectMetadata
(
this
.
file
,
Logger
logger
)
:
_logger
=
logger
,
migrateConfig
=
MigrateConfig
()
{
if
(!
_metadataF
ile
.
existsSync
())
{
_logger
.
printTrace
(
'No .metadata file found at
${
_metadataF
ile.path}
.'
);
if
(!
f
ile
.
existsSync
())
{
_logger
.
printTrace
(
'No .metadata file found at
${
f
ile.path}
.'
);
// Create a default empty metadata.
return
;
}
Object
?
yamlRoot
;
try
{
yamlRoot
=
loadYaml
(
_metadataF
ile
.
readAsStringSync
());
yamlRoot
=
loadYaml
(
f
ile
.
readAsStringSync
());
}
on
YamlException
{
// Handled in _validate below.
}
if
(
yamlRoot
is
!
YamlMap
)
{
_logger
.
printTrace
(
'.metadata file at
${
_metadataF
ile.path}
was empty or malformed.'
);
_logger
.
printTrace
(
'.metadata file at
${
f
ile.path}
was empty or malformed.'
);
return
;
}
if
(
_validateMetadataMap
(
yamlRoot
,
<
String
,
Type
>{
'version'
:
YamlMap
},
_logger
))
{
...
...
@@ -109,9 +108,9 @@ class FlutterProjectMetadata {
}
}
/// Creates a
MigrateConfig
by explicitly providing all values.
/// Creates a
FlutterProjectMetadata
by explicitly providing all values.
FlutterProjectMetadata
.
explicit
({
required
File
file
,
required
this
.
file
,
required
String
?
versionRevision
,
required
String
?
versionChannel
,
required
FlutterProjectType
?
projectType
,
...
...
@@ -120,8 +119,7 @@ class FlutterProjectMetadata {
})
:
_logger
=
logger
,
_versionChannel
=
versionChannel
,
_versionRevision
=
versionRevision
,
_projectType
=
projectType
,
_metadataFile
=
file
;
_projectType
=
projectType
;
/// The name of the config file.
static
const
String
kFileName
=
'.metadata'
;
...
...
@@ -140,17 +138,27 @@ class FlutterProjectMetadata {
final
Logger
_logger
;
final
File
_metadataF
ile
;
final
File
f
ile
;
/// Writes the .migrate_config file in the provided project directory's platform subdirectory.
///
/// We write the file manually instead of with a template because this
/// needs to be able to write the .migrate_config file into legacy apps.
void
writeFile
({
File
?
outputFile
})
{
outputFile
=
outputFile
??
_metadataFile
;
outputFile
=
outputFile
??
file
;
if
(
outputFile
==
null
)
{
// In-memory FlutterProjectMetadata instances requires an output file to
// be passed or specified in the constructor.
throw
const
FileSystemException
(
'No outputFile specified to write .metadata to. Initialize with a file or provide one when writing.'
);
}
outputFile
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
'''
..
writeAsStringSync
(
toString
(),
flush:
true
);
}
@override
String
toString
()
{
return
'''
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
...
...
@@ -161,13 +169,12 @@ version:
channel:
$_versionChannel
project_type:
${flutterProjectTypeToString(projectType)}
${migrateConfig.getOutputFileString()}
'''
,
flush:
true
);
${migrateConfig.getOutputFileString()}
'''
;
}
void
populate
({
List
<
SupportedPlatform
>?
platforms
,
Directory
?
projectDirectory
,
required
Directory
projectDirectory
,
String
?
currentRevision
,
String
?
createRevision
,
bool
create
=
true
,
...
...
@@ -205,11 +212,11 @@ ${migrateConfig.getOutputFileString()}''',
class
MigrateConfig
{
MigrateConfig
({
Map
<
SupportedPlatform
,
MigratePlatformConfig
>?
platformConfigs
,
this
.
unmanagedFiles
=
_
kDefaultUnmanagedFiles
this
.
unmanagedFiles
=
kDefaultUnmanagedFiles
})
:
platformConfigs
=
platformConfigs
??
<
SupportedPlatform
,
MigratePlatformConfig
>{};
/// A mapping of the files that are unmanaged by defult for each platform.
static
const
List
<
String
>
_
kDefaultUnmanagedFiles
=
<
String
>[
static
const
List
<
String
>
kDefaultUnmanagedFiles
=
<
String
>[
'lib/main.dart'
,
'ios/Runner.xcodeproj/project.pbxproj'
,
];
...
...
@@ -222,20 +229,20 @@ class MigrateConfig {
/// These files are typically user-owned files that should not be changed.
List
<
String
>
unmanagedFiles
;
bool
get
isEmpty
=>
platformConfigs
.
isEmpty
&&
(
unmanagedFiles
.
isEmpty
||
unmanagedFiles
==
_
kDefaultUnmanagedFiles
);
bool
get
isEmpty
=>
platformConfigs
.
isEmpty
&&
(
unmanagedFiles
.
isEmpty
||
unmanagedFiles
==
kDefaultUnmanagedFiles
);
/// Parses the project for all supported platforms and populates the [MigrateConfig]
/// to reflect the project.
void
populate
({
List
<
SupportedPlatform
>?
platforms
,
Directory
?
projectDirectory
,
required
Directory
projectDirectory
,
String
?
currentRevision
,
String
?
createRevision
,
bool
create
=
true
,
bool
update
=
true
,
required
Logger
logger
,
})
{
final
FlutterProject
flutterProject
=
projectDirectory
==
null
?
FlutterProject
.
current
()
:
FlutterProject
.
fromDirectory
(
projectDirectory
);
final
FlutterProject
flutterProject
=
FlutterProject
.
fromDirectory
(
projectDirectory
);
platforms
??=
flutterProject
.
getSupportedPlatforms
(
includeRoot:
true
);
for
(
final
SupportedPlatform
platform
in
platforms
)
{
...
...
@@ -245,7 +252,7 @@ class MigrateConfig {
}
}
else
{
if
(
create
)
{
platformConfigs
[
platform
]
=
MigratePlatformConfig
(
createRevision:
createRevision
,
baseRevision:
currentRevision
);
platformConfigs
[
platform
]
=
MigratePlatformConfig
(
platform:
platform
,
createRevision:
createRevision
,
baseRevision:
currentRevision
);
}
}
}
...
...
@@ -290,10 +297,11 @@ migration:
'create_revision'
:
String
,
'base_revision'
:
String
,
},
logger
))
{
final
SupportedPlatform
platform
String
=
SupportedPlatform
.
values
.
firstWhere
(
final
SupportedPlatform
platform
Value
=
SupportedPlatform
.
values
.
firstWhere
(
(
SupportedPlatform
val
)
=>
val
.
toString
()
==
'SupportedPlatform.
${platformYamlMap['platform'] as String}
'
);
platformConfigs
[
platformString
]
=
MigratePlatformConfig
(
platformConfigs
[
platformValue
]
=
MigratePlatformConfig
(
platform:
platformValue
,
createRevision:
platformYamlMap
[
'create_revision'
]
as
String
?,
baseRevision:
platformYamlMap
[
'base_revision'
]
as
String
?,
);
...
...
@@ -315,7 +323,14 @@ migration:
/// Holds the revisions for a single platform for use by the flutter migrate command.
class
MigratePlatformConfig
{
MigratePlatformConfig
({
this
.
createRevision
,
this
.
baseRevision
});
MigratePlatformConfig
({
required
this
.
platform
,
this
.
createRevision
,
this
.
baseRevision
});
/// The platform this config describes.
SupportedPlatform
platform
;
/// The Flutter SDK revision this platform was created by.
///
...
...
@@ -326,4 +341,10 @@ class MigratePlatformConfig {
///
/// Null if the project was never migrated or the revision is unknown.
String
?
baseRevision
;
bool
equals
(
MigratePlatformConfig
other
)
{
return
platform
==
other
.
platform
&&
createRevision
==
other
.
createRevision
&&
baseRevision
==
other
.
baseRevision
;
}
}
packages/flutter_tools/test/integration.shard/migrate_config_test.dart
View file @
ddfcda73
...
...
@@ -105,10 +105,10 @@ project_type: app
const
String
testBaseRevision
=
'testanas9anlnq9ba7bjhavan3kma'
;
MigrateConfig
config
=
MigrateConfig
(
platformConfigs:
<
SupportedPlatform
,
MigratePlatformConfig
>{
SupportedPlatform
.
android
:
MigratePlatformConfig
(
createRevision:
testCreateRevision
,
baseRevision:
testBaseRevision
),
SupportedPlatform
.
ios
:
MigratePlatformConfig
(
createRevision:
testCreateRevision
,
baseRevision:
testBaseRevision
),
SupportedPlatform
.
root
:
MigratePlatformConfig
(
createRevision:
testCreateRevision
,
baseRevision:
testBaseRevision
),
SupportedPlatform
.
windows
:
MigratePlatformConfig
(
createRevision:
testCreateRevision
,
baseRevision:
testBaseRevision
),
SupportedPlatform
.
android
:
MigratePlatformConfig
(
platform:
SupportedPlatform
.
android
,
createRevision:
testCreateRevision
,
baseRevision:
testBaseRevision
),
SupportedPlatform
.
ios
:
MigratePlatformConfig
(
platform:
SupportedPlatform
.
ios
,
createRevision:
testCreateRevision
,
baseRevision:
testBaseRevision
),
SupportedPlatform
.
root
:
MigratePlatformConfig
(
platform:
SupportedPlatform
.
root
,
createRevision:
testCreateRevision
,
baseRevision:
testBaseRevision
),
SupportedPlatform
.
windows
:
MigratePlatformConfig
(
platform:
SupportedPlatform
.
windows
,
createRevision:
testCreateRevision
,
baseRevision:
testBaseRevision
),
},
unmanagedFiles:
<
String
>[
'lib/main.dart'
,
...
...
@@ -224,4 +224,15 @@ migration:
- '
ios
/
Runner
.
xcodeproj
/
project
.
pbxproj
'
'''
));
});
testUsingContext
(
'equality compares platform'
,
()
async
{
const
String
testCreateRevision
=
'testmc9skl32nlnf23lnakcs9njr3'
;
const
String
testBaseRevision
=
'testanas9anlnq9ba7bjhavan3kma'
;
final
MigratePlatformConfig
configAndroid
=
MigratePlatformConfig
(
platform:
SupportedPlatform
.
android
,
createRevision:
testCreateRevision
,
baseRevision:
testBaseRevision
);
final
MigratePlatformConfig
configIos
=
MigratePlatformConfig
(
platform:
SupportedPlatform
.
ios
,
createRevision:
testCreateRevision
,
baseRevision:
testBaseRevision
);
expect
(
configAndroid
.
equals
(
configIos
),
false
);
expect
(
configAndroid
.
equals
(
configAndroid
),
true
);
expect
(
configIos
.
equals
(
configIos
),
true
);
});
}
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