Skip to content

Commit

Permalink
[infra] Port serve.py from Python2 to 3
Browse files Browse the repository at this point in the history
These scripts are useful when testing WebAssembly locally
because the mimetype impacts how the binaries are loaded.

The porting was achieved by doing the following:
python -m lib2to3 -w -n serve.py


Change-Id: I09673fa881339a9b157c5fc993e190766efcd85e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/443884
Reviewed-by: Erik Rose <[email protected]>
  • Loading branch information
kjlubick committed Aug 31, 2021
1 parent 9c975c5 commit 2910452
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 42 deletions.
2 changes: 1 addition & 1 deletion experimental/skottiekit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ clean_npm:

serve:
echo "Go check out http://localhost:8001/"
cd examples && python ../serve.py
cd examples && python3 ../serve.py
15 changes: 8 additions & 7 deletions experimental/skottiekit/serve.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# Copyright 2020 Google LLC

#!/usr/bin/env python3
# Copyright 2018 Google LLC
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import SimpleHTTPServer
import SocketServer
import http.server
import socketserver

PORT = 8001
PORT = 8000

class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
class Handler(http.server.SimpleHTTPRequestHandler):
pass

Handler.extensions_map['.js'] = 'application/javascript'
# Without the correct MIME type, async compilation doesn't work
Handler.extensions_map['.wasm'] = 'application/wasm'

httpd = SocketServer.TCPServer(("", PORT), Handler)
httpd = socketserver.TCPServer(("", PORT), Handler)

httpd.serve_forever()
2 changes: 1 addition & 1 deletion experimental/tskit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ release:

serve:
echo "Go check out http://localhost:8000/npm_build/example.html"
python2 serve.py
python3 serve.py

lint:
npx eslint . --ext .ts
Expand Down
11 changes: 6 additions & 5 deletions experimental/tskit/serve.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#!/usr/bin/env python3
# Copyright 2018 Google LLC

#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import SimpleHTTPServer
import SocketServer
import http.server
import socketserver

PORT = 8000

class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
class Handler(http.server.SimpleHTTPRequestHandler):
pass

Handler.extensions_map['.js'] = 'application/javascript'
# Without the correct MIME type, async compilation doesn't work
Handler.extensions_map['.wasm'] = 'application/wasm'

httpd = SocketServer.TCPServer(("", PORT), Handler)
httpd = socketserver.TCPServer(("", PORT), Handler)

httpd.serve_forever()
11 changes: 6 additions & 5 deletions experimental/wasm-skp-debugger/serve.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#!/usr/bin/env python3
# Copyright 2018 Google LLC

#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import SimpleHTTPServer
import SocketServer
import http.server
import socketserver

PORT = 8000

class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
class Handler(http.server.SimpleHTTPRequestHandler):
pass

Handler.extensions_map['.js'] = 'application/javascript'
# Without the correct MIME type, async compilation doesn't work
Handler.extensions_map['.wasm'] = 'application/wasm'

httpd = SocketServer.TCPServer(("", PORT), Handler)
httpd = socketserver.TCPServer(("", PORT), Handler)

httpd.serve_forever()
2 changes: 1 addition & 1 deletion modules/canvaskit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ local-example:
mkdir -p node_modules
ln -s ../npm_build node_modules/canvaskit
echo "Go check out http://localhost:8000/npm_build/example.html"
python2 serve.py
python3 serve.py

test-continuous:
echo "Assuming npm ci has been run by user"
Expand Down
11 changes: 6 additions & 5 deletions modules/canvaskit/serve.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#!/usr/bin/env python3
# Copyright 2018 Google LLC

#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import SimpleHTTPServer
import SocketServer
import http.server
import socketserver

PORT = 8000

class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
class Handler(http.server.SimpleHTTPRequestHandler):
pass

Handler.extensions_map['.js'] = 'application/javascript'
# Without the correct MIME type, async compilation doesn't work
Handler.extensions_map['.wasm'] = 'application/wasm'

httpd = SocketServer.TCPServer(("", PORT), Handler)
httpd = socketserver.TCPServer(("", PORT), Handler)

httpd.serve_forever()
2 changes: 1 addition & 1 deletion modules/canvaskit/wasm_tools/SIMD/build_simd_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ grep -f wasm_simd_types.txt output/simd_test.wat
# Serve the compiled WASM so output can be manually inspected for correctness.
echo "Go check out http://localhost:8000/output/simd_test.html in Chrome Canary 86.0.4186.0 \
or later and enable the chrome://flags#enable-webassembly-simd flag!"
python ../../serve.py
python3 ../../serve.py
8 changes: 4 additions & 4 deletions modules/pathkit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ npm-debug:
example:
npm install pathkit-asmjs pathkit-wasm
echo "Go check out localhost:8000/npm-wasm/example.html"
python serve.py
python3 serve.py

local-example:
rm -rf node_modules/pathkit-wasm
Expand All @@ -119,7 +119,7 @@ local-example:
ln -s -T ../npm-asmjs node_modules/pathkit-asmjs
echo "Go check out http://localhost:8000/npm-wasm/example.html"
echo "or http://localhost:8000/npm-asmjs/example.html"
python serve.py
python3 serve.py

local-example-test:
rm -rf node_modules/pathkit-wasm
Expand All @@ -130,7 +130,7 @@ local-example-test:
ln -s -T ../../npm-asmjs/bin/test node_modules/pathkit-asmjs/bin
echo "Go check out localhost:8000/npm-wasm/example.html"
echo "or http://localhost:8000/npm-asmjs/example.html"
python serve.py
python3 serve.py

local-example-debug:
rm -rf node_modules/pathkit-wasm
Expand All @@ -141,5 +141,5 @@ local-example-debug:
ln -s -T ../../npm-asmjs/bin/debug node_modules/pathkit-asmjs/bin
echo "Go check out localhost:8000/npm-wasm/example.html"
echo "or http://localhost:8000/npm-asmjs/example.html"
python serve.py
python3 serve.py

2 changes: 1 addition & 1 deletion modules/pathkit/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ ${BUILD_DIR}/libpathkit.a

if [[ $@ == *serve* ]]; then
pushd $BUILD_DIR
python serve.py
python3 serve.py
fi

11 changes: 6 additions & 5 deletions modules/pathkit/serve.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#!/usr/bin/env python3
# Copyright 2018 Google LLC

#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import SimpleHTTPServer
import SocketServer
import http.server
import socketserver

PORT = 8000

class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
class Handler(http.server.SimpleHTTPRequestHandler):
pass

Handler.extensions_map['.js'] = 'application/javascript'
# Without the correct MIME type, async compilation doesn't work
Handler.extensions_map['.wasm'] = 'application/wasm'

httpd = SocketServer.TCPServer(("", PORT), Handler)
httpd = socketserver.TCPServer(("", PORT), Handler)

httpd.serve_forever()
13 changes: 7 additions & 6 deletions specs/web-img-decode/proposed/serve.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#!/usr/bin/env python3
# Copyright 2018 Google LLC

#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import SimpleHTTPServer
import SocketServer
import http.server
import socketserver

PORT = 8005
PORT = 8000

class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
class Handler(http.server.SimpleHTTPRequestHandler):
pass

Handler.extensions_map['.js'] = 'application/javascript'
# Without the correct MIME type, async compilation doesn't work
Handler.extensions_map['.wasm'] = 'application/wasm'

httpd = SocketServer.TCPServer(("", PORT), Handler)
httpd = socketserver.TCPServer(("", PORT), Handler)

httpd.serve_forever()

0 comments on commit 2910452

Please sign in to comment.