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
6cf554b0
Unverified
Commit
6cf554b0
authored
Jan 25, 2019
by
Jonah Williams
Committed by
GitHub
Jan 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make UriMapper and StdoutHandler public and add test cases (#26932)
parent
496c5738
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
18 deletions
+64
-18
compile.dart
packages/flutter_tools/lib/src/compile.dart
+17
-18
compile_test.dart
packages/flutter_tools/test/compile_test.dart
+47
-0
No files found.
packages/flutter_tools/lib/src/compile.dart
View file @
6cf554b0
...
...
@@ -63,8 +63,9 @@ class CompilerOutput {
final
int
errorCount
;
}
class
_StdoutHandler
{
_StdoutHandler
({
this
.
consumer
=
printError
})
{
/// Handles stdin/stdout communication with the frontend server.
class
StdoutHandler
{
StdoutHandler
({
this
.
consumer
=
printError
})
{
reset
();
}
...
...
@@ -90,8 +91,7 @@ class _StdoutHandler {
CompilerOutput
(
message
.
substring
(
boundaryKey
.
length
+
1
,
spaceDelimiter
),
int
.
parse
(
message
.
substring
(
spaceDelimiter
+
1
).
trim
())));
}
else
if
(!
_suppressCompilerMessages
)
{
}
else
if
(!
_suppressCompilerMessages
)
{
if
(
compilerMessageReceived
==
false
)
{
consumer
(
'
\n
Compiler message:'
);
compilerMessageReceived
=
true
;
...
...
@@ -110,9 +110,9 @@ class _StdoutHandler {
}
}
// Converts filesystem paths to package URIs.
class
_
PackageUriMapper
{
_
PackageUriMapper
(
String
scriptPath
,
String
packagesPath
)
{
//
/
Converts filesystem paths to package URIs.
class
PackageUriMapper
{
PackageUriMapper
(
String
scriptPath
,
String
packagesPath
)
{
final
Map
<
String
,
Uri
>
packageMap
=
PackageMap
(
fs
.
path
.
absolute
(
packagesPath
)).
map
;
final
String
scriptUri
=
Uri
.
file
(
scriptPath
,
windows:
platform
.
isWindows
).
toString
();
...
...
@@ -132,7 +132,6 @@ class _PackageUriMapper {
Uri
map
(
String
scriptPath
)
{
if
(
_packageName
==
null
)
return
null
;
final
String
scriptUri
=
Uri
.
file
(
scriptPath
,
windows:
platform
.
isWindows
).
toString
();
if
(
scriptUri
.
startsWith
(
_uriPrefix
))
{
return
Uri
.
parse
(
'package:
$_packageName
/
${scriptUri.substring(_uriPrefix.length)}
'
);
...
...
@@ -142,7 +141,7 @@ class _PackageUriMapper {
}
static
Uri
findUri
(
String
scriptPath
,
String
packagesPath
)
{
return
_
PackageUriMapper
(
scriptPath
,
packagesPath
).
map
(
scriptPath
);
return
PackageUriMapper
(
scriptPath
,
packagesPath
).
map
(
scriptPath
);
}
}
...
...
@@ -224,7 +223,7 @@ class KernelCompiler {
Uri
mainUri
;
if
(
packagesPath
!=
null
)
{
command
.
addAll
(<
String
>[
'--packages'
,
packagesPath
]);
mainUri
=
_
PackageUriMapper
.
findUri
(
mainPath
,
packagesPath
);
mainUri
=
PackageUriMapper
.
findUri
(
mainPath
,
packagesPath
);
}
if
(
outputFilePath
!=
null
)
{
command
.
addAll
(<
String
>[
'--output-dill'
,
outputFilePath
]);
...
...
@@ -253,7 +252,7 @@ class KernelCompiler {
printError
(
'Failed to start frontend server
$error
,
$stack
'
);
});
final
_StdoutHandler
_stdoutHandler
=
_
StdoutHandler
();
final
StdoutHandler
_stdoutHandler
=
StdoutHandler
();
server
.
stderr
.
transform
<
String
>(
utf8
.
decoder
)
...
...
@@ -340,7 +339,7 @@ class ResidentCompiler {
_fileSystemRoots
=
fileSystemRoots
,
_fileSystemScheme
=
fileSystemScheme
,
_targetModel
=
targetModel
,
_stdoutHandler
=
_
StdoutHandler
(
consumer:
compilerMessageConsumer
),
_stdoutHandler
=
StdoutHandler
(
consumer:
compilerMessageConsumer
),
_controller
=
StreamController
<
_CompilationRequest
>(),
_initializeFromDill
=
initializeFromDill
,
_unsafePackageSerialization
=
unsafePackageSerialization
,
...
...
@@ -357,7 +356,7 @@ class ResidentCompiler {
final
String
_fileSystemScheme
;
String
_sdkRoot
;
Process
_server
;
final
_
StdoutHandler
_stdoutHandler
;
final
StdoutHandler
_stdoutHandler
;
String
_initializeFromDill
;
bool
_unsafePackageSerialization
;
final
List
<
String
>
_experimentalFlags
;
...
...
@@ -390,9 +389,9 @@ class ResidentCompiler {
// First time recompile is called we actually have to compile the app from
// scratch ignoring list of invalidated files.
_
PackageUriMapper
packageUriMapper
;
PackageUriMapper
packageUriMapper
;
if
(
request
.
packagesFilePath
!=
null
)
{
packageUriMapper
=
_
PackageUriMapper
(
request
.
mainPath
,
request
.
packagesFilePath
);
packageUriMapper
=
PackageUriMapper
(
request
.
mainPath
,
request
.
packagesFilePath
);
}
if
(
_server
==
null
)
{
...
...
@@ -560,11 +559,11 @@ class ResidentCompiler {
_server
?.
stdin
?.
writeln
(
'reset'
);
}
String
_mapFilename
(
String
filename
,
_
PackageUriMapper
packageUriMapper
)
{
String
_mapFilename
(
String
filename
,
PackageUriMapper
packageUriMapper
)
{
return
_doMapFilename
(
filename
,
packageUriMapper
)
??
filename
;
}
String
_mapFileUri
(
String
fileUri
,
_
PackageUriMapper
packageUriMapper
)
{
String
_mapFileUri
(
String
fileUri
,
PackageUriMapper
packageUriMapper
)
{
String
filename
;
try
{
filename
=
Uri
.
parse
(
fileUri
).
toFilePath
();
...
...
@@ -574,7 +573,7 @@ class ResidentCompiler {
return
_doMapFilename
(
filename
,
packageUriMapper
)
??
fileUri
;
}
String
_doMapFilename
(
String
filename
,
_
PackageUriMapper
packageUriMapper
)
{
String
_doMapFilename
(
String
filename
,
PackageUriMapper
packageUriMapper
)
{
if
(
packageUriMapper
!=
null
)
{
final
Uri
packageUri
=
packageUriMapper
.
map
(
filename
);
if
(
packageUri
!=
null
)
...
...
packages/flutter_tools/test/compile_test.dart
View file @
6cf554b0
...
...
@@ -5,6 +5,7 @@
import
'dart:async'
;
import
'dart:convert'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/context.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
...
...
@@ -20,6 +21,50 @@ import 'src/context.dart';
final
Generator
_kNoColorTerminalPlatform
=
()
=>
FakePlatform
.
fromPlatform
(
const
LocalPlatform
())..
stdoutSupportsAnsi
=
false
;
void
main
(
)
{
group
(
PackageUriMapper
,
()
{
const
String
packagesContents
=
r''
'
xml:file:///Users/flutter_user/.pub-cache/hosted/pub.dartlang.org/xml-3.2.3/lib/
yaml:file:///Users/flutter_user/.pub-cache/hosted/pub.dartlang.org/yaml-2.1.15/lib/
example:file:///example/lib/
'''
;
final
MockFileSystem
mockFileSystem
=
MockFileSystem
();
final
MockFile
mockFile
=
MockFile
();
when
(
mockFileSystem
.
path
).
thenReturn
(
fs
.
path
);
when
(
mockFileSystem
.
file
(
any
)).
thenReturn
(
mockFile
);
when
(
mockFile
.
readAsBytesSync
()).
thenReturn
(
utf8
.
encode
(
packagesContents
));
testUsingContext
(
'Can map main.dart to correct package'
,
()
async
{
final
PackageUriMapper
packageUriMapper
=
PackageUriMapper
(
'/example/lib/main.dart'
,
'.packages'
);
expect
(
packageUriMapper
.
map
(
'/example/lib/main.dart'
).
toString
(),
'package:example/main.dart'
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
mockFileSystem
,
});
testUsingContext
(
'Maps file from other package to null'
,
()
async
{
final
PackageUriMapper
packageUriMapper
=
PackageUriMapper
(
'/example/lib/main.dart'
,
'.packages'
);
expect
(
packageUriMapper
.
map
(
'/xml/lib/xml.dart'
),
null
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
mockFileSystem
,
});
testUsingContext
(
'Maps non-main file from same package'
,
()
async
{
final
PackageUriMapper
packageUriMapper
=
PackageUriMapper
(
'/example/lib/main.dart'
,
'.packages'
);
expect
(
packageUriMapper
.
map
(
'/example/lib/src/foo.dart'
).
toString
(),
'package:example/src/foo.dart'
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
mockFileSystem
,
});
});
test
(
StdoutHandler
,
()
async
{
final
StdoutHandler
stdoutHandler
=
StdoutHandler
();
stdoutHandler
.
handler
(
'result 12345'
);
expect
(
stdoutHandler
.
boundaryKey
,
'12345'
);
stdoutHandler
.
handler
(
'12345 message 0'
);
final
CompilerOutput
output
=
await
stdoutHandler
.
compilerOutput
.
future
;
expect
(
output
.
errorCount
,
0
);
expect
(
output
.
outputFilename
,
'message'
);
});
group
(
'batch compile'
,
()
{
ProcessManager
mockProcessManager
;
MockProcess
mockFrontendServer
;
...
...
@@ -458,3 +503,5 @@ class MockStdIn extends Mock implements IOSink {
_stdInWrites
.
writeln
(
o
);
}
}
class
MockFileSystem
extends
Mock
implements
FileSystem
{}
class
MockFile
extends
Mock
implements
File
{}
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