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
--- 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)