Bug 585011 - Move cl.py to mozbuild; r=ted
authorGregory Szorc <gps@mozilla.com>
Tue, 22 Oct 2013 14:25:56 -0700
changeset 151713 2131ecb804a85720775d4200dad58b4e0781a82e
parent 151712 d8d851a1ed2a199a5116be587222eed6c89b6d6d
child 151714 ce0759a746fb526db7044b7ab1096e2c08823200
push id25504
push userphilringnalda@gmail.com
push dateWed, 23 Oct 2013 02:50:41 +0000
treeherdermozilla-central@21d97baadc05 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs585011
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 585011 - Move cl.py to mozbuild; r=ted
build/cl.py
config/config.mk
config/makefiles/functions.mk
js/src/build/cl.py
js/src/config/config.mk
js/src/config/makefiles/functions.mk
python/mozbuild/mozbuild/action/cl.py
--- a/config/config.mk
+++ b/config/config.mk
@@ -211,18 +211,18 @@ endif
 endif
 
 OS_CONFIG	:= $(OS_ARCH)$(OS_RELEASE)
 
 MOZ_UNICHARUTIL_LIBS = $(LIBXUL_DIST)/lib/$(LIB_PREFIX)unicharutil_s.$(LIB_SUFFIX)
 MOZ_WIDGET_SUPPORT_LIBS    = $(DIST)/lib/$(LIB_PREFIX)widgetsupport_s.$(LIB_SUFFIX)
 
 ifdef _MSC_VER
-CC_WRAPPER ?= $(PYTHON) -O $(topsrcdir)/build/cl.py
-CXX_WRAPPER ?= $(PYTHON) -O $(topsrcdir)/build/cl.py
+CC_WRAPPER = $(call py_action,cl)
+CXX_WRAPPER = $(call py_action,cl)
 endif # _MSC_VER
 
 CC := $(CC_WRAPPER) $(CC)
 CXX := $(CXX_WRAPPER) $(CXX)
 MKDIR ?= mkdir
 SLEEP ?= sleep
 TOUCH ?= touch
 
@@ -891,20 +891,8 @@ PLY_INCLUDE = -I$(topsrcdir)/other-licen
 
 export CL_INCLUDES_PREFIX
 
 ifdef MOZ_GTK2_CFLAGS
 MOZ_GTK2_CFLAGS := -I$(topsrcdir)/widget/gtk/compat $(MOZ_GTK2_CFLAGS)
 endif
 
 DEFINES += -DNO_NSPR_10_SUPPORT
-
-# Run a named Python build action. The first argument is the name of the build
-# action. The second argument are the arguments to pass to the action (space
-# delimited arguments). e.g.
-#
-#   libs::
-#       $(call py_action,purge_manifests,_build_manifests/purge/foo.manifest)
-ifdef .PYMAKE
-py_action = %mozbuild.action.$(1) main $(2)
-else
-py_action = $(PYTHON) -m mozbuild.action.$(1) $(2)
-endif
--- a/config/makefiles/functions.mk
+++ b/config/makefiles/functions.mk
@@ -15,8 +15,20 @@ ifdef INCLUDED_FUNCTIONS_MK
 $(error Do not include functions.mk twice!)
 endif
 INCLUDED_FUNCTIONS_MK = 1
 
 core_abspath = $(error core_abspath is unsupported, use $$(abspath) instead)
 core_realpath = $(error core_realpath is unsupported)
 
 core_winabspath = $(error core_winabspath is unsupported)
+
+# Run a named Python build action. The first argument is the name of the build
+# action. The second argument are the arguments to pass to the action (space
+# delimited arguments). e.g.
+#
+#   libs::
+#       $(call py_action,purge_manifests,_build_manifests/purge/foo.manifest)
+ifdef .PYMAKE
+py_action = %mozbuild.action.$(1) main $(2)
+else
+py_action = $(PYTHON) -m mozbuild.action.$(1) $(2)
+endif
deleted file mode 100644
--- a/js/src/build/cl.py
+++ /dev/null
@@ -1,114 +0,0 @@
-# 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 ctypes
-import os
-import sys
-
-from mozprocess.processhandler import ProcessHandlerMixin
-from mozbuild.makeutil import Makefile
-
-CL_INCLUDES_PREFIX = os.environ.get("CL_INCLUDES_PREFIX", "Note: including file:")
-
-GetShortPathName = ctypes.windll.kernel32.GetShortPathNameW
-GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW
-
-
-# cl.exe likes to print inconsistent paths in the showIncludes output
-# (some lowercased, some not, with different directions of slashes),
-# and we need the original file case for make/pymake to be happy.
-# As this is slow and needs to be called a lot of times, use a cache
-# to speed things up.
-_normcase_cache = {}
-
-def normcase(path):
-    # Get*PathName want paths with backslashes
-    path = path.replace('/', os.sep)
-    dir = os.path.dirname(path)
-    # name is fortunately always going to have the right case,
-    # so we can use a cache for the directory part only.
-    name = os.path.basename(path)
-    if dir in _normcase_cache:
-        result = _normcase_cache[dir]
-    else:
-        path = ctypes.create_unicode_buffer(dir)
-        length = GetShortPathName(path, None, 0)
-        shortpath = ctypes.create_unicode_buffer(length)
-        GetShortPathName(path, shortpath, length)
-        length = GetLongPathName(shortpath, None, 0)
-        if length > len(path):
-            path = ctypes.create_unicode_buffer(length)
-        GetLongPathName(shortpath, path, length)
-        result = _normcase_cache[dir] = path.value
-    return os.path.join(result, name)
-
-
-def InvokeClWithDependencyGeneration(cmdline):
-    target = ""
-    # Figure out what the target is
-    for arg in cmdline:
-        if arg.startswith("-Fo"):
-            target = arg[3:]
-            break
-
-    if target == None:
-        print >>sys.stderr, "No target set" and sys.exit(1)
-
-    # Assume the source file is the last argument
-    source = cmdline[-1]
-    assert not source.startswith('-')
-
-    # The deps target lives here
-    depstarget = os.path.basename(target) + ".pp"
-
-    cmdline += ['-showIncludes']
-
-    mk = Makefile()
-    rule = mk.create_rule([target])
-    rule.add_dependencies([normcase(source)])
-
-    def on_line(line):
-        # cl -showIncludes prefixes every header with "Note: including file:"
-        # and an indentation corresponding to the depth (which we don't need)
-        if line.startswith(CL_INCLUDES_PREFIX):
-            dep = line[len(CL_INCLUDES_PREFIX):].strip()
-            # We can't handle pathes with spaces properly in mddepend.pl, but
-            # we can assume that anything in a path with spaces is a system
-            # header and throw it away.
-            dep = normcase(dep)
-            if ' ' not in dep:
-                rule.add_dependencies([dep])
-        else:
-            # Make sure we preserve the relevant output from cl. mozprocess
-            # swallows the newline delimiter, so we need to re-add it.
-            sys.stdout.write(line)
-            sys.stdout.write('\n')
-
-    # We need to ignore children because MSVC can fire up a background process
-    # during compilation. This process is cleaned up on its own. If we kill it,
-    # we can run into weird compilation issues.
-    p = ProcessHandlerMixin(cmdline, processOutputLine=[on_line],
-        ignore_children=True)
-    p.run()
-    p.processOutput()
-    ret = p.wait()
-
-    if ret != 0 or target == "":
-        sys.exit(ret)
-
-    depsdir = os.path.normpath(os.path.join(os.curdir, ".deps"))
-    depstarget = os.path.join(depsdir, depstarget)
-    if not os.path.isdir(depsdir):
-        try:
-            os.makedirs(depsdir)
-        except OSError:
-            pass # This suppresses the error we get when the dir exists, at the
-                 # cost of masking failure to create the directory.  We'll just
-                 # die on the next line though, so it's not that much of a loss.
-
-    with open(depstarget, "w") as f:
-        mk.dump(f)
-
-if __name__ == "__main__":
-    InvokeClWithDependencyGeneration(sys.argv[1:])
--- a/js/src/config/config.mk
+++ b/js/src/config/config.mk
@@ -211,18 +211,18 @@ endif
 endif
 
 OS_CONFIG	:= $(OS_ARCH)$(OS_RELEASE)
 
 MOZ_UNICHARUTIL_LIBS = $(LIBXUL_DIST)/lib/$(LIB_PREFIX)unicharutil_s.$(LIB_SUFFIX)
 MOZ_WIDGET_SUPPORT_LIBS    = $(DIST)/lib/$(LIB_PREFIX)widgetsupport_s.$(LIB_SUFFIX)
 
 ifdef _MSC_VER
-CC_WRAPPER ?= $(PYTHON) -O $(topsrcdir)/build/cl.py
-CXX_WRAPPER ?= $(PYTHON) -O $(topsrcdir)/build/cl.py
+CC_WRAPPER = $(call py_action,cl)
+CXX_WRAPPER = $(call py_action,cl)
 endif # _MSC_VER
 
 CC := $(CC_WRAPPER) $(CC)
 CXX := $(CXX_WRAPPER) $(CXX)
 MKDIR ?= mkdir
 SLEEP ?= sleep
 TOUCH ?= touch
 
@@ -891,20 +891,8 @@ PLY_INCLUDE = -I$(topsrcdir)/other-licen
 
 export CL_INCLUDES_PREFIX
 
 ifdef MOZ_GTK2_CFLAGS
 MOZ_GTK2_CFLAGS := -I$(topsrcdir)/widget/gtk/compat $(MOZ_GTK2_CFLAGS)
 endif
 
 DEFINES += -DNO_NSPR_10_SUPPORT
-
-# Run a named Python build action. The first argument is the name of the build
-# action. The second argument are the arguments to pass to the action (space
-# delimited arguments). e.g.
-#
-#   libs::
-#       $(call py_action,purge_manifests,_build_manifests/purge/foo.manifest)
-ifdef .PYMAKE
-py_action = %mozbuild.action.$(1) main $(2)
-else
-py_action = $(PYTHON) -m mozbuild.action.$(1) $(2)
-endif
--- a/js/src/config/makefiles/functions.mk
+++ b/js/src/config/makefiles/functions.mk
@@ -15,8 +15,20 @@ ifdef INCLUDED_FUNCTIONS_MK
 $(error Do not include functions.mk twice!)
 endif
 INCLUDED_FUNCTIONS_MK = 1
 
 core_abspath = $(error core_abspath is unsupported, use $$(abspath) instead)
 core_realpath = $(error core_realpath is unsupported)
 
 core_winabspath = $(error core_winabspath is unsupported)
+
+# Run a named Python build action. The first argument is the name of the build
+# action. The second argument are the arguments to pass to the action (space
+# delimited arguments). e.g.
+#
+#   libs::
+#       $(call py_action,purge_manifests,_build_manifests/purge/foo.manifest)
+ifdef .PYMAKE
+py_action = %mozbuild.action.$(1) main $(2)
+else
+py_action = $(PYTHON) -m mozbuild.action.$(1) $(2)
+endif
rename from build/cl.py
rename to python/mozbuild/mozbuild/action/cl.py
--- a/build/cl.py
+++ b/python/mozbuild/mozbuild/action/cl.py
@@ -47,18 +47,19 @@ def normcase(path):
 def InvokeClWithDependencyGeneration(cmdline):
     target = ""
     # Figure out what the target is
     for arg in cmdline:
         if arg.startswith("-Fo"):
             target = arg[3:]
             break
 
-    if target == None:
-        print >>sys.stderr, "No target set" and sys.exit(1)
+    if target is None:
+        print >>sys.stderr, "No target set"
+        return 1
 
     # Assume the source file is the last argument
     source = cmdline[-1]
     assert not source.startswith('-')
 
     # The deps target lives here
     depstarget = os.path.basename(target) + ".pp"
 
@@ -90,25 +91,30 @@ def InvokeClWithDependencyGeneration(cmd
     # we can run into weird compilation issues.
     p = ProcessHandlerMixin(cmdline, processOutputLine=[on_line],
         ignore_children=True)
     p.run()
     p.processOutput()
     ret = p.wait()
 
     if ret != 0 or target == "":
-        sys.exit(ret)
+        return ret
 
     depsdir = os.path.normpath(os.path.join(os.curdir, ".deps"))
     depstarget = os.path.join(depsdir, depstarget)
     if not os.path.isdir(depsdir):
         try:
             os.makedirs(depsdir)
         except OSError:
             pass # This suppresses the error we get when the dir exists, at the
                  # cost of masking failure to create the directory.  We'll just
                  # die on the next line though, so it's not that much of a loss.
 
     with open(depstarget, "w") as f:
         mk.dump(f)
 
+    return 0
+
+def main(args):
+    return InvokeClWithDependencyGeneration(args)
+
 if __name__ == "__main__":
-    InvokeClWithDependencyGeneration(sys.argv[1:])
+    sys.exit(main(sys.argv[1:]))