Skip to content

[native_assets_cli] User-defines from command-line arguments #2215

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

Open
dcharkes opened this issue Apr 17, 2025 · 0 comments
Open

[native_assets_cli] User-defines from command-line arguments #2215

dcharkes opened this issue Apr 17, 2025 · 0 comments

Comments

@dcharkes
Copy link
Collaborator

We should consider adding support for user-defines as command-line arguments from Dart and Flutter.

CLI sketch:

dart run --hook-define=<package>.<key>=<value>
flutter run --hook-define=<package>.<key>=<value>

The defines are namespace by package similar to how these are nested in the pubspec.yaml user defines.

The defines are shared for all hooks, similar to how the are shared across all hooks (currently only build.dart and link.dart) in the pubspec.yaml user-defines.

Hooks API: Unchanged from current API. Command-line arguments "override" arguments from the pubspec.

JSON protocol sketch:

{
  "user_defines": {
    "command_line_arguments": {
      "base_path": "/private/var/folders/2y/mngq9h194yzglt4kzttzfq6800klzg/T/QqYcWN/workspace/pkgs/my_package/",
      "defines": {
        "user_define_key": "user_define_value",
        "some_file": "assets/data.json"
      }
    },
    "workspace_pubspec": {
      "base_path": "/private/var/folders/2y/mngq9h194yzglt4kzttzfq6800klzg/T/QqYcWN/workspace/pubspec.yaml",
      "defines": {
        "user_define_key": "user_define_value",
        "user_define_key2": {
          "foo": "bar"
        },
        "some_file": "pkgs/my_package/assets/data.json"
      }
    },
  },
}

Caching behavior:

Overrides the non-cli-args cache with cli args. So for a second invocation with the same cli args the cache is used.
A later invocation without cli args needs to be rerun.

If no CLI args are passed the whole command_line_arguments from the JSON is omitted. So invoking builds from multiple root packages in the same directory without cli arguments will always hit caching.

Using cli args invalidates caching.

(If we keep the config in JSON dictates cache directory, we could use a different cache directory if there are any CLI arguments. E.g. config->has_cli_args = true.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

1 participant