Skip to content

Commit

Permalink
Print a diagnostic if a BUILD file references a source file that does…
Browse files Browse the repository at this point in the history
… not exist

Testing Done:
Edited a BUILD file, added a reference to a source file that does not exist.

```
diff --git a/src/python/pants/backend/core/BUILD b/src/python/pants/backend/core/BUILD
index 2da9682..8b1e827 100644
--- a/src/python/pants/backend/core/BUILD
+++ b/src/python/pants/backend/core/BUILD
@@ -4,7 +4,7 @@

 python_library(
   name = 'plugin',
-  sources = ['register.py'],
+  sources = ['register.py', 'does-not-exist.py'],
   dependencies = [
     'src/python/pants/backend/core/targets:all',
     'src/python/pants/backend/core/tasks:all',

```

Before this change, when running

```
PANTS_DEV=1 goal test tests/python/pants_test:all
```

the build would end with an error but not give any further information:

```
Exception message: [Errno 2] No such file or directory
```

After this change, you now get a diagnostic message that gives you a hint why the test failed:

```
 ERROR] Failed to copy src/python/pants/backend/core/does-not-exist.py for library PythonLibrary(BuildFileAddress(/Users/zundel/Src/pants/src/python/pants/backend/core/BUILD, plugin))

               FAILURE

Exception message: [Errno 2] No such file or directory
```

Reviewed at https://rbcommons.com/s/twitter/r/1198/
  • Loading branch information
ericzundel committed Oct 22, 2014
1 parent ef1ac14 commit 4456b0c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/python/pants/backend/python/python_chroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
print_function, unicode_literals)

from collections import defaultdict
import logging
import os
import shutil
import sys
Expand Down Expand Up @@ -35,6 +36,8 @@
from pants.util.dirutil import safe_mkdir, safe_rmtree


logger = logging.getLogger(__name__)

class PythonChroot(object):
_VALID_DEPENDENCIES = {
PrepCommand: 'prep',
Expand Down Expand Up @@ -104,12 +107,25 @@ def copy_to_chroot(base, path, add_function):

self.debug(' Dumping library: %s' % library)
for relpath in library.sources_relative_to_source_root():
copy_to_chroot(library.target_base, relpath, self._builder.add_source)
try:
copy_to_chroot(library.target_base, relpath, self._builder.add_source)
except OSError as e:
logger.error("Failed to copy {path} for library {library}"
.format(path=os.path.join(library.target_base, relpath),
library=library))
raise

for resources_tgt in library.resources:
for resource_file_from_source_root in resources_tgt.sources_relative_to_source_root():
copy_to_chroot(resources_tgt.target_base, resource_file_from_source_root,
self._builder.add_resource)
try:
copy_to_chroot(resources_tgt.target_base, resource_file_from_source_root,
self._builder.add_resource)
except OSError as e:
logger.error("Failed to copy {path} for resource {resource}"
.format(path=os.path.join(resources_tgt.target_base,
resource_file_from_source_root),
resource=resources_tgt.address.spec))
raise

def _dump_requirement(self, req, dynamic, repo):
self.debug(' Dumping requirement: %s%s%s' % (str(req),
Expand Down

0 comments on commit 4456b0c

Please sign in to comment.