Bug 1325490 - Give a helpful error message if eclipse project generation is invoked and 'eclipse' is not in the PATH. r?Build draft
authorBotond Ballo <botond@mozilla.com>
Wed, 07 Feb 2018 15:22:43 -0500
changeset 752283 4c63230a22839365eebe86055f55083c3fc0a9f0
parent 752282 c262c0520be3af03bf0516e74cb05f2245b77a49
push id98212
push userbballo@mozilla.com
push dateWed, 07 Feb 2018 20:26:37 +0000
reviewersBuild
bugs1325490
milestone60.0a1
Bug 1325490 - Give a helpful error message if eclipse project generation is invoked and 'eclipse' is not in the PATH. r?Build MozReview-Commit-ID: B9CfN3WHZZO
python/mozbuild/mozbuild/backend/cpp_eclipse.py
--- a/python/mozbuild/mozbuild/backend/cpp_eclipse.py
+++ b/python/mozbuild/mozbuild/backend/cpp_eclipse.py
@@ -2,16 +2,17 @@
 # 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 absolute_import
 
 import errno
 import random
 import os
+import shutil
 import subprocess
 import types
 import xml.etree.ElementTree as ET
 from .common import CommonBackend
 
 from ..frontend.data import (
     Defines,
 )
@@ -166,27 +167,42 @@ class CppEclipseBackend(CommonBackend):
         # the whole codebase when importing the project. Indexing the project can take 20 minutes.
         self._write_noindex()
 
         try:
             process = subprocess.check_call(
                              ["eclipse", "-application", "-nosplash",
                               "org.eclipse.cdt.managedbuilder.core.headlessbuild",
                               "-data", self._workspace_dir, "-importAll", self._project_dir])
+        except OSError as e:
+            # Remove the workspace directory so we re-generate it and
+            # try to import again when the backend is invoked again.
+            shutil.rmtree(self._workspace_dir)
+
+            if e.errno == errno.ENOENT:
+                raise Exception("Failed to launch eclipse to import project. "
+                                "Ensure 'eclipse' is in your PATH and try again")
+            else:
+                raise
         finally:
             self._remove_noindex()
 
     def _write_noindex(self):
         noindex_path = os.path.join(self._project_dir, '.settings/org.eclipse.cdt.core.prefs')
         with open(noindex_path, 'wb') as fh:
             fh.write(NOINDEX_TEMPLATE);
 
     def _remove_noindex(self):
         noindex_path = os.path.join(self._project_dir, '.settings/org.eclipse.cdt.core.prefs')
-        os.remove(noindex_path)
+        # This may fail if the entire tree has been removed; that's fine.
+        try:
+            os.remove(noindex_path)
+        except OSError as e:
+            if e.errno != errno.ENOENT:
+                raise
 
     def _define_entry(self, name, value):
         define = ET.Element('entry')
         define.set('kind', 'macro')
         define.set('name', name)
         define.set('value', value)
         return ET.tostring(define)