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 {
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
Future<Null> runCommand() async {
if (argResults.rest.length > 1)
......@@ -71,13 +80,16 @@ class PackagesGetCommand extends FlutterCommand {
);
}
await pubGet(context: PubContext.pubGet,
directory: target,
upgrade: upgrade,
offline: argResults['offline'],
checkLastModified: false,
);
new FlutterProject(fs.directory(target)).ensureReadyForPlatformSpecificTooling();
await _runPubGet(target);
final FlutterProject rootProject = new FlutterProject(fs.directory(target));
rootProject.ensureReadyForPlatformSpecificTooling();
// Get/upgrade packages in example app as well
if (rootProject.hasExampleApp) {
final FlutterProject exampleProject = rootProject.example;
await _runPubGet(exampleProject.directory.path);
exampleProject.ensureReadyForPlatformSpecificTooling();
}
}
}
......
......@@ -28,17 +28,19 @@ String _generatedXcodePropertiesPath(String projectPath) {
return fs.path.join(projectPath, 'ios', 'Flutter', 'Generated.xcconfig');
}
/// Writes default Xcode properties files in the Flutter project at
/// [projectPath], if such files do not already exist.
/// Writes default Xcode properties files in the Flutter project at [projectPath],
/// if project is an iOS project and such files do not already exist.
void generateXcodeProperties(String projectPath) {
if (fs.file(_generatedXcodePropertiesPath(projectPath)).existsSync())
return;
updateGeneratedXcodeProperties(
if (fs.isDirectorySync(fs.path.join(projectPath, 'ios'))) {
if (fs.file(_generatedXcodePropertiesPath(projectPath)).existsSync())
return;
updateGeneratedXcodeProperties(
projectPath: projectPath,
buildInfo: BuildInfo.debug,
target: bundle.defaultMainPath,
previewDart2: false,
);
);
}
}
/// Writes or rewrites Xcode property files with the specified information.
......
......@@ -231,12 +231,9 @@ class InjectPluginsResult{
/// Injects plugins found in `pubspec.yaml` into the platform-specific projects.
void injectPlugins({String directory}) {
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 bool changed = _writeFlutterPluginsList(directory, plugins);
if (fs.isDirectorySync(fs.path.join(directory, 'android')))
_writeAndroidPluginRegistrant(directory, plugins);
if (fs.isDirectorySync(fs.path.join(directory, 'ios'))) {
......
......@@ -47,16 +47,16 @@ class FlutterProject {
/// The Android sub project of this project.
AndroidProject get android => new AndroidProject(directory.childDirectory('android'));
/// Returns true if this project is a plugin project.
bool get isPluginProject => directory.childDirectory('example').childFile('pubspec.yaml').existsSync();
/// Returns true if this project has an example application
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'));
/// 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() {
if (!directory.existsSync() || isPluginProject) {
if (!directory.existsSync() || hasExampleApp) {
return;
}
injectPlugins(directory: directory.path);
......
......@@ -23,11 +23,11 @@ void main() {
project.ensureReadyForPlatformSpecificTooling();
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();
project.ensureReadyForPlatformSpecificTooling();
expect(project.example.ios.directory.childFile('Runner/GeneratedPluginRegistrant.h').existsSync(), isFalse);
expect(project.example.ios.directory.childFile('Flutter/Generated.xcconfig').existsSync(), isFalse);
expect(project.ios.directory.childFile('Runner/GeneratedPluginRegistrant.h').existsSync(), isFalse);
expect(project.ios.directory.childFile('Flutter/Generated.xcconfig').existsSync(), isFalse);
});
testInMemory('injects plugins', () async {
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