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
eda014197f
This commit is contained in:
Relintai 2022-12-22 17:45:13 +01:00
parent 91e598aa7b
commit b6252e8d3a
2 changed files with 25 additions and 9 deletions

View File

@ -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",

View File

@ -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)
serve(args.root, args.port, args.browser)