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
9431229e
Unverified
Commit
9431229e
authored
Feb 13, 2020
by
Jonah Williams
Committed by
GitHub
Feb 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] remove globals from depfile usage (#50710)
parent
8769f94c
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
248 additions
and
124 deletions
+248
-124
depfile.dart
packages/flutter_tools/lib/src/build_system/depfile.dart
+57
-39
android.dart
...s/flutter_tools/lib/src/build_system/targets/android.dart
+9
-1
assets.dart
...es/flutter_tools/lib/src/build_system/targets/assets.dart
+9
-1
dart.dart
...ages/flutter_tools/lib/src/build_system/targets/dart.dart
+9
-1
ios.dart
packages/flutter_tools/lib/src/build_system/targets/ios.dart
+9
-1
linux.dart
...ges/flutter_tools/lib/src/build_system/targets/linux.dart
+18
-2
macos.dart
...ges/flutter_tools/lib/src/build_system/targets/macos.dart
+9
-1
web.dart
packages/flutter_tools/lib/src/build_system/targets/web.dart
+32
-6
bundle.dart
packages/flutter_tools/lib/src/bundle.dart
+6
-1
assemble.dart
packages/flutter_tools/lib/src/commands/assemble.dart
+6
-1
depfile_test.dart
...r_tools/test/general.shard/build_system/depfile_test.dart
+77
-69
web_test.dart
...ols/test/general.shard/build_system/targets/web_test.dart
+7
-1
No files found.
packages/flutter_tools/lib/src/build_system/depfile.dart
View file @
9431229e
...
...
@@ -2,22 +2,54 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:meta/meta.dart'
;
import
'package:platform/platform.dart'
;
import
'../base/file_system.dart'
;
import
'../
globals.dart'
as
globals
;
import
'../
base/logger.dart'
;
/// A class for representing depfile formats.
class
Depfile
{
/// Create a [Depfile] from a list of [input] files and [output] files.
const
Depfile
(
this
.
inputs
,
this
.
outputs
);
/// A service for creating and parsing [Depfile]s.
class
DepfileService
{
DepfileService
({
@required
Logger
logger
,
@required
FileSystem
fileSystem
,
@required
Platform
platform
,
})
:
_logger
=
logger
,
_fileSystem
=
fileSystem
,
_platform
=
platform
;
final
Logger
_logger
;
final
FileSystem
_fileSystem
;
final
Platform
_platform
;
static
final
RegExp
_separatorExpr
=
RegExp
(
r'([^\\]) '
);
static
final
RegExp
_escapeExpr
=
RegExp
(
r'\\(.)'
);
/// Given an [depfile] File, write the depfile contents.
///
/// If either [inputs] or [outputs] is empty, ensures the file does not
/// exist.
void
writeToFile
(
Depfile
depfile
,
File
output
)
{
if
(
depfile
.
inputs
.
isEmpty
||
depfile
.
outputs
.
isEmpty
)
{
if
(
output
.
existsSync
())
{
output
.
deleteSync
();
}
return
;
}
final
StringBuffer
buffer
=
StringBuffer
();
_writeFilesToBuffer
(
depfile
.
outputs
,
buffer
);
buffer
.
write
(
': '
);
_writeFilesToBuffer
(
depfile
.
inputs
,
buffer
);
output
.
writeAsStringSync
(
buffer
.
toString
());
}
/// Parse the depfile contents from [file].
///
/// If the syntax is invalid, returns an empty [Depfile].
factory
Depfile
.
parse
(
File
file
)
{
Depfile
parse
(
File
file
)
{
final
String
contents
=
file
.
readAsStringSync
();
final
List
<
String
>
colonSeparated
=
contents
.
split
(
': '
);
if
(
colonSeparated
.
length
!=
2
)
{
globals
.
printError
(
'Invalid depfile:
${file.path}
'
);
_logger
.
printError
(
'Invalid depfile:
${file.path}
'
);
return
const
Depfile
(<
File
>[],
<
File
>[]);
}
final
List
<
File
>
inputs
=
_processList
(
colonSeparated
[
1
].
trim
());
...
...
@@ -25,11 +57,12 @@ class Depfile {
return
Depfile
(
inputs
,
outputs
);
}
/// Parse the output of dart2js's used dependencies.
///
/// The [file] contains a list of newline separated file URIs. The output
/// file must be manually specified.
factory
Depfile
.
parseDart2js
(
File
file
,
File
output
)
{
Depfile
parseDart2js
(
File
file
,
File
output
)
{
final
List
<
File
>
inputs
=
<
File
>[];
for
(
final
String
rawUri
in
file
.
readAsLinesSync
())
{
if
(
rawUri
.
trim
().
isEmpty
)
{
...
...
@@ -42,38 +75,14 @@ class Depfile {
if
(
fileUri
.
scheme
!=
'file'
)
{
continue
;
}
inputs
.
add
(
globals
.
fs
.
file
(
fileUri
));
inputs
.
add
(
_fileSystem
.
file
(
fileUri
));
}
return
Depfile
(
inputs
,
<
File
>[
output
]);
}
/// The input files for this depfile.
final
List
<
File
>
inputs
;
/// The output files for this depfile.
final
List
<
File
>
outputs
;
/// Given an [depfile] File, write the depfile contents.
///
/// If either [inputs] or [outputs] is empty, ensures the file does not
/// exist.
void
writeToFile
(
File
depfile
)
{
if
(
inputs
.
isEmpty
||
outputs
.
isEmpty
)
{
if
(
depfile
.
existsSync
())
{
depfile
.
deleteSync
();
}
return
;
}
final
StringBuffer
buffer
=
StringBuffer
();
_writeFilesToBuffer
(
outputs
,
buffer
);
buffer
.
write
(
': '
);
_writeFilesToBuffer
(
inputs
,
buffer
);
depfile
.
writeAsStringSync
(
buffer
.
toString
());
}
void
_writeFilesToBuffer
(
List
<
File
>
files
,
StringBuffer
buffer
)
{
for
(
final
File
outputFile
in
files
)
{
if
(
globals
.
platform
.
isWindows
)
{
if
(
_
platform
.
isWindows
)
{
// Foward slashes and spaces in a depfile have to be escaped on windows.
final
String
path
=
outputFile
.
path
.
replaceAll
(
r'\'
,
r'\\'
)
...
...
@@ -87,10 +96,7 @@ class Depfile {
}
}
static
final
RegExp
_separatorExpr
=
RegExp
(
r'([^\\]) '
);
static
final
RegExp
_escapeExpr
=
RegExp
(
r'\\(.)'
);
static
List
<
File
>
_processList
(
String
rawText
)
{
List
<
File
>
_processList
(
String
rawText
)
{
return
rawText
// Put every file on right-hand side on the separate line
.
replaceAllMapped
(
_separatorExpr
,
(
Match
match
)
=>
'
${match.group(1)}
\n
'
)
...
...
@@ -101,7 +107,19 @@ class Depfile {
// The tool doesn't write duplicates to these lists. This call is an attempt to
// be resillient to the outputs of other tools which write or user edits to depfiles.
.
toSet
()
.
map
(
(
String
path
)
=>
globals
.
fs
.
file
(
path
)
)
.
map
(
_fileSystem
.
file
)
.
toList
();
}
}
/// A class for representing depfile formats.
class
Depfile
{
/// Create a [Depfile] from a list of [input] files and [output] files.
const
Depfile
(
this
.
inputs
,
this
.
outputs
);
/// The input files for this depfile.
final
List
<
File
>
inputs
;
/// The output files for this depfile.
final
List
<
File
>
outputs
;
}
packages/flutter_tools/lib/src/build_system/targets/android.dart
View file @
9431229e
...
...
@@ -63,7 +63,15 @@ abstract class AndroidAssetBundle extends Target {
}
if
(
_copyAssets
)
{
final
Depfile
assetDepfile
=
await
copyAssets
(
environment
,
outputDirectory
);
assetDepfile
.
writeToFile
(
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
));
final
DepfileService
depfileService
=
DepfileService
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
);
depfileService
.
writeToFile
(
assetDepfile
,
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
),
);
}
}
...
...
packages/flutter_tools/lib/src/build_system/targets/assets.dart
View file @
9431229e
...
...
@@ -108,7 +108,15 @@ class CopyAssets extends Target {
.
childDirectory
(
'flutter_assets'
);
output
.
createSync
(
recursive:
true
);
final
Depfile
depfile
=
await
copyAssets
(
environment
,
output
);
depfile
.
writeToFile
(
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
));
final
DepfileService
depfileService
=
DepfileService
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
);
depfileService
.
writeToFile
(
depfile
,
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
),
);
}
}
...
...
packages/flutter_tools/lib/src/build_system/targets/dart.dart
View file @
9431229e
...
...
@@ -114,7 +114,15 @@ class CopyFlutterBundle extends Target {
.
copySync
(
environment
.
outputDir
.
childFile
(
'isolate_snapshot_data'
).
path
);
}
final
Depfile
assetDepfile
=
await
copyAssets
(
environment
,
environment
.
outputDir
);
assetDepfile
.
writeToFile
(
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
));
final
DepfileService
depfileService
=
DepfileService
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
);
depfileService
.
writeToFile
(
assetDepfile
,
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
),
);
}
@override
...
...
packages/flutter_tools/lib/src/build_system/targets/ios.dart
View file @
9431229e
...
...
@@ -284,7 +284,15 @@ abstract class IosAssetBundle extends Target {
// Copy the assets.
final
Depfile
assetDepfile
=
await
copyAssets
(
environment
,
assetDirectory
);
assetDepfile
.
writeToFile
(
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
));
final
DepfileService
depfileService
=
DepfileService
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
);
depfileService
.
writeToFile
(
assetDepfile
,
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
),
);
// Copy the plist from either the project or module.
...
...
packages/flutter_tools/lib/src/build_system/targets/linux.dart
View file @
9431229e
...
...
@@ -98,7 +98,15 @@ class UnpackLinuxDebug extends Target {
}
}
final
Depfile
depfile
=
Depfile
(
inputs
,
outputs
);
depfile
.
writeToFile
(
environment
.
buildDir
.
childFile
(
'linux_engine_sources.d'
));
final
DepfileService
depfileService
=
DepfileService
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
);
depfileService
.
writeToFile
(
depfile
,
environment
.
buildDir
.
childFile
(
'linux_engine_sources.d'
),
);
}
}
...
...
@@ -151,6 +159,14 @@ class DebugBundleLinuxAssets extends Target {
.
copySync
(
outputDirectory
.
childFile
(
'kernel_blob.bin'
).
path
);
}
final
Depfile
depfile
=
await
copyAssets
(
environment
,
outputDirectory
);
depfile
.
writeToFile
(
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
));
final
DepfileService
depfileService
=
DepfileService
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
);
depfileService
.
writeToFile
(
depfile
,
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
),
);
}
}
packages/flutter_tools/lib/src/build_system/targets/macos.dart
View file @
9431229e
...
...
@@ -286,7 +286,15 @@ abstract class MacOSBundleFlutterAssets extends Target {
.
childDirectory
(
'flutter_assets'
);
assetDirectory
.
createSync
(
recursive:
true
);
final
Depfile
depfile
=
await
copyAssets
(
environment
,
assetDirectory
);
depfile
.
writeToFile
(
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
));
final
DepfileService
depfileService
=
DepfileService
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
);
depfileService
.
writeToFile
(
depfile
,
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
),
);
// Copy Info.plist template.
assetDirectory
.
parent
.
childFile
(
'Info.plist'
)
...
...
packages/flutter_tools/lib/src/build_system/targets/web.dart
View file @
9431229e
...
...
@@ -191,11 +191,19 @@ class Dart2JSTarget extends Target {
'
${dart2jsDeps.path}
'
);
return
;
}
final
Depfile
depfile
=
Depfile
.
parseDart2js
(
final
DepfileService
depfileService
=
DepfileService
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
);
final
Depfile
depfile
=
depfileService
.
parseDart2js
(
environment
.
buildDir
.
childFile
(
'main.dart.js.deps'
),
outputFile
,
);
depfile
.
writeToFile
(
environment
.
buildDir
.
childFile
(
'dart2js.d'
));
depfileService
.
writeToFile
(
depfile
,
environment
.
buildDir
.
childFile
(
'dart2js.d'
),
);
}
}
...
...
@@ -247,7 +255,15 @@ class WebReleaseBundle extends Target {
final
Directory
outputDirectory
=
environment
.
outputDir
.
childDirectory
(
'assets'
);
outputDirectory
.
createSync
(
recursive:
true
);
final
Depfile
depfile
=
await
copyAssets
(
environment
,
environment
.
outputDir
.
childDirectory
(
'assets'
));
depfile
.
writeToFile
(
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
));
final
DepfileService
depfileService
=
DepfileService
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
);
depfileService
.
writeToFile
(
depfile
,
environment
.
buildDir
.
childFile
(
'flutter_assets.d'
),
);
final
Directory
webResources
=
environment
.
projectDir
.
childDirectory
(
'web'
);
...
...
@@ -269,8 +285,10 @@ class WebReleaseBundle extends Target {
outputResourcesFiles
.
add
(
outputFile
);
}
final
Depfile
resourceFile
=
Depfile
(
inputResourceFiles
,
outputResourcesFiles
);
resourceFile
.
writeToFile
(
environment
.
buildDir
.
childFile
(
'web_resources.d'
));
depfileService
.
writeToFile
(
resourceFile
,
environment
.
buildDir
.
childFile
(
'web_resources.d'
),
);
}
}
...
...
@@ -320,7 +338,15 @@ class WebServiceWorker extends Target {
final
String
serviceWorker
=
generateServiceWorker
(
uriToHash
);
serviceWorkerFile
.
writeAsStringSync
(
serviceWorker
);
depfile
.
writeToFile
(
environment
.
buildDir
.
childFile
(
'service_worker.d'
));
final
DepfileService
depfileService
=
DepfileService
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
);
depfileService
.
writeToFile
(
depfile
,
environment
.
buildDir
.
childFile
(
'service_worker.d'
),
);
}
}
...
...
packages/flutter_tools/lib/src/bundle.dart
View file @
9431229e
...
...
@@ -149,7 +149,12 @@ Future<void> buildWithAssemble({
if
(!
outputDepfile
.
parent
.
existsSync
())
{
outputDepfile
.
parent
.
createSync
(
recursive:
true
);
}
depfile
.
writeToFile
(
outputDepfile
);
final
DepfileService
depfileService
=
DepfileService
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
);
depfileService
.
writeToFile
(
depfile
,
outputDepfile
);
}
}
...
...
packages/flutter_tools/lib/src/commands/assemble.dart
View file @
9431229e
...
...
@@ -202,7 +202,12 @@ class AssembleCommand extends FlutterCommand {
if
(
argResults
.
wasParsed
(
'depfile'
))
{
final
File
depfileFile
=
globals
.
fs
.
file
(
stringArg
(
'depfile'
));
final
Depfile
depfile
=
Depfile
(
result
.
inputFiles
,
result
.
outputFiles
);
depfile
.
writeToFile
(
globals
.
fs
.
file
(
depfileFile
));
final
DepfileService
depfileService
=
DepfileService
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
);
depfileService
.
writeToFile
(
depfile
,
globals
.
fs
.
file
(
depfileFile
));
}
return
FlutterCommandResult
.
success
();
}
...
...
packages/flutter_tools/test/general.shard/build_system/depfile_test.dart
View file @
9431229e
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/general.shard/build_system/targets/web_test.dart
View file @
9431229e
...
...
@@ -24,6 +24,7 @@ void main() {
Environment
environment
;
MockPlatform
mockPlatform
;
MockPlatform
mockWindowsPlatform
;
DepfileService
depfileService
;
setUp
(()
{
mockPlatform
=
MockPlatform
();
...
...
@@ -53,6 +54,11 @@ void main() {
kTargetFile:
globals
.
fs
.
path
.
join
(
'foo'
,
'lib'
,
'main.dart'
),
}
);
depfileService
=
DepfileService
(
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
);
environment
.
buildDir
.
createSync
(
recursive:
true
);
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
mockPlatform
,
...
...
@@ -315,7 +321,7 @@ void main() {
await
const
Dart2JSTarget
().
build
(
environment
);
expect
(
environment
.
buildDir
.
childFile
(
'dart2js.d'
).
existsSync
(),
true
);
final
Depfile
depfile
=
Depfil
e
.
parse
(
environment
.
buildDir
.
childFile
(
'dart2js.d'
));
final
Depfile
depfile
=
depfileServic
e
.
parse
(
environment
.
buildDir
.
childFile
(
'dart2js.d'
));
expect
(
depfile
.
inputs
.
single
.
path
,
globals
.
fs
.
path
.
absolute
(
'a.dart'
));
expect
(
depfile
.
outputs
.
single
.
path
,
...
...
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