-
Notifications
You must be signed in to change notification settings - Fork 53
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
[native_assets_cli] Refactor into BuildInput
#1871
Conversation
PR HealthBreaking changes ✔️
Changelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. API leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
License Headers ✔️
All source files should start with a license header. Unrelated files missing license headers
|
In general I think this is good, I haven't looked at the code yet, but from commit message
Lastly, given these changes and choice of checksuming, I think we should probably rename
That may be a good thing, so users can easily see what takes up most space and can selectively |
Done. The API now looks like this: void main(List<String> args) async {
await build(args, (input, output) async {
// a. shared
input.packageName;
input.packageRoot;
input.outputDirectory;
input.outputDirectoryShared;
// b. hook-specific
input.metadata; // build only
input.assets.code; // link only
input.assets.data; // link only
input.recordedUsagesFile; // link only
// c. target config
// c.1. per hook
input.config.linkingEnabled; // build only
input.config.dryRun; // build only, deleted soon
// c.2. per asset
input.config.buildAssetTypes;
input.config.code.linkModePreference;
input.config.code.targetArchitecture;
input.config.code.targetOS;
input.config.code.android.targetNdkApi;
input.config.code.iOS.targetSdk;
input.config.code.iOS.targetVersion;
input.config.code.macOS.targetVersion;
input.config.code.cCompiler?.archiver;
input.config.code.cCompiler?.compiler;
input.config.code.cCompiler?.linker;
output.assets.code.add(CodeAsset(
package: 'package',
name: 'name',
linkMode: DynamicLoadingBundled(),
os: input.config.code.targetOS,
architecture: input.config.code.targetArchitecture,
file: input.outputDirectory.resolve('foo'),
));
output.assets.data.add(
DataAsset(
file: input.outputDirectory.resolve('foo'),
name: 'name',
package: 'package',
),
linkInPackage: 'foo',
);
output.addDependency(input.packageRoot.resolve('x.txt'));
});
} I also dropped the final inputBuilder = LinkInputBuilder()
..setupShared(
packageName: packageName,
packageRoot: packageRootUri,
outputDirectory: outDirUri,
outputDirectoryShared: outputDirectoryShared,
)
..setupLink(
assets: assets,
recordedUsesFile: null,
)
..config.setupShared(buildAssetTypes: [CodeAsset.type])
..config.setupCode(
targetOS: OS.android,
targetArchitecture: Architecture.arm64,
android: AndroidConfig(targetNdkApi: 30),
linkModePreference: LinkModePreference.preferStatic,
cCompiler: CCompilerConfig(
compiler: fakeClang,
linker: fakeLd,
archiver: fakeAr,
envScript: fakeVcVars,
envScriptArgs: ['arg0', 'arg1'],
),
);
I can't really come up with good names. I'd like to avoid making the names longer and also avoid making the names unrelated. Maybe adding documentation is enough. I believe that most users should be using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments, the main one is about layering and buildAssetTypes
.
required BuildValidator buildValidator, | ||
required ApplicationAssetValidator applicationAssetValidator, | ||
required Uri workingDirectory, | ||
PackageLayout? packageLayout, | ||
String? runPackageName, | ||
required List<String> buildAssetTypes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this?
The current code has separation based on how the protocol is layered:
- The optional things / protocol extensions are handled by embedder by calling out to it (e.g. code config)
- The core protocol is handled in
package:native_assets_builder
, this field is core protocol support
So the build
and link
methods should take all things it needs for the core protocol, thereby ensuring those are setup as required by core protocol.
By moving it to the embedder, the package:native_assets_builder
can no longer guarantee the core protocol fields are setup, it relies on the embedder to handle core protocol functionality - which doesn't seem right to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I forgot to revert this when I added buildAssetTypes
back in. Thanks!
..setupCodeConfig( | ||
inputCreator: () => BuildInputBuilder() | ||
..config.setupShared(buildAssetTypes: [ | ||
CodeAsset.type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before it was DataAsset
only, why did you have to add CodeAsset
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't be calling setupCode
below without the CodeAsset.type
here.
We need the setupCode
to ensure differences in the directories.
I guess it's technically correct to add more config that's never read by anyone, but it's messy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the setupCode
call should be removed instead if it worked with data assets only?
There's 3 things that should be in sync
- the
buildAssetTypes
- the config
- the validation
With your changes we support code assets but it doesn't validate them, see
buildValidator: (input, output) async =>
await validateDataAssetBuildOutput(input, output),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we work with data assets only, then we don't exercise the fact that we can have both identical and non-identical output directories. This test is doing directory locking and concurrency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the code validator
pkgs/native_assets_builder/test_data/package_reading_metadata/hook/build.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm with comment
Thanks for the quick roundtrip @mkustermann! 🙏 I don't see a comment, did you forget to press send? |
Oh, it's in an existing conversation. Yay to GitHub UI. 🙈 |
This PR changes the public API according to #1738, and should have minimal behavior changes.
Everything in
HookConfig
causes a differentinput.outputDirectory
, all the other elements in theinput
do not.packageName
no longer influencing the checksum, so the default output directory has been changed to.dart_tool/native_assets_builder/$packageName/$checksum
.Follow up PRs:
Design:
BuildConfig.targetOS
toBuildConfig.codeConfig.targetOS
, remove it entirely or extend to cover web #1738