Bug 1549206. Fix Eclipse CDT project generation to automatically run the indexer on first run. r=botond
authorJonathan Watt <jwatt@jwatt.org>
Sun, 21 Apr 2019 15:59:31 +0100
changeset 531472 5cb37293574991dc095d46f7bea8fadb08dbfe91
parent 531471 8dca7df2949204ed09622839bb0bbb0da11cbfca
child 531473 e17258dcca609c263307b83c1b09235d715cfba9
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1549206
milestone68.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
Bug 1549206. Fix Eclipse CDT project generation to automatically run the indexer on first run. r=botond Differential Revision: https://phabricator.services.mozilla.com/D29965
python/mozbuild/mozbuild/backend/cpp_eclipse.py
--- a/python/mozbuild/mozbuild/backend/cpp_eclipse.py
+++ b/python/mozbuild/mozbuild/backend/cpp_eclipse.py
@@ -1,15 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # 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 glob
 import random
 import os
 import shutil
 import subprocess
 import types
 from xml.sax.saxutils import quoteattr
 import xml.etree.ElementTree as ET
 from .common import CommonBackend
@@ -36,16 +37,17 @@ class CppEclipseBackend(CommonBackend):
         super(CppEclipseBackend, self).__init__(environment)
 
     def _init(self):
         CommonBackend._init(self)
 
         self._args_for_dirs = {}
         self._project_name = 'Gecko'
         self._workspace_dir = self._get_workspace_path()
+        self._workspace_lang_dir = os.path.join(self._workspace_dir, '.metadata/.plugins/org.eclipse.cdt.core')
         self._project_dir = os.path.join(self._workspace_dir, self._project_name)
         self._overwriting_workspace = os.path.isdir(self._workspace_dir)
 
         self._macbundle = self.environment.substs['MOZ_MACBUNDLE_NAME']
         self._appname = self.environment.substs['MOZ_APP_NAME']
         self._bin_suffix = self.environment.substs['BIN_SUFFIX']
         self._cxx = self.environment.substs['CXX']
         # Note: We need the C Pre Processor (CPP) flags, not the CXX flags
@@ -99,19 +101,18 @@ class CppEclipseBackend(CommonBackend):
                 defs += obj.flags["LIBRARY_DEFINES"]
 
         return True
 
     def consume_finished(self):
         settings_dir = os.path.join(self._project_dir, '.settings')
         launch_dir = os.path.join(self._project_dir, 'RunConfigurations')
         workspace_settings_dir = os.path.join(self._workspace_dir, '.metadata/.plugins/org.eclipse.core.runtime/.settings')
-        workspace_language_dir = os.path.join(self._workspace_dir, '.metadata/.plugins/org.eclipse.cdt.core')
 
-        for dir_name in [self._project_dir, settings_dir, launch_dir, workspace_settings_dir, workspace_language_dir]:
+        for dir_name in [self._project_dir, settings_dir, launch_dir, workspace_settings_dir, self._workspace_lang_dir]:
             try:
                 os.makedirs(dir_name)
             except OSError as e:
                 if e.errno != errno.EEXIST:
                     raise
 
         project_path = os.path.join(self._project_dir, '.project')
         with open(project_path, 'wb') as fh:
@@ -120,17 +121,17 @@ class CppEclipseBackend(CommonBackend):
         cproject_path = os.path.join(self._project_dir, '.cproject')
         with open(cproject_path, 'wb') as fh:
             self._write_cproject(fh)
 
         language_path = os.path.join(settings_dir, 'language.settings.xml')
         with open(language_path, 'wb') as fh:
             self._write_language_settings(fh)
 
-        workspace_language_path = os.path.join(workspace_language_dir, 'language.settings.xml')
+        workspace_language_path = os.path.join(self._workspace_lang_dir, 'language.settings.xml')
         with open(workspace_language_path, 'wb') as fh:
             workspace_lang_settings = WORKSPACE_LANGUAGE_SETTINGS_TEMPLATE
             workspace_lang_settings = workspace_lang_settings.replace("@COMPILER_FLAGS@", self._cxx + " " + self._cppflags);
             fh.write(workspace_lang_settings)
 
         self._write_launch_files(launch_dir)
 
         core_resources_prefs_path = os.path.join(workspace_settings_dir, 'org.eclipse.core.resources.prefs')
@@ -205,16 +206,23 @@ class CppEclipseBackend(CommonBackend):
             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):
+        # Below we remove the config file that temporarily disabled the indexer
+        # while we were importing the project. Unfornutanely, CDT doesn't
+        # notice indexer settings changes in config files when it restarts. To
+        # work around that we remove the index database here to force it to:
+        for f in glob.glob(os.path.join(self._workspace_lang_dir, "*.pdom")):
+            os.remove(f)
+
         noindex_path = os.path.join(self._project_dir, '.settings/org.eclipse.cdt.core.prefs')
         # 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