Skip to content

PackageLayout constructor for already parsed PackageConfig #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkgs/native_assets_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.1

- Provide a `PackageLayout` constructor for already parsed `PackageConfig`
[flutter#134427](https://github.com/flutter/flutter/issues/134427).

## 0.2.0

- **Breaking change** `NativeAssetsBuildRunner`s methods now return an object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ class PackageLayout {
PackageLayout._(
this.rootPackageRoot, this.packageConfig, this.packageConfigUri);

factory PackageLayout.fromPackageConfig(
PackageConfig packageConfig,
Uri packageConfigUri,
) {
assert(File.fromUri(packageConfigUri).existsSync());
packageConfigUri = packageConfigUri.normalizePath();
final rootPackageRoot = packageConfigUri.resolve('../');
return PackageLayout._(rootPackageRoot, packageConfig, packageConfigUri);
}

static Future<PackageLayout> fromRootPackageRoot(Uri rootPackageRoot) async {
rootPackageRoot = rootPackageRoot.normalizePath();
final packageConfigUri =
Expand Down
2 changes: 1 addition & 1 deletion pkgs/native_assets_builder/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: native_assets_builder
description: >-
This package is the backend that invokes top-level `build.dart` scripts.
version: 0.2.0
version: 0.2.1
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_builder

environment:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2023, 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 'package:native_assets_builder/native_assets_builder.dart';
import 'package:test/test.dart';

import '../helpers.dart';
import 'helpers.dart';

void main() async {
test('fromRootPackageRoot', () async {
await inTempDir((tempUri) async {
await copyTestProjects(targetUri: tempUri);
final nativeAddUri = tempUri.resolve('native_add/');

// First, run `pub get`, we need pub to resolve our dependencies.
await runPubGet(workingDirectory: nativeAddUri, logger: logger);

final packageLayout =
await PackageLayout.fromRootPackageRoot(nativeAddUri);
final packageLayout2 = PackageLayout.fromPackageConfig(
packageLayout.packageConfig,
packageLayout.packageConfigUri,
);
expect(packageLayout.rootPackageRoot, packageLayout2.rootPackageRoot);
});
});
}