Bug 962954 - Add clang-format downloading support for OSX; r=gps
authorAnthony Jones <ajones@mozilla.com>
Tue, 28 Jan 2014 14:11:46 +1300
changeset 175656 4a1e002cb3c2ee6d93d271ecb750dca80c7fd2a8
parent 175655 a16b224233d9e7241300e91e874a1d7bef4aa4c5
child 175657 42bb4abbd6c935e698c1872c1f0efdaf7bd708bb
push idunknown
push userunknown
push dateunknown
reviewersgps
bugs962954
milestone29.0a1
Bug 962954 - Add clang-format downloading support for OSX; r=gps
tools/mach_commands.py
--- a/tools/mach_commands.py
+++ b/tools/mach_commands.py
@@ -320,34 +320,34 @@ class ReviewboardToolsProvider(MachComma
 class FormatProvider(MachCommandBase):
     @Command('clang-format', category='devenv', allow_all_args=True,
         description='Run clang-format on current changes')
     @CommandArgument('args', nargs='...', help='Arguments to clang-format tool')
     def clang_format(self, args):
         if not args:
             args = ['help']
 
-        fmt = "clang-format-3.5"
+        plat = platform.system()
+        fmt = plat.lower() + "/clang-format-3.5"
         fmt_diff = "clang-format-diff-3.5"
 
         # We are currently using a modified verion of clang-format hosted on people.mozilla.org.
         # This is a temporary work around until we upstream the necessary changes and we can use
         # a system version of clang-format. See bug 961541.
-        self.prompt = 1
-        plat = platform.system()
         if plat == "Windows":
             fmt += ".exe"
         else:
             arch = os.uname()[4]
-            if plat != "Linux" or arch != 'x86_64':
+            if (plat != "Linux" and plat != "Darwin") or arch != 'x86_64':
                 print("Unsupported platform " + plat + "/" + arch +
-                      ". Supported platforms are Windows/* and Linux/x86_64")
+                      ". Supported platforms are Windows/*, Linux/x86_64 and Darwin/x86_64")
                 return 1
 
         os.chdir(self.topsrcdir)
+        self.prompt = True
 
         try:
             if not self.locate_or_fetch(fmt):
                 return 1
             clang_format_diff = self.locate_or_fetch(fmt_diff)
             if not clang_format_diff:
                 return 1
 
@@ -357,23 +357,23 @@ class FormatProvider(MachCommandBase):
 
         from subprocess import Popen, PIPE
         p1 = Popen(["hg", "diff", "-U0", "-r", "tip^", "--include", "glob:**.c", "--include", "glob:**.cpp",
                    "--include", "glob:**.h", "--exclude", "listfile:.clang-format-ignore"], stdout=PIPE)
         p2 = Popen([sys.executable, clang_format_diff, "-i", "-p1", "-style=Mozilla"], stdin=p1.stdout)
         return p2.communicate()[0]
 
     def locate_or_fetch(self, root):
-        target = os.path.join(self._mach_context.state_dir, root)
+        target = os.path.join(self._mach_context.state_dir, os.path.basename(root))
         if not os.path.exists(target):
-            site = "http://people.mozilla.org/~ajones/clang-format/"
+            site = "https://people.mozilla.org/~ajones/clang-format/"
             if self.prompt and raw_input("Download clang-format executables from {0} (yN)? ".format(site)).lower() != 'y':
                 print("Download aborted.")
                 return 1
-            self.prompt = 0
+            self.prompt = False
 
             u = site + root
             print("Downloading {0} to {1}".format(u, target))
             data = urllib2.urlopen(url=u).read()
             temp = target + ".tmp"
             with open(temp, "wb") as fh:
                 fh.write(data)
                 fh.close()