Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 102 deletions.
14 changes: 10 additions & 4 deletions build/WebIDL.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# from http://mxr.mozilla.org/mozilla-central/source/dom/bindings/parser/WebIDL.py
## JavascriptSubtitlesOctopus
## Patched to:
## - add integer pointers (IntPtr)
## From https://github.com/emscripten-core/emscripten/blob/f36f9fcaf83db93e6a6d0f0cdc47ab6379ade139/third_party/WebIDL.py

# from https://hg.mozilla.org/mozilla-central/file/tip/dom/bindings/parser/WebIDL.py
# rev 501baeb3a034

# This Source Code Form is subject to the terms of the Mozilla Public
Expand Down Expand Up @@ -4923,11 +4928,12 @@ def p_error(self, p):

def __init__(self, outputdir='', lexer=None):
Tokenizer.__init__(self, outputdir, lexer)
self.parser = yacc.yacc(module=self,
self.parser = yacc.yacc(debug=0,
module=self,
outputdir=outputdir,
tabmodule='webidlyacc',
errorlog=yacc.NullLogger(),
picklefile='WebIDLGrammar.pkl')
write_tables=0,
errorlog=yacc.NullLogger())
self._globalScope = IDLScope(BuiltinLocation("<Global Scope>"), None, None)
self._installBuiltins(self._globalScope)
self._productions = []
Expand Down
41 changes: 20 additions & 21 deletions build/tempfiles.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
## JavascriptSubtitlesOctopus
## From https://github.com/emscripten-core/emscripten/blob/c834ef7d69ccb4100239eeba0b0f6573fed063bc/tools/tempfiles.py

# Copyright 2013 The Emscripten Authors. All rights reserved.
# Emscripten is available under two separate licenses, the MIT license and the
# University of Illinois/NCSA Open Source License. Both these licenses can be
# found in the LICENSE file.

from __future__ import print_function
import os
import shutil
import tempfile
Expand All @@ -28,13 +30,14 @@ def try_delete(pathname):
if not os.path.exists(pathname):
return

write_bits = stat.S_IWRITE | stat.S_IWGRP | stat.S_IWOTH
# Ensure all files are readable and writable by the current user.
permission_bits = stat.S_IWRITE | stat.S_IREAD

def is_writable(path):
return (os.stat(path).st_mode & write_bits) == write_bits
return (os.stat(path).st_mode & permission_bits) != permission_bits

def make_writable(path):
os.chmod(path, os.stat(path).st_mode | write_bits)
os.chmod(path, os.stat(path).st_mode | permission_bits)

# Some tests make files and subdirectories read-only, so rmtree/unlink will not delete
# them. Force-make everything writable in the subdirectory to make it
Expand All @@ -54,9 +57,9 @@ def make_writable(path):
pass


class TempFiles(object):
def __init__(self, tmp, save_debug_files=False):
self.tmp = tmp
class TempFiles:
def __init__(self, tmpdir, save_debug_files):
self.tmpdir = tmpdir
self.save_debug_files = save_debug_files
self.to_clean = []

Expand All @@ -67,17 +70,19 @@ def note(self, filename):

def get(self, suffix):
"""Returns a named temp file with the given prefix."""
named_file = tempfile.NamedTemporaryFile(dir=self.tmp, suffix=suffix, delete=False)
named_file = tempfile.NamedTemporaryFile(dir=self.tmpdir, suffix=suffix, delete=False)
self.note(named_file.name)
return named_file

def get_file(self, suffix):
"""Returns an object representing a RAII-like access to a temp file, that has convenient pythonesque
semantics for being used via a construct 'with TempFiles.get_file(..) as filename:'. The file will be
deleted immediately once the 'with' block is exited."""
class TempFileObject(object):
"""Returns an object representing a RAII-like access to a temp file
that has convenient pythonesque semantics for being used via a construct
'with TempFiles.get_file(..) as filename:'.
The file will be deleted immediately once the 'with' block is exited.
"""
class TempFileObject:
def __enter__(self_):
self_.file = tempfile.NamedTemporaryFile(dir=self.tmp, suffix=suffix, delete=False)
self_.file = tempfile.NamedTemporaryFile(dir=self.tmpdir, suffix=suffix, delete=False)
self_.file.close() # NamedTemporaryFile passes out open file handles, but callers prefer filenames (and open their own handles manually if needed)
return self_.file.name

Expand All @@ -88,20 +93,14 @@ def __exit__(self_, type, value, traceback):

def get_dir(self):
"""Returns a named temp directory with the given prefix."""
directory = tempfile.mkdtemp(dir=self.tmp)
directory = tempfile.mkdtemp(dir=self.tmpdir)
self.note(directory)
return directory

def clean(self):
if self.save_debug_files:
print('not cleaning up temp files since in debug-save mode, see them in %s' % (self.tmp,), file=sys.stderr)
print(f'not cleaning up temp files since in debug-save mode, see them in {self.tmpdir}', file=sys.stderr)
return
for filename in self.to_clean:
try_delete(filename)
self.to_clean = []

def run_and_clean(self, func):
try:
return func()
finally:
self.clean()
Loading

0 comments on commit ed8d9a5

Please sign in to comment.