Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
add a --dart-sdk option to the repo analysis command (#3959)
Browse files Browse the repository at this point in the history
  • Loading branch information
devoncarew authored May 24, 2021
1 parent bd597db commit 7d64ffc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tool_setup_template: &TOOL_SETUP_TEMPLATE
tool_setup_script:
- git fetch origin master # To set FETCH_HEAD for "git merge-base" to work
- cd script/tool
- pub get
- dart pub get

flutter_upgrade_template: &FLUTTER_UPGRADE_TEMPLATE
upgrade_flutter_script:
Expand Down Expand Up @@ -167,7 +167,7 @@ task:
install_script:
- git clone https://github.com/flutter/web_installers.git
- cd web_installers/packages/web_drivers/
- pub get
- dart pub get
- dart lib/web_driver_installer.dart chromedriver --install-only
- ./chromedriver/chromedriver --port=4444 &
build_script:
Expand Down
2 changes: 1 addition & 1 deletion script/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ function error() {
# Runs the plugin tools from the plugin_tools git submodule.
function plugin_tools() {
(pushd "$REPO_DIR/script/tool" && dart pub get && popd) >/dev/null
dart run "$REPO_DIR/script/tool/lib/src/main.dart" "$@"
dart run "$REPO_DIR/script/tool/bin/flutter_plugin_tools.dart" "$@"
}
17 changes: 14 additions & 3 deletions script/tool/lib/src/analyze_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ class AnalyzeCommand extends PluginCommand {
}) : super(packagesDir, fileSystem, processRunner: processRunner) {
argParser.addMultiOption(_customAnalysisFlag,
help:
'Directories (comma seperated) that are allowed to have their own analysis options.',
'Directories (comma separated) that are allowed to have their own analysis options.',
defaultsTo: <String>[]);
argParser.addOption(_analysisSdk,
valueHelp: 'dart-sdk',
help: 'An optional path to a Dart SDK; this is used to override the '
'SDK used to provide analysis.');
}

static const String _customAnalysisFlag = 'custom-analysis';

static const String _analysisSdk = 'analysis-sdk';

@override
final String name = 'analyze';

Expand Down Expand Up @@ -62,15 +68,20 @@ class AnalyzeCommand extends PluginCommand {
await processRunner.runAndStream('flutter', <String>['packages', 'get'],
workingDir: package, exitOnError: true);
} else {
await processRunner.runAndStream('pub', <String>['get'],
await processRunner.runAndStream('dart', <String>['pub', 'get'],
workingDir: package, exitOnError: true);
}
}

// Use the Dart SDK override if one was passed in.
final String? dartSdk = argResults![_analysisSdk] as String?;
final String dartBinary =
dartSdk == null ? 'dart' : p.join(dartSdk, 'bin', 'dart');

final List<String> failingPackages = <String>[];
await for (final Directory package in getPlugins()) {
final int exitCode = await processRunner.runAndStream(
'dart', <String>['analyze', '--fatal-infos'],
dartBinary, <String>['analyze', '--fatal-infos'],
workingDir: package);
if (exitCode != 0) {
failingPackages.add(p.basename(package.path));
Expand Down
25 changes: 25 additions & 0 deletions script/tool/test/analyze_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,31 @@ void main() {
]));
});

test('uses a separate analysis sdk', () async {
final Directory pluginDir = createFakePlugin('a');

final MockProcess mockProcess = MockProcess();
mockProcess.exitCodeCompleter.complete(0);
processRunner.processToReturn = mockProcess;
await runner.run(<String>['analyze', '--analysis-sdk', 'foo/bar/baz']);

expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall(
'flutter',
const <String>['packages', 'get'],
pluginDir.path,
),
ProcessCall(
'foo/bar/baz/bin/dart',
const <String>['analyze', '--fatal-infos'],
pluginDir.path,
),
]),
);
});

group('verifies analysis settings', () {
test('fails analysis_options.yaml', () async {
createFakePlugin('foo', withExtraFiles: <List<String>>[
Expand Down
6 changes: 3 additions & 3 deletions script/tool_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ readonly CUSTOM_FLAG=$(IFS=, ; echo "${CUSTOM_ANALYSIS_PLUGINS[*]}")
ACTIONS=("$@")
if [[ "${#ACTIONS[@]}" == 0 ]]; then
ACTIONS=("analyze" "--custom-analysis" "$CUSTOM_FLAG" "test" "java-test")
elif [[ "${ACTIONS[@]}" == "analyze" ]]; then
ACTIONS=("analyze" "--custom-analysis" "$CUSTOM_FLAG")
elif [[ "${ACTIONS[0]}" == "analyze" ]]; then
ACTIONS=("${ACTIONS[@]}" "--custom-analysis" "$CUSTOM_FLAG")
fi

BRANCH_NAME="${BRANCH_NAME:-"$(git rev-parse --abbrev-ref HEAD)"}"
Expand All @@ -74,5 +74,5 @@ if [[ "${BRANCH_NAME}" == "master" ]]; then
(cd "$REPO_DIR" && plugin_tools "${ACTIONS[@]}" --exclude="$ALL_EXCLUDED" ${PLUGIN_SHARDING[@]})
else
echo running "${ACTIONS[@]}"
(cd "$REPO_DIR" && plugin_tools "${ACTIONS[@]}" --run-on-changed-packages --exclude="$ALL_EXCLUDED" ${PLUGIN_SHARDING[@]})
(cd "$REPO_DIR" && plugin_tools "${ACTIONS[@]}" --run-on-changed-packages --exclude="$ALL_EXCLUDED" ${PLUGIN_SHARDING[@]})
fi

0 comments on commit 7d64ffc

Please sign in to comment.