servo: Merge #17085 - Fix `./mach upload-nightly macbrew` (from aneeshusa:fix-mach-upload-nightly-for-macbrew); r=larsbergstrom
authorAneesh Agrawal <aneeshusa@gmail.com>
Tue, 30 May 2017 14:06:59 -0500
changeset 409492 821fcba2308102ad8ab603ad1dd5f906559c82d9
parent 409491 07370e32ef6ac127c501d63edcc8051dd2a5fc45
child 409493 c1351451c0d652a8e215adcb2f3ee0e43b8bcd10
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslarsbergstrom
bugs17085, 16565, 17045
milestone55.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
servo: Merge #17085 - Fix `./mach upload-nightly macbrew` (from aneeshusa:fix-mach-upload-nightly-for-macbrew); r=larsbergstrom <!-- Please describe your changes on the following line: --> Fix a few issues with the Homebrew repository updating. Follow-up to #16565; should finish off #17045. Lightly smoke-tested locally this time. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because they will be tested on the builders <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 011a7adf56d9a58be9707cdeeeb824c4b70df84a
servo/etc/ci/servo-binary-formula.rb.in
servo/python/servo/package_commands.py
servo/python/servo/servo-binary-formula.rb.in
--- a/servo/python/servo/package_commands.py
+++ b/servo/python/servo/package_commands.py
@@ -54,16 +54,34 @@ PACKAGES = {
     ],
     'windows-msvc': [
         r'target\release\msi\Servo.msi',
         r'target\release\msi\Servo.zip',
     ],
 }
 
 
+TemporaryDirectory = None
+if sys.version_info >= (3, 2):
+    TemporaryDirectory = tempfile.TemporaryDirectory
+else:
+    import contextlib
+
+    # Not quite as robust as tempfile.TemporaryDirectory,
+    # but good enough for most purposes
+    @contextlib.contextmanager
+    def TemporaryDirectory(**kwargs):
+        dir_name = tempfile.mkdtemp(**kwargs)
+        try:
+            yield dir_name
+        except Exception as e:
+            shutil.rmtree(dir_name)
+            raise e
+
+
 def otool(s):
     o = subprocess.Popen(['/usr/bin/otool', '-L', s], stdout=subprocess.PIPE)
     for l in o.stdout:
         if l[0] == '\t':
             yield l.split(' ', 1)[0][1:]
 
 
 def listfiles(directory):
@@ -437,17 +455,17 @@ class PackageCommands(CommandBase):
             package_url = 'https://download.servo.org/nightly/macbrew/{}'.format(
                 nightly_filename(package, timestamp)
             )
             with open(package) as p:
                 digest = hashlib.sha256(p.read()).hexdigest()
 
             brew_version = timestamp.strftime('%Y.%m.%d')
 
-            with tempfile.TemporaryDirectory(prefix='homebrew-servo') as tmp_dir:
+            with TemporaryDirectory(prefix='homebrew-servo') as tmp_dir:
                 def call_git(cmd, **kwargs):
                     subprocess.check_call(
                         ['git', '-C', tmp_dir] + cmd,
                         **kwargs
                     )
 
                 call_git([
                     'clone',
@@ -456,17 +474,17 @@ class PackageCommands(CommandBase):
                 ])
 
                 script_dir = path.dirname(path.realpath(__file__))
                 with open(path.join(script_dir, 'servo-binary-formula.rb.in')) as f:
                     formula = f.read()
                 formula = formula.replace('PACKAGEURL', package_url)
                 formula = formula.replace('SHA', digest)
                 formula = formula.replace('VERSION', brew_version)
-                with open(path.join(tmp_dir, 'Formula', 'servo-bin.rb')) as f:
+                with open(path.join(tmp_dir, 'Formula', 'servo-bin.rb'), 'w') as f:
                     f.write(formula)
 
                 call_git(['add', path.join('.', 'Formula', 'servo-bin.rb')])
                 call_git([
                     '-c', 'user.name=Tom Servo',
                     '-c', 'user.email=servo@servo.org',
                     'commit',
                     '--message=Version Bump: {}'.format(brew_version),
@@ -486,11 +504,13 @@ class PackageCommands(CommandBase):
                 print("Could not find package for {} at {}".format(
                     platform,
                     package
                 ), file=sys.stderr)
                 return 1
             upload_to_s3(platform, package, timestamp)
 
         if platform == 'macbrew':
-            update_brew(package, timestamp)
+            packages = PACKAGES[platform]
+            assert(len(packages) == 1)
+            update_brew(packages[0], timestamp)
 
         return 0
rename from servo/etc/ci/servo-binary-formula.rb.in
rename to servo/python/servo/servo-binary-formula.rb.in