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
25a81311
Unverified
Commit
25a81311
authored
Feb 20, 2020
by
Jonah Williams
Committed by
GitHub
Feb 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] reload dart_sdk when sources update (#51067)
parent
29306b08
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
70 deletions
+99
-70
devfs_web.dart
packages/flutter_tools/lib/src/build_runner/devfs_web.dart
+42
-20
devfs_web_test.dart
.../flutter_tools/test/general.shard/web/devfs_web_test.dart
+57
-50
No files found.
packages/flutter_tools/lib/src/build_runner/devfs_web.dart
View file @
25a81311
...
@@ -45,6 +45,9 @@ class WebAssetServer implements AssetReader {
...
@@ -45,6 +45,9 @@ class WebAssetServer implements AssetReader {
/// Start the web asset server on a [hostname] and [port].
/// Start the web asset server on a [hostname] and [port].
///
///
/// If [testMode] is true, do not actually initialize dwds or the shelf static
/// server.
///
/// Unhandled exceptions will throw a [ToolExit] with the error and stack
/// Unhandled exceptions will throw a [ToolExit] with the error and stack
/// trace.
/// trace.
static
Future
<
WebAssetServer
>
start
(
static
Future
<
WebAssetServer
>
start
(
...
@@ -53,14 +56,18 @@ class WebAssetServer implements AssetReader {
...
@@ -53,14 +56,18 @@ class WebAssetServer implements AssetReader {
UrlTunneller
urlTunneller
,
UrlTunneller
urlTunneller
,
BuildMode
buildMode
,
BuildMode
buildMode
,
bool
enableDwds
,
bool
enableDwds
,
Uri
entrypoint
,
Uri
entrypoint
,
{
)
async
{
bool
testMode
=
false
,
})
async
{
try
{
try
{
final
InternetAddress
address
=
(
await
InternetAddress
.
lookup
(
hostname
)).
first
;
final
InternetAddress
address
=
(
await
InternetAddress
.
lookup
(
hostname
)).
first
;
final
HttpServer
httpServer
=
await
HttpServer
.
bind
(
address
,
port
);
final
HttpServer
httpServer
=
await
HttpServer
.
bind
(
address
,
port
);
final
Packages
packages
=
await
loadPackagesFile
(
final
Packages
packages
=
await
loadPackagesFile
(
Uri
.
base
.
resolve
(
'.packages'
),
loader:
(
Uri
uri
)
=>
globals
.
fs
.
file
(
uri
).
readAsBytes
());
Uri
.
base
.
resolve
(
'.packages'
),
loader:
(
Uri
uri
)
=>
globals
.
fs
.
file
(
uri
).
readAsBytes
());
final
WebAssetServer
server
=
WebAssetServer
(
httpServer
,
packages
,
address
);
final
WebAssetServer
server
=
WebAssetServer
(
httpServer
,
packages
,
address
);
if
(
testMode
)
{
return
server
;
}
// In release builds deploy a simpler proxy server.
// In release builds deploy a simpler proxy server.
if
(
buildMode
!=
BuildMode
.
debug
)
{
if
(
buildMode
!=
BuildMode
.
debug
)
{
...
@@ -244,8 +251,31 @@ class WebAssetServer implements AssetReader {
...
@@ -244,8 +251,31 @@ class WebAssetServer implements AssetReader {
return
modules
;
return
modules
;
}
}
@visibleForTesting
final
File
dartSdk
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
globals
.
artifacts
.
getArtifactPath
(
Artifact
.
flutterWebSdk
),
'kernel'
,
'amd'
,
'dart_sdk.js'
,
));
@visibleForTesting
final
File
dartSdkSourcemap
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
globals
.
artifacts
.
getArtifactPath
(
Artifact
.
flutterWebSdk
),
'kernel'
,
'amd'
,
'dart_sdk.js.map'
,
));
// Attempt to resolve `path` to a dart file.
// Attempt to resolve `path` to a dart file.
File
_resolveDartFile
(
String
path
)
{
File
_resolveDartFile
(
String
path
)
{
// Return the actual file objects so that local engine changes are automatically picked up.
switch
(
path
)
{
case
'/dart_sdk.js'
:
return
dartSdk
;
case
'.dart_sdk.js.map'
:
return
dartSdkSourcemap
;
}
// If this is a dart file, it must be on the local file system and is
// If this is a dart file, it must be on the local file system and is
// likely coming from a source map request. The tool doesn't currently
// likely coming from a source map request. The tool doesn't currently
// consider the case of Dart files as assets.
// consider the case of Dart files as assets.
...
@@ -309,7 +339,12 @@ class ConnectionResult {
...
@@ -309,7 +339,12 @@ class ConnectionResult {
final
DebugConnection
debugConnection
;
final
DebugConnection
debugConnection
;
}
}
/// The web specific DevFS implementation.
class
WebDevFS
implements
DevFS
{
class
WebDevFS
implements
DevFS
{
/// Create a new [WebDevFS] instance.
///
/// [testMode] is true, do not actually initialize dwds or the shelf static
/// server.
WebDevFS
({
WebDevFS
({
@required
this
.
hostname
,
@required
this
.
hostname
,
@required
this
.
port
,
@required
this
.
port
,
...
@@ -318,6 +353,7 @@ class WebDevFS implements DevFS {
...
@@ -318,6 +353,7 @@ class WebDevFS implements DevFS {
@required
this
.
buildMode
,
@required
this
.
buildMode
,
@required
this
.
enableDwds
,
@required
this
.
enableDwds
,
@required
this
.
entrypoint
,
@required
this
.
entrypoint
,
this
.
testMode
=
false
,
});
});
final
Uri
entrypoint
;
final
Uri
entrypoint
;
...
@@ -327,6 +363,7 @@ class WebDevFS implements DevFS {
...
@@ -327,6 +363,7 @@ class WebDevFS implements DevFS {
final
UrlTunneller
urlTunneller
;
final
UrlTunneller
urlTunneller
;
final
BuildMode
buildMode
;
final
BuildMode
buildMode
;
final
bool
enableDwds
;
final
bool
enableDwds
;
final
bool
testMode
;
@visibleForTesting
@visibleForTesting
WebAssetServer
webAssetServer
;
WebAssetServer
webAssetServer
;
...
@@ -387,6 +424,7 @@ class WebDevFS implements DevFS {
...
@@ -387,6 +424,7 @@ class WebDevFS implements DevFS {
buildMode
,
buildMode
,
enableDwds
,
enableDwds
,
entrypoint
,
entrypoint
,
testMode:
testMode
,
);
);
return
Uri
.
parse
(
'http://
$hostname
:
$port
'
);
return
Uri
.
parse
(
'http://
$hostname
:
$port
'
);
}
}
...
@@ -450,8 +488,7 @@ class WebDevFS implements DevFS {
...
@@ -450,8 +488,7 @@ class WebDevFS implements DevFS {
);
);
// TODO(jonahwilliams): switch to DWDS provided APIs when they are ready.
// TODO(jonahwilliams): switch to DWDS provided APIs when they are ready.
webAssetServer
.
writeFile
(
'/basic.digests'
,
'{}'
);
webAssetServer
.
writeFile
(
'/basic.digests'
,
'{}'
);
webAssetServer
.
writeFile
(
'/dart_sdk.js'
,
dartSdk
.
readAsStringSync
());
webAssetServer
.
writeFile
(
'/dart_sdk.js.map'
,
dartSdkSourcemap
.
readAsStringSync
());
// TODO(jonahwilliams): refactor the asset code in this and the regular devfs to
// TODO(jonahwilliams): refactor the asset code in this and the regular devfs to
// be shared.
// be shared.
if
(
bundle
!=
null
)
{
if
(
bundle
!=
null
)
{
...
@@ -498,6 +535,7 @@ class WebDevFS implements DevFS {
...
@@ -498,6 +535,7 @@ class WebDevFS implements DevFS {
}
on
FileSystemException
catch
(
err
)
{
}
on
FileSystemException
catch
(
err
)
{
throwToolExit
(
'Failed to load recompiled sources:
\n
$err
'
);
throwToolExit
(
'Failed to load recompiled sources:
\n
$err
'
);
}
}
return
UpdateFSReport
(
return
UpdateFSReport
(
success:
true
,
success:
true
,
syncedBytes:
codeFile
.
lengthSync
(),
syncedBytes:
codeFile
.
lengthSync
(),
...
@@ -515,22 +553,6 @@ class WebDevFS implements DevFS {
...
@@ -515,22 +553,6 @@ class WebDevFS implements DevFS {
'require.js'
,
'require.js'
,
));
));
@visibleForTesting
final
File
dartSdk
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
globals
.
artifacts
.
getArtifactPath
(
Artifact
.
flutterWebSdk
),
'kernel'
,
'amd'
,
'dart_sdk.js'
,
));
@visibleForTesting
final
File
dartSdkSourcemap
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
globals
.
artifacts
.
getArtifactPath
(
Artifact
.
flutterWebSdk
),
'kernel'
,
'amd'
,
'dart_sdk.js.map'
,
));
@visibleForTesting
@visibleForTesting
final
File
stackTraceMapper
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
final
File
stackTraceMapper
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
globals
.
artifacts
.
getArtifactPath
(
Artifact
.
engineDartSdkPath
),
globals
.
artifacts
.
getArtifactPath
(
Artifact
.
engineDartSdkPath
),
...
...
packages/flutter_tools/test/general.shard/web/devfs_web_test.dart
View file @
25a81311
...
@@ -18,7 +18,6 @@ import 'package:flutter_tools/src/globals.dart' as globals;
...
@@ -18,7 +18,6 @@ import 'package:flutter_tools/src/globals.dart' as globals;
import
'package:shelf/shelf.dart'
;
import
'package:shelf/shelf.dart'
;
import
'../../src/common.dart'
;
import
'../../src/common.dart'
;
import
'../../src/io.dart'
;
import
'../../src/testbed.dart'
;
import
'../../src/testbed.dart'
;
const
List
<
int
>
kTransparentImage
=
<
int
>[
const
List
<
int
>
kTransparentImage
=
<
int
>[
...
@@ -278,55 +277,63 @@ void main() {
...
@@ -278,55 +277,63 @@ void main() {
}));
}));
test
(
'Can start web server with specified assets'
,
()
=>
testbed
.
run
(()
async
{
test
(
'Can start web server with specified assets'
,
()
=>
testbed
.
run
(()
async
{
await
IOOverrides
.
runWithIOOverrides
(()
async
{
final
File
outputFile
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
'lib'
,
'main.dart'
))
final
File
outputFile
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
'lib'
,
'main.dart'
))
..
createSync
(
recursive:
true
);
..
createSync
(
recursive:
true
);
outputFile
.
parent
.
childFile
(
'a.sources'
).
writeAsStringSync
(
''
);
outputFile
.
parent
.
childFile
(
'a.sources'
).
writeAsStringSync
(
''
);
outputFile
.
parent
.
childFile
(
'a.json'
).
writeAsStringSync
(
'{}'
);
outputFile
.
parent
.
childFile
(
'a.json'
).
writeAsStringSync
(
'{}'
);
outputFile
.
parent
.
childFile
(
'a.map'
).
writeAsStringSync
(
'{}'
);
outputFile
.
parent
.
childFile
(
'a.map'
).
writeAsStringSync
(
'{}'
);
outputFile
.
parent
.
childFile
(
'.packages'
).
writeAsStringSync
(
'
\n
'
);
outputFile
.
parent
.
childFile
(
'.packages'
).
writeAsStringSync
(
'
\n
'
);
final
ResidentCompiler
residentCompiler
=
MockResidentCompiler
();
final
ResidentCompiler
residentCompiler
=
MockResidentCompiler
();
when
(
residentCompiler
.
recompile
(
when
(
residentCompiler
.
recompile
(
any
,
any
,
any
,
any
,
outputPath:
anyNamed
(
'outputPath'
),
outputPath:
anyNamed
(
'outputPath'
),
packagesFilePath:
anyNamed
(
'packagesFilePath'
),
packagesFilePath:
anyNamed
(
'packagesFilePath'
),
)).
thenAnswer
((
Invocation
invocation
)
async
{
)).
thenAnswer
((
Invocation
invocation
)
async
{
return
const
CompilerOutput
(
'a'
,
0
,
<
Uri
>[]);
return
const
CompilerOutput
(
'a'
,
0
,
<
Uri
>[]);
});
});
final
WebDevFS
webDevFS
=
WebDevFS
(
final
WebDevFS
webDevFS
=
WebDevFS
(
hostname:
'localhost'
,
hostname:
'localhost'
,
port:
0
,
port:
0
,
packagesFilePath:
'.packages'
,
packagesFilePath:
'.packages'
,
urlTunneller:
null
,
urlTunneller:
null
,
buildMode:
BuildMode
.
debug
,
buildMode:
BuildMode
.
debug
,
enableDwds:
false
,
enableDwds:
false
,
entrypoint:
Uri
.
base
,
entrypoint:
Uri
.
base
,
testMode:
true
,
);
);
webDevFS
.
requireJS
.
createSync
(
recursive:
true
);
webDevFS
.
requireJS
.
createSync
(
recursive:
true
);
webDevFS
.
dartSdk
.
createSync
(
recursive:
true
);
webDevFS
.
stackTraceMapper
.
createSync
(
recursive:
true
);
webDevFS
.
dartSdkSourcemap
.
createSync
(
recursive:
true
);
webDevFS
.
stackTraceMapper
.
createSync
(
recursive:
true
);
await
webDevFS
.
create
();
webDevFS
.
webAssetServer
.
dartSdk
await
webDevFS
.
create
();
..
createSync
(
recursive:
true
)
await
webDevFS
.
update
(
..
writeAsStringSync
(
'HELLO'
);
mainPath:
globals
.
fs
.
path
.
join
(
'lib'
,
'main.dart'
),
webDevFS
.
webAssetServer
.
dartSdkSourcemap
.
createSync
(
recursive:
true
);
generator:
residentCompiler
,
trackWidgetCreation:
true
,
await
webDevFS
.
update
(
bundleFirstUpload:
true
,
mainPath:
globals
.
fs
.
path
.
join
(
'lib'
,
'main.dart'
),
invalidatedFiles:
<
Uri
>[],
generator:
residentCompiler
,
);
trackWidgetCreation:
true
,
bundleFirstUpload:
true
,
expect
(
webDevFS
.
webAssetServer
.
getFile
(
'/main.dart'
),
isNotNull
);
invalidatedFiles:
<
Uri
>[],
expect
(
webDevFS
.
webAssetServer
.
getFile
(
'/manifest.json'
),
isNotNull
);
);
expect
(
webDevFS
.
webAssetServer
.
getFile
(
'/flutter_service_worker.js'
),
isNotNull
);
expect
(
webDevFS
.
webAssetServer
.
getFile
(
'/main.dart'
),
isNotNull
);
await
webDevFS
.
destroy
();
expect
(
webDevFS
.
webAssetServer
.
getFile
(
'/manifest.json'
),
isNotNull
);
await
webDevFS
.
dwds
.
stop
();
expect
(
webDevFS
.
webAssetServer
.
getFile
(
'/flutter_service_worker.js'
),
isNotNull
);
},
FlutterIOOverrides
(
fileSystem:
globals
.
fs
));
expect
(
await
webDevFS
.
webAssetServer
.
dartSourceContents
(
'/dart_sdk.js'
),
'HELLO'
);
}),
skip:
true
);
// Not clear the best way to test this, since shelf hits the real filesystem.
// Update to the SDK.
webDevFS
.
webAssetServer
.
dartSdk
.
writeAsStringSync
(
'BELLOW'
);
// New SDK should be visible..
expect
(
await
webDevFS
.
webAssetServer
.
dartSourceContents
(
'/dart_sdk.js'
),
'BELLOW'
);
await
webDevFS
.
destroy
();
}));
}
}
class
MockHttpServer
extends
Mock
implements
HttpServer
{}
class
MockHttpServer
extends
Mock
implements
HttpServer
{}
...
...
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