Skip to content

Commit

Permalink
Revert "Provide global option to look up BUILD files in git history"
Browse files Browse the repository at this point in the history
This reverts commit 381665d.
  • Loading branch information
dturner-tw committed Apr 30, 2015
1 parent 6bd35f3 commit 2b987cf
Show file tree
Hide file tree
Showing 20 changed files with 143 additions and 718 deletions.
1 change: 0 additions & 1 deletion build-support/bin/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ if [[ "${skip_testprojects:-false}" == "false" ]]; then
testprojects/src/python/antlr:test_antlr_failure
testprojects/src/scala/org/pantsbuild/testproject/compilation_failure
testprojects/src/thrift/org/pantsbuild/thrift_linter:
testprojects/tests/java/org/pantsbuild/testproject/empty:
testprojects/tests/java/org/pantsbuild/testproject/dummies:failing_target
testprojects/tests/python/pants/dummies:failing_target
)
Expand Down
8 changes: 6 additions & 2 deletions src/python/pants/backend/jvm/targets/java_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
class JavaTests(JvmTarget):
"""Tests JVM sources with JUnit."""

def __init__(self, **kwargs):
def __init__(self, sources=None, **kwargs):
_sources = self.assert_list(sources)

super(JavaTests, self).__init__(**kwargs)
super(JavaTests, self).__init__(sources=_sources, **kwargs)

if not _sources:
raise TargetDefinitionException(self, 'JavaTests must include a non-empty set of sources.')

# TODO(John Sirois): These could be scala, clojure, etc. 'jvm' and 'tests' are the only truly
# applicable labels - fixup the 'java' misnomer.
Expand Down
5 changes: 5 additions & 0 deletions src/python/pants/backend/jvm/targets/jvm_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def __init__(self, parse_context, rel_path=None, mapper=None, relative_to=None,

if relative_to:
base = os.path.join(get_buildroot(), self._rel_path, relative_to)
if not os.path.isdir(os.path.join(get_buildroot(), base)):
raise ValueError('Could not find a directory to bundle relative to at {}'.format(base))
self.mapper = RelativeToMapper(base)
else:
self.mapper = mapper or RelativeToMapper(os.path.join(get_buildroot(), self._rel_path))
Expand All @@ -131,6 +133,9 @@ def _add(self, filesets):
abspath = path
if not os.path.isabs(abspath):
abspath = os.path.join(get_buildroot(), self._rel_path, path)
if not os.path.exists(abspath):
raise ValueError('Given path: {} with absolute path: {} which does not exist'
.format(path, abspath))
self.filemap[abspath] = self.mapper(abspath)
return self

Expand Down
2 changes: 0 additions & 2 deletions src/python/pants/backend/jvm/tasks/bundle_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ def add_jars(target):
for bundle in app.bundles:
for path, relpath in bundle.filemap.items():
bundle_path = os.path.join(bundle_dir, relpath)
if not os.path.exists(bundle_path):
raise ValueError('Given path: {} does not exist'.format(bundle_path))
safe_mkdir(os.path.dirname(bundle_path))
verbose_symlink(path, bundle_path)

Expand Down
6 changes: 0 additions & 6 deletions src/python/pants/backend/jvm/tasks/junit_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,4 @@ def __init__(self, *args, **kwargs):
def execute(self):
if not self.get_options().skip:
targets = self.context.targets()
# TODO: move this check to an optional phase in goal_runner, so
# that missing sources can be detected early.
for target in targets:
if isinstance(target, junit_tests) and not target.payload.sources.source_paths:
raise TargetDefinitionException(target, 'JavaTests must include a non-empty set of sources.')

self._runner.execute(targets)
8 changes: 0 additions & 8 deletions src/python/pants/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ python_library(
]
)

python_library(
name = 'scm_build_file',
sources = ['scm_build_file.py'],
dependencies = [
':build_file',
]
)

python_library(
name = 'build_file_address_mapper',
sources = ['build_file_address_mapper.py'],
Expand Down
45 changes: 22 additions & 23 deletions src/python/pants/base/build_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def from_cache(cls, root_dir, relpath, must_exist=True):
return cls._cache[key]

@abstractmethod
def _glob1(self, path, glob):
def glob1(self, path, glob):
"""Returns a list of paths in path that match glob"""

def _get_all_build_files(self, path):
"""Returns all the BUILD files on a path"""
results = []
for build in self._glob1(path, '{prefix}*'.format(prefix=self._BUILD_FILE_PREFIX)):
for build in self.glob1(path, '{prefix}*'.format(prefix=self._BUILD_FILE_PREFIX)):
if self._is_buildfile_name(build):
results.append(build)
return sorted(results)
Expand Down Expand Up @@ -110,7 +110,7 @@ def find_excluded(root, dirs, exclude_roots):
else:
exclude_roots = calc_exclude_roots(root_dir, spec_excludes)

for root, dirs, files in cls._walk(root_dir, base_path or '', topdown=True):
for root, dirs, files in cls.walk(os.path.join(root_dir, base_path or ''), topdown=True):
to_remove = find_excluded(root, dirs, exclude_roots)
for subdir in to_remove:
dirs.remove(subdir)
Expand All @@ -120,20 +120,21 @@ def find_excluded(root, dirs, exclude_roots):
buildfiles.append(cls.from_cache(root_dir, buildfile_relpath))
return OrderedSet(sorted(buildfiles, key=lambda buildfile: buildfile.full_path))

@classmethod
@abstractmethod
def _walk(self, root_dir, relpath, topdown=False):
def walk(cls, path, topdown=False):
"""Walk the file tree rooted at `path`. Works like os.walk"""

@abstractmethod
def _isdir(self, path):
def isdir(self, path):
"""Returns True if path is a directory"""

@abstractmethod
def _isfile(self, path):
def isfile(self, path):
"""Returns True if path is a file"""

@abstractmethod
def _exists(self, path):
def exists(self, path):
"""Returns True if path exists"""

def __init__(self, root_dir, relpath=None, must_exist=True):
Expand All @@ -151,41 +152,40 @@ def __init__(self, root_dir, relpath=None, must_exist=True):
raise self.InvalidRootDirError('BuildFile root_dir {root_dir} must be an absolute path.'
.format(root_dir=root_dir))

self.root_dir = os.path.realpath(root_dir)

path = os.path.join(root_dir, relpath) if relpath else root_dir
self._build_basename = self._BUILD_FILE_PREFIX
buildfile = os.path.join(path, self._build_basename) if self._isdir(path) else path
buildfile = os.path.join(path, self._build_basename) if self.isdir(path) else path

if must_exist:
# If the build file must exist then we want to make sure it's not a dir.
# In other cases we are ok with it being a dir, for example someone might have
# repo/scripts/build/doit.sh.
if self._isdir(buildfile):
if self.isdir(buildfile):
raise self.MissingBuildFileError(
'Path to buildfile ({buildfile}) is a directory, but it must be a file.'
.format(buildfile=buildfile))

if not self._exists(os.path.dirname(buildfile)):
if not self.exists(os.path.dirname(buildfile)):
raise self.MissingBuildFileError('Path to BUILD file does not exist at: {path}'
.format(path=os.path.dirname(buildfile)))

# There is no BUILD file without a prefix so select any viable sibling
if not self._exists(buildfile) or self._isdir(buildfile):
if not self.exists(buildfile) or self.isdir(buildfile):
for build in self._get_all_build_files(os.path.dirname(buildfile)):
self._build_basename = build
buildfile = os.path.join(path, self._build_basename)
break

if must_exist:
if not self._exists(buildfile):
if not self.exists(buildfile):
raise self.MissingBuildFileError('BUILD file does not exist at: {path}'
.format(path=buildfile))

if not self._is_buildfile_name(os.path.basename(buildfile)):
raise self.MissingBuildFileError('{path} is not a BUILD file'
.format(path=buildfile))

self.root_dir = os.path.realpath(root_dir)
self.full_path = os.path.realpath(buildfile)

self.name = os.path.basename(self.full_path)
Expand All @@ -196,7 +196,7 @@ def __init__(self, root_dir, relpath=None, must_exist=True):

def file_exists(self):
"""Returns True if this BuildFile corresponds to a real BUILD file on disk."""
return self._isfile(self.full_path)
return self.isfile(self.full_path)

def descendants(self, spec_excludes=None):
"""Returns all BUILD files in descendant directories of this BUILD file's parent directory."""
Expand All @@ -214,7 +214,7 @@ def find_parent(dir):
parent = os.path.dirname(dir)
for parent_buildfile in self._get_all_build_files(parent):
buildfile = os.path.join(parent, parent_buildfile)
if self._isfile(buildfile):
if self.isfile(buildfile):
return parent, self.from_cache(self.root_dir,
os.path.relpath(buildfile, self.root_dir))
return parent, None
Expand All @@ -241,7 +241,7 @@ def siblings(self):
for build in self._get_all_build_files(self.parent_path):
if self.name != build:
siblingpath = os.path.join(os.path.dirname(self.relpath), build)
if not self._isdir(os.path.join(self.root_dir, siblingpath)):
if not self.isdir(os.path.join(self.root_dir, siblingpath)):
yield self.from_cache(self.root_dir, siblingpath)

def family(self):
Expand Down Expand Up @@ -282,24 +282,23 @@ class FilesystemBuildFile(BuildFile):
# class needs to access it, so it can't be moved yet.
_cache = {}

def _glob1(self, path, glob):
def glob1(self, path, glob):
return glob1(path, glob)

def source(self):
"""Returns the source code for this BUILD file."""
with open(self.full_path, 'rb') as source:
return source.read()

def _isdir(self, path):
def isdir(self, path):
return os.path.isdir(path)

def _isfile(self, path):
def isfile(self, path):
return os.path.isfile(path)

def _exists(self, path):
def exists(self, path):
return os.path.exists(path)

@classmethod
def _walk(self, root_dir, relpath, topdown=False):
path = os.path.join(root_dir, relpath)
def walk(self, path, topdown=False):
return safe_walk(path, topdown=True)
117 changes: 0 additions & 117 deletions src/python/pants/base/scm_build_file.py

This file was deleted.

1 change: 0 additions & 1 deletion src/python/pants/bin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ python_library(
'src/python/pants/base:cmd_line_spec_parser',
'src/python/pants/base:config',
'src/python/pants/base:extension_loader',
'src/python/pants/base:scm_build_file',
'src/python/pants/base:workunit',
'src/python/pants/engine',
'src/python/pants/goal',
Expand Down
13 changes: 2 additions & 11 deletions src/python/pants/bin/goal_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@

from pants.backend.core.tasks.task import QuietTaskMixin
from pants.backend.jvm.tasks.nailgun_task import NailgunTask # XXX(pl)
from pants.base.build_environment import get_buildroot, get_scm
from pants.base.build_environment import get_buildroot
from pants.base.build_file import FilesystemBuildFile
from pants.base.build_file_address_mapper import BuildFileAddressMapper
from pants.base.build_file_parser import BuildFileParser
from pants.base.build_graph import BuildGraph
from pants.base.cmd_line_spec_parser import CmdLineSpecParser
from pants.base.config import Config
from pants.base.extension_loader import load_plugins_and_backends
from pants.base.scm_build_file import ScmBuildFile
from pants.base.workunit import WorkUnit
from pants.engine.round_engine import RoundEngine
from pants.goal.context import Context
Expand Down Expand Up @@ -106,15 +105,7 @@ def setup(self):
self.build_file_parser = BuildFileParser(build_configuration=build_configuration,
root_dir=self.root_dir,
run_tracker=self.run_tracker)

rev = self.options.for_global_scope().build_file_rev
if rev:
ScmBuildFile.set_rev(rev)
ScmBuildFile.set_scm(get_scm())
build_file_type = ScmBuildFile
else:
build_file_type = FilesystemBuildFile
self.address_mapper = BuildFileAddressMapper(self.build_file_parser, build_file_type)
self.address_mapper = BuildFileAddressMapper(self.build_file_parser, FilesystemBuildFile)
self.build_graph = BuildGraph(run_tracker=self.run_tracker,
address_mapper=self.address_mapper)

Expand Down
Loading

0 comments on commit 2b987cf

Please sign in to comment.