Skip to content

Commit

Permalink
Allow modification of a BuildOutput's raw dependencies (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough authored Oct 27, 2023
1 parent 762b4da commit 9629a55
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pkgs/native_assets_cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.3.2

- Fixed an issue where `Depenendencies.dependencies` could not be
modified when expected to.

## 0.3.1

- Added `Target.androidRiscv64`.
Expand Down
6 changes: 4 additions & 2 deletions pkgs/native_assets_cli/lib/src/model/build_output.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ class BuildOutput {
Metadata? metadata,
}) : timestamp = (timestamp ?? DateTime.now()).roundDownToSeconds(),
assets = assets ?? [],
dependencies = dependencies ?? const Dependencies([]),
metadata = metadata ?? const Metadata({});
// ignore: prefer_const_constructors
dependencies = dependencies ?? Dependencies([]),
// ignore: prefer_const_constructors
metadata = metadata ?? Metadata({});

static const _assetsKey = 'assets';
static const _dependenciesKey = 'dependencies';
Expand Down
4 changes: 3 additions & 1 deletion pkgs/native_assets_cli/lib/src/model/dependencies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import '../utils/uri.dart';
import '../utils/yaml.dart';

class Dependencies {
/// The dependencies a build relied on.
final List<Uri> dependencies;

const Dependencies(this.dependencies);
Expand All @@ -19,7 +20,8 @@ class Dependencies {
if (yaml is YamlList) {
return Dependencies.fromYaml(yaml);
}
return const Dependencies([]);
// ignore: prefer_const_constructors
return Dependencies([]);
}

factory Dependencies.fromYaml(YamlList? yamlList) => Dependencies([
Expand Down
2 changes: 1 addition & 1 deletion pkgs/native_assets_cli/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: native_assets_cli
description: >-
A library that contains the argument and file formats for implementing a
native assets CLI.
version: 0.3.1
version: 0.3.2
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_assets_cli

topics:
Expand Down
11 changes: 11 additions & 0 deletions pkgs/native_assets_cli/test/model/build_output_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,15 @@ version: ${BuildOutput.version}'''),
throwsFormatException,
);
});

test('BuildOutput dependencies can be modified', () {
// TODO(https://github.com/dart-lang/native/issues/25):
// Remove once dependencies are made immutable.
final buildOutput = BuildOutput();
expect(
() => buildOutput.dependencies.dependencies
.add(Uri.file('path/to/file.ext')),
returnsNormally,
);
});
}

0 comments on commit 9629a55

Please sign in to comment.