Skip to content

Commit

Permalink
Add Javac compile option as an alternative to Zinc
Browse files Browse the repository at this point in the history
  • Loading branch information
cheister committed Apr 24, 2018
1 parent a0072d3 commit ae82d7d
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 1 deletion.
20 changes: 20 additions & 0 deletions pants.ini
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,26 @@ no_warning_args: [
'-S-nowarn',
]

[compile.javac]
args: [
'-encoding', 'UTF-8',
'-J-Xmx2g',
]

# javac -help -X will show the complete list
warning_args: [
'-Xlint:deprecation',
'-Xlint:empty',
'-Xlint:finally',
'-Xlint:overrides',
'-Xlint:static',
'-Xlint:unchecked',
'-Xlint:try',
]
no_warning_args: [
'-Xlint:none',
]

[node-distribution]
eslint_setupdir: %(pants_supportdir)s/eslint
eslint_config: %(pants_supportdir)s/eslint/.eslintrc
Expand Down
2 changes: 2 additions & 0 deletions src/python/pants/backend/jvm/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from pants.backend.jvm.tasks.jar_publish import JarPublish
from pants.backend.jvm.tasks.javadoc_gen import JavadocGen
from pants.backend.jvm.tasks.junit_run import JUnitRun
from pants.backend.jvm.tasks.jvm_compile.javac.javac_compile import JavacCompile
from pants.backend.jvm.tasks.jvm_compile.jvm_classpath_publisher import RuntimeClasspathPublisher
from pants.backend.jvm.tasks.jvm_compile.zinc.zinc_compile import ZincCompile
from pants.backend.jvm.tasks.jvm_dependency_check import JvmDependencyCheck
Expand Down Expand Up @@ -157,6 +158,7 @@ def register_goals():

# Compile
task(name='zinc', action=ZincCompile).install('compile')
task(name='javac', action=JavacCompile).install('compile')

# Dependency resolution.
task(name='ivy', action=IvyResolve).install('resolve', first=True)
Expand Down
8 changes: 8 additions & 0 deletions src/python/pants/backend/jvm/subsystems/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ python_library(
]
)

python_library(
name='compile_subsystem',
sources=['compile_subsystem.py'],
dependencies=[
'src/python/pants/subsystem',
],
)

python_library(
name='resolve_subsystem',
sources=['resolve_subsystem.py'],
Expand Down
26 changes: 26 additions & 0 deletions src/python/pants/backend/jvm/subsystems/compile_subsystem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# coding=utf-8
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import logging

from pants.subsystem.subsystem import Subsystem


logger = logging.getLogger(__name__)


class JvmCompileSubsystem(Subsystem):
"""Used to keep track of global jvm compiler option
:API: public
"""
options_scope = 'compiler'

@classmethod
def register_options(cls, register):
super(JvmCompileSubsystem, cls).register_options(register)
register('--compiler', choices=['zinc', 'javac'], default='zinc', help='Java compiler implementation to use.')
27 changes: 27 additions & 0 deletions src/python/pants/backend/jvm/tasks/jvm_compile/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ target(
':analysis_parser',
':analysis_tools',
':anonymizer',
':javac',
':jvm_classpath_publisher',
':jvm_compile',
':zinc',
Expand Down Expand Up @@ -101,6 +102,31 @@ python_library(
sources = ['anonymizer.py'],
)

python_library(
name = 'javac',
sources = globs('javac/*.py'),
dependencies = [
'3rdparty/python/twitter/commons:twitter.common.collections',
'3rdparty/python:six',
':analysis',
':analysis_parser',
':analysis_tools',
':jvm_compile',
'src/python/pants/backend/jvm/subsystems:compile_subsystem',
'src/python/pants/backend/jvm/subsystems:java',
'src/python/pants/backend/jvm/subsystems:shader',
'src/python/pants/backend/jvm/targets:java',
'src/python/pants/base:exceptions',
'src/python/pants/base:hash_utils',
'src/python/pants/base:workunit',
'src/python/pants/java/distribution',
'src/python/pants/option',
'src/python/pants/util:contextutil',
'src/python/pants/util:dirutil',
'src/python/pants/util:memo',
],
)

python_library(
name = 'zinc',
sources = globs('zinc/*.py'),
Expand All @@ -112,6 +138,7 @@ python_library(
'3rdparty/python/twitter/commons:twitter.common.collections',
'3rdparty/python:six',
'src/python/pants/java/jar',
'src/python/pants/backend/jvm/subsystems:compile_subsystem',
'src/python/pants/backend/jvm/subsystems:java',
'src/python/pants/backend/jvm/subsystems:scala_platform',
'src/python/pants/backend/jvm/subsystems:shader',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import logging
import os
import shutil

from pants.util.contextutil import temporary_dir

logger = logging.getLogger(__name__)


class AnalysisTools(object):
"""Analysis manipulation methods required by JvmCompile."""
Expand All @@ -27,6 +30,9 @@ def __init__(self, java_home, parser, analysis_cls, pants_buildroot, pants_workd
self.localize_mappings = {v:k for k, v in self.rebase_mappings.items()}

def relativize(self, src_analysis, relativized_analysis):
if not os.path.isfile(src_analysis):
logger.debug("AnalysisTools: src_analysis file {} does not exist, skipping relativize".format(src_analysis))
return
with temporary_dir() as tmp_analysis_dir:
tmp_analysis_file = os.path.join(tmp_analysis_dir, 'analysis.relativized')

Expand All @@ -43,6 +49,9 @@ def relativize(self, src_analysis, relativized_analysis):
shutil.move(tmp_analysis_file, relativized_analysis)

def localize(self, src_analysis, localized_analysis):
if not os.path.isfile(src_analysis):
logger.debug("AnalysisTools: src_analysis file {} does not exist, skipping localize".format(src_analysis))
return
with temporary_dir() as tmp_analysis_dir:
tmp_analysis_file = os.path.join(tmp_analysis_dir, 'analysis')

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# coding=utf-8
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from pants.backend.jvm.tasks.jvm_compile.analysis import Analysis


class JavacAnalysis(Analysis):

def write(self, outfile):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# coding=utf-8
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)


class JavacAnalysisParser(object):

def parse(self, infile):
pass

def parse_products(self, infile, classes_dir):
pass

def parse_deps(self, infile):
pass

def rebase(self, infile, outfile, pants_home_from, pants_home_to, java_home=None):
pass

def rebase_from_path(self, infile_path, outfile_path, rebase_mappings, java_home=None):
pass

def parse_deps_from_path(self, infile_path):
pass
Loading

0 comments on commit ae82d7d

Please sign in to comment.