Skip to content

Commit

Permalink
Fix configuration directory issue. (#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos committed Feb 27, 2024
1 parent c1d47d4 commit f0ae1f2
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.22.2

- `dartdoc` processing is run as the last step of the generated report.
- Fix: missing custom SDK environment (config directory use) when invoking Flutter.

## 0.22.1

Expand Down
14 changes: 3 additions & 11 deletions lib/src/sdk_env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'logging.dart';
import 'model.dart' show PanaRuntimeInfo;
import 'package_analyzer.dart' show InspectOptions;
import 'pana_cache.dart';
import 'tool/flutter_tool.dart';
import 'tool/run_constrained.dart';
import 'utils.dart';
import 'version.dart';
Expand Down Expand Up @@ -295,19 +296,10 @@ class ToolEnvironment {
Future<Map<String, dynamic>> _getFlutterVersion() async {
final result = await runConstrained(
[..._flutterSdk.flutterCmd, '--version', '--machine'],
environment: _flutterSdk.environment,
throwOnError: true,
);
final waitingForString = 'Waiting for another flutter';
return result.parseJson(transform: (content) {
if (content.contains(waitingForString)) {
return content
.split('\n')
.where((e) => !e.contains(waitingForString))
.join('\n');
} else {
return content;
}
});
return result.parseJson(transform: stripIntermittentFlutterMessages);
}

Future<PanaProcessResult> runUpgrade(
Expand Down
24 changes: 24 additions & 0 deletions lib/src/tool/flutter_tool.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// Removes intermittent messages that may be mixed with regular Flutter output.
String stripIntermittentFlutterMessages(String content) {
// filter for concurrent flutter execution
final waitingForString = 'Waiting for another flutter';
if (content.contains(waitingForString)) {
content = content
.split('\n')
.where((e) => !e.contains(waitingForString))
.join('\n');
}
// filter for welcome screen
if (content.contains('Welcome to Flutter!')) {
final lines = content.split('\n');
final separator = lines.indexWhere((l) => l.trim().isEmpty);
if (separator >= 0) {
content = lines.take(separator).join('\n');
}
}
return content;
}
2 changes: 1 addition & 1 deletion lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pana
description: PAckage aNAlyzer - produce a report summarizing the health and quality of a Dart package.
version: 0.22.2-dev
version: 0.22.2
repository: https://github.com/dart-lang/pana
topics:
- tool
Expand Down
6 changes: 6 additions & 0 deletions test/end2end_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@ void main() {
.resolveSymbolicLinksSync();
final pubCacheDir = p.join(tempDir, 'pub-cache');
final panaCacheDir = p.join(tempDir, 'pana-cache');
final dartConfigDir = p.join(tempDir, 'config', 'dart');
final flutterConfigDir = p.join(tempDir, 'config', 'flutter');
final goldenDirLastModified = await _detectGoldenLastModified();
Directory(pubCacheDir).createSync();
Directory(panaCacheDir).createSync();
Directory(dartConfigDir).createSync(recursive: true);
Directory(flutterConfigDir).createSync(recursive: true);
httpClient = http.Client();
httpServer = await _startLocalProxy(
httpClient: httpClient,
blockPublishAfter: goldenDirLastModified,
);
analyzer = PackageAnalyzer(await ToolEnvironment.create(
dartSdkConfig: SdkConfig(configHomePath: dartConfigDir),
flutterSdkConfig: SdkConfig(configHomePath: flutterConfigDir),
pubCacheDir: pubCacheDir,
panaCacheDir: panaCacheDir,
pubHostedUrl: 'http://127.0.0.1:${httpServer.port}',
Expand Down
66 changes: 66 additions & 0 deletions test/tool/flutter_tool_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:convert';

import 'package:pana/src/tool/flutter_tool.dart';
import 'package:test/test.dart';

void main() {
group('Intermittent messages', () {
final jsonOutput =
const JsonEncoder.withIndent(' ').convert({'key': 'value'});

test('unchanged text', () {
expect(stripIntermittentFlutterMessages(jsonOutput), jsonOutput);
});

test('waiting for another process', () {
expect(
stripIntermittentFlutterMessages(
'Waiting for another flutter process to complete.\n$jsonOutput'),
jsonOutput,
);
});

test('welcome screen', () {
expect(
stripIntermittentFlutterMessages(
'$jsonOutput\n\n$_welcomeScreenOutput'),
jsonOutput,
);
});
});
}

final _welcomeScreenOutput =
''' ╔════════════════════════════════════════════════════════════════════════════╗
║ Welcome to Flutter! - https://flutter.dev ║
║ ║
║ The Flutter tool uses Google Analytics to anonymously report feature usage ║
║ statistics and basic crash reports. This data is used to help improve ║
║ Flutter tools over time. ║
║ ║
║ Flutter tool analytics are not sent on the very first run. To disable ║
║ reporting, type 'flutter config --no-analytics'. To display the current ║
║ setting, type 'flutter config'. If you opt out of analytics, an opt-out ║
║ event will be sent, and then no further information will be sent by the ║
║ Flutter tool. ║
║ ║
║ By downloading the Flutter SDK, you agree to the Google Terms of Service. ║
║ The Google Privacy Policy describes how data is handled in this service. ║
║ ║
║ Moreover, Flutter includes the Dart SDK, which may send usage metrics and ║
║ crash reports to Google. ║
║ ║
║ Read about data we send with crash reports: ║
║ https://flutter.dev/docs/reference/crash-reporting ║
║ ║
║ See Google's privacy policy: ║
║ https://policies.google.com/privacy ║
║ ║
║ To disable animations in this tool, use ║
║ 'flutter config --no-cli-animations'. ║
╚════════════════════════════════════════════════════════════════════════════╝
''';

0 comments on commit f0ae1f2

Please sign in to comment.