From c3441d156f8beb8cdd76880988132c197ddef2e1 Mon Sep 17 00:00:00 2001 From: dpranke Date: Tue, 23 Jun 2015 16:01:35 -0700 Subject: [PATCH] Fix errors in MB when run for the first time on a new builder. The first time we run a build on a GN builder, it's possible that MB will run and the build directory (//out/Release) may not exist yet; in that case, we need to create the directory before trying to write the list of runtime_deps that GN will need to read. R=maruel@chromium.org BUG=480053 Review URL: https://codereview.chromium.org/1204793002 Cr-Commit-Position: refs/heads/master@{#335793} --- tools/mb/mb.py | 12 ++++++++++++ tools/mb/mb_unittest.py | 9 +++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/mb/mb.py b/tools/mb/mb.py index 5b43c61d5fda..35c0e9124fd6 100755 --- a/tools/mb/mb.py +++ b/tools/mb/mb.py @@ -13,6 +13,7 @@ from __future__ import print_function import argparse import ast +import errno import json import os import pipes @@ -339,6 +340,10 @@ class MetaBuildWrapper(object): gn_labels.append(ninja_targets_to_labels[target]) gn_runtime_deps_path = self.ToAbsPath(path, 'runtime_deps') + + # Since GN hasn't run yet, the build directory may not even exist. + self.MaybeMakeDirectory(self.ToAbsPath(path)) + self.WriteFile(gn_runtime_deps_path, '\n'.join(gn_labels) + '\n') cmd.append('--runtime-deps-list-file=%s' % gn_runtime_deps_path) @@ -738,6 +743,13 @@ class MetaBuildWrapper(object): # This function largely exists so it can be overridden for testing. return os.path.exists(path) + def MaybeMakeDirectory(self, path): + try: + os.makedirs(path) + except OSError, e: + if e.errno != errno.EEXIST: + raise + def ReadFile(self, path): # This function largely exists so it can be overriden for testing. with open(path) as fp: diff --git a/tools/mb/mb_unittest.py b/tools/mb/mb_unittest.py index d0326ca06d87..2d6ae62e8e1a 100644 --- a/tools/mb/mb_unittest.py +++ b/tools/mb/mb_unittest.py @@ -16,6 +16,7 @@ class FakeMBW(mb.MetaBuildWrapper): super(FakeMBW, self).__init__() self.files = {} self.calls = [] + self.cmds = [] self.out = '' self.err = '' self.platform = 'linux2' @@ -28,6 +29,9 @@ class FakeMBW(mb.MetaBuildWrapper): def Exists(self, path): return self.files.get(path) is not None + def MaybeMakeDirectory(self, path): + pass + def ReadFile(self, path): return self.files[path] @@ -36,6 +40,8 @@ class FakeMBW(mb.MetaBuildWrapper): def Call(self, cmd): self.calls.append(cmd) + if self.cmds: + return self.cmds.pop(0) return 0, '', '' def Print(self, *args, **kwargs): @@ -47,7 +53,7 @@ class FakeMBW(mb.MetaBuildWrapper): else: self.out += sep.join(args) + end - def TempFile(self): + def TempFile(self, mode='w'): return FakeFile(self.files) def RemoveFile(self, path): @@ -185,7 +191,6 @@ class UnitTest(unittest.TestCase): (1, 'The input matches no targets, configs, or files\n', ''), (1, 'The input matches no targets, configs, or files\n', ''), ] - mbw.Call = lambda cmd: mbw.cmds.pop(0) self.check(['analyze', '-c', 'gn_debug', '//out/Default', '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) -- 2.11.4.GIT