Skip to content

Commit

Permalink
Add checks to allow certain build commands according to "build_on" pl…
Browse files Browse the repository at this point in the history
…atform. (flet-dev#2343)

* Add checks to allow certain build commands

Add checks to allow certain build commands according to build on platform according to matrix given at https://flet.dev/docs/guides/python/packaging-app-for-distribution/#build-platform-matrix

* Make platform name more user friendly in platform checks.

* More oop approach

* Apply black formatting

* Fixed bug in checks

* Fix a typo
  • Loading branch information
taaaf11 authored and zrr1999 committed Jul 17, 2024
1 parent 99c264c commit 946f964
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions sdk/python/packages/flet/src/flet/cli/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,49 @@ def __init__(self, parser: argparse.ArgumentParser) -> None:
"status_text": "Windows app",
"output": "build/windows/x64/runner/Release/*",
"dist": "windows",
"can_be_run_on": ["Windows"],
},
"macos": {
"build_command": "macos",
"status_text": "macOS bundle",
"output": "build/macos/Build/Products/Release/{project_name}.app",
"dist": "macos",
"can_be_run_on": ["Darwin"],
},
"linux": {
"build_command": "linux",
"status_text": "app for Linux",
"output": "build/linux/{arch}/release/bundle/*",
"dist": "linux",
"can_be_run_on": ["Linux"],
},
"web": {
"build_command": "web",
"status_text": "web app",
"output": "build/web/*",
"dist": "web",
"can_be_run_on": ["Darwin", "Windows", "Linux"],
},
"apk": {
"build_command": "apk",
"status_text": ".apk for Android",
"output": "build/app/outputs/flutter-apk/*",
"dist": "apk",
"can_be_run_on": ["Darwin", "Windows", "Linux"],
},
"aab": {
"build_command": "appbundle",
"status_text": ".aab bundle for Android",
"output": "build/app/outputs/bundle/release/*",
"dist": "aab",
"can_be_run_on": ["Darwin", "Windows", "Linux"],
},
"ipa": {
"build_command": "ipa",
"status_text": ".ipa bundle for iOS",
"output": "build/ios/archive/*",
"dist": "ipa",
"can_be_run_on": ["Darwin"],
},
}

Expand Down Expand Up @@ -267,6 +274,16 @@ def handle(self, options: argparse.Namespace) -> None:
sys.exit(1)

target_platform = options.target_platform.lower()
# platform check
current_platform = platform.system()
if current_platform not in self.platforms[target_platform]["can_be_run_on"]:
# make the platform name more user friendly
if current_platform == "Darwin":
current_platform = "macOS"

print(f"Can't build {target_platform} on {current_platform}")
sys.exit(1)

self.verbose = options.verbose

python_app_path = Path(options.python_app_path).resolve()
Expand Down

0 comments on commit 946f964

Please sign in to comment.