diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /xpcom/reflect/xptcall/md/win32/preprocess.py | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xpcom/reflect/xptcall/md/win32/preprocess.py')
-rw-r--r-- | xpcom/reflect/xptcall/md/win32/preprocess.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/xpcom/reflect/xptcall/md/win32/preprocess.py b/xpcom/reflect/xptcall/md/win32/preprocess.py new file mode 100644 index 0000000000..a2f3232c34 --- /dev/null +++ b/xpcom/reflect/xptcall/md/win32/preprocess.py @@ -0,0 +1,44 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import errno +import os +import shlex +import subprocess +import sys +import tempfile + +import buildconfig +from mozfile import which + + +def preprocess(out, asm_file): + cxx = shlex.split(buildconfig.substs["CXX"]) + if not os.path.exists(cxx[0]): + tool = cxx[0] + cxx[0] = which(tool) + if not cxx[0]: + raise OSError(errno.ENOENT, "Could not find {} on PATH.".format(tool)) + + cppflags = buildconfig.substs["OS_CPPFLAGS"] + + # subprocess.Popen(stdout=) only accepts actual file objects, which `out`, + # above, is not. So fake a temporary file to write to. + (outhandle, tmpout) = tempfile.mkstemp(suffix=".cpp") + + # #line directives will confuse armasm64, and /EP is the only way to + # preprocess without emitting #line directives. + command = cxx + ["/EP"] + cppflags + ["/TP", asm_file] + with open(tmpout, "wb") as t: + result = subprocess.Popen(command, stdout=t).wait() + if result != 0: + sys.exit(result) + + with open(tmpout, "rb") as t: + out.write(t.read()) + + os.close(outhandle) + os.remove(tmpout) |