Bug 1460690 - [mozlint] Make sure vcs_paths are always joined to the repository root, r=standard8

Files returned from version control (i.e via --outgoing or --workdir), are currently joined to
cwd. This will cause failures if |mach lint| is run from anywhere other than topsrcdir.

However we *do* want to join manually specified paths to cwd so things like:
cd devtools && mach lint client

continue to work. This patch makes sure we join the proper kind of path to the proper place.

MozReview-Commit-ID: EQmRhAr3Oog

--HG--
extra : rebase_source : 2629cc27f79059e44369d46d4f8278f83923582c
This commit is contained in:
Andrew Halberstadt 2018-05-11 11:13:36 -04:00
parent 53d03bac82
commit f6cad69dd3
2 changed files with 36 additions and 2 deletions

View File

@ -156,8 +156,7 @@ class LintRoller(object):
else: else:
lpaths = paths.union(vcs_paths) lpaths = paths.union(vcs_paths)
lpaths = lpaths or ['.'] lpaths = list(lpaths) or [os.getcwd()]
lpaths = map(os.path.abspath, lpaths)
chunk_size = min(self.MAX_PATHS_PER_JOB, int(ceil(len(lpaths) / num_procs))) or 1 chunk_size = min(self.MAX_PATHS_PER_JOB, int(ceil(len(lpaths) / num_procs))) or 1
assert chunk_size > 0 assert chunk_size > 0
@ -223,6 +222,11 @@ class LintRoller(object):
print("warning: no files linted") print("warning: no files linted")
return {} return {}
# Make sure all paths are absolute. Join `paths` to cwd and `vcs_paths` to root.
paths = set(map(os.path.abspath, paths))
vcs_paths = set([os.path.join(self.root, p) if not os.path.isabs(p) else p
for p in vcs_paths])
num_procs = num_procs or cpu_count() num_procs = num_procs or cpu_count()
jobs = list(self._generate_jobs(paths, vcs_paths, num_procs)) jobs = list(self._generate_jobs(paths, vcs_paths, num_procs))

View File

@ -50,6 +50,36 @@ def test_roll_successful(lint, linters, files):
assert container.rule == 'no-foobar' assert container.rule == 'no-foobar'
def test_roll_from_subdir(lint, linters):
lint.read(linters)
oldcwd = os.getcwd()
try:
os.chdir(os.path.join(lint.root, 'files'))
# Path relative to cwd works
result = lint.roll('no_foobar.js')
assert len(result) == 0
assert len(lint.failed) == 0
# Path relative to root doesn't work
result = lint.roll(os.path.join('files', 'no_foobar.js'))
assert len(result) == 0
assert len(lint.failed) == 3
# Paths from vcs are always joined to root instead of cwd
lint.mock_vcs([os.path.join('files', 'no_foobar.js')])
result = lint.roll(outgoing=True)
assert len(result) == 0
assert len(lint.failed) == 0
result = lint.roll(workdir=True)
assert len(result) == 0
assert len(lint.failed) == 0
finally:
os.chdir(oldcwd)
def test_roll_catch_exception(lint, lintdir, files, capfd): def test_roll_catch_exception(lint, lintdir, files, capfd):
lint.read(os.path.join(lintdir, 'raises.yml')) lint.read(os.path.join(lintdir, 'raises.yml'))