Files
sdk/pkg/analysis_server/test/support/sdk_paths.dart
T
Danny Tuppeny 5803acf31f [analysis_server] Update plugin tests to work through test runner
This removes a use of `Platform.script` so the tests work through the test runner. It also extracts some common code between this and the other integration tests to remove some duplication.

Change-Id: Ia9d441424789ea99decb071f7fdc6c71c8e54a72
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419860
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-04-02 09:06:09 -07:00

54 lines
2.0 KiB
Dart

// Copyright (c) 2025, 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:io';
import 'dart:isolate';
import 'package:path/path.dart' as path;
/// The path of the `pkg/analysis_server` folder, resolved using the active
/// `package_config.json`.
String get analysisServerPackagePath {
// Locate the root of the analysis server package without using
// `Platform.script` as it fails when run through the `dart test`.
// https://github.com/dart-lang/test/issues/110
var serverLibUri = Isolate.resolvePackageUriSync(
Uri.parse('package:analysis_server/'),
);
return path.normalize(path.join(serverLibUri!.toFilePath(), '..'));
}
/// The path of the `package_config.json` file in the root of the SDK,
/// computed by resolving the path to `pkg:analysis_server`.
String get sdkPackageConfigPath {
return path.normalize(
path.join(sdkRootPath, '.dart_tool', 'package_config.json'),
);
}
/// The path the SDK, computed as the parent of the `pkg/analysis_server`
/// folder, resolved using the active `package_config.json`.
String get sdkRootPath {
return path.normalize(path.join(analysisServerPackagePath, '..', '..'));
}
/// Gets the path of the analysis server entry point which may be a snapshot
/// or the source script depending on the `TEST_SERVER_SNAPSHOT` environment
/// variable.
String getAnalysisServerPath(String dartSdkPath) {
var snapshotPath = path.join(
dartSdkPath,
'bin',
'snapshots',
'analysis_server.dart.snapshot',
);
var sourcePath = path.join(analysisServerPackagePath, 'bin', 'server.dart');
// Setting the `TEST_SERVER_SNAPSHOT` env var to 'false' will disable the
// snapshot and run from source.
var useSnapshot = Platform.environment['TEST_SERVER_SNAPSHOT'] != 'false';
var serverPath = useSnapshot ? snapshotPath : sourcePath;
return path.normalize(serverPath);
}