Bug 1251870 - Disable indexing of objdir on Windows; r=ted

The Windows content indexing service has been known to scan the objdir.
This can add significant system overhead and slow down builds or
subsequent operations. The objdir is meant to be a short-lived black box
and there really isn't a major benefit to indexing it.

There is a file attribute on Windows that disables content indexing.
This commit adds a utility function for creating a directory and
optionally disabling indexing on it. We call it at the top of
`mach build` to ensure the objdir as content indexing disabled.

MozReview-Commit-ID: 68gxCxbkVAN
This commit is contained in:
Gregory Szorc 2016-02-27 11:58:12 -08:00
parent e60dbe178d
commit 7514ab86b0
2 changed files with 36 additions and 1 deletions

View File

@ -305,7 +305,10 @@ class Build(MachCommandBase):
"""
import which
from mozbuild.controller.building import BuildMonitor
from mozbuild.util import resolve_target_to_make
from mozbuild.util import (
mkdir,
resolve_target_to_make,
)
self.log_manager.register_structured_logger(logging.getLogger('mozbuild'))
@ -314,6 +317,10 @@ class Build(MachCommandBase):
monitor.init(warnings_path)
ccache_start = monitor.ccache_stats()
# Disable indexing in objdir because it is not necessary and can slow
# down builds.
mkdir(self.topobjdir, not_indexed=True)
with BuildOutputManager(self.log_manager, monitor) as output:
monitor.start()

View File

@ -9,6 +9,7 @@ from __future__ import absolute_import, unicode_literals
import argparse
import collections
import ctypes
import difflib
import errno
import functools
@ -36,6 +37,11 @@ if sys.version_info[0] == 3:
else:
str_type = basestring
if sys.platform == 'win32':
_kernel32 = ctypes.windll.kernel32
_FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x2000
def hash_file(path, hasher=None):
"""Hashes a file specified by the path given and returns the hex digest."""
@ -111,6 +117,28 @@ def ensureParentDir(path):
raise
def mkdir(path, not_indexed=False):
"""Ensure a directory exists.
If ``not_indexed`` is True, an attribute is set that disables content
indexing on the directory.
"""
try:
os.makedirs(path)
except OSError as e:
if e.errno != errno.EEXIST:
raise
if not_indexed:
if sys.platform == 'win32':
if isinstance(path, str_type):
fn = _kernel32.SetFileAttributesW
else:
fn = _kernel32.SetFileAttributesA
fn(path, _FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)
def simple_diff(filename, old_lines, new_lines):
"""Returns the diff between old_lines and new_lines, in unified diff form,
as a list of lines.