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
ffbca11f
Unverified
Commit
ffbca11f
authored
Dec 01, 2020
by
Jonah Williams
Committed by
GitHub
Dec 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] delete BuildRunnerWebCompilationProxy and WebCompilationProxy (#70914)
parent
18167785
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
240 additions
and
33 deletions
+240
-33
executable.dart
packages/flutter_tools/lib/executable.dart
+0
-3
bundle.dart
packages/flutter_tools/lib/src/bundle.dart
+7
-1
runner.dart
packages/flutter_tools/lib/src/test/runner.dart
+9
-2
web_test_compiler.dart
packages/flutter_tools/lib/src/test/web_test_compiler.dart
+151
-0
bootstrap.dart
packages/flutter_tools/lib/src/web/bootstrap.dart
+70
-0
compile.dart
packages/flutter_tools/lib/src/web/compile.dart
+0
-24
event_printer_test.dart
...ter_tools/test/general.shard/test/event_printer_test.dart
+0
-0
test_compiler_test.dart
...ter_tools/test/general.shard/test/test_compiler_test.dart
+3
-3
No files found.
packages/flutter_tools/lib/executable.dart
View file @
ffbca11f
...
...
@@ -50,10 +50,8 @@ import 'src/globals.dart' as globals;
import
'src/isolated/devtools_launcher.dart'
;
import
'src/isolated/mustache_template.dart'
;
import
'src/isolated/resident_web_runner.dart'
;
import
'src/isolated/web_compilation_delegate.dart'
;
import
'src/resident_runner.dart'
;
import
'src/runner/flutter_command.dart'
;
import
'src/web/compile.dart'
;
import
'src/web/web_runner.dart'
;
/// Main entry point for commands.
...
...
@@ -145,7 +143,6 @@ Future<void> main(List<String> args) async {
muteCommandLogging:
muteCommandLogging
,
verboseHelp:
verboseHelp
,
overrides:
<
Type
,
Generator
>{
WebCompilationProxy:
()
=>
BuildRunnerWebCompilationProxy
(),
// The web runner is not supported in google3 because it depends
// on dwds.
WebRunnerFactory:
()
=>
DwdsWebRunnerFactory
(),
...
...
packages/flutter_tools/lib/src/bundle.dart
View file @
ffbca11f
...
...
@@ -9,6 +9,7 @@ import 'package:pool/pool.dart';
import
'asset.dart'
;
import
'base/common.dart'
;
import
'base/config.dart'
;
import
'base/file_system.dart'
;
import
'base/logger.dart'
;
import
'build_info.dart'
;
...
...
@@ -40,6 +41,8 @@ String getDefaultCachedKernelPath({
@required
bool
trackWidgetCreation
,
@required
List
<
String
>
dartDefines
,
@required
List
<
String
>
extraFrontEndOptions
,
FileSystem
fileSystem
,
Config
config
,
})
{
final
StringBuffer
buffer
=
StringBuffer
();
buffer
.
writeAll
(
dartDefines
);
...
...
@@ -51,7 +54,10 @@ String getDefaultCachedKernelPath({
buildPrefix
=
'
${hex.encode(digest.bytes)}
.'
;
}
return
getKernelPathForTransformerOptions
(
globals
.
fs
.
path
.
join
(
getBuildDirectory
(),
'
${buildPrefix}
cache.dill'
),
(
fileSystem
??
globals
.
fs
).
path
.
join
(
getBuildDirectory
(
config
??
globals
.
config
,
fileSystem
??
globals
.
fs
),
'
${buildPrefix}
cache.dill'
),
trackWidgetCreation:
trackWidgetCreation
,
);
}
...
...
packages/flutter_tools/lib/src/test/runner.dart
View file @
ffbca11f
...
...
@@ -12,12 +12,12 @@ import '../build_info.dart';
import
'../globals.dart'
as
globals
;
import
'../project.dart'
;
import
'../web/chrome.dart'
;
import
'../web/compile.dart'
;
import
'../web/memory_fs.dart'
;
import
'flutter_platform.dart'
as
loader
;
import
'flutter_web_platform.dart'
;
import
'test_wrapper.dart'
;
import
'watcher.dart'
;
import
'web_test_compiler.dart'
;
/// A class that abstracts launching the test process from the test runner.
abstract
class
FlutterTestRunner
{
...
...
@@ -123,7 +123,14 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
.
absolute
.
uri
.
toFilePath
();
final
WebMemoryFS
result
=
await
webCompilationProxy
.
initialize
(
final
WebMemoryFS
result
=
await
WebTestCompiler
(
logger:
globals
.
logger
,
fileSystem:
globals
.
fs
,
platform:
globals
.
platform
,
artifacts:
globals
.
artifacts
,
processManager:
globals
.
processManager
,
config:
globals
.
config
,
).
initialize
(
projectDirectory:
flutterProject
.
directory
,
testOutputDir:
tempBuildDir
,
testFiles:
testFiles
,
...
...
packages/flutter_tools/lib/src/
isolated/web_compilation_delegate
.dart
→
packages/flutter_tools/lib/src/
test/web_test_compiler
.dart
View file @
ffbca11f
...
...
@@ -4,25 +4,44 @@
import
'package:meta/meta.dart'
;
import
'package:package_config/package_config.dart'
;
import
'package:process/process.dart'
;
import
'../artifacts.dart'
;
import
'../base/common.dart'
;
import
'../base/config.dart'
;
import
'../base/file_system.dart'
;
import
'../base/logger.dart'
;
import
'../base/platform.dart'
;
import
'../build_info.dart'
;
import
'../bundle.dart'
;
import
'../compile.dart'
;
import
'../dart/language_version.dart'
;
import
'../globals.dart'
as
globals
;
import
'../web/compile.dart'
;
import
'../web/bootstrap.dart'
;
import
'../web/memory_fs.dart'
;
// TODO(jonahwilliams): this class was kept around to reduce the diff in the migration
// from build_runner to the frontend_server, but should be removed/refactored to be
// similar to the test_compiler pattern used for regular flutter tests
class
BuildRunnerWebCompilationProxy
extends
WebCompilationProxy
{
BuildRunnerWebCompilationProxy
();
/// A web compiler for the test runner.
class
WebTestCompiler
{
WebTestCompiler
({
@required
FileSystem
fileSystem
,
@required
Logger
logger
,
@required
Artifacts
artifacts
,
@required
Platform
platform
,
@required
ProcessManager
processManager
,
@required
Config
config
,
})
:
_logger
=
logger
,
_fileSystem
=
fileSystem
,
_artifacts
=
artifacts
,
_platform
=
platform
,
_processManager
=
processManager
,
_config
=
config
;
final
Logger
_logger
;
final
FileSystem
_fileSystem
;
final
Artifacts
_artifacts
;
final
Platform
_platform
;
final
ProcessManager
_processManager
;
final
Config
_config
;
@override
Future
<
WebMemoryFS
>
initialize
({
@required
Directory
projectDirectory
,
@required
String
testOutputDir
,
...
...
@@ -47,32 +66,43 @@ class BuildRunnerWebCompilationProxy extends WebCompilationProxy {
}
}
final
Directory
outputDirectory
=
globals
.
fs
.
directory
(
testOutputDir
)
final
Directory
outputDirectory
=
_fileSystem
.
directory
(
testOutputDir
)
..
createSync
(
recursive:
true
);
final
List
<
File
>
generatedFiles
=
<
File
>[];
for
(
final
String
testFilePath
in
testFiles
)
{
final
List
<
String
>
relativeTestSegments
=
globals
.
fs
.
path
.
split
(
globals
.
fs
.
path
.
relative
(
testFilePath
,
from:
projectDirectory
.
childDirectory
(
'test'
).
path
));
final
File
generatedFile
=
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
outputDirectory
.
path
,
'
${relativeTestSegments.join('_')}
.test.dart'
));
final
List
<
String
>
relativeTestSegments
=
_fileSystem
.
path
.
split
(
_fileSystem
.
path
.
relative
(
testFilePath
,
from:
projectDirectory
.
childDirectory
(
'test'
).
path
));
final
File
generatedFile
=
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
outputDirectory
.
path
,
'
${relativeTestSegments.join('_')}
.test.dart'
));
generatedFile
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
_generateEntrypoint
(
relativeTestSegments
.
join
(
'/'
),
testFilePath
,
languageVersion
));
..
writeAsStringSync
(
generateTestEntrypoint
(
relativeTestPath:
relativeTestSegments
.
join
(
'/'
),
absolutePath:
testFilePath
,
languageVersion:
languageVersion
,
));
generatedFiles
.
add
(
generatedFile
);
}
// Generate a fake main file that imports all tests to be executed. This will force
// each of them to be compiled.
final
StringBuffer
buffer
=
StringBuffer
(
'// @dart=
${languageVersion.major}
.
${languageVersion.minor}
\n
'
);
for
(
final
File
generatedFile
in
generatedFiles
)
{
buffer
.
writeln
(
'import "
${
globals.fs
.path.basename(generatedFile.path)}
";'
);
buffer
.
writeln
(
'import "
${
_fileSystem
.path.basename(generatedFile.path)}
";'
);
}
buffer
.
writeln
(
'void main() {}'
);
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
outputDirectory
.
path
,
'main.dart'
))
_fileSystem
.
file
(
_fileSystem
.
path
.
join
(
outputDirectory
.
path
,
'main.dart'
))
..
createSync
()
..
writeAsStringSync
(
buffer
.
toString
());
final
String
cachedKernelPath
=
getDefaultCachedKernelPath
(
trackWidgetCreation:
buildInfo
.
trackWidgetCreation
,
dartDefines:
buildInfo
.
dartDefines
,
extraFrontEndOptions:
extraFrontEndOptions
,
fileSystem:
_fileSystem
,
config:
_config
,
);
final
ResidentCompiler
residentCompiler
=
ResidentCompiler
(
globals
.
artifacts
.
getArtifactPath
(
Artifact
.
flutterWebSdk
,
mode:
buildInfo
.
mode
),
_
artifacts
.
getArtifactPath
(
Artifact
.
flutterWebSdk
,
mode:
buildInfo
.
mode
),
buildMode:
buildInfo
.
mode
,
trackWidgetCreation:
buildInfo
.
trackWidgetCreation
,
fileSystemRoots:
<
String
>[
...
...
@@ -82,24 +112,20 @@ class BuildRunnerWebCompilationProxy extends WebCompilationProxy {
// Override the filesystem scheme so that the frontend_server can find
// the generated entrypoint code.
fileSystemScheme:
'org-dartlang-app'
,
initializeFromDill:
getDefaultCachedKernelPath
(
trackWidgetCreation:
buildInfo
.
trackWidgetCreation
,
dartDefines:
buildInfo
.
dartDefines
,
extraFrontEndOptions:
extraFrontEndOptions
,
),
initializeFromDill:
cachedKernelPath
,
targetModel:
TargetModel
.
dartdevc
,
extraFrontEndOptions:
extraFrontEndOptions
,
platformDill:
globals
.
fs
.
file
(
globals
.
artifacts
platformDill:
_fileSystem
.
file
(
_
artifacts
.
getArtifactPath
(
platformDillArtifact
,
mode:
buildInfo
.
mode
))
.
absolute
.
uri
.
toString
(),
dartDefines:
buildInfo
.
dartDefines
,
librariesSpec:
globals
.
fs
.
file
(
globals
.
artifacts
librariesSpec:
_fileSystem
.
file
(
_
artifacts
.
getArtifactPath
(
Artifact
.
flutterWebLibrariesJson
)).
uri
.
toString
(),
packagesPath:
buildInfo
.
packagesPath
,
artifacts:
globals
.
artifacts
,
processManager:
globals
.
processManager
,
logger:
globals
.
logger
,
platform:
globals
.
platform
,
artifacts:
_
artifacts
,
processManager:
_
processManager
,
logger:
_
logger
,
platform:
_
platform
,
);
final
CompilerOutput
output
=
await
residentCompiler
.
recompile
(
...
...
@@ -111,6 +137,10 @@ class BuildRunnerWebCompilationProxy extends WebCompilationProxy {
if
(
output
.
errorCount
>
0
)
{
throwToolExit
(
'Failed to compile'
);
}
// Cache the output kernel file to speed up subsequent compiles.
_fileSystem
.
file
(
cachedKernelPath
).
parent
.
createSync
(
recursive:
true
);
_fileSystem
.
file
(
output
.
outputFilename
).
copySync
(
cachedKernelPath
);
final
File
codeFile
=
outputDirectory
.
childFile
(
'
${output.outputFilename}
.sources'
);
final
File
manifestFile
=
outputDirectory
.
childFile
(
'
${output.outputFilename}
.json'
);
final
File
sourcemapFile
=
outputDirectory
.
childFile
(
'
${output.outputFilename}
.map'
);
...
...
@@ -118,70 +148,4 @@ class BuildRunnerWebCompilationProxy extends WebCompilationProxy {
return
WebMemoryFS
()
..
write
(
codeFile
,
manifestFile
,
sourcemapFile
,
metadataFile
);
}
String
_generateEntrypoint
(
String
relativeTestPath
,
String
absolutePath
,
LanguageVersion
languageVersion
)
{
return
'''
// @dart =
${languageVersion.major}
.
${languageVersion.minor}
import '
org
-
dartlang
-
app:
///$relativeTestPath' as test;
import
'dart:ui'
as
ui
;
import
'dart:html'
;
import
'dart:js'
;
import
'package:stream_channel/stream_channel.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:test_api/src/backend/stack_trace_formatter.dart'
;
// ignore: implementation_imports
import
'package:test_api/src/remote_listener.dart'
;
// ignore: implementation_imports
import
'package:test_api/src/suite_channel_manager.dart'
;
// ignore: implementation_imports
// Extra initialization for flutter_web.
// The following parameters are hard-coded in Flutter's test embedder. Since
// we don't have an embedder yet this is the lowest-most layer we can put
// this stuff in.
Future
<
void
>
main
()
async
{
ui
.
debugEmulateFlutterTesterEnvironment
=
true
;
await
ui
.
webOnlyInitializePlatform
();
webGoldenComparator
=
DefaultWebGoldenComparator
(
Uri
.
parse
(
'
$absolutePath
'
));
(
ui
.
window
as
dynamic
).
debugOverrideDevicePixelRatio
(
3.0
);
(
ui
.
window
as
dynamic
).
webOnlyDebugPhysicalSizeOverride
=
const
ui
.
Size
(
2400
,
1800
);
internalBootstrapBrowserTest
(()
=>
test
.
main
);
}
void
internalBootstrapBrowserTest
(
Function
getMain
())
{
var
channel
=
serializeSuite
(
getMain
,
hidePrints:
false
);
postMessageChannel
().
pipe
(
channel
);
}
StreamChannel
serializeSuite
(
Function
getMain
(),
{
bool
hidePrints
=
true
})
=>
RemoteListener
.
start
(
getMain
,
hidePrints:
hidePrints
);
StreamChannel
suiteChannel
(
String
name
)
{
var
manager
=
SuiteChannelManager
.
current
;
if
(
manager
==
null
)
{
throw
StateError
(
'suiteChannel() may only be called within a test worker.'
);
}
return
manager
.
connectOut
(
name
);
}
StreamChannel
postMessageChannel
()
{
var
controller
=
StreamChannelController
(
sync:
true
);
window
.
onMessage
.
firstWhere
((
message
)
{
return
message
.
origin
==
window
.
location
.
origin
&&
message
.
data
==
"port"
;
}).
then
((
message
)
{
var
port
=
message
.
ports
.
first
;
var
portSubscription
=
port
.
onMessage
.
listen
((
message
)
{
controller
.
local
.
sink
.
add
(
message
.
data
);
});
controller
.
local
.
stream
.
listen
((
data
)
{
port
.
postMessage
({
"data"
:
data
});
},
onDone:
()
{
port
.
postMessage
({
"event"
:
"done"
});
portSubscription
.
cancel
();
});
});
context
[
'parent'
].
callMethod
(
'postMessage'
,
[
JsObject
.
jsify
({
"href"
:
window
.
location
.
href
,
"ready"
:
true
}),
window
.
location
.
origin
,
]);
return
controller
.
foreign
;
}
''';
}
}
packages/flutter_tools/lib/src/web/bootstrap.dart
View file @
ffbca11f
...
...
@@ -3,6 +3,7 @@
// found in the LICENSE file.
import
'package:meta/meta.dart'
;
import
'package:package_config/package_config.dart'
;
/// The JavaScript bootstrap script to support in-browser hot restart.
///
...
...
@@ -95,6 +96,75 @@ define("$bootstrapModule", ["$entrypoint", "dart_sdk"], function(app, dart_sdk)
''';
}
/// Generates the bootstrap logic required for a flutter test running in a browser.
///
/// This hard-codes the device pixel ratio to 3.0 and a 2400 x 1800 window size.
String generateTestEntrypoint({
@required String relativeTestPath,
@required String absolutePath,
@required LanguageVersion languageVersion,
}) {
return '''
// @dart = ${languageVersion.major}.${languageVersion.minor}
import
'org-dartlang-app:///
$relativeTestPath
'
as
test
;
import
'dart:ui'
as
ui
;
import
'dart:html'
;
import
'dart:js'
;
import
'package:stream_channel/stream_channel.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:test_api/src/backend/stack_trace_formatter.dart'
;
// ignore: implementation_imports
import
'package:test_api/src/remote_listener.dart'
;
// ignore: implementation_imports
import
'package:test_api/src/suite_channel_manager.dart'
;
// ignore: implementation_imports
Future
<
void
>
main
()
async
{
ui
.
debugEmulateFlutterTesterEnvironment
=
true
;
await
ui
.
webOnlyInitializePlatform
();
webGoldenComparator
=
DefaultWebGoldenComparator
(
Uri
.
parse
(
'
$absolutePath
'
));
(
ui
.
window
as
dynamic
).
debugOverrideDevicePixelRatio
(
3.0
);
(
ui
.
window
as
dynamic
).
webOnlyDebugPhysicalSizeOverride
=
const
ui
.
Size
(
2400
,
1800
);
internalBootstrapBrowserTest
(()
=>
test
.
main
);
}
void
internalBootstrapBrowserTest
(
Function
getMain
())
{
var
channel
=
serializeSuite
(
getMain
,
hidePrints:
false
);
postMessageChannel
().
pipe
(
channel
);
}
StreamChannel
serializeSuite
(
Function
getMain
(),
{
bool
hidePrints
=
true
})
=>
RemoteListener
.
start
(
getMain
,
hidePrints:
hidePrints
);
StreamChannel
suiteChannel
(
String
name
)
{
var
manager
=
SuiteChannelManager
.
current
;
if
(
manager
==
null
)
{
throw
StateError
(
'suiteChannel() may only be called within a test worker.'
);
}
return
manager
.
connectOut
(
name
);
}
StreamChannel
postMessageChannel
()
{
var
controller
=
StreamChannelController
(
sync:
true
);
window
.
onMessage
.
firstWhere
((
message
)
{
return
message
.
origin
==
window
.
location
.
origin
&&
message
.
data
==
"port"
;
}).
then
((
message
)
{
var
port
=
message
.
ports
.
first
;
var
portSubscription
=
port
.
onMessage
.
listen
((
message
)
{
controller
.
local
.
sink
.
add
(
message
.
data
);
});
controller
.
local
.
stream
.
listen
((
data
)
{
port
.
postMessage
({
"data"
:
data
});
},
onDone:
()
{
port
.
postMessage
({
"event"
:
"done"
});
portSubscription
.
cancel
();
});
});
context
[
'parent'
].
callMethod
(
'postMessage'
,
[
JsObject
.
jsify
({
"href"
:
window
.
location
.
href
,
"ready"
:
true
}),
window
.
location
.
origin
,
]);
return
controller
.
foreign
;
}
''';
}
/// Generate the unit test bootstrap file.
String generateTestBootstrapFileContents(String mainUri, String requireUrl, String mapperUrl) {
return '''
...
...
packages/flutter_tools/lib/src/web/compile.dart
View file @
ffbca11f
...
...
@@ -2,11 +2,8 @@
// 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
'../artifacts.dart'
;
import
'../base/common.dart'
;
import
'../base/context.dart'
;
import
'../base/file_system.dart'
;
import
'../base/logger.dart'
;
import
'../build_info.dart'
;
...
...
@@ -19,10 +16,6 @@ import '../globals.dart' as globals;
import
'../platform_plugins.dart'
;
import
'../plugins.dart'
;
import
'../project.dart'
;
import
'../web/memory_fs.dart'
;
/// The [WebCompilationProxy] instance.
WebCompilationProxy
get
webCompilationProxy
=>
context
.
get
<
WebCompilationProxy
>();
Future
<
void
>
buildWeb
(
FlutterProject
flutterProject
,
...
...
@@ -91,23 +84,6 @@ Future<void> buildWeb(
globals
.
flutterUsage
.
sendTiming
(
'build'
,
'dart2js'
,
Duration
(
milliseconds:
sw
.
elapsedMilliseconds
));
}
/// An indirection on web compilation.
///
/// Avoids issues with syncing build_runner_core to other repos.
class
WebCompilationProxy
{
const
WebCompilationProxy
();
/// Initialize the web compiler from the `projectDirectory`.
Future
<
WebMemoryFS
>
initialize
({
@required
Directory
projectDirectory
,
@required
String
testOutputDir
,
@required
List
<
String
>
testFiles
,
@required
BuildInfo
buildInfo
,
})
async
{
throw
UnimplementedError
();
}
}
/// Web rendering backend mode.
enum
WebRendererMode
{
/// Auto detects which rendering backend to use.
...
...
packages/flutter_tools/test/general.shard/test
er
/event_printer_test.dart
→
packages/flutter_tools/test/general.shard/test/event_printer_test.dart
View file @
ffbca11f
File moved
packages/flutter_tools/test/general.shard/test_compiler_test.dart
→
packages/flutter_tools/test/general.shard/test
/test
_compiler_test.dart
View file @
ffbca11f
...
...
@@ -14,9 +14,9 @@ import 'package:flutter_tools/src/test/test_compiler.dart';
import
'package:mockito/mockito.dart'
;
import
'package:package_config/package_config_types.dart'
;
import
'../src/common.dart'
;
import
'../src/context.dart'
;
import
'../src/testbed.dart'
;
import
'../
../
src/common.dart'
;
import
'../
../
src/context.dart'
;
import
'../
../
src/testbed.dart'
;
final
Platform
linuxPlatform
=
FakePlatform
(
operatingSystem:
'linux'
,
...
...
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