forked from dart-lang/build
/
patch_build_dependencies.dart
55 lines (45 loc) · 1.61 KB
/
patch_build_dependencies.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2022, 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 p;
import 'package:yaml/yaml.dart';
import 'package:yaml_edit/yaml_edit.dart';
const _buildPackages = [
'build',
'build_config',
'build_daemon',
'build_modules',
'build_resolvers',
'build_runner',
'build_runner_core',
'build_test',
'build_vm_compilers',
'build_web_compilers',
'scratch_space',
];
/// Adds `dependency_overrides` for to a pubspec.yaml file in [packageDir]
/// build packages, assuming that the current working directory is the root of
/// the `build` repository checkout.
Future<void> patchBuildDependencies(String packageDir) async {
final pubspec = File(p.join(packageDir, 'pubspec.yaml'));
if (!await pubspec.exists()) {
throw UnsupportedError('No pubspec.yaml in $packageDir');
}
final editor = YamlEditor(await pubspec.readAsString());
const targetSection = ['dependency_overrides'];
if (editor
.parseAt(targetSection, orElse: () => YamlScalar.wrap(null))
.value ==
null) {
// There are no `dependency_overrides` in this pubspec, so create an empty
// block first.
editor.update(targetSection, {});
}
final buildCheckout = Directory.current.path;
for (final buildPackage in _buildPackages) {
final path = p.join(buildCheckout, buildPackage);
editor.update([...targetSection, buildPackage], {'path': path});
}
await pubspec.writeAsString(editor.toString());
}