Fix some GENERATED_FILES scripts to use relative paths draft
authorTed Mielczarek <ted@mielczarek.org>
Thu, 14 Sep 2017 06:48:12 -0400
changeset 668591 96949eaa5fbda1d6a4fb53ac922d760f6dcb729f
parent 668590 64d1de14b18da52e92d83eab9d8fb737cd0d5a3c
child 668592 c43dc471da4b9b8a61d46edf7e5a683d3aa4f484
push id81087
push userbmo:ted@mielczarek.org
push dateThu, 21 Sep 2017 20:59:05 +0000
milestone57.0a1
Fix some GENERATED_FILES scripts to use relative paths MozReview-Commit-ID: Kkt2b6PX4aR
dom/bindings/GenerateCSS2PropertiesWebIDL.py
gfx/layers/d3d11/genshaders.py
layout/style/GenerateCSSPropsGenerated.py
--- a/dom/bindings/GenerateCSS2PropertiesWebIDL.py
+++ b/dom/bindings/GenerateCSS2PropertiesWebIDL.py
@@ -3,27 +3,29 @@
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import sys
 import string
 import argparse
 import subprocess
 import buildconfig
 from mozbuild import shellutil
+import mozpack.path as mozpath
+import os
 
 # Generates a line of WebIDL with the given spelling of the property name
 # (whether camelCase, _underscorePrefixed, etc.) and the given array of
 # extended attributes.
 def generateLine(propName, extendedAttrs):
     return "  [%s] attribute DOMString %s;\n" % (", ".join(extendedAttrs),
                                                  propName)
 def generate(output, idlFilename, preprocessorHeader):
     cpp = list(buildconfig.substs['CPP'])
     cpp += shellutil.split(buildconfig.substs['ACDEFINES'])
-    cpp.append(preprocessorHeader)
+    cpp.append(mozpath.relpath(preprocessorHeader, os.getcwd()))
     preprocessed = subprocess.check_output(cpp)
 
     propList = eval(preprocessed)
     props = ""
     for [name, prop, id, flags, pref, proptype] in propList:
         if "CSS_PROPERTY_INTERNAL" in flags:
             continue
         # Unfortunately, even some of the getters here are fallible
--- a/gfx/layers/d3d11/genshaders.py
+++ b/gfx/layers/d3d11/genshaders.py
@@ -1,21 +1,25 @@
 # 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/.
+
+from __future__ import print_function
+
 import argparse
 import codecs
 import locale
 import os
 import re
 import subprocess
 import sys
 import tempfile
 import yaml
 import buildconfig
+import mozpack.path as mozpath
 
 def shell_main():
   parser = argparse.ArgumentParser()
   parser.add_argument('-o', '--output', type=str, required=True,
                       help='Output file')
   parser.add_argument('manifest', type=str,
                       help='Manifest source file')
   args = parser.parse_args()
@@ -68,35 +72,39 @@ def process_manifest(output_fp, manifest
   return deps
 
 def run_fxc(shader_model,
             shader_file,
             shader_name,
             output_fp):
   fxc_location = buildconfig.substs['FXC']
 
+  cwd = os.getcwd()
+  def rel(path):
+    return mozpath.relpath(path, cwd)
+
   argv = [
     fxc_location,
     '-nologo',
     '-T{0}'.format(shader_model),
-    shader_file,
+    mozpath.relpath(shader_file, os.getcwd()),
     '-E{0}'.format(shader_name),
     '-Vn{0}'.format(shader_name),
     '-Vi',
   ]
   if 'Linux' in buildconfig.substs['HOST_OS_ARCH']:
     argv.insert(0, buildconfig.substs['WINE'])
   if shader_model.startswith('vs_'):
     argv += ['-DVERTEX_SHADER']
   elif shader_model.startswith('ps_'):
     argv += ['-DPIXEL_SHADER']
 
   deps = None
   with ScopedTempFilename() as temp_filename:
-    argv += ['-Fh{0}'.format(temp_filename)]
+    argv += ['-Fh{0}'.format(mozpath.basename(temp_filename))]
 
     sys.stdout.write('{0}\n'.format(' '.join(argv)))
     proc_stdout = subprocess.check_output(argv)
     proc_stdout = decode_console_text(sys.stdout, proc_stdout)
     deps = find_dependencies(proc_stdout)
     assert 'fxc2' in fxc_location or len(deps) > 0
 
     with open(temp_filename, 'r') as temp_fp:
@@ -114,17 +122,18 @@ def find_dependencies(fxc_output):
   # instead of pattern matching on that string, we take everything in between
   # brackets. We filter out potentially bogus strings later.
   deps = set()
   for line in fxc_output.split('\n'):
     m = re.search(r"\[([^\]]+)\]", line)
     if m is None:
       continue
     dep_path = m.group(1)
-    dep_path = os.path.normpath(dep_path)
+    dep_path = mozpath.nativepath(dep_path)
+    print(dep_path)
     if os.path.isfile(dep_path):
       deps.add(dep_path)
   return deps
 
 # Python reads the raw bytes from stdout, so we need to try our best to
 # capture that as a valid Python string.
 def decode_console_text(pipe, text):
   try:
@@ -138,17 +147,17 @@ def decode_console_text(pipe, text):
     return text.decode('utf8', 'replace')
 
 # Allocate a temporary file name and delete it when done. We need an extra
 # wrapper for this since TemporaryNamedFile holds the file open.
 class ScopedTempFilename(object):
   def __init__(self):
     self.name = None
   def __enter__(self):
-    with tempfile.NamedTemporaryFile(delete = False) as tmp:
+    with tempfile.NamedTemporaryFile(delete=False, dir=os.getcwd()) as tmp:
       self.name = tmp.name
       return self.name
   def __exit__(self, type, value, traceback):
     if not self.name:
       return
     try:
       os.unlink(self.name)
     except:
--- a/layout/style/GenerateCSSPropsGenerated.py
+++ b/layout/style/GenerateCSSPropsGenerated.py
@@ -1,23 +1,29 @@
 # 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/.
 
+from __future__ import print_function
+
 import sys
 import string
 import argparse
 import subprocess
 import buildconfig
 from mozbuild import shellutil
+import mozpack.path as mozpath
+import os
 
 def get_properties(preprocessorHeader):
     cpp = list(buildconfig.substs['CPP'])
     cpp += shellutil.split(buildconfig.substs['ACDEFINES'])
+    preprocessorHeader = mozpath.relpath(preprocessorHeader, os.getcwd())
     cpp.append(preprocessorHeader)
+    print(' '.join(cpp))
     preprocessed = subprocess.check_output(cpp)
     properties = [{"name":p[0], "prop":p[1], "id":p[2],
                    "flags":p[3], "pref":p[4], "proptype":p[5]}
                   for (i, p) in enumerate(eval(preprocessed))]
 
     # Sort the list so that longhand and logical properties are intermingled
     # first, shorthand properties follow, then aliases appear last.  This matches
     # the order of the nsCSSPropertyID enum.