Commit 3cbbbf06 authored by Sarah Zakarias's avatar Sarah Zakarias Committed by GitHub

Allow empty pubspec file when building asset bundle (#12269)

parent 65e3df88
...@@ -75,13 +75,19 @@ class AssetBundle { ...@@ -75,13 +75,19 @@ class AssetBundle {
FlutterManifest flutterManifest; FlutterManifest flutterManifest;
try { try {
flutterManifest = await FlutterManifest.createFromPath(manifestPath); flutterManifest = await FlutterManifest.createFromPath(manifestPath);
if (flutterManifest == null)
return 1;
} catch (e) { } catch (e) {
printStatus('Error detected in pubspec.yaml:', emphasis: true); printStatus('Error detected in pubspec.yaml:', emphasis: true);
printError('$e'); printError('$e');
return 1; return 1;
} }
if (flutterManifest == null)
return 1;
if (flutterManifest.isEmpty) {
entries[_kAssetManifestJson] = new DevFSStringContent('{}');
return 0;
}
final String assetBasePath = fs.path.dirname(fs.path.absolute(manifestPath)); final String assetBasePath = fs.path.dirname(fs.path.absolute(manifestPath));
_lastBuildTimestamp = new DateTime.now(); _lastBuildTimestamp = new DateTime.now();
......
...@@ -26,10 +26,10 @@ class FlutterManifest { ...@@ -26,10 +26,10 @@ class FlutterManifest {
static Future<FlutterManifest> _createFromYaml(Object yamlDocument) async { static Future<FlutterManifest> _createFromYaml(Object yamlDocument) async {
final FlutterManifest pubspec = new FlutterManifest._(); final FlutterManifest pubspec = new FlutterManifest._();
if (yamlDocument == null || !await _validate(yamlDocument)) if (yamlDocument != null && !await _validate(yamlDocument))
return null; return null;
pubspec._descriptor = yamlDocument; pubspec._descriptor = yamlDocument ?? <String, dynamic>{};
pubspec._flutterDescriptor = pubspec._descriptor['flutter'] ?? <String, dynamic>{}; pubspec._flutterDescriptor = pubspec._descriptor['flutter'] ?? <String, dynamic>{};
return pubspec; return pubspec;
} }
...@@ -40,7 +40,9 @@ class FlutterManifest { ...@@ -40,7 +40,9 @@ class FlutterManifest {
/// A map representation of the `flutter` section in the `pubspec.yaml` file. /// A map representation of the `flutter` section in the `pubspec.yaml` file.
Map<String, dynamic> _flutterDescriptor; Map<String, dynamic> _flutterDescriptor;
String get appName => _descriptor['name']; bool get isEmpty => _descriptor.isEmpty;
String get appName => _descriptor['name'] ?? '';
bool get usesMaterialDesign { bool get usesMaterialDesign {
return _flutterDescriptor['uses-material-design'] ?? false; return _flutterDescriptor['uses-material-design'] ?? false;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:convert'; import 'dart:convert';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/asset.dart'; import 'package:flutter_tools/src/asset.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
...@@ -80,6 +81,21 @@ void main() { ...@@ -80,6 +81,21 @@ void main() {
expect(await ab.build(), 0); expect(await ab.build(), 0);
expect(ab.entries.length, greaterThan(0)); expect(ab.entries.length, greaterThan(0));
}); });
testUsingContext('empty pubspec', () async {
fs.file('pubspec.yaml')
..createSync()
..writeAsStringSync('');
final AssetBundle bundle = new AssetBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
expect(bundle.entries.length, 1);
final String expectedAssetManifest = '{}';
expect(
UTF8.decode(await bundle.entries['AssetManifest.json'].contentsAsBytes()),
expectedAssetManifest,
);
}, overrides: <Type, Generator>{FileSystem: () => new MemoryFileSystem(),});
}); });
} }
...@@ -16,6 +16,16 @@ void main() { ...@@ -16,6 +16,16 @@ void main() {
}); });
group('FlutterManifest', () { group('FlutterManifest', () {
testUsingContext('is empty when the pubspec.yaml file is empty', () async {
final FlutterManifest flutterManifest = await FlutterManifest.createFromString('');
expect(flutterManifest.isEmpty, true);
expect(flutterManifest.appName, '');
expect(flutterManifest.usesMaterialDesign, false);
expect(flutterManifest.fontsDescriptor, isEmpty);
expect(flutterManifest.fonts, isEmpty);
expect(flutterManifest.assets, isEmpty);
});
test('has no fonts or assets when the "flutter" section is empty', () async { test('has no fonts or assets when the "flutter" section is empty', () async {
final String manifest = ''' final String manifest = '''
name: test name: test
...@@ -25,6 +35,7 @@ dependencies: ...@@ -25,6 +35,7 @@ dependencies:
'''; ''';
final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest); final FlutterManifest flutterManifest = await FlutterManifest.createFromString(manifest);
expect(flutterManifest, isNotNull); expect(flutterManifest, isNotNull);
expect(flutterManifest.isEmpty, false);
expect(flutterManifest.appName, 'test'); expect(flutterManifest.appName, 'test');
expect(flutterManifest.usesMaterialDesign, false); expect(flutterManifest.usesMaterialDesign, false);
expect(flutterManifest.fontsDescriptor, isEmpty); expect(flutterManifest.fontsDescriptor, isEmpty);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment