Skip to content

Commit 88e3f37

Browse files
authored
Add checks to allow certain build commands according to "build_on" platform. (#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
1 parent cdf4b62 commit 88e3f37

File tree

1 file changed

+17
-0
lines changed
  • sdk/python/packages/flet/src/flet/cli/commands

1 file changed

+17
-0
lines changed

sdk/python/packages/flet/src/flet/cli/commands/build.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,42 +36,49 @@ def __init__(self, parser: argparse.ArgumentParser) -> None:
3636
"status_text": "Windows app",
3737
"output": "build/windows/x64/runner/Release/*",
3838
"dist": "windows",
39+
"can_be_run_on": ["Windows"],
3940
},
4041
"macos": {
4142
"build_command": "macos",
4243
"status_text": "macOS bundle",
4344
"output": "build/macos/Build/Products/Release/{project_name}.app",
4445
"dist": "macos",
46+
"can_be_run_on": ["Darwin"],
4547
},
4648
"linux": {
4749
"build_command": "linux",
4850
"status_text": "app for Linux",
4951
"output": "build/linux/{arch}/release/bundle/*",
5052
"dist": "linux",
53+
"can_be_run_on": ["Linux"],
5154
},
5255
"web": {
5356
"build_command": "web",
5457
"status_text": "web app",
5558
"output": "build/web/*",
5659
"dist": "web",
60+
"can_be_run_on": ["Darwin", "Windows", "Linux"],
5761
},
5862
"apk": {
5963
"build_command": "apk",
6064
"status_text": ".apk for Android",
6165
"output": "build/app/outputs/flutter-apk/*",
6266
"dist": "apk",
67+
"can_be_run_on": ["Darwin", "Windows", "Linux"],
6368
},
6469
"aab": {
6570
"build_command": "appbundle",
6671
"status_text": ".aab bundle for Android",
6772
"output": "build/app/outputs/bundle/release/*",
6873
"dist": "aab",
74+
"can_be_run_on": ["Darwin", "Windows", "Linux"],
6975
},
7076
"ipa": {
7177
"build_command": "ipa",
7278
"status_text": ".ipa bundle for iOS",
7379
"output": "build/ios/archive/*",
7480
"dist": "ipa",
81+
"can_be_run_on": ["Darwin"],
7582
},
7683
}
7784

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

269276
target_platform = options.target_platform.lower()
277+
# platform check
278+
current_platform = platform.system()
279+
if current_platform not in self.platforms[target_platform]["can_be_run_on"]:
280+
# make the platform name more user friendly
281+
if current_platform == "Darwin":
282+
current_platform = "macOS"
283+
284+
print(f"Can't build {target_platform} on {current_platform}")
285+
sys.exit(1)
286+
270287
self.verbose = options.verbose
271288

272289
python_app_path = Path(options.python_app_path).resolve()

0 commit comments

Comments
 (0)