Use platform appropriate filepaths when constructing asset bundle (#44221)

This commit is contained in:
Jonah Williams 2019-11-06 12:50:18 -08:00 committed by GitHub
parent aa333fda25
commit 383e90eb13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 10 deletions

View file

@ -34,7 +34,7 @@ Future<Depfile> copyAssets(Environment environment, Directory outputDirectory) a
assetBundle.entries.entries.map<Future<void>>((MapEntry<String, DevFSContent> entry) async {
final PoolResource resource = await pool.request();
try {
final File file = fs.file(fs.path.join(outputDirectory.path, entry.key));
final File file = fs.file(outputDirectory.uri.resolve(entry.key));
outputs.add(file);
file.parent.createSync(recursive: true);
final DevFSContent content = entry.value;

View file

@ -182,7 +182,7 @@ Future<void> writeBundle(
assetEntries.entries.map<Future<void>>((MapEntry<String, DevFSContent> entry) async {
final PoolResource resource = await pool.request();
try {
final File file = fs.file(fs.path.join(bundleDir.path, entry.key));
final File file = fs.file(bundleDir.uri.resolve(entry.key));
file.parent.createSync(recursive: true);
await file.writeAsBytes(await entry.value.contentsAsBytes());
} finally {

View file

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/targets/assets.dart';
@ -47,14 +45,14 @@ flutter:
expect(fs.file(fs.path.join(environment.buildDir.path, 'flutter_assets', 'AssetManifest.json')).existsSync(), true);
expect(fs.file(fs.path.join(environment.buildDir.path, 'flutter_assets', 'FontManifest.json')).existsSync(), true);
expect(fs.file(fs.path.join(environment.buildDir.path, 'flutter_assets', 'LICENSE')).existsSync(), true);
// See https://github.com/flutter/flutter/issues/35293
expect(fs.file(fs.path.join(environment.buildDir.path, 'flutter_assets', 'assets/foo/bar.png')).existsSync(), true);
expect(fs.file(fs.path.join(environment.buildDir.path, 'flutter_assets', 'assets', 'foo', 'bar.png')).existsSync(), true);
}));
test('Does not leave stale files in build directory', () => testbed.run(() async {
await buildSystem.build(const CopyAssets(), environment);
final File assetFile = fs.file(fs.path.join(environment.buildDir.path, 'flutter_assets', 'assets', 'foo', 'bar.png'));
expect(fs.file(fs.path.join(environment.buildDir.path, 'flutter_assets', 'assets/foo/bar.png')).existsSync(), true);
expect(assetFile.existsSync(), true);
// Modify manifest to remove asset.
fs.file('pubspec.yaml')
..createSync()
@ -65,9 +63,8 @@ flutter:
''');
await buildSystem.build(const CopyAssets(), environment);
// See https://github.com/flutter/flutter/issues/35293
expect(fs.file(fs.path.join(environment.buildDir.path, 'flutter_assets', 'assets/foo/bar.png')).existsSync(), false);
}), skip: Platform.isWindows); // See https://github.com/google/file.dart/issues/131
expect(assetFile.existsSync(), false);
}));
test('FlutterPlugins updates required files as needed', () => testbed.run(() async {
fs.file('pubspec.yaml')