Files
sdk/pkg/analysis_server_client/test/utils/package_root.dart
T
Brian Wilkerson 93313eb244 Enable omit_loval_variable_types in analysis_server_client
Change-Id: I21271bfc6b2b7949fcafc5f91f23f8364697bcfc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/141580
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2020-03-30 03:59:07 +00:00

30 lines
1.1 KiB
Dart

// Copyright (c) 2017, 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 'package:path/path.dart' as pathos;
/// Returns a path to the directory containing source code for packages such as
/// kernel, front_end, and analyzer.
String get packageRoot {
// If the package root directory is specified on the command line using
// -DpkgRoot=..., use it.
const pkgRootVar =
bool.hasEnvironment('pkgRoot') ? String.fromEnvironment('pkgRoot') : null;
if (pkgRootVar != null) {
var path = pathos.join(Directory.current.path, pkgRootVar);
if (!path.endsWith(pathos.separator)) path += pathos.separator;
return path;
}
// Otherwise try to guess based on the script path.
var scriptPath = pathos.fromUri(Platform.script);
var parts = pathos.split(scriptPath);
var pkgIndex = parts.indexOf('pkg');
if (pkgIndex != -1) {
return pathos.joinAll(parts.sublist(0, pkgIndex + 1)) + pathos.separator;
}
throw StateError('Unable to find sdk/pkg/ in $scriptPath');
}