Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion dev/bots/analyze_snippet_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,13 @@ class _SnippetChecker {
/// Invokes the analyzer on the given [directory] and returns the stdout (with some lines filtered).
List<String> _runAnalyzer() {
_createConfigurationFiles();
// Run pub get to avoid output from getting dependencies in the analyzer
// output.
Process.runSync(
_flutter,
<String>['pub', 'get'],
workingDirectory: _tempDirectory.absolute.path,
);
final ProcessResult result = Process.runSync(
_flutter,
<String>['--no-wrap', 'analyze', '--no-preamble', '--no-congratulate', '.'],
Expand All @@ -1006,7 +1013,7 @@ class _SnippetChecker {
if (stdout.isNotEmpty && stdout.first == 'Building flutter tool...') {
stdout.removeAt(0);
}
if (stdout.isNotEmpty && stdout.first.startsWith('Running "flutter pub get" in ')) {
if (stdout.isNotEmpty && stdout.first.isEmpty) {
stdout.removeAt(0);
}
return stdout;
Expand Down
94 changes: 52 additions & 42 deletions packages/flutter_tools/lib/src/commands/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class CreateCommand extends CreateBase {
}

validateOutputDirectoryArg();

String? sampleCode;
final String? sampleArgument = stringArg('sample');
if (sampleArgument != null) {
Expand Down Expand Up @@ -255,7 +254,29 @@ class CreateCommand extends CreateBase {
}

final String dartSdk = globals.cache.dartSdkBuild;
final bool includeIos = featureFlags.isIOSEnabled && platforms.contains('ios');
final bool includeIos;
final bool includeAndroid;
final bool includeWeb;
final bool includeLinux;
final bool includeMacos;
final bool includeWindows;
if (template == FlutterProjectType.module) {
// The module template only supports iOS and Android.
includeIos = true;
Copy link
Contributor

@christopherfujino christopherfujino Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we still check if platforms.contains('ios') (and ditto for android)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

includeAndroid = true;
includeWeb = false;
includeLinux = false;
includeMacos = false;
includeWindows = false;
} else {
includeIos = featureFlags.isIOSEnabled && platforms.contains('ios');
includeAndroid = featureFlags.isAndroidEnabled && platforms.contains('android');
includeWeb = featureFlags.isWebEnabled && platforms.contains('web');
includeLinux = featureFlags.isLinuxEnabled && platforms.contains('linux');
includeMacos = featureFlags.isMacOSEnabled && platforms.contains('macos');
includeWindows = featureFlags.isWindowsEnabled && platforms.contains('windows');
}

String? developmentTeam;
if (includeIos) {
developmentTeam = await getCodeSigningIdentityDevelopmentTeam(
Expand All @@ -282,11 +303,11 @@ class CreateCommand extends CreateBase {
iosLanguage: stringArgDeprecated('ios-language'),
iosDevelopmentTeam: developmentTeam,
ios: includeIos,
android: featureFlags.isAndroidEnabled && platforms.contains('android'),
web: featureFlags.isWebEnabled && platforms.contains('web'),
linux: featureFlags.isLinuxEnabled && platforms.contains('linux'),
macos: featureFlags.isMacOSEnabled && platforms.contains('macos'),
windows: featureFlags.isWindowsEnabled && platforms.contains('windows'),
android: includeAndroid,
web: includeWeb,
linux: includeLinux,
macos: includeMacos,
windows: includeWindows,
// Enable null safety everywhere.
dartSdkVersionBounds: "'>=$dartSdk <3.0.0'",
implementationTests: boolArgDeprecated('implementation-tests'),
Expand All @@ -309,6 +330,7 @@ class CreateCommand extends CreateBase {

final Directory relativeDir = globals.fs.directory(projectDirPath);
int generatedFileCount = 0;
final PubContext pubContext;
switch (template) {
case FlutterProjectType.app:
generatedFileCount += await generateApp(
Expand All @@ -319,6 +341,7 @@ class CreateCommand extends CreateBase {
printStatusWhenWriting: !creatingNewProject,
projectType: template,
);
pubContext = PubContext.create;
break;
case FlutterProjectType.skeleton:
generatedFileCount += await generateApp(
Expand All @@ -329,6 +352,7 @@ class CreateCommand extends CreateBase {
printStatusWhenWriting: !creatingNewProject,
generateMetadata: false,
);
pubContext = PubContext.create;
break;
case FlutterProjectType.module:
generatedFileCount += await _generateModule(
Expand All @@ -337,6 +361,7 @@ class CreateCommand extends CreateBase {
overwrite: overwrite,
printStatusWhenWriting: !creatingNewProject,
);
pubContext = PubContext.create;
break;
case FlutterProjectType.package:
generatedFileCount += await _generatePackage(
Expand All @@ -345,6 +370,7 @@ class CreateCommand extends CreateBase {
overwrite: overwrite,
printStatusWhenWriting: !creatingNewProject,
);
pubContext = PubContext.createPackage;
break;
case FlutterProjectType.plugin:
generatedFileCount += await _generateMethodChannelPlugin(
Expand All @@ -354,6 +380,7 @@ class CreateCommand extends CreateBase {
printStatusWhenWriting: !creatingNewProject,
projectType: template,
);
pubContext = PubContext.createPlugin;
break;
case FlutterProjectType.ffiPlugin:
generatedFileCount += await _generateFfiPlugin(
Expand All @@ -363,8 +390,26 @@ class CreateCommand extends CreateBase {
printStatusWhenWriting: !creatingNewProject,
projectType: template,
);
pubContext = PubContext.createPlugin;
break;
}

if (boolArgDeprecated('pub')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commands are hard to read--can you explain why you're adding this here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, did this used to be called earlier in the _generateModule() and such helper functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is moved from the helper-functions.

final FlutterProject project = FlutterProject.fromDirectory(relativeDir);
await pub.get(
context: pubContext,
project: project,
offline: boolArgDeprecated('offline'),
);
await project.ensureReadyForPlatformSpecificTooling(
androidPlatform: includeAndroid,
iosPlatform: includeIos,
linuxPlatform: includeLinux,
macOSPlatform: includeMacos,
windowsPlatform: includeWindows,
webPlatform: includeWeb,
);
}
if (sampleCode != null) {
generatedFileCount += _applySample(relativeDir, sampleCode);
}
Expand Down Expand Up @@ -447,18 +492,6 @@ Your $application code is in $relativeAppMain.
overwrite: overwrite,
printStatusWhenWriting: printStatusWhenWriting,
);
if (boolArgDeprecated('pub')) {
await pub.get(
context: PubContext.create,
directory: directory.path,
offline: boolArgDeprecated('offline'),
);
final FlutterProject project = FlutterProject.fromDirectory(directory);
await project.ensureReadyForPlatformSpecificTooling(
androidPlatform: true,
iosPlatform: true,
);
}
return generatedCount;
}

Expand All @@ -480,13 +513,6 @@ Your $application code is in $relativeAppMain.
overwrite: overwrite,
printStatusWhenWriting: printStatusWhenWriting,
);
if (boolArgDeprecated('pub')) {
await pub.get(
context: PubContext.createPackage,
directory: directory.path,
offline: boolArgDeprecated('offline'),
);
}
return generatedCount;
}

Expand Down Expand Up @@ -526,14 +552,6 @@ Your $application code is in $relativeAppMain.
printStatusWhenWriting: printStatusWhenWriting,
);

if (boolArgDeprecated('pub')) {
await pub.get(
context: PubContext.createPlugin,
directory: directory.path,
offline: boolArgDeprecated('offline'),
);
}

final FlutterProject project = FlutterProject.fromDirectory(directory);
final bool generateAndroid = templateContext['android'] == true;
if (generateAndroid) {
Expand Down Expand Up @@ -604,14 +622,6 @@ Your $application code is in $relativeAppMain.
printStatusWhenWriting: printStatusWhenWriting,
);

if (boolArgDeprecated('pub')) {
await pub.get(
context: PubContext.createPlugin,
directory: directory.path,
offline: boolArgDeprecated('offline'),
);
}

final FlutterProject project = FlutterProject.fromDirectory(directory);
final bool generateAndroid = templateContext['android'] == true;
if (generateAndroid) {
Expand Down
19 changes: 0 additions & 19 deletions packages/flutter_tools/lib/src/commands/create_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import '../build_system/build_system.dart';
import '../cache.dart';
import '../convert.dart';
import '../dart/generate_synthetic_packages.dart';
import '../dart/pub.dart';
import '../flutter_project_metadata.dart';
import '../globals.dart' as globals;
import '../project.dart';
Expand Down Expand Up @@ -549,24 +548,6 @@ abstract class CreateBase extends FlutterCommand {
environment: environment,
buildSystem: globals.buildSystem,
);

await pub.get(
context: PubContext.create,
directory: directory.path,
offline: boolArgDeprecated('offline'),
// For templates that use the l10n localization tooling, make sure
// importing the generated package works right after `flutter create`.
generateSyntheticPackage: true,
);

await project.ensureReadyForPlatformSpecificTooling(
androidPlatform: androidPlatform,
iosPlatform: iosPlatform,
linuxPlatform: linuxPlatform,
macOSPlatform: macOSPlatform,
windowsPlatform: windowsPlatform,
webPlatform: webPlatform,
);
}
final List<SupportedPlatform> platformsForMigrateConfig = <SupportedPlatform>[SupportedPlatform.root];
if (androidPlatform) {
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_tools/lib/src/commands/daemon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ class AppRunLogger extends DelegatingLogger {
}

@override
bool get supportsColor => throw UnimplementedError();
bool get supportsColor => false;

@override
bool get hasTerminal => false;
Expand Down
12 changes: 6 additions & 6 deletions packages/flutter_tools/lib/src/commands/packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,10 @@ class PackagesGetCommand extends FlutterCommand {
try {
await pub.get(
context: PubContext.pubGet,
directory: directory,
project: flutterProject,
upgrade: upgrade,
shouldSkipThirdPartyGenerator: false,
offline: boolArgDeprecated('offline'),
generateSyntheticPackage: flutterProject.manifest.generateSyntheticPackage,
);
pubGetTimer.stop();
globals.flutterUsage.sendTiming('pub', 'get', pubGetTimer.elapsed, label: 'success');
Expand Down Expand Up @@ -172,13 +171,14 @@ class PackagesGetCommand extends FlutterCommand {
}
final FlutterProject rootProject = FlutterProject.fromDirectory(globals.fs.directory(target));

// This will also resolve dependencies for the example folder,
await _runPubGet(target, rootProject);
await rootProject.regeneratePlatformSpecificTooling();

// Get/upgrade packages in example app as well
// We need to regenerate the platform specific tooling for both the project
// itself and example (if present).
await rootProject.regeneratePlatformSpecificTooling();
if (rootProject.hasExampleApp && rootProject.example.pubspecFile.existsSync()) {
final FlutterProject exampleProject = rootProject.example;
await _runPubGet(exampleProject.directory.path, exampleProject);
await exampleProject.regeneratePlatformSpecificTooling();
}

Expand Down Expand Up @@ -211,7 +211,7 @@ class PackagesTestCommand extends FlutterCommand {

@override
Future<FlutterCommandResult> runCommand() async {
await pub.batch(<String>['run', 'test', ...argResults!.rest], context: PubContext.runTest, retry: false);
await pub.batch(<String>['run', 'test', ...argResults!.rest], context: PubContext.runTest);
return FlutterCommandResult.success();
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter_tools/lib/src/commands/update_packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import '../base/task_queue.dart';
import '../cache.dart';
import '../dart/pub.dart';
import '../globals.dart' as globals;
import '../project.dart';
import '../runner/flutter_command.dart';

/// Map from package name to package version, used to artificially pin a pub
Expand Down Expand Up @@ -401,7 +402,7 @@ class UpdatePackagesCommand extends FlutterCommand {
// needed packages to the pub cache, upgrading if requested.
await pub.get(
context: PubContext.updatePackages,
directory: tempDir.path,
project: FlutterProject.fromDirectory(tempDir),
upgrade: doUpgrade,
offline: boolArgDeprecated('offline'),
flutterRootOverride: temporaryFlutterSdk?.path,
Expand All @@ -424,7 +425,6 @@ class UpdatePackagesCommand extends FlutterCommand {
context: PubContext.updatePackages,
directory: tempDir.path,
filter: tree.fill,
retry: false, // errors here are usually fatal since we're not hitting the network
);
}
} finally {
Expand Down Expand Up @@ -504,7 +504,7 @@ class UpdatePackagesCommand extends FlutterCommand {
stopwatch.start();
await pub.get(
context: PubContext.updatePackages,
directory: dir.path,
project: FlutterProject.fromDirectory(dir),
// All dependencies should already have been downloaded by the fake
// package, so the concurrent checks can all happen offline.
offline: true,
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter_tools/lib/src/commands/upgrade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import '../cache.dart';
import '../dart/pub.dart';
import '../globals.dart' as globals;
import '../persistent_tool_state.dart';
import '../project.dart';
import '../runner/flutter_command.dart';
import '../version.dart';
import 'channel.dart';
Expand Down Expand Up @@ -330,7 +331,7 @@ class UpgradeCommandRunner {
globals.printStatus('');
await pub.get(
context: PubContext.pubUpgrade,
directory: projectRoot,
project: FlutterProject.fromDirectory(globals.fs.directory(projectRoot)),
upgrade: true,
);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter_tools/lib/src/context_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Future<T> runInContext<T>(
logger: globals.logger,
platform: globals.platform,
osUtils: globals.os,
projectFactory: globals.projectFactory,
),
CocoaPods: () => CocoaPods(
fileSystem: globals.fs,
Expand Down Expand Up @@ -312,6 +313,7 @@ Future<T> runInContext<T>(
botDetector: globals.botDetector,
platform: globals.platform,
usage: globals.flutterUsage,
stdio: globals.stdio,
),
ShutdownHooks: () => ShutdownHooks(logger: globals.logger),
Stdio: () => Stdio(),
Expand Down
Loading