Skip to content

Commit

Permalink
Relativize most paths in the zinc compile command line (#6322)
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion authored and cosmicexplorer committed Aug 10, 2018
1 parent aa22bf1 commit b7e48c1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
45 changes: 33 additions & 12 deletions src/python/pants/backend/jvm/tasks/jvm_compile/zinc/zinc_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from pants.base.workunit import WorkUnitLabel
from pants.java.distribution.distribution import DistributionLocator
from pants.util.contextutil import open_zip
from pants.util.dirutil import safe_open
from pants.util.dirutil import fast_relpath, safe_open
from pants.util.memo import memoized_method, memoized_property


Expand Down Expand Up @@ -279,28 +279,46 @@ def _zinc_cache_dir(self):
def compile(self, ctx, args, dependency_classpath, upstream_analysis,
settings, compiler_option_sets, zinc_file_manager,
javac_plugin_map, scalac_plugin_map):
classpath = (ctx.classes_dir,) + tuple(ce.path for ce in dependency_classpath)
absolute_classpath = (ctx.classes_dir,) + tuple(ce.path for ce in dependency_classpath)

if self.get_options().capture_classpath:
self._record_compile_classpath(classpath, ctx.target, ctx.classes_dir)
self._record_compile_classpath(absolute_classpath, ctx.target, ctx.classes_dir)

self._verify_zinc_classpath(classpath)
self._verify_zinc_classpath(absolute_classpath)
self._verify_zinc_classpath(list(upstream_analysis.keys()))

def relative_to_exec_root(path):
return fast_relpath(path, get_buildroot())

scala_path = self.scalac_classpath()
compiler_interface = self._zinc.compiler_interface
compiler_bridge = self._zinc.compiler_bridge
classes_dir = ctx.classes_dir
analysis_cache = ctx.analysis_file

scala_path = tuple(relative_to_exec_root(c) for c in scala_path)
compiler_interface = relative_to_exec_root(compiler_interface)
compiler_bridge = relative_to_exec_root(compiler_bridge)
analysis_cache = relative_to_exec_root(analysis_cache)
classes_dir = relative_to_exec_root(classes_dir)
# TODO: Have these produced correctly, rather than having to relativize them here
relative_classpath = tuple(relative_to_exec_root(c) for c in absolute_classpath)

zinc_args = []
zinc_args.extend([
'-log-level', self.get_options().level,
'-analysis-cache', ctx.analysis_file,
'-classpath', ':'.join(classpath),
'-d', ctx.classes_dir
'-analysis-cache', analysis_cache,
'-classpath', ':'.join(relative_classpath),
'-d', classes_dir,
])
if not self.get_options().colors:
zinc_args.append('-no-color')

zinc_args.extend(['-compiler-interface', self._zinc.compiler_interface])
zinc_args.extend(['-compiler-bridge', self._zinc.compiler_bridge])
zinc_args.extend(['-compiler-interface', compiler_interface])
zinc_args.extend(['-compiler-bridge', compiler_bridge])
# TODO: Move this to live inside the workdir: https://github.com/pantsbuild/pants/issues/6155
zinc_args.extend(['-zinc-cache-dir', self._zinc_cache_dir])
zinc_args.extend(['-scala-path', ':'.join(self.scalac_classpath())])
zinc_args.extend(['-scala-path', ':'.join(scala_path)])

zinc_args.extend(self._javac_plugin_args(javac_plugin_map))
# Search for scalac plugins on the classpath.
Expand All @@ -313,13 +331,16 @@ def compile(self, ctx, args, dependency_classpath, upstream_analysis,
# memoized (which in practice will only happen if this plugin uses some other plugin, thus
# triggering the plugin search mechanism, which does the memoizing).
scalac_plugin_search_classpath = (
(set(classpath) | set(self.scalac_plugin_classpath_elements())) -
(set(absolute_classpath) | set(self.scalac_plugin_classpath_elements())) -
{ctx.classes_dir, ctx.jar_file}
)
zinc_args.extend(self._scalac_plugin_args(scalac_plugin_map, scalac_plugin_search_classpath))
if upstream_analysis:
zinc_args.extend(['-analysis-map',
','.join('{}:{}'.format(*kv) for kv in upstream_analysis.items())])
','.join('{}:{}'.format(
relative_to_exec_root(k),
relative_to_exec_root(v)
) for k, v in upstream_analysis.items())])

zinc_args.extend(self._zinc.rebase_map_args)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ def test_workdir_stale_builds_cleanup(self):
will be kept, and the rest will be purged.
"""

with temporary_dir() as tmp_dir:
workdir = os.path.join(tmp_dir, '.pants.d')

with self.temporary_workdir() as workdir:
self.assert_success(self.run_pants_with_workdir([
'compile',
'export-classpath',
Expand Down

0 comments on commit b7e48c1

Please sign in to comment.