From b6252e8d3abab34522ad14327fea71a85307d335 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 22 Dec 2022 17:45:13 +0100 Subject: [PATCH] Ported: [Web] Add the "serve" and "run" scons targets. You can now run the test HTTP server by calling: scons p=javascript serve If you also wish to run the browser, call instead: scons p=javascript run The default listen port is 8060, but can be overriden via the env variable GODOT_WEB_TEST_PORT which must be a valid integer. - Faless https://github.com/godotengine/godot/commit/eda014197fe37accf843bdc11c838c0997f4acf7 --- platform/javascript/SCsub | 15 +++++++++++++++ platform/javascript/serve.py | 19 ++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub index 31c6ff967..aaf414bd9 100644 --- a/platform/javascript/SCsub +++ b/platform/javascript/SCsub @@ -2,6 +2,21 @@ Import("env") +# The HTTP server "targets". Run with "scons p=javascript serve", or "scons p=javascript run" +if "serve" in COMMAND_LINE_TARGETS or "run" in COMMAND_LINE_TARGETS: + from serve import serve + import os + + port = os.environ.get("PANDEMONIUM_WEB_TEST_PORT", 8060) + try: + port = int(port) + except Exception: + print("PANDEMONIUM_WEB_TEST_PORT must be a valid integer") + sys.exit(255) + serve(env.Dir("#bin/.javascript_zip").abspath, port, "run" in COMMAND_LINE_TARGETS) + sys.exit(0) + + javascript_files = [ "audio_driver_javascript.cpp", "http_client_javascript.cpp", diff --git a/platform/javascript/serve.py b/platform/javascript/serve.py index 4e7b0cf76..21325aaff 100644 --- a/platform/javascript/serve.py +++ b/platform/javascript/serve.py @@ -23,6 +23,15 @@ def shell_open(url): opener = "open" if sys.platform == "darwin" else "xdg-open" 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() @@ -41,12 +50,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) \ No newline at end of file + serve(args.root, args.port, args.browser) \ No newline at end of file