Skip to content
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] Validate conditionally required fields #2126

Merged
merged 2 commits into from
Mar 26, 2025

Conversation

dcharkes
Copy link
Collaborator

@dcharkes dcharkes commented Mar 24, 2025

Closes: #1826

This PR adds the final step to the generated syntax validation: conditionally required fields:

  1. If target OS is x, then require x config in code config.
  2. If target OS is windows, then require windows in the c compiler config (more info [native_assets_cli] Introduce CCompilerConfig.windows #1913).
  3. If link mode is dynamic library bundled or static library, then require a file in a code asset.

We could consider trying to nest the fields under the condition, but that has other downsides:

RE 1: Then the OS is no longer an enum usable in the code-asset as OS field. (We could consider this if we remove the OS/arch from code asset outputs. We should be able to do this due to the code config always having a single OS and architecture anyway. #2127)
RE 2: That would mean the compiler config would be split over two places. input.config.code.cCompiler and inputconfig.code.windows.cCompiler. Maybe that's better? Maybe not?
RE 3: Treating a group of files in assets would then become input.assets.code.switch( ... ) instead of simply input.assets.code.map((a) => a.file). Maybe that's okay because we don't often use files in such way anyway?

WDYT @mosuem @HosseinYousefi?

(I'd probably do any of those refactorings in follow up PRs.)

Copy link

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
Changelog Entry ✔️
Package Changed Files

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.

Package Leaked API symbols
License Headers ✔️
// Copyright (c) 2025, 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.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/jni/lib/src/third_party/generated_bindings.dart
pkgs/objective_c/lib/src/ns_input_stream.dart

@dcharkes dcharkes force-pushed the syntax-required-conditionally branch from 62df51b to 7a550bf Compare March 24, 2025 11:06
@dcharkes dcharkes marked this pull request as ready for review March 24, 2025 11:07
@coveralls
Copy link

coveralls commented Mar 24, 2025

Coverage Status

coverage: 85.992% (+0.06%) from 85.936%
when pulling fd8940c on syntax-required-conditionally
into 2fc2bab on main.

@HosseinYousefi
Copy link
Member

conditionally required fields

Are these available in json schemas?

@dcharkes
Copy link
Collaborator Author

conditionally required fields

Are these available in json schemas?

Yes, that's where we are generating them from.

Search for "if" in the schemas:

        {
          "if": {
            "properties": {
              "target_os": {
                "const": "macos"
              }
            }
          },
          "then": {
            "required": [
              "macos"
            ]
          }
        },

Object? tryTraverse(List<String> path) {
Object? json = this.json;
while (path.isNotEmpty) {
final key = path.removeAt(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's slightly inefficient to remove the first element from the list (O(N^2)). Why not just loop over the path?

@auto-submit auto-submit bot merged commit 4073532 into main Mar 26, 2025
40 checks passed
@auto-submit auto-submit bot deleted the syntax-required-conditionally branch March 26, 2025 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[native_assets_cli] Use a schema and schema checker for hook config and output
3 participants