leanflutter / flutter_distributor

An all-in-one Flutter application packaging and distribution tool, providing you with a one-stop solution to meet various distribution needs.
https://distributor.leanflutter.dev/
MIT License
772 stars 106 forks source link

Add possibility to customize shell commands with env #108

Closed cybrox closed 1 year ago

cybrox commented 1 year ago

This is a suggestion to solve this issue by allowing users to overwrite executables in shell_executor from the environment.

In short:
Set SHELL_EXECUTOR_..._COMMAND to overwrite the executable for a command. E.g. SHELL_EXECUTOR_FLUTTER_COMMAND=/usr/bin/flutter2

Example when using with flutter_distributor:

flutter_distributor package --platform android --targets=apk                           
$ flutter clean
$ flutter build apk --dart-define FLUTTER_BUILD_NAME=1.2.8 --dart-define FLUTTER_BUILD_NUMBER=1365

SHELL_EXECUTOR_FLUTTER_COMMAND="fvm flutter" flutter_distributor package --platform android --targets=apk
$ fvm flutter clean
$ fvm flutter build apk --dart-define FLUTTER_BUILD_NAME=1.2.8 --dart-define FLUTTER_BUILD_NUMBER=1365
cybrox commented 1 year ago

:+1: I'll get the checks passing tomorrow

lijy91 commented 1 year ago

I think it would be better to add a FLUTTER_ROOT environment in distribute_options.yaml to specify the flutter path.

env:
+  FLUTTER_ROOT: /Users/lijy91/fvm/default
  # PGYER_API_KEY: your api key
output: dist/
releases:
  - name: dev
    jobs:
      - name: android-aab
+        env:
+          FLUTTER_ROOT: /Users/lijy91/fvm/versions/3.3.10
        package:
          platform: android
          target: aab
          build_args:
            profile: true
            target-platform: android-arm,android-arm64
            dart-define:
              APP_ENV: dev
      - name: android-apk
+        env:
+          FLUTTER_ROOT: /Users/lijy91/fvm/versions/3.7.3
        package:
          platform: android
          target: apk
          build_args:
            # profile: true
            target-platform: android-arm,android-arm64
            dart-define:
              APP_ENV: dev
cybrox commented 1 year ago

That's a good idea. I think we should support DART_PATH as well, since flutter_distributor uses the Dart command for auto-updating and it might be managed by a version manager as well.

The flutter and dart commands are currently used in 3 packages (flutter_app_builder, flutter_app_packager, app_package_publisher). Would you add this in all of these packages separately or to shell_executor directly?

ahmednfwela commented 1 year ago

I think it would also be a good idea to add options to override other commands, e.g.: xcrun

cybrox commented 1 year ago

Thanks for the input @ahmednfwela! I "feared" as soon as we add custom flutter/dart paths, there will be need for changing other binary paths as well.

@lijy91 What do you think about supporting FLUTTER_ROOT and DART_ROOT from the distribute_options.yaml, which should suffice for >90% of users and keeping this solution for advanced use-cases?

This would provide an easy solution for most users but we could still have a small hint in the docs for advanced customization for those who really need it.

lijy91 commented 1 year ago

I'm working on a refactor to support this feature, you can follow it on the develop branch.