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
9904a7f4
Unverified
Commit
9904a7f4
authored
Apr 17, 2021
by
Jonah Williams
Committed by
GitHub
Apr 17, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor core resident runner logic (#80462)
parent
aa9f6a2a
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
505 additions
and
847 deletions
+505
-847
file_system.dart
packages/flutter_tools/lib/src/base/file_system.dart
+22
-12
daemon.dart
packages/flutter_tools/lib/src/commands/daemon.dart
+11
-3
resident_web_runner.dart
...s/flutter_tools/lib/src/isolated/resident_web_runner.dart
+2
-19
resident_runner.dart
packages/flutter_tools/lib/src/resident_runner.dart
+442
-422
run_cold.dart
packages/flutter_tools/lib/src/run_cold.dart
+5
-1
run_hot.dart
packages/flutter_tools/lib/src/run_hot.dart
+2
-5
resident_runner_test.dart
...lutter_tools/test/general.shard/resident_runner_test.dart
+5
-370
resident_web_runner_cold_test.dart
...ols/test/general.shard/resident_web_runner_cold_test.dart
+0
-1
resident_web_runner_test.dart
...er_tools/test/general.shard/resident_web_runner_test.dart
+1
-10
terminal_handler_test.dart
...utter_tools/test/general.shard/terminal_handler_test.dart
+15
-4
No files found.
packages/flutter_tools/lib/src/base/file_system.dart
View file @
9904a7f4
...
...
@@ -41,18 +41,7 @@ class FileSystemUtils {
/// Appends a number to a filename in order to make it unique under a
/// directory.
File
getUniqueFile
(
Directory
dir
,
String
baseName
,
String
ext
)
{
final
FileSystem
fs
=
dir
.
fileSystem
;
int
i
=
1
;
while
(
true
)
{
final
String
name
=
'
${baseName}
_
${i.toString().padLeft(2, '0')}
.
$ext
'
;
final
File
file
=
fs
.
file
(
_fileSystem
.
path
.
join
(
dir
.
path
,
name
));
if
(!
file
.
existsSync
())
{
file
.
createSync
(
recursive:
true
);
return
file
;
}
i
+=
1
;
}
return
_getUniqueFile
(
dir
,
baseName
,
ext
);
}
/// Appends a number to a directory name in order to make it unique under a
...
...
@@ -157,6 +146,27 @@ void copyDirectory(
}
}
File
_getUniqueFile
(
Directory
dir
,
String
baseName
,
String
ext
)
{
final
FileSystem
fs
=
dir
.
fileSystem
;
int
i
=
1
;
while
(
true
)
{
final
String
name
=
'
${baseName}
_
${i.toString().padLeft(2, '0')}
.
$ext
'
;
final
File
file
=
fs
.
file
(
dir
.
fileSystem
.
path
.
join
(
dir
.
path
,
name
));
if
(!
file
.
existsSync
())
{
file
.
createSync
(
recursive:
true
);
return
file
;
}
i
+=
1
;
}
}
/// Appends a number to a filename in order to make it unique under a
/// directory.
File
getUniqueFile
(
Directory
dir
,
String
baseName
,
String
ext
)
{
return
_getUniqueFile
(
dir
,
baseName
,
ext
);
}
/// This class extends [local_fs.LocalFileSystem] in order to clean up
/// directories and files that the tool creates under the system temporary
/// directory when the tool exits either normally or when killed by a signal.
...
...
packages/flutter_tools/lib/src/commands/daemon.dart
View file @
9904a7f4
...
...
@@ -29,6 +29,7 @@ import '../resident_runner.dart';
import
'../run_cold.dart'
;
import
'../run_hot.dart'
;
import
'../runner/flutter_command.dart'
;
import
'../vmservice.dart'
;
import
'../web/web_runner.dart'
;
const
String
protocolVersion
=
'0.6.0'
;
...
...
@@ -687,9 +688,16 @@ class AppDomain extends Domain {
if
(
app
==
null
)
{
throw
"app '
$appId
' not found"
;
}
final
Map
<
String
,
dynamic
>
result
=
await
app
.
runner
.
invokeFlutterExtensionRpcRawOnFirstIsolate
(
methodName
,
params:
params
);
final
FlutterDevice
device
=
app
.
runner
.
flutterDevices
.
first
;
final
List
<
FlutterView
>
views
=
await
device
.
vmService
.
getFlutterViews
();
final
Map
<
String
,
dynamic
>
result
=
await
device
.
vmService
.
invokeFlutterExtensionRpcRaw
(
methodName
,
args:
params
,
isolateId:
views
.
first
.
uiIsolate
.
id
);
if
(
result
==
null
)
{
throw
'method not available:
$methodName
'
;
}
...
...
packages/flutter_tools/lib/src/isolated/resident_web_runner.dart
View file @
9904a7f4
...
...
@@ -76,7 +76,6 @@ class DwdsWebRunnerFactory extends WebRunnerFactory {
systemClock:
systemClock
,
fileSystem:
fileSystem
,
logger:
logger
,
featureFlags:
featureFlags
,
);
}
}
...
...
@@ -99,14 +98,12 @@ class ResidentWebRunner extends ResidentRunner {
@required
SystemClock
systemClock
,
@required
Usage
usage
,
@required
UrlTunneller
urlTunneller
,
@required
FeatureFlags
featureFlags
,
ResidentDevtoolsHandlerFactory
devtoolsHandler
=
createDefaultHandler
,
})
:
_fileSystem
=
fileSystem
,
_logger
=
logger
,
_systemClock
=
systemClock
,
_usage
=
usage
,
_urlTunneller
=
urlTunneller
,
_featureFlags
=
featureFlags
,
super
(
<
FlutterDevice
>[
device
],
target:
target
??
fileSystem
.
path
.
join
(
'lib'
,
'main.dart'
),
...
...
@@ -122,7 +119,6 @@ class ResidentWebRunner extends ResidentRunner {
final
SystemClock
_systemClock
;
final
Usage
_usage
;
final
UrlTunneller
_urlTunneller
;
final
FeatureFlags
_featureFlags
;
FlutterDevice
get
device
=>
flutterDevices
.
first
;
final
FlutterProject
flutterProject
;
...
...
@@ -167,20 +163,7 @@ class ResidentWebRunner extends ResidentRunner {
FlutterVmService
_instance
;
@override
bool
get
canHotRestart
{
return
true
;
}
@override
Future
<
Map
<
String
,
dynamic
>>
invokeFlutterExtensionRpcRawOnFirstIsolate
(
String
method
,
{
FlutterDevice
device
,
Map
<
String
,
dynamic
>
params
,
})
async
{
final
vmservice
.
Response
response
=
await
_vmService
.
service
.
callServiceExtension
(
method
,
args:
params
);
return
response
.
toJson
();
}
bool
get
supportsRestart
=>
true
;
@override
Future
<
void
>
cleanupAfterSignal
()
async
{
...
...
@@ -313,7 +296,7 @@ class ResidentWebRunner extends ResidentRunner {
?.
flutterPlatformOverride
(
isolateId:
null
,
);
final
String
platform
=
nextPlatform
(
currentPlatform
,
_featureFlags
);
final
String
platform
=
nextPlatform
(
currentPlatform
);
await
_vmService
?.
flutterPlatformOverride
(
platform:
platform
,
...
...
packages/flutter_tools/lib/src/resident_runner.dart
View file @
9904a7f4
This diff is collapsed.
Click to expand it.
packages/flutter_tools/lib/src/run_cold.dart
View file @
9904a7f4
...
...
@@ -10,6 +10,7 @@ import 'package:meta/meta.dart';
import
'base/common.dart'
;
import
'base/file_system.dart'
;
import
'base/logger.dart'
;
import
'build_info.dart'
;
import
'device.dart'
;
import
'globals_null_migrated.dart'
as
globals
;
...
...
@@ -51,7 +52,10 @@ class ColdRunner extends ResidentRunner {
bool
get
canHotReload
=>
false
;
@override
bool
get
canHotRestart
=>
false
;
Logger
get
logger
=>
globals
.
logger
;
@override
FileSystem
get
fileSystem
=>
globals
.
fs
;
@override
Future
<
int
>
run
({
...
...
packages/flutter_tools/lib/src/run_hot.dart
View file @
9904a7f4
...
...
@@ -598,9 +598,6 @@ class HotRunner extends ResidentRunner {
return
true
;
}
@override
bool
get
supportsRestart
=>
true
;
@override
Future
<
OperationResult
>
restart
({
bool
fullRestart
=
false
,
...
...
@@ -670,7 +667,7 @@ class HotRunner extends ResidentRunner {
String
reason
,
bool
silent
,
})
async
{
if
(!
canHot
Restart
)
{
if
(!
supports
Restart
)
{
return
OperationResult
(
1
,
'hotRestart not supported'
);
}
Status
status
;
...
...
@@ -1089,7 +1086,7 @@ class HotRunner extends ResidentRunner {
void
printHelp
({
@required
bool
details
})
{
globals
.
printStatus
(
'Flutter run key commands.'
);
commandHelp
.
r
.
print
();
if
(
canHot
Restart
)
{
if
(
supports
Restart
)
{
commandHelp
.
R
.
print
();
}
commandHelp
.
h
.
print
();
// TODO(ianh): print different message if "details" is false
...
...
packages/flutter_tools/test/general.shard/resident_runner_test.dart
View file @
9904a7f4
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/general.shard/resident_web_runner_cold_test.dart
View file @
9904a7f4
...
...
@@ -55,7 +55,6 @@ void main() {
ipv6:
true
,
stayResident:
true
,
urlTunneller:
null
,
featureFlags:
TestFeatureFlags
(),
fileSystem:
globals
.
fs
,
logger:
globals
.
logger
,
systemClock:
globals
.
systemClock
,
...
...
packages/flutter_tools/test/general.shard/resident_web_runner_test.dart
View file @
9904a7f4
...
...
@@ -195,7 +195,6 @@ void main() {
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
usage:
globals
.
flutterUsage
,
featureFlags:
TestFeatureFlags
(),
systemClock:
globals
.
systemClock
,
);
...
...
@@ -229,7 +228,7 @@ void main() {
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
usage:
globals
.
flutterUsage
,
featureFlags:
TestFeatureFlags
(),
systemClock:
globals
.
systemClock
,
);
...
...
@@ -253,7 +252,6 @@ void main() {
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
usage:
globals
.
flutterUsage
,
featureFlags:
TestFeatureFlags
(),
systemClock:
globals
.
systemClock
,
);
fakeVmServiceHost
=
FakeVmServiceHost
(
requests:
<
VmServiceExpectation
>[]);
...
...
@@ -268,7 +266,6 @@ void main() {
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
usage:
globals
.
flutterUsage
,
featureFlags:
TestFeatureFlags
(),
systemClock:
globals
.
systemClock
,
);
...
...
@@ -373,7 +370,6 @@ void main() {
fileSystem:
fileSystem
,
logger:
logger
,
usage:
globals
.
flutterUsage
,
featureFlags:
TestFeatureFlags
(),
systemClock:
globals
.
systemClock
,
);
...
...
@@ -398,7 +394,6 @@ void main() {
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
usage:
globals
.
flutterUsage
,
featureFlags:
TestFeatureFlags
(),
systemClock:
globals
.
systemClock
,
);
...
...
@@ -517,7 +512,6 @@ void main() {
fileSystem:
fileSystem
,
logger:
BufferLogger
.
test
(),
usage:
globals
.
flutterUsage
,
featureFlags:
TestFeatureFlags
(),
systemClock:
globals
.
systemClock
,
);
fakeVmServiceHost
=
FakeVmServiceHost
(
requests:
kAttachExpectations
.
toList
());
...
...
@@ -1439,7 +1433,6 @@ void main() {
fileSystem:
fileSystem
,
logger:
logger
,
usage:
globals
.
flutterUsage
,
featureFlags:
TestFeatureFlags
(),
systemClock:
globals
.
systemClock
,
);
...
...
@@ -1487,7 +1480,6 @@ void main() {
fileSystem:
fileSystem
,
logger:
logger
,
usage:
globals
.
flutterUsage
,
featureFlags:
TestFeatureFlags
(),
systemClock:
globals
.
systemClock
,
);
...
...
@@ -1606,7 +1598,6 @@ ResidentRunner setUpResidentRunner(FlutterDevice flutterDevice, {
systemClock:
systemClock
??
SystemClock
.
fixed
(
DateTime
.
now
()),
fileSystem:
globals
.
fs
,
logger:
logger
??
BufferLogger
.
test
(),
featureFlags:
TestFeatureFlags
(),
);
}
...
...
packages/flutter_tools/test/general.shard/terminal_handler_test.dart
View file @
9904a7f4
...
...
@@ -240,7 +240,7 @@ void main() {
});
testWithoutContext
(
'R - hotRestart supported and succeeds'
,
()
async
{
when
(
mockResidentRunner
.
canHot
Restart
).
thenReturn
(
true
);
when
(
mockResidentRunner
.
supports
Restart
).
thenReturn
(
true
);
when
(
mockResidentRunner
.
hotMode
).
thenReturn
(
true
);
when
(
mockResidentRunner
.
restart
(
fullRestart:
true
))
.
thenAnswer
((
Invocation
invocation
)
async
{
...
...
@@ -252,7 +252,7 @@ void main() {
});
testWithoutContext
(
'R - hotRestart supported and fails'
,
()
async
{
when
(
mockResidentRunner
.
canHot
Restart
).
thenReturn
(
true
);
when
(
mockResidentRunner
.
supports
Restart
).
thenReturn
(
true
);
when
(
mockResidentRunner
.
hotMode
).
thenReturn
(
true
);
when
(
mockResidentRunner
.
restart
(
fullRestart:
true
))
.
thenAnswer
((
Invocation
invocation
)
async
{
...
...
@@ -266,7 +266,7 @@ void main() {
});
testWithoutContext
(
'R - hotRestart supported and fails fatally'
,
()
async
{
when
(
mockResidentRunner
.
canHot
Restart
).
thenReturn
(
true
);
when
(
mockResidentRunner
.
supports
Restart
).
thenReturn
(
true
);
when
(
mockResidentRunner
.
hotMode
).
thenReturn
(
true
);
when
(
mockResidentRunner
.
restart
(
fullRestart:
true
))
.
thenAnswer
((
Invocation
invocation
)
async
{
...
...
@@ -276,12 +276,23 @@ void main() {
});
testWithoutContext
(
'R - hot restart unsupported'
,
()
async
{
when
(
mockResidentRunner
.
canHot
Restart
).
thenReturn
(
false
);
when
(
mockResidentRunner
.
supports
Restart
).
thenReturn
(
false
);
await
terminalHandler
.
processTerminalInput
(
'R'
);
verifyNever
(
mockResidentRunner
.
restart
(
fullRestart:
true
));
});
testWithoutContext
(
'ResidentRunner clears the screen when it should'
,
()
async
{
const
String
message
=
'This should be cleared'
;
expect
(
testLogger
.
statusText
,
equals
(
''
));
testLogger
.
printStatus
(
message
);
expect
(
testLogger
.
statusText
,
equals
(
message
+
'
\n
'
));
// printStatus makes a newline
await
terminalHandler
.
processTerminalInput
(
'c'
);
expect
(
testLogger
.
statusText
,
equals
(
''
));
});
testWithoutContext
(
'S - debugDumpSemanticsTreeInTraversalOrder with service protocol'
,
()
async
{
await
terminalHandler
.
processTerminalInput
(
'S'
);
...
...
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