@@ -120,12 +120,12 @@ Future<bool> _createMergedOutputDir(
120
120
return false ;
121
121
}
122
122
123
- var outputAssets = < AssetId > [];
123
+ var outputPaths = < String > [];
124
124
if (! outputDirExists) {
125
125
await outputDir.create (recursive: true );
126
126
}
127
127
128
- outputAssets .addAll (
128
+ outputPaths .addAll (
129
129
await Future .wait ([
130
130
for (var id in builtAssets)
131
131
_writeAsset (
@@ -154,24 +154,23 @@ Future<bool> _createMergedOutputDir(
154
154
}
155
155
}
156
156
157
- var paths = outputAssets.map ((id) => id.path).toList ()..sort ();
158
- var content = paths.join (_manifestSeparator);
159
- await _writeAsString (
160
- outputDir,
161
- AssetId (packageGraph.root.name, _manifestName),
162
- content,
163
- );
157
+ outputPaths.sort ();
158
+ var content = outputPaths
159
+ // Normalize path separators for the manifest.
160
+ .map ((path) => path.replaceAll (r'\' , '/' ))
161
+ .join (_manifestSeparator);
162
+ await _writeAsString (outputDir, _manifestName, content);
164
163
165
164
return true ;
166
165
} on FileSystemException catch (e) {
167
166
if (e.osError? .errorCode != 1314 ) rethrow ;
168
- var devModeLink =
167
+ final devModeLink =
169
168
'https://docs.microsoft.com/en-us/windows/uwp/get-started/'
170
169
'enable-your-device-for-development' ;
171
170
buildLog.error (
172
- 'Unable to create symlink ${ e . path }. Note that to create '
173
- 'symlinks on windows you need to either run in a console with admin '
174
- 'privileges or enable developer mode (see $devModeLink ) .' ,
171
+ 'Failed to create merged output directory with symlinks. '
172
+ 'To allow creation of symlinks run in a console with admin privileges '
173
+ 'or enable developer mode following $devModeLink .' ,
175
174
);
176
175
return false ;
177
176
}
@@ -186,12 +185,14 @@ Future<bool> _createMergedOutputDir(
186
185
/// package uri are equivalent.
187
186
///
188
187
/// All other fields are left as is.
189
- Future <AssetId > _writeModifiedPackageConfig (
188
+ ///
189
+ /// Returns the relative path that was written to.
190
+ Future <String > _writeModifiedPackageConfig (
190
191
String rootPackage,
191
192
PackageGraph packageGraph,
192
193
Directory outputDir,
193
194
) async {
194
- var packageConfig = < String , Object ? > {
195
+ final packageConfig = < String , Object ? > {
195
196
'configVersion' : 2 ,
196
197
'packages' : [
197
198
for (var package in packageGraph.allPackages.values)
@@ -208,9 +209,9 @@ Future<AssetId> _writeModifiedPackageConfig(
208
209
},
209
210
],
210
211
};
211
- var packageConfigId = AssetId (rootPackage, '.dart_tool/package_config.json' ) ;
212
- await _writeAsString (outputDir, packageConfigId , jsonEncode (packageConfig));
213
- return packageConfigId ;
212
+ final packageConfigPath = '.dart_tool/package_config.json' ;
213
+ await _writeAsString (outputDir, packageConfigPath , jsonEncode (packageConfig));
214
+ return packageConfigPath ;
214
215
}
215
216
216
217
Set <String > _findRootDirs (Iterable <AssetId > allAssets, String outputPath) {
@@ -225,7 +226,10 @@ Set<String> _findRootDirs(Iterable<AssetId> allAssets, String outputPath) {
225
226
return rootDirs;
226
227
}
227
228
228
- Future <AssetId > _writeAsset (
229
+ /// Writes [id] to [outputDir] .
230
+ ///
231
+ /// Returns the relative path under [outputDir] that it was written to.
232
+ Future <String > _writeAsset (
229
233
AssetId id,
230
234
Directory outputDir,
231
235
String root,
@@ -250,19 +254,18 @@ Future<AssetId> _writeAsset(
250
254
}
251
255
}
252
256
253
- var outputId = AssetId (packageGraph.root.name, assetPath);
254
257
try {
255
258
if (symlinkOnly) {
256
259
// We assert at the top of `createMergedOutputDirectories` that the
257
260
// reader filesystem is `IoFilesystem`, so symlinks make sense.
258
- await Link (_filePathFor (outputDir, outputId )).create (
261
+ await Link (_filePathFor (outputDir, assetPath )).create (
259
262
reader.assetPathProvider.pathFor (
260
263
reader.generatedAssetHider.maybeHide (id, packageGraph.root.name),
261
264
),
262
265
recursive: true ,
263
266
);
264
267
} else {
265
- await _writeAsBytes (outputDir, outputId , await reader.readAsBytes (id));
268
+ await _writeAsBytes (outputDir, assetPath , await reader.readAsBytes (id));
266
269
}
267
270
} on AssetNotFoundException catch (e) {
268
271
if (! p.basename (id.path).startsWith ('.' )) {
@@ -275,32 +278,25 @@ Future<AssetId> _writeAsset(
275
278
rethrow ;
276
279
}
277
280
}
278
- return outputId ;
281
+ return assetPath ;
279
282
});
280
283
}
281
284
282
- Future <void > _writeAsBytes (Directory outputDir, AssetId id , List <int > bytes) =>
283
- _fileFor (outputDir, id ).then ((file) => file.writeAsBytes (bytes));
285
+ Future <void > _writeAsBytes (Directory outputDir, String path , List <int > bytes) =>
286
+ _fileFor (outputDir, path ).then ((file) => file.writeAsBytes (bytes));
284
287
285
- Future <void > _writeAsString (Directory outputDir, AssetId id, String contents) =>
286
- _fileFor (outputDir, id).then ((file) => file.writeAsString (contents));
288
+ Future <void > _writeAsString (
289
+ Directory outputDir,
290
+ String path,
291
+ String contents,
292
+ ) => _fileFor (outputDir, path).then ((file) => file.writeAsString (contents));
287
293
288
- Future <File > _fileFor (Directory outputDir, AssetId id ) {
289
- return File (_filePathFor (outputDir, id )).create (recursive: true );
294
+ Future <File > _fileFor (Directory outputDir, String path ) {
295
+ return File (_filePathFor (outputDir, path )).create (recursive: true );
290
296
}
291
297
292
- String _filePathFor (Directory outputDir, AssetId id) {
293
- String relativePath;
294
- if (id.path.startsWith ('lib' )) {
295
- relativePath = p.join (
296
- 'packages' ,
297
- id.package,
298
- p.joinAll (p.url.split (id.path).skip (1 )),
299
- );
300
- } else {
301
- relativePath = id.path;
302
- }
303
- return p.join (outputDir.path, relativePath);
298
+ String _filePathFor (Directory outputDir, String path) {
299
+ return p.join (outputDir.path, path);
304
300
}
305
301
306
302
/// Checks for a manifest file in [outputDir] and deletes all referenced files.
0 commit comments