Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move PanaCache out of ToolEnvironment (also from public API), adding in InspectOptions #1384

Merged
merged 1 commit into from
Jul 5, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Updated dependency: `tar: ^2.0.0`.
- New text logging format.
- *Breaking change:* Removed `ToolEnvironment.panaCache` field (not intended for public API).

## 0.22.7

Expand Down
2 changes: 1 addition & 1 deletion bin/pana.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ Future<void> main(List<String> args) async {
final pubHostedUrl = result['hosted-url'] as String?;
final analyzer = PackageAnalyzer(await ToolEnvironment.create(
pubCacheDir: pubCacheDir,
panaCacheDir: Platform.environment['PANA_CACHE'],
dartSdkConfig: SdkConfig(
rootPath: result['dart-sdk'] as String?,
configHomePath: result['dart-config-home'] as String?,
Expand All @@ -185,6 +184,7 @@ Future<void> main(List<String> args) async {
));
final options = InspectOptions(
pubHostedUrl: pubHostedUrl,
panaCacheDir: Platform.environment['PANA_CACHE'],
lineLength: int.tryParse(result['line-length'] as String? ?? ''),
dartdocOutputDir: runDartdoc ? dartdocOutputDir : null,
resourcesOutputDir: resourcesOutputDir,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/package_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class InspectOptions {
/// The PUB_HOSTED_URL to use for the package download and dependency analysis.
final String? pubHostedUrl;

/// The cache directory for cross-analysis (shared) pana results.
final String? panaCacheDir;

/// The output directory to copy the generated docs. When not specified,
/// the generated docs will be discarded.
final String? dartdocOutputDir;
Expand All @@ -54,6 +57,7 @@ class InspectOptions {

InspectOptions({
this.pubHostedUrl,
this.panaCacheDir,
this.dartdocOutputDir,
this.resourcesOutputDir,
this.totalTimeout,
Expand Down
18 changes: 9 additions & 9 deletions lib/src/package_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'license.dart';
import 'logging.dart';
import 'messages.dart' as messages;
import 'package_analyzer.dart' show InspectOptions;
import 'pana_cache.dart';
import 'pkg_resolution.dart';
import 'pubspec.dart';
import 'pubspec_io.dart';
Expand All @@ -32,28 +33,29 @@ import 'utils.dart' show listFocusDirs;
/// External systems that may be independent of the archive content may be
/// stored here, e.g. repository and URL verification.
class SharedAnalysisContext {
final PanaCache panaCache;
final ToolEnvironment toolEnvironment;
final InspectOptions options;
final UrlChecker _urlChecker;

SharedAnalysisContext({
PanaCache? panaCache,
required this.toolEnvironment,
InspectOptions? options,
UrlChecker? urlChecker,
}) : options = options ?? InspectOptions(),
}) : panaCache = panaCache ?? PanaCache(),
options = options ?? InspectOptions(),
_urlChecker = urlChecker ?? UrlChecker();

Future<UrlStatus> checkUrlStatus(String url) async {
final cacheType = 'url';
final cacheKey = url;
final cachedData =
await toolEnvironment.panaCache.readData(cacheType, cacheKey);
final cachedData = await panaCache.readData(cacheType, cacheKey);
if (cachedData != null) {
return UrlStatus.fromJson(cachedData);
}
final status = await _urlChecker.checkStatus(url);
await toolEnvironment.panaCache
.writeData(cacheType, cacheKey, status.toJson());
await panaCache.writeData(cacheType, cacheKey, status.toJson());
return status;
}

Expand All @@ -66,8 +68,7 @@ class SharedAnalysisContext {
}
final cacheType = 'repository';
final cacheKey = '$package/$repositoryOrHomepage';
final cachedData =
await toolEnvironment.panaCache.readData(cacheType, cacheKey);
final cachedData = await panaCache.readData(cacheType, cacheKey);
if (cachedData != null) {
return VerifiedRepository.fromJson(cachedData);
}
Expand All @@ -77,8 +78,7 @@ class SharedAnalysisContext {
sourceUrl: repositoryOrHomepage,
);
if (repository != null) {
await toolEnvironment.panaCache
.writeData(cacheType, cacheKey, repository.toJson());
await panaCache.writeData(cacheType, cacheKey, repository.toJson());
}
return repository;
}
Expand Down
11 changes: 2 additions & 9 deletions lib/src/sdk_env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import 'internal_model.dart';
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';
Expand Down Expand Up @@ -75,7 +74,6 @@ class SdkConfig {

class ToolEnvironment {
final String? pubCacheDir;
final PanaCache panaCache;
final _DartSdk _dartSdk;
final _FlutterSdk _flutterSdk;
PanaRuntimeInfo? _runtimeInfo;
Expand All @@ -85,19 +83,16 @@ class ToolEnvironment {

ToolEnvironment._(
this.pubCacheDir,
this.panaCache,
this._dartSdk,
this._flutterSdk,
this._dartdocVersion,
);

ToolEnvironment.fake({
this.pubCacheDir,
PanaCache? panaCache,
Map<String, String> environment = const <String, String>{},
required PanaRuntimeInfo runtimeInfo,
}) : panaCache = panaCache ?? PanaCache(),
_dartSdk = _DartSdk._(SdkConfig(environment: environment)),
}) : _dartSdk = _DartSdk._(SdkConfig(environment: environment)),
_flutterSdk = _FlutterSdk._(SdkConfig(environment: environment),
_DartSdk._(SdkConfig(environment: environment))),
_dartdocVersion = null,
Expand Down Expand Up @@ -129,7 +124,7 @@ class ToolEnvironment {
SdkConfig? dartSdkConfig,
SdkConfig? flutterSdkConfig,
String? pubCacheDir,
String? panaCacheDir,
@Deprecated('parameter no longer used') String? panaCacheDir,
String? pubHostedUrl,

/// When specified, this version of `dartdoc` will be initialized
Expand All @@ -142,7 +137,6 @@ class ToolEnvironment {
dartSdkConfig ??= SdkConfig(rootPath: cli.getSdkPath());
flutterSdkConfig ??= SdkConfig();
final resolvedPubCache = await _resolve(pubCacheDir);
final resolvedPanaCache = await _resolve(panaCacheDir);

final origPubEnvValue = Platform.environment[_pubEnvironmentKey] ?? '';
final origPubEnvValues = origPubEnvValue
Expand Down Expand Up @@ -170,7 +164,6 @@ class ToolEnvironment {

final toolEnv = ToolEnvironment._(
resolvedPubCache,
PanaCache(path: resolvedPanaCache),
await _DartSdk.detect(dartSdkConfig, env),
flutterSdk,
dartdocVersion,
Expand Down
2 changes: 1 addition & 1 deletion test/end2end_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ void main() {
dartSdkConfig: SdkConfig(configHomePath: dartConfigDir),
flutterSdkConfig: SdkConfig(configHomePath: flutterConfigDir),
pubCacheDir: pubCacheDir,
panaCacheDir: panaCacheDir,
pubHostedUrl: 'http://127.0.0.1:${httpServer.port}',
dartdocVersion: 'any',
));
Expand All @@ -66,6 +65,7 @@ void main() {
version: version,
options: InspectOptions(
pubHostedUrl: 'http://127.0.0.1:${httpServer.port}',
panaCacheDir: panaCacheDir,
dartdocOutputDir: skipDartdoc ? null : dartdocOutputDir,
),
);
Expand Down