Commit fd7222ee authored by PJ Essien's avatar PJ Essien Committed by Todd Volkert

Fix error with 'flutter packages get' in package projects (#16861)

Package projects were erroneously being treated as apps
parent fb18ac65
...@@ -56,6 +56,15 @@ class PackagesGetCommand extends FlutterCommand { ...@@ -56,6 +56,15 @@ class PackagesGetCommand extends FlutterCommand {
return '${runner.executableName} packages $name [<target directory>]'; return '${runner.executableName} packages $name [<target directory>]';
} }
Future<void> _runPubGet (String directory) async {
await pubGet(context: PubContext.pubGet,
directory: directory,
upgrade: upgrade ,
offline: argResults['offline'],
checkLastModified: false,
);
}
@override @override
Future<Null> runCommand() async { Future<Null> runCommand() async {
if (argResults.rest.length > 1) if (argResults.rest.length > 1)
...@@ -71,13 +80,16 @@ class PackagesGetCommand extends FlutterCommand { ...@@ -71,13 +80,16 @@ class PackagesGetCommand extends FlutterCommand {
); );
} }
await pubGet(context: PubContext.pubGet, await _runPubGet(target);
directory: target, final FlutterProject rootProject = new FlutterProject(fs.directory(target));
upgrade: upgrade, rootProject.ensureReadyForPlatformSpecificTooling();
offline: argResults['offline'],
checkLastModified: false, // Get/upgrade packages in example app as well
); if (rootProject.hasExampleApp) {
new FlutterProject(fs.directory(target)).ensureReadyForPlatformSpecificTooling(); final FlutterProject exampleProject = rootProject.example;
await _runPubGet(exampleProject.directory.path);
exampleProject.ensureReadyForPlatformSpecificTooling();
}
} }
} }
......
...@@ -28,9 +28,10 @@ String _generatedXcodePropertiesPath(String projectPath) { ...@@ -28,9 +28,10 @@ String _generatedXcodePropertiesPath(String projectPath) {
return fs.path.join(projectPath, 'ios', 'Flutter', 'Generated.xcconfig'); return fs.path.join(projectPath, 'ios', 'Flutter', 'Generated.xcconfig');
} }
/// Writes default Xcode properties files in the Flutter project at /// Writes default Xcode properties files in the Flutter project at [projectPath],
/// [projectPath], if such files do not already exist. /// if project is an iOS project and such files do not already exist.
void generateXcodeProperties(String projectPath) { void generateXcodeProperties(String projectPath) {
if (fs.isDirectorySync(fs.path.join(projectPath, 'ios'))) {
if (fs.file(_generatedXcodePropertiesPath(projectPath)).existsSync()) if (fs.file(_generatedXcodePropertiesPath(projectPath)).existsSync())
return; return;
updateGeneratedXcodeProperties( updateGeneratedXcodeProperties(
...@@ -39,6 +40,7 @@ void generateXcodeProperties(String projectPath) { ...@@ -39,6 +40,7 @@ void generateXcodeProperties(String projectPath) {
target: bundle.defaultMainPath, target: bundle.defaultMainPath,
previewDart2: false, previewDart2: false,
); );
}
} }
/// Writes or rewrites Xcode property files with the specified information. /// Writes or rewrites Xcode property files with the specified information.
......
...@@ -231,12 +231,9 @@ class InjectPluginsResult{ ...@@ -231,12 +231,9 @@ class InjectPluginsResult{
/// Injects plugins found in `pubspec.yaml` into the platform-specific projects. /// Injects plugins found in `pubspec.yaml` into the platform-specific projects.
void injectPlugins({String directory}) { void injectPlugins({String directory}) {
directory ??= fs.currentDirectory.path; directory ??= fs.currentDirectory.path;
if (fs.file(fs.path.join(directory, 'example', 'pubspec.yaml')).existsSync()) {
// Switch to example app if in plugin project template.
directory = fs.path.join(directory, 'example');
}
final List<Plugin> plugins = _findPlugins(directory); final List<Plugin> plugins = _findPlugins(directory);
final bool changed = _writeFlutterPluginsList(directory, plugins); final bool changed = _writeFlutterPluginsList(directory, plugins);
if (fs.isDirectorySync(fs.path.join(directory, 'android'))) if (fs.isDirectorySync(fs.path.join(directory, 'android')))
_writeAndroidPluginRegistrant(directory, plugins); _writeAndroidPluginRegistrant(directory, plugins);
if (fs.isDirectorySync(fs.path.join(directory, 'ios'))) { if (fs.isDirectorySync(fs.path.join(directory, 'ios'))) {
......
...@@ -47,16 +47,16 @@ class FlutterProject { ...@@ -47,16 +47,16 @@ class FlutterProject {
/// The Android sub project of this project. /// The Android sub project of this project.
AndroidProject get android => new AndroidProject(directory.childDirectory('android')); AndroidProject get android => new AndroidProject(directory.childDirectory('android'));
/// Returns true if this project is a plugin project. /// Returns true if this project has an example application
bool get isPluginProject => directory.childDirectory('example').childFile('pubspec.yaml').existsSync(); bool get hasExampleApp => directory.childDirectory('example').childFile('pubspec.yaml').existsSync();
/// The example sub project of this (plugin) project. /// The example sub project of this (package or plugin) project.
FlutterProject get example => new FlutterProject(directory.childDirectory('example')); FlutterProject get example => new FlutterProject(directory.childDirectory('example'));
/// Generates project files necessary to make Gradle builds work on Android /// Generates project files necessary to make Gradle builds work on Android
/// and CocoaPods+Xcode work on iOS. /// and CocoaPods+Xcode work on iOS, for app projects only
void ensureReadyForPlatformSpecificTooling() { void ensureReadyForPlatformSpecificTooling() {
if (!directory.existsSync() || isPluginProject) { if (!directory.existsSync() || hasExampleApp) {
return; return;
} }
injectPlugins(directory: directory.path); injectPlugins(directory: directory.path);
......
...@@ -23,11 +23,11 @@ void main() { ...@@ -23,11 +23,11 @@ void main() {
project.ensureReadyForPlatformSpecificTooling(); project.ensureReadyForPlatformSpecificTooling();
expect(project.directory.existsSync(), isFalse); expect(project.directory.existsSync(), isFalse);
}); });
testInMemory('does nothing in plugin root project', () async { testInMemory('does nothing in plugin or package root project', () async {
final FlutterProject project = aPluginProject(); final FlutterProject project = aPluginProject();
project.ensureReadyForPlatformSpecificTooling(); project.ensureReadyForPlatformSpecificTooling();
expect(project.example.ios.directory.childFile('Runner/GeneratedPluginRegistrant.h').existsSync(), isFalse); expect(project.ios.directory.childFile('Runner/GeneratedPluginRegistrant.h').existsSync(), isFalse);
expect(project.example.ios.directory.childFile('Flutter/Generated.xcconfig').existsSync(), isFalse); expect(project.ios.directory.childFile('Flutter/Generated.xcconfig').existsSync(), isFalse);
}); });
testInMemory('injects plugins', () async { testInMemory('injects plugins', () async {
final FlutterProject project = aProjectWithIos(); final FlutterProject project = aProjectWithIos();
......
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