Add a script to generate a package_config.json for the SDK.

Also include the generated output.

Change-Id: Ic2818f544972c737f69913122e366ea48375e950
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135795
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
Robert Nystrom 2020-02-27 17:52:23 +00:00 committed by commit-bot@chromium.org
parent 95f87f321a
commit 4b7ba5a72f
4 changed files with 934 additions and 1 deletions

View file

@ -0,0 +1,793 @@
{
"copyright": [
"Copyright (c) 2020, 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."
],
"comment": [
"Package configuration for all packages in /pkg, and checked out by DEPS",
"into /third_party/pkg and /third_party/pkg_tested.",
"If you add a package to DEPS or /pkg or change a package's SDK",
"constraint, update this by running tools/generate_package_config.dart."
],
"configVersion": 2,
"generated": "2020-02-27T09:12:42.886102",
"generator": "tools/generate_package_config.dart",
"packages": [
{
"name": "_fe_analyzer_shared",
"rootUri": "../pkg/_fe_analyzer_shared",
"packageUri": "lib/",
"languageVersion": "2.2"
},
{
"name": "_js_interop_checks",
"rootUri": "../pkg/_js_interop_checks",
"packageUri": "lib/",
"languageVersion": "2.7"
},
{
"name": "analysis_server",
"rootUri": "../pkg/analysis_server",
"packageUri": "lib/",
"languageVersion": "2.6"
},
{
"name": "analysis_server_client",
"rootUri": "../pkg/analysis_server_client",
"packageUri": "lib/",
"languageVersion": "2.1"
},
{
"name": "analysis_tool",
"rootUri": "../pkg/analysis_tool",
"packageUri": "lib/",
"languageVersion": "2.1"
},
{
"name": "analyzer",
"rootUri": "../pkg/analyzer",
"packageUri": "lib/",
"languageVersion": "2.6"
},
{
"name": "analyzer_cli",
"rootUri": "../pkg/analyzer_cli",
"packageUri": "lib/",
"languageVersion": "2.7"
},
{
"name": "analyzer_fe_comparison",
"rootUri": "../pkg/analyzer_fe_comparison",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "analyzer_plugin",
"rootUri": "../pkg/analyzer_plugin",
"packageUri": "lib/",
"languageVersion": "2.3"
},
{
"name": "args",
"rootUri": "../third_party/pkg/args",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "async",
"rootUri": "../third_party/pkg/async",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "async_helper",
"rootUri": "../pkg/async_helper",
"packageUri": "lib/",
"languageVersion": "2.7"
},
{
"name": "bazel_worker",
"rootUri": "../third_party/pkg/bazel_worker",
"packageUri": "lib/",
"languageVersion": "2.1"
},
{
"name": "benchmark_harness",
"rootUri": "../third_party/pkg/benchmark_harness",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "boolean_selector",
"rootUri": "../third_party/pkg/boolean_selector",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "build_integration",
"rootUri": "../pkg/build_integration",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "charcode",
"rootUri": "../third_party/pkg/charcode",
"packageUri": "lib/",
"languageVersion": "1.0"
},
{
"name": "cli_util",
"rootUri": "../third_party/pkg/cli_util",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "code_transformers",
"rootUri": "../third_party/pkg/code_transformers",
"packageUri": "lib/",
"languageVersion": "1.0"
},
{
"name": "collection",
"rootUri": "../third_party/pkg/collection",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "compiler",
"rootUri": "../pkg/compiler",
"packageUri": "lib/",
"languageVersion": "2.6"
},
{
"name": "convert",
"rootUri": "../third_party/pkg/convert",
"packageUri": "lib/",
"languageVersion": "1.17"
},
{
"name": "crypto",
"rootUri": "../third_party/pkg/crypto",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "csslib",
"rootUri": "../third_party/pkg/csslib",
"packageUri": "lib/",
"languageVersion": "2.1"
},
{
"name": "dart2js_info",
"rootUri": "../third_party/pkg/dart2js_info",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "dart2js_tools",
"rootUri": "../pkg/dart2js_tools",
"packageUri": "lib/",
"languageVersion": "2.3"
},
{
"name": "dart2native",
"rootUri": "../pkg/dart2native",
"packageUri": "lib/",
"languageVersion": "2.7"
},
{
"name": "dart_internal",
"rootUri": "../pkg/dart_internal",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "dart_style",
"rootUri": "../third_party/pkg_tested/dart_style",
"packageUri": "lib/",
"languageVersion": "2.3"
},
{
"name": "dartdev",
"rootUri": "../pkg/dartdev",
"packageUri": "lib/",
"languageVersion": "2.6"
},
{
"name": "dartdoc",
"rootUri": "../third_party/pkg/dartdoc",
"packageUri": "lib/",
"languageVersion": "2.6"
},
{
"name": "dartfix",
"rootUri": "../pkg/dartfix",
"packageUri": "lib/",
"languageVersion": "2.3"
},
{
"name": "dev_compiler",
"rootUri": "../pkg/dev_compiler",
"packageUri": "lib/",
"languageVersion": "2.3"
},
{
"name": "diagnostic",
"rootUri": "../pkg/diagnostic",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "expect",
"rootUri": "../pkg/expect",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "ffi",
"rootUri": "../third_party/pkg/ffi",
"packageUri": "lib/",
"languageVersion": "2.6"
},
{
"name": "fixnum",
"rootUri": "../third_party/pkg/fixnum",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "front_end",
"rootUri": "../pkg/front_end",
"packageUri": "lib/",
"languageVersion": "2.2"
},
{
"name": "front_end_agnostic",
"rootUri": "../pkg/front_end/testcases/agnostic",
"packageUri": ".nonexisting/"
},
{
"name": "front_end_general_nnbd_opt_out",
"rootUri": "../pkg/front_end/testcases/general_nnbd_opt_out",
"packageUri": ".nonexisting/"
},
{
"name": "front_end_late_lowering",
"rootUri": "../pkg/front_end/testcases/late_lowering",
"packageUri": ".nonexisting/"
},
{
"name": "front_end_nnbd",
"rootUri": "../pkg/front_end/testcases/nnbd",
"packageUri": ".nonexisting/"
},
{
"name": "frontend_server",
"rootUri": "../pkg/frontend_server",
"packageUri": "lib/",
"languageVersion": "2.7"
},
{
"name": "func",
"rootUri": "../third_party/pkg/func",
"packageUri": "lib/",
"languageVersion": "1.9"
},
{
"name": "gardening",
"rootUri": "../tools/gardening",
"packageUri": "lib/",
"languageVersion": "2.7"
},
{
"name": "glob",
"rootUri": "../third_party/pkg/glob",
"packageUri": "lib/",
"languageVersion": "1.23"
},
{
"name": "html",
"rootUri": "../third_party/pkg/html",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "http",
"rootUri": "../third_party/pkg/http",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "http_io",
"rootUri": "../third_party/pkg_tested/http_io",
"packageUri": "lib/",
"languageVersion": "2.5"
},
{
"name": "http_multi_server",
"rootUri": "../third_party/pkg/http_multi_server",
"packageUri": "lib/",
"languageVersion": "2.1"
},
{
"name": "http_parser",
"rootUri": "../third_party/pkg/http_parser",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "http_retry",
"rootUri": "../third_party/pkg/http_retry",
"packageUri": "lib/",
"languageVersion": "1.24"
},
{
"name": "http_throttle",
"rootUri": "../third_party/pkg/http_throttle",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "initialize",
"rootUri": "../third_party/pkg/initialize",
"packageUri": "lib/",
"languageVersion": "1.9"
},
{
"name": "intl",
"rootUri": "../third_party/pkg/intl",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "js",
"rootUri": "../pkg/js",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "js_ast",
"rootUri": "../pkg/js_ast",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "js_runtime",
"rootUri": "../sdk/lib/_internal/js_runtime",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "json_rpc_2",
"rootUri": "../third_party/pkg/json_rpc_2",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "kernel",
"rootUri": "../pkg/kernel",
"packageUri": "lib/",
"languageVersion": "2.2"
},
{
"name": "linter",
"rootUri": "../third_party/pkg/linter",
"packageUri": "lib/",
"languageVersion": "2.2"
},
{
"name": "logging",
"rootUri": "../third_party/pkg/logging",
"packageUri": "lib/",
"languageVersion": "1.5"
},
{
"name": "markdown",
"rootUri": "../third_party/pkg/markdown",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "matcher",
"rootUri": "../third_party/pkg/matcher",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "meta",
"rootUri": "../pkg/meta",
"packageUri": "lib/",
"languageVersion": "1.12"
},
{
"name": "metatest",
"rootUri": "../third_party/pkg/metatest",
"packageUri": "lib/",
"languageVersion": "1.8"
},
{
"name": "mime",
"rootUri": "../third_party/pkg/mime",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "mockito",
"rootUri": "../third_party/pkg/mockito",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "modular_test",
"rootUri": "../pkg/modular_test",
"packageUri": "lib/",
"languageVersion": "2.2"
},
{
"name": "mustache",
"rootUri": "../third_party/pkg/mustache",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "native_stack_traces",
"rootUri": "../pkg/native_stack_traces",
"packageUri": "lib/",
"languageVersion": "2.7"
},
{
"name": "nnbd_migration",
"rootUri": "../pkg/nnbd_migration",
"packageUri": "lib/",
"languageVersion": "2.6"
},
{
"name": "oauth2",
"rootUri": "../third_party/pkg/oauth2",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "observable",
"rootUri": "../third_party/pkg/observable",
"packageUri": "lib/",
"languageVersion": "1.19"
},
{
"name": "observatory",
"rootUri": "../runtime/observatory",
"packageUri": "lib/",
"languageVersion": "2.2"
},
{
"name": "observatory_test_package",
"rootUri": "../runtime/observatory/tests/service/observatory_test_package",
"languageVersion": "2.7"
},
{
"name": "observe",
"rootUri": "../third_party/pkg/observe",
"packageUri": "lib/",
"languageVersion": "1.9"
},
{
"name": "package_config",
"rootUri": "../third_party/pkg_tested/package_config",
"packageUri": "lib/",
"languageVersion": "2.7"
},
{
"name": "package_resolver",
"rootUri": "../third_party/pkg_tested/package_resolver",
"packageUri": "lib/",
"languageVersion": "2.1"
},
{
"name": "path",
"rootUri": "../third_party/pkg/path",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "pedantic",
"rootUri": "../third_party/pkg/pedantic",
"packageUri": "lib/",
"languageVersion": "2.1"
},
{
"name": "platform",
"rootUri": "../third_party/pkg/platform",
"packageUri": "lib/",
"languageVersion": "1.24"
},
{
"name": "plugin",
"rootUri": "../third_party/pkg/plugin",
"packageUri": "lib/",
"languageVersion": "1.0"
},
{
"name": "pool",
"rootUri": "../third_party/pkg/pool",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "process",
"rootUri": "../third_party/pkg/process",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "protobuf",
"rootUri": "../third_party/pkg/protobuf/protobuf",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "pub",
"rootUri": "../third_party/pkg/pub",
"packageUri": "lib/",
"languageVersion": "2.3"
},
{
"name": "pub_semver",
"rootUri": "../third_party/pkg/pub_semver",
"packageUri": "lib/",
"languageVersion": "1.0"
},
{
"name": "quiver",
"rootUri": "../third_party/pkg/quiver",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "resource",
"rootUri": "../third_party/pkg/resource",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "scheduled_test",
"rootUri": "../third_party/pkg/scheduled_test",
"packageUri": "lib/",
"languageVersion": "1.22"
},
{
"name": "sdk_library_metadata",
"rootUri": "../sdk/lib/_internal/sdk_library_metadata",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "shelf",
"rootUri": "../third_party/pkg/shelf",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "shelf_packages_handler",
"rootUri": "../third_party/pkg/shelf_packages_handler",
"packageUri": "lib/",
"languageVersion": "1.22"
},
{
"name": "shelf_static",
"rootUri": "../third_party/pkg/shelf_static",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "shelf_web_socket",
"rootUri": "../third_party/pkg/shelf_web_socket",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "smith",
"rootUri": "../pkg/smith",
"packageUri": "lib/",
"languageVersion": "2.3"
},
{
"name": "smoke",
"rootUri": "../third_party/pkg/smoke",
"packageUri": "lib/",
"languageVersion": "1.12"
},
{
"name": "source_map_stack_trace",
"rootUri": "../third_party/pkg/source_map_stack_trace",
"packageUri": "lib/",
"languageVersion": "1.8"
},
{
"name": "source_maps",
"rootUri": "../third_party/pkg/source_maps",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "source_span",
"rootUri": "../third_party/pkg/source_span",
"packageUri": "lib/",
"languageVersion": "1.8"
},
{
"name": "sourcemap_testing",
"rootUri": "../pkg/sourcemap_testing",
"packageUri": "lib/",
"languageVersion": "2.1"
},
{
"name": "stack_trace",
"rootUri": "../third_party/pkg/stack_trace",
"packageUri": "lib/",
"languageVersion": "1.23"
},
{
"name": "stagehand",
"rootUri": "../third_party/pkg/stagehand",
"packageUri": "lib/",
"languageVersion": "2.7"
},
{
"name": "status_file",
"rootUri": "../pkg/status_file",
"packageUri": "lib/",
"languageVersion": "2.3"
},
{
"name": "stream_channel",
"rootUri": "../third_party/pkg/stream_channel",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "string_scanner",
"rootUri": "../third_party/pkg/string_scanner",
"packageUri": "lib/",
"languageVersion": "1.8"
},
{
"name": "telemetry",
"rootUri": "../pkg/telemetry",
"packageUri": "lib/",
"languageVersion": "1.0"
},
{
"name": "term_glyph",
"rootUri": "../third_party/pkg/term_glyph",
"packageUri": "lib/",
"languageVersion": "1.8"
},
{
"name": "test",
"rootUri": "../third_party/pkg/test/pkgs/test",
"packageUri": "lib/",
"languageVersion": "2.2"
},
{
"name": "test_api",
"rootUri": "../third_party/pkg/test/pkgs/test_api",
"packageUri": "lib/",
"languageVersion": "2.1"
},
{
"name": "test_core",
"rootUri": "../third_party/pkg/test/pkgs/test_core",
"packageUri": "lib/",
"languageVersion": "2.1"
},
{
"name": "test_descriptor",
"rootUri": "../third_party/pkg/test_descriptor",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "test_process",
"rootUri": "../third_party/pkg/test_process",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "test_reflective_loader",
"rootUri": "../third_party/pkg/test_reflective_loader",
"packageUri": "lib/",
"languageVersion": "1.8"
},
{
"name": "test_runner",
"rootUri": "../pkg/test_runner",
"packageUri": "lib/",
"languageVersion": "2.3"
},
{
"name": "testing",
"rootUri": "../pkg/testing",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "tflite_native",
"rootUri": "../third_party/pkg/tflite_native",
"packageUri": "lib/",
"languageVersion": "2.6"
},
{
"name": "tuple",
"rootUri": "../third_party/pkg/tuple",
"packageUri": "lib/",
"languageVersion": "1.6"
},
{
"name": "typed_data",
"rootUri": "../third_party/pkg/typed_data",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "unittest",
"rootUri": "../third_party/pkg/unittest",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "unittest-orig",
"rootUri": "../third_party/pkg/unittest-orig",
"packageUri": "lib/",
"languageVersion": "1.0"
},
{
"name": "usage",
"rootUri": "../third_party/pkg/usage",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "utf",
"rootUri": "../third_party/pkg/utf",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "vm",
"rootUri": "../pkg/vm",
"packageUri": "lib/",
"languageVersion": "2.7"
},
{
"name": "vm_service",
"rootUri": "../pkg/vm_service",
"packageUri": "lib/",
"languageVersion": "2.6"
},
{
"name": "watcher",
"rootUri": "../third_party/pkg/watcher",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "web_components",
"rootUri": "../third_party/pkg/web_components",
"packageUri": "lib/",
"languageVersion": "1.9"
},
{
"name": "web_socket_channel",
"rootUri": "../third_party/pkg/web_socket_channel",
"packageUri": "lib/",
"languageVersion": "2.0"
},
{
"name": "yaml",
"rootUri": "../third_party/pkg/yaml",
"packageUri": "lib/",
"languageVersion": "2.0"
}
]
}

View file

@ -7,7 +7,7 @@ description: >
the expect() function in the unit test library instead for
test assertions.
environment:
sdk: ">=0.8.10+6 <3.0.0"
sdk: ">=2.0.0 <3.0.0"
dependencies:
meta: any

View file

@ -117,6 +117,7 @@ Future<void> main() async {
// Remove white-listed non-dart files.
otherNonDartUris.remove(dotPackagesUri);
otherNonDartUris.remove(repoDir.resolve("sdk/lib/libraries.json"));
otherNonDartUris.remove(repoDir.resolve(".dart_tool/package_config.json"));
// Remove white-listed dart files.
for (String s in whitelistedExternalDartFiles) {

View file

@ -0,0 +1,139 @@
#!/usr/bin/env dart
/// Generates the repo's ".dart_tool/package_config.json" file.
import 'dart:convert';
import 'dart:io';
import 'package:path/path.dart' as p;
import 'package:pub_semver/pub_semver.dart';
import 'package:yaml/yaml.dart';
/// Version to use if a package doesn't constrain the language version.
final defaultVersion = Version(2, 7, 0);
final repoRoot = p.dirname(p.dirname(p.fromUri(Platform.script)));
final configFilePath = p.join(repoRoot, '.dart_tool/package_config.json');
void main(List<String> args) {
var packageDirs = [
...listSubdirectories('pkg'),
...listSubdirectories('third_party/pkg'),
...listSubdirectories('third_party/pkg_tested'),
...listSubdirectories('third_party/pkg/test/pkgs'),
packageDirectory('runtime/observatory'),
packageDirectory(
'runtime/observatory/tests/service/observatory_test_package'),
packageDirectory('sdk/lib/_internal/sdk_library_metadata'),
packageDirectory('sdk/lib/_internal/js_runtime'),
packageDirectory('third_party/pkg/protobuf/protobuf'),
packageDirectory('tools/gardening'),
];
var cfePackageDirs = [
packageDirectory('pkg/front_end/testcases/agnostic/'),
packageDirectory('pkg/front_end/testcases/general_nnbd_opt_out/'),
packageDirectory('pkg/front_end/testcases/late_lowering/'),
packageDirectory('pkg/front_end/testcases/nnbd/'),
];
var packages = [
...makePackageConfigs(packageDirs),
...makeCfePackageConfigs(cfePackageDirs)
];
packages.sort((a, b) => a["name"].compareTo(b["name"]));
var year = DateTime.now().year;
var config = <String, dynamic>{
'copyright': [
'Copyright (c) $year, 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.'
],
'comment': [
'Package configuration for all packages in /pkg, and checked out by DEPS',
'into /third_party/pkg and /third_party/pkg_tested.',
'If you add a package to DEPS or /pkg or change a package\'s SDK',
'constraint, update this by running tools/generate_package_config.dart.'
],
'configVersion': 2,
'generated': DateTime.now().toIso8601String(),
'generator': 'tools/generate_package_config.dart',
'packages': packages,
};
// TODO(rnystrom): Consider using package_config_v2 to generate this instead.
var json = JsonEncoder.withIndent(' ').convert(config);
File(p.join(repoRoot, '.dart_tool', 'package_config.json'))
.writeAsStringSync(json);
print('Generated .dart_tool/package_config.dart containing '
'${packages.length} packages.');
}
/// Generates package configurations for each package in [packageDirs].
Iterable<Map<String, String>> makePackageConfigs(
List<String> packageDirs) sync* {
for (var packageDir in packageDirs) {
var version = pubspecLanguageVersion(packageDir);
if (version == null) {
print('Warning: Unknown language version for ${p.basename(packageDir)}.');
version = defaultVersion;
}
var hasLibDirectory = Directory(p.join(packageDir, 'lib')).existsSync();
yield {
'name': p.basename(packageDir),
'rootUri': p.relative(packageDir, from: p.dirname(configFilePath)),
if (hasLibDirectory) 'packageUri': 'lib/',
'languageVersion': '${version.major}.${version.minor}'
};
}
}
/// Generates package configurations for the special pseudo-packages used by
/// the CFE unit tests (`pkg/front_end/test/unit_test_suites.dart`).
Iterable<Map<String, String>> makeCfePackageConfigs(
List<String> packageDirs) sync* {
for (var packageDir in packageDirs) {
yield {
'name': 'front_end_${p.basename(packageDir)}',
'rootUri': p.relative(packageDir, from: p.dirname(configFilePath)),
'packageUri': '.nonexisting/',
};
}
}
/// Generates a path to [relativePath] within the repo.
String packageDirectory(String relativePath) => p.join(repoRoot, relativePath);
/// Finds the paths of the immediate subdirectories of [packagesDir] that
/// contain pubspecs.
Iterable<String> listSubdirectories(String packagesDir) sync* {
for (var entry in Directory(p.join(repoRoot, packagesDir)).listSync()) {
if (entry is! Directory) continue;
if (!File(p.join(entry.path, 'pubspec.yaml')).existsSync()) continue;
yield entry.path;
}
}
/// Infers the language version from the SDK constraint in the pubspec for
/// [packageDir].
///
/// Returns `null` if there is no pubspec or no SDK constraint.
Version pubspecLanguageVersion(String packageDir) {
var pubspecFile = File(p.join(packageDir, 'pubspec.yaml'));
if (!pubspecFile.existsSync()) return null;
var pubspec =
loadYaml(pubspecFile.readAsStringSync()) as Map<dynamic, dynamic>;
if (!pubspec.containsKey('environment')) return null;
var environment = pubspec['environment'] as Map<dynamic, dynamic>;
if (!environment.containsKey('sdk')) return null;
var sdkConstraint = VersionConstraint.parse(environment['sdk'] as String);
if (sdkConstraint is VersionRange) return sdkConstraint.min;
return null;
}