e3af7e724f
Breaking change 40678 requires the constructors int.fromEnvironment and String.fromEnvironment to get new default values for the named parameter `defaultValue`. This CL changes usages of these constructors such that they do not depend on the default value, such that it becomes a non-breaking change for code in the SDK repo to perform the change in sdk and in sdk_nnbd. Change-Id: I82af0e1f92d6cd3618b65c0c50d754ae8c39eb0a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140284 Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Reviewed-by: Leaf Petersen <leafp@google.com> Commit-Queue: Erik Ernst <eernst@google.com>
31 lines
1.2 KiB
Dart
31 lines
1.2 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.
|
|
String pkgRootVar = const bool.hasEnvironment('pkgRoot')
|
|
? const String.fromEnvironment('pkgRoot')
|
|
: null;
|
|
if (pkgRootVar != null) {
|
|
String 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.
|
|
String scriptPath = pathos.fromUri(Platform.script);
|
|
List<String> parts = pathos.split(scriptPath);
|
|
int 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');
|
|
}
|