Skip to content

Commit a7cd31e

Browse files
authored
PackageLayout constructor for already parsed PackageConfig (#126)
1 parent 9f24b64 commit a7cd31e

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

pkgs/native_assets_builder/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.2.1
2+
3+
- Provide a `PackageLayout` constructor for already parsed `PackageConfig`
4+
[flutter#134427](https://github.com/flutter/flutter/issues/134427).
5+
16
## 0.2.0
27

38
- **Breaking change** `NativeAssetsBuildRunner`s methods now return an object

pkgs/native_assets_builder/lib/src/package_layout/package_layout.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ class PackageLayout {
3131
PackageLayout._(
3232
this.rootPackageRoot, this.packageConfig, this.packageConfigUri);
3333

34+
factory PackageLayout.fromPackageConfig(
35+
PackageConfig packageConfig,
36+
Uri packageConfigUri,
37+
) {
38+
assert(File.fromUri(packageConfigUri).existsSync());
39+
packageConfigUri = packageConfigUri.normalizePath();
40+
final rootPackageRoot = packageConfigUri.resolve('../');
41+
return PackageLayout._(rootPackageRoot, packageConfig, packageConfigUri);
42+
}
43+
3444
static Future<PackageLayout> fromRootPackageRoot(Uri rootPackageRoot) async {
3545
rootPackageRoot = rootPackageRoot.normalizePath();
3646
final packageConfigUri =

pkgs/native_assets_builder/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: native_assets_builder
22
description: >-
33
This package is the backend that invokes top-level `build.dart` scripts.
4-
version: 0.2.0
4+
version: 0.2.1
55
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_builder
66

77
environment:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:native_assets_builder/native_assets_builder.dart';
6+
import 'package:test/test.dart';
7+
8+
import '../helpers.dart';
9+
import 'helpers.dart';
10+
11+
void main() async {
12+
test('fromRootPackageRoot', () async {
13+
await inTempDir((tempUri) async {
14+
await copyTestProjects(targetUri: tempUri);
15+
final nativeAddUri = tempUri.resolve('native_add/');
16+
17+
// First, run `pub get`, we need pub to resolve our dependencies.
18+
await runPubGet(workingDirectory: nativeAddUri, logger: logger);
19+
20+
final packageLayout =
21+
await PackageLayout.fromRootPackageRoot(nativeAddUri);
22+
final packageLayout2 = PackageLayout.fromPackageConfig(
23+
packageLayout.packageConfig,
24+
packageLayout.packageConfigUri,
25+
);
26+
expect(packageLayout.rootPackageRoot, packageLayout2.rootPackageRoot);
27+
});
28+
});
29+
}

0 commit comments

Comments
 (0)