diff options
author | hacker1024 <hacker1024@users.sourceforge.net> | 2023-10-26 19:59:39 +1100 |
---|---|---|
committer | FlafyDev <flafyarazi@gmail.com> | 2023-12-26 17:08:51 +0200 |
commit | 65d2cc04a31ce77e949b90d5745f607e6ee26151 (patch) | |
tree | 1f649252d5e7d84859587b896277ad123a90a891 | |
parent | d41348a68a130b5358740e394f50d7fb5fc69838 (diff) | |
download | nixlib-65d2cc04a31ce77e949b90d5745f607e6ee26151.tar nixlib-65d2cc04a31ce77e949b90d5745f607e6ee26151.tar.gz nixlib-65d2cc04a31ce77e949b90d5745f607e6ee26151.tar.bz2 nixlib-65d2cc04a31ce77e949b90d5745f607e6ee26151.tar.lz nixlib-65d2cc04a31ce77e949b90d5745f607e6ee26151.tar.xz nixlib-65d2cc04a31ce77e949b90d5745f607e6ee26151.tar.zst nixlib-65d2cc04a31ce77e949b90d5745f607e6ee26151.zip |
dartHooks.dartConfigHook: Simplify packageRun function
3 files changed, 32 insertions, 7 deletions
diff --git a/doc/languages-frameworks/dart.section.md b/doc/languages-frameworks/dart.section.md index e5acd9902634..512f55a68b6b 100644 --- a/doc/languages-frameworks/dart.section.md +++ b/doc/languages-frameworks/dart.section.md @@ -56,7 +56,7 @@ This is an alternative to `dart run` that does not rely on Pub. e.g., for `build_runner`: ```bash -packageRun build_runner -- build +packageRun build_runner build ``` Do _not_ use `dart run <package_name>`, as this will attempt to download dependencies with Pub. diff --git a/pkgs/build-support/dart/build-dart-application/hooks/dart-config-hook.sh b/pkgs/build-support/dart/build-dart-application/hooks/dart-config-hook.sh index a4d2809c44b8..dae74c3f77e6 100644 --- a/pkgs/build-support/dart/build-dart-application/hooks/dart-config-hook.sh +++ b/pkgs/build-support/dart/build-dart-application/hooks/dart-config-hook.sh @@ -10,14 +10,18 @@ dartConfigHook() { mkdir -p .dart_tool cp "$packageConfig" .dart_tool/package_config.json - # Runs a Dart executable from a package. + packagePath() { + jq --raw-output --arg name "$1" '.packages.[] | select(.name == $name) .rootUri | sub("file://"; "")' .dart_tool/package_config.json + } + + # Runs a Dart executable from a package with a custom path. # # Usage: - # packageRun <package> [executable] [bin_dir] + # packageRunCustom <package> [executable] [bin_dir] # # By default, [bin_dir] is "bin", and [executable] is <package>. - # i.e. `packageRun build_runner` is equivalent to `packageRun build_runner build_runner bin`, which runs `bin/build_runner.dart` from the build_runner package. - packageRun() { + # i.e. `packageRunCustom build_runner` is equivalent to `packageRunCustom build_runner build_runner bin`, which runs `bin/build_runner.dart` from the build_runner package. + packageRunCustom() { local args=() local passthrough=() @@ -36,8 +40,28 @@ dartConfigHook() { local path="${args[1]:-$name}" local prefix="${args[2]:-bin}" - local packagePath="$(jq --raw-output --arg name "$name" '.packages.[] | select(.name == $name) .rootUri | sub("file://"; "")' .dart_tool/package_config.json)" - dart --packages=.dart_tool/package_config.json "$packagePath/$prefix/$path.dart" "${passthrough[@]}" + dart --packages=.dart_tool/package_config.json "$(packagePath "$name")/$prefix/$path.dart" "${passthrough[@]}" + } + + # Runs a Dart executable from a package. + # + # Usage: + # packageRun <package> [-e executable] [...] + # + # To run an executable from an unconventional location, use packageRunCustom. + packageRun() { + local name="$1" + shift + + local executableName="$name" + if [ "$1" = "-e" ]; then + shift + executableName="$1" + shift + fi + + fileName="$(@yq@ --raw-output --arg name "$executableName" '.executables.[$name] // $name' "$(packagePath "$name")/pubspec.yaml")" + packageRunCustom "$name" "$fileName" -- "$@" } echo "Generating the dependency list" diff --git a/pkgs/build-support/dart/build-dart-application/hooks/default.nix b/pkgs/build-support/dart/build-dart-application/hooks/default.nix index 49599128ff63..253d3132ad02 100644 --- a/pkgs/build-support/dart/build-dart-application/hooks/default.nix +++ b/pkgs/build-support/dart/build-dart-application/hooks/default.nix @@ -3,6 +3,7 @@ { dartConfigHook = makeSetupHook { name = "dart-config-hook"; + substitutions.yq = "${yq}/bin/yq"; substitutions.jq = "${jq}/bin/jq"; } ./dart-config-hook.sh; dartBuildHook = makeSetupHook { |