diff --git a/specs/1.0.2/Makefile b/specs/1.0.2/Makefile deleted file mode 100644 index 35af6112ca..0000000000 --- a/specs/1.0.2/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -.PHONY: all - -all: webgl.idl - -webgl.idl: index.html Makefile - echo "// AUTOGENERATED FILE -- DO NOT EDIT -- SEE Makefile" > webgl.idl - echo "//" >> webgl.idl - echo "// WebGL IDL definitions scraped from the Khronos specification:" >> webgl.idl - echo "// https://www.khronos.org/registry/webgl/specs/latest/" >> webgl.idl - echo "//" >> webgl.idl - echo "// This IDL depends on the typed array specification defined at:" >> webgl.idl - echo "// https://www.khronos.org/registry/typedarray/specs/latest/typedarrays.idl" >> webgl.idl - echo "" >> webgl.idl - PYTHONPATH=../../resources/html5lib/src python extract-idl.py index.html >> webgl.idl diff --git a/specs/1.0.2/extract-idl.py b/specs/1.0.2/extract-idl.py deleted file mode 100755 index cc3cd5b90a..0000000000 --- a/specs/1.0.2/extract-idl.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/python - -import sys -import html5lib - -htmlfilename = sys.argv[1] -htmlfile = open(htmlfilename) -try: - doc = html5lib.parse(htmlfile, treebuilder="dom") -finally: - htmlfile.close() - -def elementHasClass(el, classArg): - """ - Return true if and only if classArg is one of the classes of el - """ - classes = [ c for c in el.getAttribute("class").split(" ") if c is not "" ] - return classArg in classes - -def elementTextContent(el): - """ - Implementation of DOM Core's .textContent - """ - textContent = "" - for child in el.childNodes: - if child.nodeType == 3: # Node.TEXT_NODE - textContent += child.data - elif child.nodeType == 1: # Node.ELEMENT_NODE - textContent += elementTextContent(child) - else: - # Other nodes are ignored - pass - return textContent - -preList = doc.getElementsByTagName("pre") -idlList = [elementTextContent(p) for p in preList if elementHasClass(p, "idl") ] -print "\n\n".join(idlList) diff --git a/specs/1.0.3/Makefile b/specs/1.0.3/Makefile deleted file mode 100644 index 35af6112ca..0000000000 --- a/specs/1.0.3/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -.PHONY: all - -all: webgl.idl - -webgl.idl: index.html Makefile - echo "// AUTOGENERATED FILE -- DO NOT EDIT -- SEE Makefile" > webgl.idl - echo "//" >> webgl.idl - echo "// WebGL IDL definitions scraped from the Khronos specification:" >> webgl.idl - echo "// https://www.khronos.org/registry/webgl/specs/latest/" >> webgl.idl - echo "//" >> webgl.idl - echo "// This IDL depends on the typed array specification defined at:" >> webgl.idl - echo "// https://www.khronos.org/registry/typedarray/specs/latest/typedarrays.idl" >> webgl.idl - echo "" >> webgl.idl - PYTHONPATH=../../resources/html5lib/src python extract-idl.py index.html >> webgl.idl diff --git a/specs/1.0.3/extract-idl.py b/specs/1.0.3/extract-idl.py deleted file mode 100755 index cc3cd5b90a..0000000000 --- a/specs/1.0.3/extract-idl.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/python - -import sys -import html5lib - -htmlfilename = sys.argv[1] -htmlfile = open(htmlfilename) -try: - doc = html5lib.parse(htmlfile, treebuilder="dom") -finally: - htmlfile.close() - -def elementHasClass(el, classArg): - """ - Return true if and only if classArg is one of the classes of el - """ - classes = [ c for c in el.getAttribute("class").split(" ") if c is not "" ] - return classArg in classes - -def elementTextContent(el): - """ - Implementation of DOM Core's .textContent - """ - textContent = "" - for child in el.childNodes: - if child.nodeType == 3: # Node.TEXT_NODE - textContent += child.data - elif child.nodeType == 1: # Node.ELEMENT_NODE - textContent += elementTextContent(child) - else: - # Other nodes are ignored - pass - return textContent - -preList = doc.getElementsByTagName("pre") -idlList = [elementTextContent(p) for p in preList if elementHasClass(p, "idl") ] -print "\n\n".join(idlList) diff --git a/specs/2.0.0/Makefile b/specs/2.0.0/Makefile deleted file mode 100644 index c5be1d14a2..0000000000 --- a/specs/2.0.0/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -.PHONY: all - -all: webgl2.idl - -webgl2.idl: index.html Makefile - echo "// AUTOGENERATED FILE -- DO NOT EDIT -- SEE Makefile" > webgl2.idl - echo "//" >> webgl2.idl - echo "// WebGL IDL definitions scraped from the Khronos specification:" >> webgl2.idl - echo "// https://www.khronos.org/registry/webgl/specs/latest/" >> webgl2.idl - echo "//" >> webgl2.idl - echo "// This IDL depends on the typed array specification defined at:" >> webgl2.idl - echo "// https://www.khronos.org/registry/typedarray/specs/latest/typedarrays.idl" >> webgl2.idl - echo "" >> webgl2.idl - PYTHONPATH=../../../resources/html5lib/src python extract-idl.py index.html >> webgl2.idl diff --git a/specs/2.0.0/extract-idl.py b/specs/2.0.0/extract-idl.py deleted file mode 100755 index cc3cd5b90a..0000000000 --- a/specs/2.0.0/extract-idl.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/python - -import sys -import html5lib - -htmlfilename = sys.argv[1] -htmlfile = open(htmlfilename) -try: - doc = html5lib.parse(htmlfile, treebuilder="dom") -finally: - htmlfile.close() - -def elementHasClass(el, classArg): - """ - Return true if and only if classArg is one of the classes of el - """ - classes = [ c for c in el.getAttribute("class").split(" ") if c is not "" ] - return classArg in classes - -def elementTextContent(el): - """ - Implementation of DOM Core's .textContent - """ - textContent = "" - for child in el.childNodes: - if child.nodeType == 3: # Node.TEXT_NODE - textContent += child.data - elif child.nodeType == 1: # Node.ELEMENT_NODE - textContent += elementTextContent(child) - else: - # Other nodes are ignored - pass - return textContent - -preList = doc.getElementsByTagName("pre") -idlList = [elementTextContent(p) for p in preList if elementHasClass(p, "idl") ] -print "\n\n".join(idlList) diff --git a/specs/build-idl.py b/specs/build-idl.py new file mode 100644 index 0000000000..f063f7827a --- /dev/null +++ b/specs/build-idl.py @@ -0,0 +1,45 @@ +#! /usr/bin/env python3 +# Usage: +# build-idl.py latest/2.0/webgl2.idl +import os +import pathlib +import subprocess +import sys + +OUT_IDL = pathlib.Path(sys.argv[1]) +INDEX_HTML = OUT_IDL.parent / 'index.html' +assert INDEX_HTML.exists(), INDEX_HTML + +BASE_DIR = pathlib.Path(__file__).parent.parent +assert (BASE_DIR / '.git').exists(), BASE_DIR / '.git' + +# - +# Extract the idl from index.html. + +PYTHONPATH_LIBS = [ + BASE_DIR / 'resources/html5lib-1.1/src/html5lib', + BASE_DIR / 'resources/webencodings-0.5.1/src/webencodings', +] +for lib in PYTHONPATH_LIBS: + assert lib.exists(), lib +PYTHONPATH = os.pathsep.join([str(lib.parent) for lib in PYTHONPATH_LIBS]) + +ENV = os.environ +ENV['PYTHONPATH'] = PYTHONPATH + +args = [sys.executable, BASE_DIR / 'specs/extract-idl.py', INDEX_HTML] +print(f'Running {args}...') +p = subprocess.run(args, env=ENV, stdout=subprocess.PIPE, text=True) +p.check_returncode() +idl = p.stdout +assert '\r' not in idl + +idl_file_data = '''\ +// AUTOGENERATED FILE -- DO NOT EDIT -- SEE Makefile +// +// WebGL IDL definitions scraped from the Khronos specification: +// https://www.khronos.org/registry/webgl/specs/latest/ +''' + idl + +print(f'Writing "{OUT_IDL}"...') +OUT_IDL.write_bytes(idl_file_data.encode()) diff --git a/specs/latest/1.0/extract-idl.py b/specs/extract-idl.py old mode 100755 new mode 100644 similarity index 100% rename from specs/latest/1.0/extract-idl.py rename to specs/extract-idl.py diff --git a/specs/latest/1.0/build.py b/specs/latest/1.0/build.py new file mode 100644 index 0000000000..0fee58009b --- /dev/null +++ b/specs/latest/1.0/build.py @@ -0,0 +1,11 @@ +#! /usr/bin/env python3 +# Usage: build.py (no args) +import pathlib +import subprocess +import sys + +THIS_DIR = pathlib.Path(__file__).parent +BASE_DIR = THIS_DIR.parent.parent.parent +assert (BASE_DIR / '.git').exists(), BASE_DIR / '.git' + +subprocess.run([sys.executable, BASE_DIR / 'specs/build-idl.py', THIS_DIR / 'webgl.idl'], check=True) diff --git a/specs/latest/2.0/build.py b/specs/latest/2.0/build.py index 5b1622688e..0f57264584 100644 --- a/specs/latest/2.0/build.py +++ b/specs/latest/2.0/build.py @@ -1,41 +1,11 @@ #! /usr/bin/env python3 -import os +# Usage: build.py (no args) import pathlib import subprocess import sys -DIR = pathlib.Path(__file__).parent +THIS_DIR = pathlib.Path(__file__).parent +BASE_DIR = THIS_DIR.parent.parent.parent +assert (BASE_DIR / '.git').exists(), BASE_DIR / '.git' -# - -# Extract the idl from index.html. - -RESOURCES = DIR.parent.parent.parent / 'resources' -assert RESOURCES.exists(), RESOURCES -PYTHONPATH_LIBS = [ - RESOURCES / 'html5lib-1.1/src/html5lib', - RESOURCES / 'webencodings-0.5.1/src/webencodings', -] -for lib in PYTHONPATH_LIBS: - assert lib.exists(), lib -PYTHONPATH = os.pathsep.join([str(lib.parent) for lib in PYTHONPATH_LIBS]) - -ENV = os.environ -ENV['PYTHONPATH'] = PYTHONPATH - -args = [sys.executable, 'extract-idl.py', 'index.html'] -print(f'Running {args}...') -p = subprocess.run([sys.executable, 'extract-idl.py', 'index.html'], cwd=DIR, env=ENV, stdout=subprocess.PIPE, text=True) -p.check_returncode() -idl = p.stdout -assert '\r' not in idl - -idl_file_data = '''\ -// AUTOGENERATED FILE -- DO NOT EDIT -- SEE Makefile -// -// WebGL IDL definitions scraped from the Khronos specification: -// https://www.khronos.org/registry/webgl/specs/latest/ -''' + idl - -out_file = DIR / 'webgl2.idl' -print(f'Writing "{out_file}"...') -out_file.write_bytes(idl_file_data.encode()) +subprocess.run([sys.executable, BASE_DIR / 'specs/build-idl.py', THIS_DIR / 'webgl2.idl'], check=True) diff --git a/specs/latest/2.0/extract-idl.py b/specs/latest/2.0/extract-idl.py deleted file mode 100755 index 6a22b22485..0000000000 --- a/specs/latest/2.0/extract-idl.py +++ /dev/null @@ -1,64 +0,0 @@ -#! /usr/bin/env python3 - -from datetime import date -from string import Template -import sys -import html5lib - -LICENSE = """ -// Copyright (c) $YEAR The Khronos Group Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and/or associated documentation files (the -// "Materials"), to deal in the Materials without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Materials, and to -// permit persons to whom the Materials are furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Materials. -// -// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - -""" - -htmlfilename = sys.argv[1] -htmlfile = open(htmlfilename) -try: - doc = html5lib.parse(htmlfile, treebuilder="dom") -finally: - htmlfile.close() - -def elementHasClass(el, classArg): - """ - Return true if and only if classArg is one of the classes of el - """ - classes = [ c for c in el.getAttribute("class").split(" ") if c != "" ] - return classArg in classes - -def elementTextContent(el): - """ - Implementation of DOM Core's .textContent - """ - textContent = "" - for child in el.childNodes: - if child.nodeType == 3: # Node.TEXT_NODE - textContent += child.data - elif child.nodeType == 1: # Node.ELEMENT_NODE - textContent += elementTextContent(child) - else: - # Other nodes are ignored - pass - return textContent - -preList = doc.getElementsByTagName("pre") -idlList = [elementTextContent(p) for p in preList if elementHasClass(p, "idl") ] -licenseTemplate = Template(LICENSE) -print(licenseTemplate.substitute(YEAR=date.today().year) + "\n\n".join(idlList))