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
afbfc1f3
Unverified
Commit
afbfc1f3
authored
Oct 06, 2021
by
Jenn Magder
Committed by
GitHub
Oct 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate assets, common, icon_tree_shaker to null safety (#91309)
parent
79412662
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
113 additions
and
119 deletions
+113
-119
build_info.dart
packages/flutter_tools/lib/src/build_info.dart
+2
-3
assets.dart
...es/flutter_tools/lib/src/build_system/targets/assets.dart
+22
-22
common.dart
...es/flutter_tools/lib/src/build_system/targets/common.dart
+21
-18
icon_tree_shaker.dart
..._tools/lib/src/build_system/targets/icon_tree_shaker.dart
+55
-60
compile.dart
packages/flutter_tools/lib/src/compile.dart
+2
-2
assets_test.dart
.../test/general.shard/build_system/targets/assets_test.dart
+1
-1
icon_tree_shaker_test.dart
...ral.shard/build_system/targets/icon_tree_shaker_test.dart
+10
-13
No files found.
packages/flutter_tools/lib/src/build_info.dart
View file @
afbfc1f3
...
@@ -634,7 +634,7 @@ String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch? darwinArch
...
@@ -634,7 +634,7 @@ String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch? darwinArch
}
}
}
}
TargetPlatform
?
getTargetPlatformForName
(
String
platform
)
{
TargetPlatform
getTargetPlatformForName
(
String
platform
)
{
switch
(
platform
)
{
switch
(
platform
)
{
case
'android'
:
case
'android'
:
return
TargetPlatform
.
android
;
return
TargetPlatform
.
android
;
...
@@ -669,8 +669,7 @@ TargetPlatform? getTargetPlatformForName(String platform) {
...
@@ -669,8 +669,7 @@ TargetPlatform? getTargetPlatformForName(String platform) {
case
'web-javascript'
:
case
'web-javascript'
:
return
TargetPlatform
.
web_javascript
;
return
TargetPlatform
.
web_javascript
;
}
}
assert
(
platform
!=
null
);
throw
Exception
(
'Unsupported platform name "
$platform
"'
);
return
null
;
}
}
AndroidArch
getAndroidArchForName
(
String
platform
)
{
AndroidArch
getAndroidArchForName
(
String
platform
)
{
...
...
packages/flutter_tools/lib/src/build_system/targets/assets.dart
View file @
afbfc1f3
...
@@ -2,9 +2,6 @@
...
@@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'package:meta/meta.dart'
;
import
'package:pool/pool.dart'
;
import
'package:pool/pool.dart'
;
import
'../../asset.dart'
;
import
'../../asset.dart'
;
...
@@ -28,13 +25,13 @@ import 'icon_tree_shaker.dart';
...
@@ -28,13 +25,13 @@ import 'icon_tree_shaker.dart';
///
///
/// Returns a [Depfile] containing all assets used in the build.
/// Returns a [Depfile] containing all assets used in the build.
Future
<
Depfile
>
copyAssets
(
Environment
environment
,
Directory
outputDirectory
,
{
Future
<
Depfile
>
copyAssets
(
Environment
environment
,
Directory
outputDirectory
,
{
Map
<
String
,
DevFSContent
>
additionalContent
,
Map
<
String
,
DevFSContent
>
?
additionalContent
,
@
required
TargetPlatform
targetPlatform
,
required
TargetPlatform
targetPlatform
,
BuildMode
buildMode
,
BuildMode
?
buildMode
,
})
async
{
})
async
{
// Check for an SkSL bundle.
// Check for an SkSL bundle.
final
String
shaderBundlePath
=
environment
.
defines
[
kBundleSkSLPath
]
??
environment
.
inputs
[
kBundleSkSLPath
];
final
String
?
shaderBundlePath
=
environment
.
defines
[
kBundleSkSLPath
]
??
environment
.
inputs
[
kBundleSkSLPath
];
final
DevFSContent
skslBundle
=
processSkSLBundle
(
final
DevFSContent
?
skslBundle
=
processSkSLBundle
(
shaderBundlePath
,
shaderBundlePath
,
engineVersion:
environment
.
engineVersion
,
engineVersion:
environment
.
engineVersion
,
fileSystem:
environment
.
fileSystem
,
fileSystem:
environment
.
fileSystem
,
...
@@ -70,7 +67,7 @@ Future<Depfile> copyAssets(Environment environment, Directory outputDirectory, {
...
@@ -70,7 +67,7 @@ Future<Depfile> copyAssets(Environment environment, Directory outputDirectory, {
final
IconTreeShaker
iconTreeShaker
=
IconTreeShaker
(
final
IconTreeShaker
iconTreeShaker
=
IconTreeShaker
(
environment
,
environment
,
assetBundle
.
entries
[
kFontManifestJson
]
as
DevFSStringContent
,
assetBundle
.
entries
[
kFontManifestJson
]
as
DevFSStringContent
?
,
processManager:
environment
.
processManager
,
processManager:
environment
.
processManager
,
logger:
environment
.
logger
,
logger:
environment
.
logger
,
fileSystem:
environment
.
fileSystem
,
fileSystem:
environment
.
fileSystem
,
...
@@ -118,7 +115,7 @@ Future<Depfile> copyAssets(Environment environment, Directory outputDirectory, {
...
@@ -118,7 +115,7 @@ Future<Depfile> copyAssets(Environment environment, Directory outputDirectory, {
// Copy deferred components assets only for release or profile builds.
// Copy deferred components assets only for release or profile builds.
// The assets are included in assetBundle.entries as a normal asset when
// The assets are included in assetBundle.entries as a normal asset when
// building as debug.
// building as debug.
if
(
environment
.
defines
[
kDeferredComponents
]
==
'true'
)
{
if
(
environment
.
defines
[
kDeferredComponents
]
==
'true'
&&
buildMode
!=
null
)
{
await
Future
.
wait
<
void
>(
await
Future
.
wait
<
void
>(
assetBundle
.
deferredComponentsEntries
.
entries
.
map
<
Future
<
void
>>((
MapEntry
<
String
,
Map
<
String
,
DevFSContent
>>
componentEntries
)
async
{
assetBundle
.
deferredComponentsEntries
.
entries
.
map
<
Future
<
void
>>((
MapEntry
<
String
,
Map
<
String
,
DevFSContent
>>
componentEntries
)
async
{
final
Directory
componentOutputDir
=
final
Directory
componentOutputDir
=
...
@@ -185,11 +182,11 @@ const String kSkSLShaderBundlePath = 'io.flutter.shaders.json';
...
@@ -185,11 +182,11 @@ const String kSkSLShaderBundlePath = 'io.flutter.shaders.json';
///
///
/// If the current target platform is different than the platform constructed
/// If the current target platform is different than the platform constructed
/// for the bundle, a warning will be printed.
/// for the bundle, a warning will be printed.
DevFSContent
processSkSLBundle
(
String
bundlePath
,
{
DevFSContent
?
processSkSLBundle
(
String
?
bundlePath
,
{
@
required
TargetPlatform
targetPlatform
,
required
TargetPlatform
targetPlatform
,
@
required
FileSystem
fileSystem
,
required
FileSystem
fileSystem
,
@
required
Logger
logger
,
required
Logger
logger
,
@required
String
engineVersion
,
String
?
engineVersion
,
})
{
})
{
if
(
bundlePath
==
null
)
{
if
(
bundlePath
==
null
)
{
return
null
;
return
null
;
...
@@ -202,9 +199,9 @@ DevFSContent processSkSLBundle(String bundlePath, {
...
@@ -202,9 +199,9 @@ DevFSContent processSkSLBundle(String bundlePath, {
}
}
// Step 2: validate top level bundle structure.
// Step 2: validate top level bundle structure.
Map
<
String
,
Object
>
bundle
;
Map
<
String
,
Object
>
?
bundle
;
try
{
try
{
final
Object
rawBundle
=
json
.
decode
(
skSLBundleFile
.
readAsStringSync
());
final
Object
?
rawBundle
=
json
.
decode
(
skSLBundleFile
.
readAsStringSync
());
if
(
rawBundle
is
Map
<
String
,
Object
>)
{
if
(
rawBundle
is
Map
<
String
,
Object
>)
{
bundle
=
rawBundle
;
bundle
=
rawBundle
;
}
else
{
}
else
{
...
@@ -219,7 +216,7 @@ DevFSContent processSkSLBundle(String bundlePath, {
...
@@ -219,7 +216,7 @@ DevFSContent processSkSLBundle(String bundlePath, {
// * The engine revision the bundle was compiled with
// * The engine revision the bundle was compiled with
// is the same as the current revision.
// is the same as the current revision.
// * The target platform is the same (this one is a warning only).
// * The target platform is the same (this one is a warning only).
final
String
bundleEngineRevision
=
bundle
[
'engineRevision'
]
as
String
;
final
String
?
bundleEngineRevision
=
bundle
[
'engineRevision'
]
as
String
?
;
if
(
bundleEngineRevision
!=
engineVersion
)
{
if
(
bundleEngineRevision
!=
engineVersion
)
{
logger
.
printError
(
logger
.
printError
(
'Expected Flutter
$bundleEngineRevision
, but found
$engineVersion
\n
'
'Expected Flutter
$bundleEngineRevision
, but found
$engineVersion
\n
'
...
@@ -229,16 +226,19 @@ DevFSContent processSkSLBundle(String bundlePath, {
...
@@ -229,16 +226,19 @@ DevFSContent processSkSLBundle(String bundlePath, {
throw
Exception
(
'SkSL bundle was invalid'
);
throw
Exception
(
'SkSL bundle was invalid'
);
}
}
final
TargetPlatform
bundleTargetPlatform
=
getTargetPlatformForName
(
final
String
?
parsedPlatform
=
bundle
[
'platform'
]
as
String
?;
bundle
[
'platform'
]
as
String
);
TargetPlatform
?
bundleTargetPlatform
;
if
(
bundleTargetPlatform
!=
targetPlatform
)
{
if
(
parsedPlatform
!=
null
)
{
bundleTargetPlatform
=
getTargetPlatformForName
(
parsedPlatform
);
}
if
(
bundleTargetPlatform
==
null
||
bundleTargetPlatform
!=
targetPlatform
)
{
logger
.
printError
(
logger
.
printError
(
'The SkSL bundle was created for
$bundleTargetPlatform
, but the current '
'The SkSL bundle was created for
$bundleTargetPlatform
, but the current '
'platform is
$targetPlatform
. This may lead to less efficient shader '
'platform is
$targetPlatform
. This may lead to less efficient shader '
'caching.'
'caching.'
);
);
}
}
return
DevFSStringContent
(
json
.
encode
(<
String
,
Object
>{
return
DevFSStringContent
(
json
.
encode
(<
String
,
Object
?
>{
'data'
:
bundle
[
'data'
],
'data'
:
bundle
[
'data'
],
}));
}));
}
}
...
...
packages/flutter_tools/lib/src/build_system/targets/common.dart
View file @
afbfc1f3
...
@@ -2,8 +2,6 @@
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'package:package_config/package_config.dart'
;
import
'package:package_config/package_config.dart'
;
import
'../../artifacts.dart'
;
import
'../../artifacts.dart'
;
...
@@ -51,10 +49,11 @@ class CopyFlutterBundle extends Target {
...
@@ -51,10 +49,11 @@ class CopyFlutterBundle extends Target {
@override
@override
Future
<
void
>
build
(
Environment
environment
)
async
{
Future
<
void
>
build
(
Environment
environment
)
async
{
if
(
environment
.
defines
[
kBuildMode
]
==
null
)
{
final
String
?
buildModeEnvironment
=
environment
.
defines
[
kBuildMode
];
if
(
buildModeEnvironment
==
null
)
{
throw
MissingDefineException
(
kBuildMode
,
'copy_flutter_bundle'
);
throw
MissingDefineException
(
kBuildMode
,
'copy_flutter_bundle'
);
}
}
final
BuildMode
buildMode
=
getBuildModeForName
(
environment
.
defines
[
kBuildMode
]
);
final
BuildMode
buildMode
=
getBuildModeForName
(
buildModeEnvironment
);
environment
.
outputDir
.
createSync
(
recursive:
true
);
environment
.
outputDir
.
createSync
(
recursive:
true
);
// Only copy the prebuilt runtimes and kernel blob in debug mode.
// Only copy the prebuilt runtimes and kernel blob in debug mode.
...
@@ -157,13 +156,15 @@ class KernelSnapshot extends Target {
...
@@ -157,13 +156,15 @@ class KernelSnapshot extends Target {
fileSystemRoots:
<
String
>[],
fileSystemRoots:
<
String
>[],
fileSystemScheme:
null
,
fileSystemScheme:
null
,
);
);
if
(
environment
.
defines
[
kBuildMode
]
==
null
)
{
final
String
?
buildModeEnvironment
=
environment
.
defines
[
kBuildMode
];
if
(
buildModeEnvironment
==
null
)
{
throw
MissingDefineException
(
kBuildMode
,
'kernel_snapshot'
);
throw
MissingDefineException
(
kBuildMode
,
'kernel_snapshot'
);
}
}
if
(
environment
.
defines
[
kTargetPlatform
]
==
null
)
{
final
String
?
targetPlatformEnvironment
=
environment
.
defines
[
kTargetPlatform
];
if
(
targetPlatformEnvironment
==
null
)
{
throw
MissingDefineException
(
kTargetPlatform
,
'kernel_snapshot'
);
throw
MissingDefineException
(
kTargetPlatform
,
'kernel_snapshot'
);
}
}
final
BuildMode
buildMode
=
getBuildModeForName
(
environment
.
defines
[
kBuildMode
]
);
final
BuildMode
buildMode
=
getBuildModeForName
(
buildModeEnvironment
);
final
String
targetFile
=
environment
.
defines
[
kTargetFile
]
??
environment
.
fileSystem
.
path
.
join
(
'lib'
,
'main.dart'
);
final
String
targetFile
=
environment
.
defines
[
kTargetFile
]
??
environment
.
fileSystem
.
path
.
join
(
'lib'
,
'main.dart'
);
final
File
packagesFile
=
environment
.
projectDir
final
File
packagesFile
=
environment
.
projectDir
.
childDirectory
(
'.dart_tool'
)
.
childDirectory
(
'.dart_tool'
)
...
@@ -171,12 +172,12 @@ class KernelSnapshot extends Target {
...
@@ -171,12 +172,12 @@ class KernelSnapshot extends Target {
final
String
targetFileAbsolute
=
environment
.
fileSystem
.
file
(
targetFile
).
absolute
.
path
;
final
String
targetFileAbsolute
=
environment
.
fileSystem
.
file
(
targetFile
).
absolute
.
path
;
// everything besides 'false' is considered to be enabled.
// everything besides 'false' is considered to be enabled.
final
bool
trackWidgetCreation
=
environment
.
defines
[
kTrackWidgetCreation
]
!=
'false'
;
final
bool
trackWidgetCreation
=
environment
.
defines
[
kTrackWidgetCreation
]
!=
'false'
;
final
TargetPlatform
targetPlatform
=
getTargetPlatformForName
(
environment
.
defines
[
kTargetPlatform
]
);
final
TargetPlatform
targetPlatform
=
getTargetPlatformForName
(
targetPlatformEnvironment
);
// This configuration is all optional.
// This configuration is all optional.
final
List
<
String
>
extraFrontEndOptions
=
decodeCommaSeparated
(
environment
.
defines
,
kExtraFrontEndOptions
);
final
List
<
String
>
extraFrontEndOptions
=
decodeCommaSeparated
(
environment
.
defines
,
kExtraFrontEndOptions
);
final
List
<
String
>
fileSystemRoots
=
environment
.
defines
[
kFileSystemRoots
]?.
split
(
','
);
final
List
<
String
>
?
fileSystemRoots
=
environment
.
defines
[
kFileSystemRoots
]?.
split
(
','
);
final
String
fileSystemScheme
=
environment
.
defines
[
kFileSystemScheme
];
final
String
?
fileSystemScheme
=
environment
.
defines
[
kFileSystemScheme
];
TargetModel
targetModel
=
TargetModel
.
flutter
;
TargetModel
targetModel
=
TargetModel
.
flutter
;
if
(
targetPlatform
==
TargetPlatform
.
fuchsia_x64
||
if
(
targetPlatform
==
TargetPlatform
.
fuchsia_x64
||
...
@@ -202,7 +203,7 @@ class KernelSnapshot extends Target {
...
@@ -202,7 +203,7 @@ class KernelSnapshot extends Target {
logger:
environment
.
logger
,
logger:
environment
.
logger
,
);
);
final
CompilerOutput
output
=
await
compiler
.
compile
(
final
CompilerOutput
?
output
=
await
compiler
.
compile
(
sdkRoot:
environment
.
artifacts
.
getArtifactPath
(
sdkRoot:
environment
.
artifacts
.
getArtifactPath
(
Artifact
.
flutterPatchedSdkPath
,
Artifact
.
flutterPatchedSdkPath
,
platform:
targetPlatform
,
platform:
targetPlatform
,
...
@@ -244,23 +245,25 @@ abstract class AotElfBase extends Target {
...
@@ -244,23 +245,25 @@ abstract class AotElfBase extends Target {
reportTimings:
false
,
reportTimings:
false
,
fileSystem:
environment
.
fileSystem
,
fileSystem:
environment
.
fileSystem
,
logger:
environment
.
logger
,
logger:
environment
.
logger
,
xcode:
globals
.
xcode
,
xcode:
globals
.
xcode
!
,
processManager:
environment
.
processManager
,
processManager:
environment
.
processManager
,
artifacts:
environment
.
artifacts
,
artifacts:
environment
.
artifacts
,
);
);
final
String
outputPath
=
environment
.
buildDir
.
path
;
final
String
outputPath
=
environment
.
buildDir
.
path
;
if
(
environment
.
defines
[
kBuildMode
]
==
null
)
{
final
String
?
buildModeEnvironment
=
environment
.
defines
[
kBuildMode
];
if
(
buildModeEnvironment
==
null
)
{
throw
MissingDefineException
(
kBuildMode
,
'aot_elf'
);
throw
MissingDefineException
(
kBuildMode
,
'aot_elf'
);
}
}
if
(
environment
.
defines
[
kTargetPlatform
]
==
null
)
{
final
String
?
targetPlatformEnvironment
=
environment
.
defines
[
kTargetPlatform
];
if
(
targetPlatformEnvironment
==
null
)
{
throw
MissingDefineException
(
kTargetPlatform
,
'aot_elf'
);
throw
MissingDefineException
(
kTargetPlatform
,
'aot_elf'
);
}
}
final
List
<
String
>
extraGenSnapshotOptions
=
decodeCommaSeparated
(
environment
.
defines
,
kExtraGenSnapshotOptions
);
final
List
<
String
>
extraGenSnapshotOptions
=
decodeCommaSeparated
(
environment
.
defines
,
kExtraGenSnapshotOptions
);
final
BuildMode
buildMode
=
getBuildModeForName
(
environment
.
defines
[
kBuildMode
]
);
final
BuildMode
buildMode
=
getBuildModeForName
(
buildModeEnvironment
);
final
TargetPlatform
targetPlatform
=
getTargetPlatformForName
(
environment
.
defines
[
kTargetPlatform
]
);
final
TargetPlatform
targetPlatform
=
getTargetPlatformForName
(
targetPlatformEnvironment
);
final
String
splitDebugInfo
=
environment
.
defines
[
kSplitDebugInfo
];
final
String
?
splitDebugInfo
=
environment
.
defines
[
kSplitDebugInfo
];
final
bool
dartObfuscation
=
environment
.
defines
[
kDartObfuscation
]
==
'true'
;
final
bool
dartObfuscation
=
environment
.
defines
[
kDartObfuscation
]
==
'true'
;
final
String
codeSizeDirectory
=
environment
.
defines
[
kCodeSizeDirectory
];
final
String
?
codeSizeDirectory
=
environment
.
defines
[
kCodeSizeDirectory
];
if
(
codeSizeDirectory
!=
null
)
{
if
(
codeSizeDirectory
!=
null
)
{
final
File
codeSizeFile
=
environment
.
fileSystem
final
File
codeSizeFile
=
environment
.
fileSystem
...
...
packages/flutter_tools/lib/src/build_system/targets/icon_tree_shaker.dart
View file @
afbfc1f3
...
@@ -2,9 +2,6 @@
...
@@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'package:meta/meta.dart'
;
import
'package:mime/mime.dart'
as
mime
;
import
'package:mime/mime.dart'
as
mime
;
import
'package:process/process.dart'
;
import
'package:process/process.dart'
;
...
@@ -18,9 +15,9 @@ import '../../convert.dart';
...
@@ -18,9 +15,9 @@ import '../../convert.dart';
import
'../../devfs.dart'
;
import
'../../devfs.dart'
;
import
'../build_system.dart'
;
import
'../build_system.dart'
;
List
<
Map
<
String
,
dynamic
>>
_getList
(
dynamic
object
,
String
errorMessage
)
{
List
<
Map
<
String
,
Object
?>>
_getList
(
Object
?
object
,
String
errorMessage
)
{
if
(
object
is
List
<
dynamic
>)
{
if
(
object
is
List
<
Object
?
>)
{
return
object
.
cast
<
Map
<
String
,
dynamic
>>();
return
object
.
cast
<
Map
<
String
,
Object
?
>>();
}
}
throw
IconTreeShakerException
.
_
(
errorMessage
);
throw
IconTreeShakerException
.
_
(
errorMessage
);
}
}
...
@@ -39,11 +36,11 @@ class IconTreeShaker {
...
@@ -39,11 +36,11 @@ class IconTreeShaker {
/// font subsetting has been requested in a debug build mode.
/// font subsetting has been requested in a debug build mode.
IconTreeShaker
(
IconTreeShaker
(
this
.
_environment
,
this
.
_environment
,
DevFSStringContent
fontManifest
,
{
DevFSStringContent
?
fontManifest
,
{
@
required
ProcessManager
processManager
,
required
ProcessManager
processManager
,
@
required
Logger
logger
,
required
Logger
logger
,
@
required
FileSystem
fileSystem
,
required
FileSystem
fileSystem
,
@
required
Artifacts
artifacts
,
required
Artifacts
artifacts
,
})
:
assert
(
_environment
!=
null
),
})
:
assert
(
_environment
!=
null
),
assert
(
processManager
!=
null
),
assert
(
processManager
!=
null
),
assert
(
logger
!=
null
),
assert
(
logger
!=
null
),
...
@@ -81,9 +78,9 @@ class IconTreeShaker {
...
@@ -81,9 +78,9 @@ class IconTreeShaker {
];
];
final
Environment
_environment
;
final
Environment
_environment
;
final
String
_fontManifest
;
final
String
?
_fontManifest
;
Future
<
void
>
_iconDataProcessing
;
Future
<
void
>
?
_iconDataProcessing
;
Map
<
String
,
_IconTreeShakerData
>
_iconData
;
Map
<
String
,
_IconTreeShakerData
>
?
_iconData
;
final
ProcessManager
_processManager
;
final
ProcessManager
_processManager
;
final
Logger
_logger
;
final
Logger
_logger
;
...
@@ -120,7 +117,7 @@ class IconTreeShaker {
...
@@ -120,7 +117,7 @@ class IconTreeShaker {
final
Set
<
String
>
familyKeys
=
iconData
.
keys
.
toSet
();
final
Set
<
String
>
familyKeys
=
iconData
.
keys
.
toSet
();
final
Map
<
String
,
String
>
fonts
=
await
_parseFontJson
(
final
Map
<
String
,
String
>
fonts
=
await
_parseFontJson
(
_fontManifest
,
_fontManifest
!,
// Guarded by `enabled`.
familyKeys
,
familyKeys
,
);
);
...
@@ -137,10 +134,14 @@ class IconTreeShaker {
...
@@ -137,10 +134,14 @@ class IconTreeShaker {
final
Map
<
String
,
_IconTreeShakerData
>
result
=
<
String
,
_IconTreeShakerData
>{};
final
Map
<
String
,
_IconTreeShakerData
>
result
=
<
String
,
_IconTreeShakerData
>{};
for
(
final
MapEntry
<
String
,
String
>
entry
in
fonts
.
entries
)
{
for
(
final
MapEntry
<
String
,
String
>
entry
in
fonts
.
entries
)
{
final
List
<
int
>?
codePoints
=
iconData
[
entry
.
key
];
if
(
codePoints
==
null
)
{
throw
IconTreeShakerException
.
_
(
'Expected to font code points for
${entry.key}
, but none were found.'
);
}
result
[
entry
.
value
]
=
_IconTreeShakerData
(
result
[
entry
.
value
]
=
_IconTreeShakerData
(
family:
entry
.
key
,
family:
entry
.
key
,
relativePath:
entry
.
value
,
relativePath:
entry
.
value
,
codePoints:
iconData
[
entry
.
key
]
,
codePoints:
codePoints
,
);
);
}
}
_iconData
=
result
;
_iconData
=
result
;
...
@@ -156,9 +157,9 @@ class IconTreeShaker {
...
@@ -156,9 +157,9 @@ class IconTreeShaker {
/// If the font-subset subprocess fails, it will [throwToolExit].
/// If the font-subset subprocess fails, it will [throwToolExit].
/// Otherwise, it will return true.
/// Otherwise, it will return true.
Future
<
bool
>
subsetFont
({
Future
<
bool
>
subsetFont
({
@
required
File
input
,
required
File
input
,
@
required
String
outputPath
,
required
String
outputPath
,
@
required
String
relativePath
,
required
String
relativePath
,
})
async
{
})
async
{
if
(!
enabled
)
{
if
(!
enabled
)
{
return
false
;
return
false
;
...
@@ -166,7 +167,7 @@ class IconTreeShaker {
...
@@ -166,7 +167,7 @@ class IconTreeShaker {
if
(
input
.
lengthSync
()
<
12
)
{
if
(
input
.
lengthSync
()
<
12
)
{
return
false
;
return
false
;
}
}
final
String
mimeType
=
mime
.
lookupMimeType
(
final
String
?
mimeType
=
mime
.
lookupMimeType
(
input
.
path
,
input
.
path
,
headerBytes:
await
input
.
openRead
(
0
,
12
).
first
,
headerBytes:
await
input
.
openRead
(
0
,
12
).
first
,
);
);
...
@@ -176,7 +177,7 @@ class IconTreeShaker {
...
@@ -176,7 +177,7 @@ class IconTreeShaker {
await
(
_iconDataProcessing
??=
_getIconData
(
_environment
));
await
(
_iconDataProcessing
??=
_getIconData
(
_environment
));
assert
(
_iconData
!=
null
);
assert
(
_iconData
!=
null
);
final
_IconTreeShakerData
iconTreeShakerData
=
_iconData
[
relativePath
];
final
_IconTreeShakerData
?
iconTreeShakerData
=
_iconData
!
[
relativePath
];
if
(
iconTreeShakerData
==
null
)
{
if
(
iconTreeShakerData
==
null
)
{
return
false
;
return
false
;
}
}
...
@@ -220,22 +221,22 @@ class IconTreeShaker {
...
@@ -220,22 +221,22 @@ class IconTreeShaker {
Set
<
String
>
families
,
Set
<
String
>
families
,
)
async
{
)
async
{
final
Map
<
String
,
String
>
result
=
<
String
,
String
>{};
final
Map
<
String
,
String
>
result
=
<
String
,
String
>{};
final
List
<
Map
<
String
,
dynamic
>>
fontList
=
_getList
(
final
List
<
Map
<
String
,
Object
?
>>
fontList
=
_getList
(
json
.
decode
(
fontManifestData
),
json
.
decode
(
fontManifestData
),
'FontManifest.json invalid: expected top level to be a list of objects.'
,
'FontManifest.json invalid: expected top level to be a list of objects.'
,
);
);
for
(
final
Map
<
String
,
dynamic
>
map
in
fontList
)
{
for
(
final
Map
<
String
,
Object
?>
map
in
fontList
)
{
if
(
map
[
'family'
]
is
!
String
)
{
final
Object
?
familyKey
=
map
[
'family'
];
if
(
familyKey
is
!
String
)
{
throw
IconTreeShakerException
.
_
(
throw
IconTreeShakerException
.
_
(
'FontManifest.json invalid: expected the family value to be a string, '
'FontManifest.json invalid: expected the family value to be a string, '
'got:
${map['family']}
.'
);
'got:
${map['family']}
.'
);
}
}
final
String
familyKey
=
map
[
'family'
]
as
String
;
if
(!
families
.
contains
(
familyKey
))
{
if
(!
families
.
contains
(
familyKey
))
{
continue
;
continue
;
}
}
final
List
<
Map
<
String
,
dynamic
>>
fonts
=
_getList
(
final
List
<
Map
<
String
,
Object
?
>>
fonts
=
_getList
(
map
[
'fonts'
],
map
[
'fonts'
],
'FontManifest.json invalid: expected "fonts" to be a list of objects.'
,
'FontManifest.json invalid: expected "fonts" to be a list of objects.'
,
);
);
...
@@ -244,12 +245,13 @@ class IconTreeShaker {
...
@@ -244,12 +245,13 @@ class IconTreeShaker {
'This tool cannot process icon fonts with multiple fonts in a '
'This tool cannot process icon fonts with multiple fonts in a '
'single family.'
);
'single family.'
);
}
}
if
(
fonts
.
first
[
'asset'
]
is
!
String
)
{
final
Object
?
asset
=
fonts
.
first
[
'asset'
];
if
(
asset
is
!
String
)
{
throw
IconTreeShakerException
.
_
(
throw
IconTreeShakerException
.
_
(
'FontManifest.json invalid: expected "asset" value to be a string, '
'FontManifest.json invalid: expected "asset" value to be a string, '
'got:
${map['assets']}
.'
);
'got:
${map['assets']}
.'
);
}
}
result
[
familyKey
]
=
fonts
.
first
[
'asset'
]
as
String
;
result
[
familyKey
]
=
asset
;
}
}
return
result
;
return
result
;
}
}
...
@@ -273,19 +275,18 @@ class IconTreeShaker {
...
@@ -273,19 +275,18 @@ class IconTreeShaker {
if
(
constFinderProcessResult
.
exitCode
!=
0
)
{
if
(
constFinderProcessResult
.
exitCode
!=
0
)
{
throw
IconTreeShakerException
.
_
(
'ConstFinder failure:
${constFinderProcessResult.stderr}
'
);
throw
IconTreeShakerException
.
_
(
'ConstFinder failure:
${constFinderProcessResult.stderr}
'
);
}
}
final
dynamic
jsonDecode
=
json
.
decode
(
constFinderProcessResult
.
stdout
as
String
);
final
Object
?
constFinderMap
=
json
.
decode
(
constFinderProcessResult
.
stdout
as
String
);
if
(
jsonDecode
is
!
Map
<
String
,
dynamic
>)
{
if
(
constFinderMap
is
!
Map
<
String
,
Object
?
>)
{
throw
IconTreeShakerException
.
_
(
throw
IconTreeShakerException
.
_
(
'Invalid ConstFinder output: expected a top level JSON object, '
'Invalid ConstFinder output: expected a top level JSON object, '
'got
$
jsonDecode
.'
);
'got
$
constFinderMap
.'
);
}
}
final
Map
<
String
,
dynamic
>
constFinderMap
=
jsonDecode
as
Map
<
String
,
dynamic
>;
final
_ConstFinderResult
constFinderResult
=
_ConstFinderResult
(
constFinderMap
);
final
_ConstFinderResult
constFinderResult
=
_ConstFinderResult
(
constFinderMap
);
if
(
constFinderResult
.
hasNonConstantLocations
)
{
if
(
constFinderResult
.
hasNonConstantLocations
)
{
_logger
.
printError
(
'This application cannot tree shake icons fonts. '
_logger
.
printError
(
'This application cannot tree shake icons fonts. '
'It has non-constant instances of IconData at the '
'It has non-constant instances of IconData at the '
'following locations:'
,
emphasis:
true
);
'following locations:'
,
emphasis:
true
);
for
(
final
Map
<
String
,
dynamic
>
location
in
constFinderResult
.
nonConstantLocations
)
{
for
(
final
Map
<
String
,
Object
?
>
location
in
constFinderResult
.
nonConstantLocations
)
{
_logger
.
printError
(
_logger
.
printError
(
'-
${location['file']}
:
${location['line']}
:
${location['column']}
'
,
'-
${location['file']}
:
${location['line']}
:
${location['column']}
'
,
indent:
2
,
indent:
2
,
...
@@ -300,22 +301,24 @@ class IconTreeShaker {
...
@@ -300,22 +301,24 @@ class IconTreeShaker {
Map
<
String
,
List
<
int
>>
_parseConstFinderResult
(
_ConstFinderResult
constants
)
{
Map
<
String
,
List
<
int
>>
_parseConstFinderResult
(
_ConstFinderResult
constants
)
{
final
Map
<
String
,
List
<
int
>>
result
=
<
String
,
List
<
int
>>{};
final
Map
<
String
,
List
<
int
>>
result
=
<
String
,
List
<
int
>>{};
for
(
final
Map
<
String
,
dynamic
>
iconDataMap
in
constants
.
constantInstances
)
{
for
(
final
Map
<
String
,
Object
?>
iconDataMap
in
constants
.
constantInstances
)
{
if
((
iconDataMap
[
'fontPackage'
]
??
''
)
is
!
String
||
// Null is ok here.
final
Object
?
package
=
iconDataMap
[
'fontPackage'
];
iconDataMap
[
'fontFamily'
]
is
!
String
||
final
Object
?
fontFamily
=
iconDataMap
[
'fontFamily'
];
iconDataMap
[
'codePoint'
]
is
!
num
)
{
final
Object
?
codePoint
=
iconDataMap
[
'codePoint'
];
if
((
package
??
''
)
is
!
String
||
// Null is ok here.
fontFamily
is
!
String
||
codePoint
is
!
num
)
{
throw
IconTreeShakerException
.
_
(
throw
IconTreeShakerException
.
_
(
'Invalid ConstFinder result. Expected "fontPackage" to be a String, '
'Invalid ConstFinder result. Expected "fontPackage" to be a String, '
'"fontFamily" to be a String, and "codePoint" to be an int, '
'"fontFamily" to be a String, and "codePoint" to be an int, '
'got:
$iconDataMap
.'
);
'got:
$iconDataMap
.'
);
}
}
final
String
package
=
iconDataMap
[
'fontPackage'
]
as
String
;
final
String
family
=
fontFamily
;
final
String
family
=
iconDataMap
[
'fontFamily'
]
as
String
;
final
String
key
=
package
==
null
final
String
key
=
package
==
null
?
family
?
family
:
'packages/
$package
/
$family
'
;
:
'packages/
$package
/
$family
'
;
result
[
key
]
??=
<
int
>[];
result
[
key
]
??=
<
int
>[];
result
[
key
]
.
add
((
iconDataMap
[
'codePoint'
]
as
num
)
.
round
());
result
[
key
]
!.
add
(
codePoint
.
round
());
}
}
return
result
;
return
result
;
}
}
...
@@ -324,25 +327,17 @@ class IconTreeShaker {
...
@@ -324,25 +327,17 @@ class IconTreeShaker {
class
_ConstFinderResult
{
class
_ConstFinderResult
{
_ConstFinderResult
(
this
.
result
);
_ConstFinderResult
(
this
.
result
);
final
Map
<
String
,
dynamic
>
result
;
final
Map
<
String
,
Object
?
>
result
;
List
<
Map
<
String
,
dynamic
>>
_constantInstances
;
late
final
List
<
Map
<
String
,
Object
?>>
constantInstances
=
_getList
(
List
<
Map
<
String
,
dynamic
>>
get
constantInstances
{
result
[
'constantInstances'
],
_constantInstances
??=
_getList
(
'Invalid ConstFinder output: Expected "constInstances" to be a list of objects.'
,
result
[
'constantInstances'
],
);
'Invalid ConstFinder output: Expected "constInstances" to be a list of objects.'
,
);
return
_constantInstances
;
}
List
<
Map
<
String
,
dynamic
>>
_nonConstantLocations
;
late
final
List
<
Map
<
String
,
Object
?>>
nonConstantLocations
=
_getList
(
List
<
Map
<
String
,
dynamic
>>
get
nonConstantLocations
{
result
[
'nonConstantLocations'
],
_nonConstantLocations
??=
_getList
(
'Invalid ConstFinder output: Expected "nonConstLocations" to be a list of objects'
,
result
[
'nonConstantLocations'
],
);
'Invalid ConstFinder output: Expected "nonConstLocations" to be a list of objects'
,
);
return
_nonConstantLocations
;
}
bool
get
hasNonConstantLocations
=>
nonConstantLocations
.
isNotEmpty
;
bool
get
hasNonConstantLocations
=>
nonConstantLocations
.
isNotEmpty
;
}
}
...
@@ -352,9 +347,9 @@ class _ConstFinderResult {
...
@@ -352,9 +347,9 @@ class _ConstFinderResult {
class
_IconTreeShakerData
{
class
_IconTreeShakerData
{
/// All parameters are required.
/// All parameters are required.
const
_IconTreeShakerData
({
const
_IconTreeShakerData
({
@
required
this
.
family
,
required
this
.
family
,
@
required
this
.
relativePath
,
required
this
.
relativePath
,
@
required
this
.
codePoints
,
required
this
.
codePoints
,
})
:
assert
(
family
!=
null
),
})
:
assert
(
family
!=
null
),
assert
(
relativePath
!=
null
),
assert
(
relativePath
!=
null
),
assert
(
codePoints
!=
null
);
assert
(
codePoints
!=
null
);
...
...
packages/flutter_tools/lib/src/compile.dart
View file @
afbfc1f3
...
@@ -196,7 +196,7 @@ class KernelCompiler {
...
@@ -196,7 +196,7 @@ class KernelCompiler {
required
ProcessManager
processManager
,
required
ProcessManager
processManager
,
required
Artifacts
artifacts
,
required
Artifacts
artifacts
,
required
List
<
String
>
fileSystemRoots
,
required
List
<
String
>
fileSystemRoots
,
required
String
fileSystemScheme
,
String
?
fileSystemScheme
,
@visibleForTesting
StdoutHandler
?
stdoutHandler
,
@visibleForTesting
StdoutHandler
?
stdoutHandler
,
})
:
_logger
=
logger
,
})
:
_logger
=
logger
,
_fileSystem
=
fileSystem
,
_fileSystem
=
fileSystem
,
...
@@ -210,7 +210,7 @@ class KernelCompiler {
...
@@ -210,7 +210,7 @@ class KernelCompiler {
final
Artifacts
_artifacts
;
final
Artifacts
_artifacts
;
final
ProcessManager
_processManager
;
final
ProcessManager
_processManager
;
final
Logger
_logger
;
final
Logger
_logger
;
final
String
_fileSystemScheme
;
final
String
?
_fileSystemScheme
;
final
List
<
String
>
_fileSystemRoots
;
final
List
<
String
>
_fileSystemRoots
;
final
StdoutHandler
_stdoutHandler
;
final
StdoutHandler
_stdoutHandler
;
...
...
packages/flutter_tools/test/general.shard/build_system/targets/assets_test.dart
View file @
afbfc1f3
...
@@ -203,7 +203,7 @@ flutter:
...
@@ -203,7 +203,7 @@ flutter:
fileSystem
.
file
(
'bundle.sksl'
).
writeAsStringSync
(
json
.
encode
(
fileSystem
.
file
(
'bundle.sksl'
).
writeAsStringSync
(
json
.
encode
(
<
String
,
Object
>{
<
String
,
Object
>{
'engineRevision'
:
'2'
,
'engineRevision'
:
'2'
,
'platform'
:
'fuchsia'
,
'platform'
:
'fuchsia
-arm64
'
,
'data'
:
<
String
,
Object
>{}
'data'
:
<
String
,
Object
>{}
}
}
));
));
...
...
packages/flutter_tools/test/general.shard/build_system/targets/icon_tree_shaker_test.dart
View file @
afbfc1f3
...
@@ -2,8 +2,6 @@
...
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'package:file/memory.dart'
;
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/artifacts.dart'
;
import
'package:flutter_tools/src/artifacts.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
...
@@ -13,7 +11,6 @@ import 'package:flutter_tools/src/build_info.dart';
...
@@ -13,7 +11,6 @@ import 'package:flutter_tools/src/build_info.dart';
import
'package:flutter_tools/src/build_system/build_system.dart'
;
import
'package:flutter_tools/src/build_system/build_system.dart'
;
import
'package:flutter_tools/src/build_system/targets/icon_tree_shaker.dart'
;
import
'package:flutter_tools/src/build_system/targets/icon_tree_shaker.dart'
;
import
'package:flutter_tools/src/devfs.dart'
;
import
'package:flutter_tools/src/devfs.dart'
;
import
'package:meta/meta.dart'
;
import
'../../../src/common.dart'
;
import
'../../../src/common.dart'
;
import
'../../../src/fake_process_manager.dart'
;
import
'../../../src/fake_process_manager.dart'
;
...
@@ -27,16 +24,16 @@ const String outputPath = '/output/fonts/MaterialIcons-Regular.otf';
...
@@ -27,16 +24,16 @@ const String outputPath = '/output/fonts/MaterialIcons-Regular.otf';
const
String
relativePath
=
'fonts/MaterialIcons-Regular.otf'
;
const
String
relativePath
=
'fonts/MaterialIcons-Regular.otf'
;
void
main
(
)
{
void
main
(
)
{
BufferLogger
logger
;
late
BufferLogger
logger
;
MemoryFileSystem
fileSystem
;
late
MemoryFileSystem
fileSystem
;
FakeProcessManager
processManager
;
late
FakeProcessManager
processManager
;
Artifacts
artifacts
;
late
Artifacts
artifacts
;
DevFSStringContent
fontManifestContent
;
late
DevFSStringContent
fontManifestContent
;
String
dartPath
;
late
String
dartPath
;
String
constFinderPath
;
late
String
constFinderPath
;
String
fontSubsetPath
;
late
String
fontSubsetPath
;
List
<
String
>
fontSubsetArgs
;
late
List
<
String
>
fontSubsetArgs
;
List
<
String
>
_getConstFinderArgs
(
String
appDillPath
)
=>
<
String
>[
List
<
String
>
_getConstFinderArgs
(
String
appDillPath
)
=>
<
String
>[
dartPath
,
dartPath
,
...
@@ -65,7 +62,7 @@ void main() {
...
@@ -65,7 +62,7 @@ void main() {
int
exitCode
=
0
,
int
exitCode
=
0
,
String
stdout
=
''
,
String
stdout
=
''
,
String
stderr
=
''
,
String
stderr
=
''
,
@
required
CompleterIOSink
stdinSink
,
required
CompleterIOSink
stdinSink
,
})
{
})
{
assert
(
stdinSink
!=
null
);
assert
(
stdinSink
!=
null
);
stdinSink
.
clear
();
stdinSink
.
clear
();
...
...
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