diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-10-12 22:56:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-12 22:56:10 +0200 |
commit | 42ebc4ef65093ac7bb4e1785054e4632d3ddc9bc (patch) | |
tree | e0409a62635b362d08b29c7036d2b6fe4e4d8ccb /platform | |
parent | 261b9da77f0e2fa0a850c4a1ac55f5a6b609e490 (diff) | |
parent | a06602363c9b001a1877afa771b3282f2230595c (diff) |
Merge pull request #67325 from Faless/web/4.x_scons_serve
[Web] Add the "serve" and "run" scons targets.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/web/SCsub | 14 | ||||
-rwxr-xr-x | platform/web/serve.py | 21 |
2 files changed, 26 insertions, 9 deletions
diff --git a/platform/web/SCsub b/platform/web/SCsub index 013b734be2..cb00fa9f5b 100644 --- a/platform/web/SCsub +++ b/platform/web/SCsub @@ -2,6 +2,20 @@ Import("env") +# The HTTP server "targets". Run with "scons p=web serve", or "scons p=web run" +if "serve" in COMMAND_LINE_TARGETS or "run" in COMMAND_LINE_TARGETS: + from serve import serve + import os + + port = os.environ.get("GODOT_WEB_TEST_PORT", 8060) + try: + port = int(port) + except Exception: + print("GODOT_WEB_TEST_PORT must be a valid integer") + sys.exit(255) + serve(env.Dir("#bin/.web_zip").abspath, port, "run" in COMMAND_LINE_TARGETS) + sys.exit(0) + web_files = [ "audio_driver_web.cpp", "display_server_web.cpp", diff --git a/platform/web/serve.py b/platform/web/serve.py index 14e87e9ea1..6a3efcc463 100755 --- a/platform/web/serve.py +++ b/platform/web/serve.py @@ -24,6 +24,17 @@ def shell_open(url): subprocess.call([opener, url]) +def serve(root, port, run_browser): + os.chdir(root) + + if run_browser: + # Open the served page in the user's default browser. + print("Opening the served URL in the default browser (use `--no-browser` or `-n` to disable this).") + shell_open(f"http://127.0.0.1:{port}") + + test(CORSRequestHandler, HTTPServer, port=port) + + if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-p", "--port", help="port to listen on", default=8060, type=int) @@ -41,12 +52,4 @@ if __name__ == "__main__": # so that the script can be run from any location. os.chdir(Path(__file__).resolve().parent) - if args.root: - os.chdir(args.root) - - if args.browser: - # Open the served page in the user's default browser. - print("Opening the served URL in the default browser (use `--no-browser` or `-n` to disable this).") - shell_open(f"http://127.0.0.1:{args.port}") - - test(CORSRequestHandler, HTTPServer, port=args.port) + serve(args.root, args.port, args.browser) |