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
763a8d6d
Unverified
Commit
763a8d6d
authored
Jan 30, 2019
by
Jonah Williams
Committed by
GitHub
Jan 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support to multiroot scheme to PackageUriMapper (#27207)
parent
39289b83
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
39 deletions
+74
-39
compile.dart
packages/flutter_tools/lib/src/compile.dart
+29
-16
compile_test.dart
packages/flutter_tools/test/compile_test.dart
+45
-23
No files found.
packages/flutter_tools/lib/src/compile.dart
View file @
763a8d6d
...
...
@@ -78,8 +78,7 @@ class StdoutHandler {
void
handler
(
String
message
)
{
const
String
kResultPrefix
=
'result '
;
if
(
boundaryKey
==
null
)
{
if
(
message
.
startsWith
(
kResultPrefix
))
if
(
boundaryKey
==
null
&&
message
.
startsWith
(
kResultPrefix
))
{
boundaryKey
=
message
.
substring
(
kResultPrefix
.
length
);
}
else
if
(
message
.
startsWith
(
boundaryKey
))
{
if
(
message
.
length
<=
boundaryKey
.
length
)
{
...
...
@@ -112,36 +111,45 @@ class StdoutHandler {
/// Converts filesystem paths to package URIs.
class
PackageUriMapper
{
PackageUriMapper
(
String
scriptPath
,
String
packagesPath
)
{
PackageUriMapper
(
String
scriptPath
,
String
packagesPath
,
String
fileSystemScheme
,
List
<
String
>
fileSystemRoots
)
{
final
Map
<
String
,
Uri
>
packageMap
=
PackageMap
(
fs
.
path
.
absolute
(
packagesPath
)).
map
;
final
String
scriptUri
=
Uri
.
file
(
scriptPath
,
windows:
platform
.
isWindows
).
toString
();
for
(
String
packageName
in
packageMap
.
keys
)
{
final
String
prefix
=
packageMap
[
packageName
].
toString
();
if
(
fileSystemScheme
!=
null
&&
fileSystemRoots
!=
null
&&
prefix
.
contains
(
fileSystemScheme
))
{
_packageName
=
packageName
;
_uriPrefixes
=
fileSystemRoots
.
map
((
String
name
)
=>
Uri
.
file
(
'
$name
/lib/'
,
windows:
platform
.
isWindows
).
toString
())
.
toList
();
return
;
}
if
(
scriptUri
.
startsWith
(
prefix
))
{
_packageName
=
packageName
;
_uriPrefix
=
prefix
;
_uriPrefix
es
=
<
String
>[
prefix
]
;
return
;
}
}
}
String
_packageName
;
String
_uriPrefix
;
List
<
String
>
_uriPrefixes
;
Uri
map
(
String
scriptPath
)
{
if
(
_packageName
==
null
)
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)}
'
);
for
(
String
uriPrefix
in
_uriPrefixes
)
{
if
(
scriptUri
.
startsWith
(
uriPrefix
))
{
return
Uri
.
parse
(
'package:
$_packageName
/
${scriptUri.substring(uriPrefix.length)}
'
);
}
}
return
null
;
}
static
Uri
findUri
(
String
scriptPath
,
String
packagesPath
)
{
return
PackageUriMapper
(
scriptPath
,
packagesPath
).
map
(
scriptPath
);
static
Uri
findUri
(
String
scriptPath
,
String
packagesPath
,
String
fileSystemScheme
,
List
<
String
>
fileSystemRoots
)
{
return
PackageUriMapper
(
scriptPath
,
packagesPath
,
fileSystemScheme
,
fileSystemRoots
).
map
(
scriptPath
);
}
}
...
...
@@ -223,7 +231,7 @@ class KernelCompiler {
Uri
mainUri
;
if
(
packagesPath
!=
null
)
{
command
.
addAll
(<
String
>[
'--packages'
,
packagesPath
]);
mainUri
=
PackageUriMapper
.
findUri
(
mainPath
,
packagesPath
);
mainUri
=
PackageUriMapper
.
findUri
(
mainPath
,
packagesPath
,
fileSystemScheme
,
fileSystemRoots
);
}
if
(
outputFilePath
!=
null
)
{
command
.
addAll
(<
String
>[
'--output-dill'
,
outputFilePath
]);
...
...
@@ -256,7 +264,7 @@ class KernelCompiler {
server
.
stderr
.
transform
<
String
>(
utf8
.
decoder
)
.
listen
(
(
String
message
)
{
printError
(
message
);
}
);
.
listen
(
printError
);
server
.
stdout
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
...
...
@@ -400,15 +408,20 @@ class ResidentCompiler {
// First time recompile is called we actually have to compile the app from
// scratch ignoring list of invalidated files.
PackageUriMapper
packageUriMapper
;
if
(
request
.
packagesFilePath
!=
null
)
{
packageUriMapper
=
PackageUriMapper
(
request
.
mainPath
,
request
.
packagesFilePath
);
if
(
request
.
packagesFilePath
!=
null
||
_packagesPath
!=
null
)
{
packageUriMapper
=
PackageUriMapper
(
request
.
mainPath
,
request
.
packagesFilePath
??
_packagesPath
,
_fileSystemScheme
,
_fileSystemRoots
,
);
}
if
(
_server
==
null
)
{
return
_compile
(
_mapFilename
(
request
.
mainPath
,
packageUriMapper
),
request
.
outputPath
,
_mapFilename
(
request
.
packagesFilePath
,
/* packageUriMapper= */
null
)
_mapFilename
(
request
.
packagesFilePath
??
_packagesPath
,
/* packageUriMapper= */
null
)
);
}
...
...
packages/flutter_tools/test/compile_test.dart
View file @
763a8d6d
...
...
@@ -22,36 +22,58 @@ final Generator _kNoColorTerminalPlatform = () => FakePlatform.fromPlatform(cons
void
main
(
)
{
group
(
PackageUriMapper
,
()
{
const
String
packagesContents
=
r''
'
group
(
'single-root'
,
()
{
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
,
});
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'
,
null
,
null
);
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 file from other package to null'
,
()
async
{
final
PackageUriMapper
packageUriMapper
=
PackageUriMapper
(
'/example/lib/main.dart'
,
'.packages'
,
null
,
null
);
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'
,
null
,
null
);
expect
(
packageUriMapper
.
map
(
'/example/lib/src/foo.dart'
).
toString
(),
'package:example/src/foo.dart'
);
},
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
,
group
(
'multi-root'
,
()
{
final
MockFileSystem
mockFileSystem
=
MockFileSystem
();
final
MockFile
mockFile
=
MockFile
();
when
(
mockFileSystem
.
path
).
thenReturn
(
fs
.
path
);
when
(
mockFileSystem
.
file
(
any
)).
thenReturn
(
mockFile
);
const
String
multiRootPackagesContents
=
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:org-dartlang-app:///lib/
'''
;
when
(
mockFile
.
readAsBytesSync
()).
thenReturn
(
utf8
.
encode
(
multiRootPackagesContents
));
testUsingContext
(
'Maps main file from same package on multiroot scheme'
,
()
async
{
final
PackageUriMapper
packageUriMapper
=
PackageUriMapper
(
'/example/lib/main.dart'
,
'.packages'
,
'org-dartlang-app'
,
<
String
>[
'/example'
,
'/gen'
]);
expect
(
packageUriMapper
.
map
(
'/example/lib/main.dart'
).
toString
(),
'package:example/main.dart'
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
mockFileSystem
,
});
});
});
...
...
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