def __init__(self, context, workdir): NailgunTask.__init__(self, context, workdir=workdir) # Set up dep checking if needed. def get_lang_specific_option(opt): full_opt_name = self.language() + '_' + opt return getattr(context.options, full_opt_name, None) def munge_flag(flag): return None if flag == 'off' else flag check_missing_deps = munge_flag( get_lang_specific_option('missing_deps')) check_missing_direct_deps = munge_flag( get_lang_specific_option('missing_direct_deps')) check_unnecessary_deps = munge_flag( get_lang_specific_option('unnecessary_deps')) if check_missing_deps or check_missing_direct_deps or check_unnecessary_deps: # Must init it here, so it can set requirements on the context. self._dep_analyzer = JvmDependencyAnalyzer( self.context, check_missing_deps, check_missing_direct_deps, check_unnecessary_deps) else: self._dep_analyzer = None
def __init__(self, context, confs=None): classpath = context.config.getlist('ivy', 'classpath') nailgun_dir = context.config.get('ivy-resolve', 'nailgun_dir') NailgunTask.__init__(self, context, classpath=classpath, workdir=nailgun_dir) self._cachedir = context.options.ivy_resolve_cache or context.config.get('ivy', 'cache_dir') self._confs = confs or context.config.getlist('ivy-resolve', 'confs') self._work_dir = context.config.get('ivy-resolve', 'workdir') self._classpath_dir = os.path.join(self._work_dir, 'mapped') self._outdir = context.options.ivy_resolve_outdir or os.path.join(self._work_dir, 'reports') self._open = context.options.ivy_resolve_open self._report = self._open or context.options.ivy_resolve_report self._ivy_bootstrap_key = 'ivy' ivy_bootstrap_tools = context.config.getlist('ivy-resolve', 'bootstrap-tools', ':xalan') self._bootstrap_utils.register_jvm_build_tools(self._ivy_bootstrap_key, ivy_bootstrap_tools) self._ivy_utils = IvyUtils(config=context.config, options=context.options, log=context.log) context.products.require_data('exclusives_groups') # Typically this should be a local cache only, since classpaths aren't portable. artifact_cache_spec = context.config.getlist('ivy-resolve', 'artifact_caches', default=[]) self.setup_artifact_cache(artifact_cache_spec)
def setup_parser(cls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) option_group.add_option( mkflag("warnings"), mkflag("warnings", negate=True), dest="scala_compile_warnings", default=True, action="callback", callback=mkflag.set_bool, help="[%default] Compile scala code with all configured warnings " "enabled.") option_group.add_option( mkflag("flatten"), mkflag("flatten", negate=True), dest="scala_compile_flatten", action="callback", callback=mkflag.set_bool, help="[%default] Compile scala code for all dependencies in a " "single compilation.") option_group.add_option(mkflag("color"), mkflag("color", negate=True), dest="scala_compile_color", action="callback", callback=mkflag.set_bool, help="[True] Enable color in logging.")
def execute(self, targets): if NailgunTask.killall: NailgunTask.killall( self.context.log, everywhere=self.context.options.ng_killall_everywhere) else: raise NotImplementedError, 'NailgunKillall not implemented on this platform'
def __init__(self, context): NailgunTask.__init__(self, context, workdir=context.config.get('java-compile', 'nailgun_dir')) self._flatten = \ context.options.java_compile_flatten if context.options.java_compile_flatten is not None else \ context.config.getbool('java-compile', 'default_to_flatten') workdir = context.config.get('java-compile', 'workdir') self._classes_dir = os.path.join(workdir, 'classes') self._resources_dir = os.path.join(workdir, 'resources') self._depfile_dir = os.path.join(workdir, 'depfiles') self._deps = Dependencies(self._classes_dir) self._jmake_profile = context.config.get('java-compile', 'jmake-profile') self._compiler_profile = context.config.get('java-compile', 'compiler-profile') self._args = context.config.getlist('java-compile', 'args') self._jvm_args = context.config.getlist('java-compile', 'jvm_args') if context.options.java_compile_warnings: self._args.extend(context.config.getlist('java-compile', 'warning_args')) else: self._args.extend(context.config.getlist('java-compile', 'no_warning_args')) self._confs = context.config.getlist('java-compile', 'confs')
def __init__(self, context, workdir=None): NailgunTask.__init__(self, context, workdir=context.config.get('scala-compile', 'nailgun_dir')) color = context.options.scala_compile_color or \ context.config.getbool('scala-compile', 'color', default=True) self._zinc_utils = ZincUtils(context=context, java_runner=self.runjava, color=color) self._partition_size_hint = \ context.options.scala_compile_partition_size_hint \ if context.options.scala_compile_partition_size_hint != -1 else \ context.config.getint('scala-compile', 'partition_size_hint') self.check_missing_deps = context.options.scala_check_missing_deps self.check_intransitive_deps = context.options.scala_check_intransitive_deps self.check_unnecessary_deps = context.options.scala_check_unnecessary_deps if self.check_missing_deps: JvmDependencyCache.init_product_requirements(self) # for dependency analysis, we need to record the list of analysis cache files generated by splitting self.generated_caches = set() workdir = context.config.get('scala-compile', 'workdir') if workdir is None else workdir self._classes_dir = os.path.join(workdir, 'classes') self._analysis_cache_dir = os.path.join(workdir, 'analysis_cache') self._resources_dir = os.path.join(workdir, 'resources') self._depfile_dir = os.path.join(workdir, 'depfiles') self._confs = context.config.getlist('scala-compile', 'confs') artifact_cache_spec = context.config.getlist('scala-compile', 'artifact_caches') self.setup_artifact_cache(artifact_cache_spec)
def __init__(self, context): NailgunTask.__init__(self, context, workdir=context.config.get( 'scala-compile', 'nailgun_dir')) self._compile_profile = context.config.get('scala-compile', 'compile-profile') self._depemitter_profile = context.config.get( 'scala-compile', 'dependencies-plugin-profile') # All scala targets implicitly depend on the selected scala runtime. scaladeps = [] for spec in context.config.getlist('scala-compile', 'scaladeps'): scaladeps.extend(context.resolve(spec)) for target in context.targets(is_scala): target.update_dependencies(scaladeps) workdir = context.config.get('scala-compile', 'workdir') self._classes_dir = os.path.join(workdir, 'classes') self._resources_dir = os.path.join(workdir, 'resources') self._main = context.config.get('scala-compile', 'main') self._args = context.config.getlist('scala-compile', 'args') if context.options.scala_compile_warnings: self._args.extend( context.config.getlist('scala-compile', 'warning_args')) else: self._args.extend( context.config.getlist('scala-compile', 'no_warning_args')) self._flatten = context.options.scala_compile_flatten self._confs = context.config.getlist('scala-compile', 'confs') self._depfile = os.path.join(workdir, 'dependencies')
def setup_parser(cls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) flag = mkflag('override') option_group.add_option(flag, action='append', dest='ivy_resolve_overrides', help='''Specifies a jar dependency override in the form: [org]#[name]=(revision|url) For example, to specify 2 overrides: %(flag)s=com.foo#bar=0.1.2 \\ %(flag)s=com.baz#spam=file:///tmp/spam.jar ''' % dict(flag=flag)) report = mkflag("report") option_group.add_option(report, mkflag("report", negate=True), dest = "ivy_resolve_report", action="callback", callback=mkflag.set_bool, default=False, help = "[%default] Generate an ivy resolve html report") option_group.add_option(mkflag("open"), mkflag("open", negate=True), dest="ivy_resolve_open", default=False, action="callback", callback=mkflag.set_bool, help="[%%default] Attempt to open the generated ivy resolve report " "in a browser (implies %s)." % report) option_group.add_option(mkflag("outdir"), dest="ivy_resolve_outdir", help="Emit ivy report outputs in to this directory.") option_group.add_option(mkflag("cache"), dest="ivy_resolve_cache", help="Use this directory as the ivy cache, instead of the " \ "default specified in pants.ini.")
def __init__(self, context): NailgunTask.__init__(self, context, workdir=context.config.get("java-compile", "nailgun_dir")) self._partition_size_hint = ( context.options.java_compile_partition_size_hint if context.options.java_compile_partition_size_hint != -1 else context.config.getint("java-compile", "partition_size_hint") ) workdir = context.config.get("java-compile", "workdir") self._classes_dir = os.path.join(workdir, "classes") self._resources_dir = os.path.join(workdir, "resources") self._depfile_dir = os.path.join(workdir, "depfiles") self._deps = Dependencies(self._classes_dir) self._jmake_profile = context.config.get("java-compile", "jmake-profile") self._compiler_profile = context.config.get("java-compile", "compiler-profile") self._args = context.config.getlist("java-compile", "args") self._jvm_args = context.config.getlist("java-compile", "jvm_args") if context.options.java_compile_warnings: self._args.extend(context.config.getlist("java-compile", "warning_args")) else: self._args.extend(context.config.getlist("java-compile", "no_warning_args")) self._confs = context.config.getlist("java-compile", "confs") # The artifact cache to read from/write to. artifact_cache_spec = context.config.getlist("java-compile", "artifact_caches") self.setup_artifact_cache(artifact_cache_spec)
def __init__(self, context): NailgunTask.__init__(self, context) self._scalastyle_config = self.context.config.get_required( Scalastyle._CONFIG_SECTION, 'config') if not os.path.exists(self._scalastyle_config): raise Config.ConfigError( 'Scalastyle config file does not exist: %s' % self._scalastyle_config) excludes_file = self.context.config.get(Scalastyle._CONFIG_SECTION, 'excludes') self._excludes = set() if excludes_file: if not os.path.exists(excludes_file): raise Config.ConfigError( 'Scalastyle excludes file does not exist: %s' % excludes_file) self.context.log.debug('Using scalastyle excludes file %s' % excludes_file) with open(excludes_file) as fh: for pattern in fh.readlines(): self._excludes.add(re.compile(pattern.strip())) self._scalastyle_bootstrap_key = 'scalastyle' self.register_jvm_tool(self._scalastyle_bootstrap_key, [':scalastyle'])
def __init__(self, context): NailgunTask.__init__(self, context, workdir=context.config.get( 'java-compile', 'nailgun_dir')) workdir = context.config.get('java-compile', 'workdir') self._classes_dir = os.path.join(workdir, 'classes') self._resources_dir = os.path.join(workdir, 'resources') self._dependencies_file = os.path.join(workdir, 'dependencies') self._jmake_profile = context.config.get('java-compile', 'jmake-profile') self._compiler_profile = context.config.get('java-compile', 'compiler-profile') self._args = context.config.getlist('java-compile', 'args') self._jvm_args = context.config.getlist('java-compile', 'jvm_args') if context.options.java_compile_warnings: self._args.extend( context.config.getlist('java-compile', 'warning_args')) else: self._args.extend( context.config.getlist('java-compile', 'no_warning_args')) self._flatten = context.options.java_compile_flatten self._confs = context.config.getlist('java-compile', 'confs')
def setup_parser(cls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) flag = mkflag('override') option_group.add_option( flag, action='append', dest='ivy_resolve_overrides', help='''Specifies a jar dependency override in the form: [org]#[name]=(revision|url) For example, to specify 2 overrides: %(flag)s=com.foo#bar=0.1.2 \\ %(flag)s=com.baz#spam=file:///tmp/spam.jar ''' % dict(flag=flag)) report = mkflag("report") option_group.add_option( report, mkflag("report", negate=True), dest="ivy_resolve_report", action="callback", callback=mkflag.set_bool, default=False, help="[%default] Generate an ivy resolve html report") option_group.add_option( mkflag("open"), mkflag("open", negate=True), dest="ivy_resolve_open", default=False, action="callback", callback=mkflag.set_bool, help="[%%default] Attempt to open the generated ivy resolve report " "in a browser (implies %s)." % report) option_group.add_option( mkflag("outdir"), dest="ivy_resolve_outdir", help="Emit ivy report outputs in to this directory.") option_group.add_option( mkflag("cache"), dest="ivy_resolve_cache", help="Use this directory as the ivy cache, instead of the " "default specified in pants.ini.") option_group.add_option(mkflag("args"), dest="ivy_args", action="append", default=[], help="Pass these extra args to ivy.") option_group.add_option( mkflag("mutable-pattern"), dest="ivy_mutable_pattern", help= "If specified, all artifact revisions matching this pattern will " "be treated as mutable unless a matching artifact explicitly " "marks mutable as False.")
def __init__(self, context, output_dir=None, classpath=None, main=None, args=None, confs=None): workdir = context.config.get('scala-compile', 'nailgun_dir') NailgunTask.__init__(self, context, workdir=workdir) self._compile_profile = context.config.get('scala-compile', 'compile-profile') # All scala targets implicitly depend on the selected scala runtime. scaladeps = [] for spec in context.config.getlist('scala-compile', 'scaladeps'): scaladeps.extend(context.resolve(spec)) for target in context.targets(is_scala): target.update_dependencies(scaladeps) self._compiler_classpath = classpath self._output_dir = output_dir or context.config.get('scala-compile', 'workdir') self._main = main or context.config.get('scala-compile', 'main') self._args = args or context.config.getlist('scala-compile', 'args') if context.options.scala_compile_warnings: self._args.extend(context.config.getlist('scala-compile', 'warning_args')) else: self._args.extend(context.config.getlist('scala-compile', 'no_warning_args')) self._confs = confs or context.config.getlist('scala-compile', 'confs') self._depfile = os.path.join(self._output_dir, 'dependencies')
def setup_parser(cls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) option_group.add_option( mkflag("warnings"), mkflag("warnings", negate=True), dest="scala_compile_warnings", default=True, action="callback", callback=mkflag.set_bool, help="[%default] Compile scala code with all configured warnings " "enabled.") option_group.add_option( mkflag("plugins"), dest="plugins", default=None, action="append", help="Use these scalac plugins. Default is set in pants.ini.") option_group.add_option(mkflag("partition-size-hint"), dest="scala_compile_partition_size_hint", action="store", type="int", default=-1, help="Roughly how many source files to attempt to compile together. Set to a large number to compile " \ "all sources together. Set this to 0 to compile target-by-target. Default is set in pants.ini.") option_group.add_option(mkflag("color"), mkflag("color", negate=True), dest="scala_compile_color", action="callback", callback=mkflag.set_bool, help="[True] Enable color in logging.")
def setup_parser(cls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) option_group.add_option(mkflag("skip"), mkflag("skip", negate=True), dest="checkstyle_skip", default=False, action="callback", callback=mkflag.set_bool, help="[%default] Skip checkstyle.")
def __init__(self, context): NailgunTask.__init__(self, context, workdir=context.config.get('scala-compile', 'nailgun_dir')) self._compile_profile = context.config.get('scala-compile', 'compile-profile') self._depemitter_profile = context.config.get('scala-compile', 'dependencies-plugin-profile') # All scala targets implicitly depend on the selected scala runtime. scaladeps = [] for spec in context.config.getlist('scala-compile', 'scaladeps'): scaladeps.extend(context.resolve(spec)) for target in context.targets(is_scala): target.update_dependencies(scaladeps) workdir = context.config.get('scala-compile', 'workdir') self._classes_dir = os.path.join(workdir, 'classes') self._resources_dir = os.path.join(workdir, 'resources') self._main = context.config.get('scala-compile', 'main') self._args = context.config.getlist('scala-compile', 'args') if context.options.scala_compile_warnings: self._args.extend(context.config.getlist('scala-compile', 'warning_args')) else: self._args.extend(context.config.getlist('scala-compile', 'no_warning_args')) self._confs = context.config.getlist('scala-compile', 'confs') self._depfile = os.path.join(workdir, 'dependencies')
def __init__(self, context): NailgunTask.__init__(self, context, workdir=context.config.get( 'java-compile', 'nailgun_dir')) self._partition_size_hint = \ context.options.java_compile_partition_size_hint \ if context.options.java_compile_partition_size_hint != -1 \ else context.config.getint('java-compile', 'partition_size_hint') workdir = context.config.get('java-compile', 'workdir') self._classes_dir = os.path.join(workdir, 'classes') self._resources_dir = os.path.join(workdir, 'resources') self._depfile_dir = os.path.join(workdir, 'depfiles') self._deps = Dependencies(self._classes_dir) self._jmake_profile = context.config.get('java-compile', 'jmake-profile') self._compiler_profile = context.config.get('java-compile', 'compiler-profile') self._args = context.config.getlist('java-compile', 'args') self._jvm_args = context.config.getlist('java-compile', 'jvm_args') if context.options.java_compile_warnings: self._args.extend( context.config.getlist('java-compile', 'warning_args')) else: self._args.extend( context.config.getlist('java-compile', 'no_warning_args')) self._confs = context.config.getlist('java-compile', 'confs')
def __init__(self, context, workdir=None): NailgunTask.__init__(self, context, workdir=context.config.get('scala-compile', 'nailgun_dir')) # Set up the zinc utils. color = context.options.scala_compile_color or \ context.config.getbool('scala-compile', 'color', default=True) self._zinc_utils = ZincUtils(context=context, java_runner=self.runjava, color=color) # The rough number of source files to build in each compiler pass. self._partition_size_hint = \ context.options.scala_compile_partition_size_hint \ if context.options.scala_compile_partition_size_hint != -1 else \ context.config.getint('scala-compile', 'partition_size_hint') # Set up dep checking if needed. if context.options.scala_check_missing_deps: JvmDependencyCache.init_product_requirements(self) # Various output directories. self._buildroot = get_buildroot() workdir = context.config.get('scala-compile', 'workdir') if workdir is None else workdir self._resources_dir = os.path.join(workdir, 'resources') self._artifact_factory = ZincArtifactFactory(workdir, self.context, self._zinc_utils) # The ivy confs for which we're building. self._confs = context.config.getlist('scala-compile', 'confs') # The artifact cache to read from/write to. artifact_cache_spec = context.config.getlist('scala-compile', 'artifact_caches') self.setup_artifact_cache(artifact_cache_spec)
def setup_parser(cls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) option_group.add_option( mkflag("warnings"), mkflag("warnings", negate=True), dest="scala_compile_warnings", default=True, action="callback", callback=mkflag.set_bool, help="[%default] Compile scala code with all configured warnings " "enabled.", ) option_group.add_option( mkflag("plugins"), dest="plugins", default=None, action="append", help="Use these scalac plugins. Default is set in pants.ini.", ) option_group.add_option( mkflag("partition-size-hint"), dest="scala_compile_partition_size_hint", action="store", type="int", default=-1, help="Roughly how many source files to attempt to compile together. Set to a large number " "to compile all sources together. Set this to 0 to compile target-by-target. " "Default is set in pants.ini.", ) JvmDependencyCache.setup_parser(option_group, args, mkflag)
def setup_parser(cls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) option_group.add_option( mkflag('warnings'), mkflag('warnings', negate=True), dest='scala_compile_warnings', default=True, action='callback', callback=mkflag.set_bool, help='[%default] Compile scala code with all configured warnings ' 'enabled.') option_group.add_option( mkflag('plugins'), dest='plugins', default=None, action='append', help='Use these scalac plugins. Default is set in pants.ini.') option_group.add_option(mkflag('partition-size-hint'), dest='scala_compile_partition_size_hint', action='store', type='int', default=-1, help='Roughly how many source files to attempt to compile together. Set to a large number ' \ 'to compile all sources together. Set this to 0 to compile target-by-target. ' \ 'Default is set in pants.ini.') JvmDependencyCache.setup_parser(option_group, args, mkflag)
def __init__(self, context): NailgunTask.__init__(self, context, workdir=context.config.get('java-compile', 'nailgun_dir')) self._partition_size_hint = \ context.options.java_compile_partition_size_hint \ if context.options.java_compile_partition_size_hint != -1 \ else context.config.getint('java-compile', 'partition_size_hint') workdir = context.config.get('java-compile', 'workdir') self._classes_dir = os.path.join(workdir, 'classes') self._resources_dir = os.path.join(workdir, 'resources') self._depfile_dir = os.path.join(workdir, 'depfiles') self._deps = Dependencies(self._classes_dir) self._jmake_profile = context.config.get('java-compile', 'jmake-profile') self._compiler_profile = context.config.get('java-compile', 'compiler-profile') self._args = context.config.getlist('java-compile', 'args') self._jvm_args = context.config.getlist('java-compile', 'jvm_args') if context.options.java_compile_warnings: self._args.extend(context.config.getlist('java-compile', 'warning_args')) else: self._args.extend(context.config.getlist('java-compile', 'no_warning_args')) self._confs = context.config.getlist('java-compile', 'confs') # The artifact cache to read from/write to. artifact_cache_spec = context.config.getlist('java-compile', 'artifact_caches') self.setup_artifact_cache(artifact_cache_spec)
def setup_parser(cls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) option_group.add_option( mkflag("warnings"), mkflag("warnings", negate=True), dest="java_compile_warnings", default=True, action="callback", callback=mkflag.set_bool, help="[%default] Compile java code with all configured warnings " "enabled.") option_group.add_option(mkflag("args"), dest="java_compile_args", action="append", help="Pass these extra args to javac.") option_group.add_option( mkflag("partition-size-hint"), dest="java_compile_partition_size_hint", action="store", type="int", default=-1, help= "Roughly how many source files to attempt to compile together. Set" " to a large number to compile all sources together. Set this to 0" " to compile target-by-target. Default is set in pants.ini.")
def __init__(self, context, workdir): NailgunTask.__init__(self, context, workdir=workdir) concrete_class = self.__class__ config_section = concrete_class._config_section def get_lang_specific_option(opt): full_opt_name = self.language() + '_' + opt return getattr(context.options, full_opt_name, None) # Various working directories. workdir = context.config.get(config_section, 'workdir') self._classes_dir = os.path.join(workdir, 'classes') self._resources_dir = os.path.join(workdir, 'resources') self._analysis_dir = os.path.join(workdir, 'analysis') safe_mkdir(self._classes_dir) safe_mkdir(self._analysis_dir) # A temporary, but well-known, dir to munge analysis/dependency files in before caching. # It must be well-known so we know where to find the files when we retrieve them from the cache. self._analysis_tmpdir = os.path.join(self._analysis_dir, 'artifact_cache_tmpdir') # Compiler options. self._opts = context.config.getlist(config_section, 'args') if get_lang_specific_option('compile_warnings'): self._opts.extend(context.config.getlist(config_section, 'warning_args')) else: self._opts.extend(context.config.getlist(config_section, 'no_warning_args')) # The rough number of source files to build in each compiler pass. self._partition_size_hint = get_lang_specific_option('partition_size_hint') if self._partition_size_hint == -1: self._partition_size_hint = \ context.config.getint(config_section, 'partition_size_hint', default=1000) # JVM args for running the compiler. self._jvm_args = context.config.getlist(config_section, 'jvm_args') # The ivy confs for which we're building. self._confs = context.config.getlist(config_section, 'confs') # Set up dep checking if needed. def munge_flag(flag): return None if flag == 'off' else flag check_missing_deps = munge_flag(get_lang_specific_option('missing_deps')) check_missing_direct_deps = munge_flag(get_lang_specific_option('missing_direct_deps')) check_unnecessary_deps = munge_flag(get_lang_specific_option('unnecessary_deps')) if check_missing_deps or check_missing_direct_deps or check_unnecessary_deps: # Must init it here, so it can set requirements on the context. self._dep_analyzer = JvmDependencyAnalyzer(self.context, check_missing_deps, check_missing_direct_deps, check_unnecessary_deps) else: self._dep_analyzer = None self.context.products.require_data('exclusives_groups') self.setup_artifact_cache_from_config(config_section=config_section)
def setup_parser(cls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) option_group.add_option(mkflag("warnings"), mkflag("warnings", negate=True), dest="scala_compile_warnings", default=True, action="callback", callback=mkflag.set_bool, help="[%default] Compile scala code with all configured warnings " "enabled.")
def _run(): version = get_version() if len(sys.argv) == 2 and sys.argv[1] == _VERSION_OPTION: _do_exit(version) root_dir = get_buildroot() if not os.path.exists(root_dir): _exit_and_fail('PANTS_BUILD_ROOT does not point to a valid path: %s' % root_dir) if len(sys.argv) < 2 or (len(sys.argv) == 2 and sys.argv[1] in _HELP_ALIASES): _help(version, root_dir) command_class, command_args = _parse_command(root_dir, sys.argv[1:]) parser = optparse.OptionParser(version=version) RcFile.install_disable_rc_option(parser) parser.add_option(_LOG_EXIT_OPTION, action='store_true', default=False, dest='log_exit', help = 'Log an exit message on success or failure.') config = Config.load() run_tracker = RunTracker(config) report = initial_reporting(config, run_tracker) run_tracker.start(report) url = run_tracker.run_info.get_info('report_url') if url: run_tracker.log(Report.INFO, 'See a report at: %s' % url) else: run_tracker.log(Report.INFO, '(To run a reporting server: ./pants server)') command = command_class(run_tracker, root_dir, parser, command_args) try: if command.serialized(): def onwait(pid): print('Waiting on pants process %s to complete' % _process_info(pid), file=sys.stderr) return True runfile = os.path.join(root_dir, '.pants.run') lock = Lock.acquire(runfile, onwait=onwait) else: lock = Lock.unlocked() try: result = command.run(lock) _do_exit(result) except KeyboardInterrupt: command.cleanup() raise finally: lock.release() finally: run_tracker.end() # Must kill nailguns only after run_tracker.end() is called, because there may still # be pending background work that needs a nailgun. if (hasattr(command.options, 'cleanup_nailguns') and command.options.cleanup_nailguns) \ or config.get('nailgun', 'autokill', default=False): NailgunTask.killall(None)
def run(self, lock): # Update the reporting settings, now that we have flags etc. def is_console_task(): for phase in self.phases: for goal in phase.goals(): if issubclass(goal.task_type, ConsoleTask): return True return False update_reporting(self.options, is_console_task(), self.run_tracker) if self.options.dry_run: print '****** Dry Run ******' context = Context(self.config, self.options, self.run_tracker, self.targets, requested_goals=self.requested_goals, lock=lock) # TODO: Time to get rid of this hack. if self.options.recursive_directory: context.log.warn( '--all-recursive is deprecated, use a target spec with the form [dir]:: instead' ) for dir in self.options.recursive_directory: self.add_target_recursive(dir) if self.options.target_directory: context.log.warn( '--all is deprecated, use a target spec with the form [dir]: instead' ) for dir in self.options.target_directory: self.add_target_directory(dir) unknown = [] for phase in self.phases: if not phase.goals(): unknown.append(phase) if unknown: print('Unknown goal(s): %s' % ' '.join(phase.name for phase in unknown)) print('') return Phase.execute(context, 'goals') ret = Phase.attempt(context, self.phases) if self.options.cleanup_nailguns or self.config.get( 'nailgun', 'autokill', default=False): if log: log.debug('auto-killing nailguns') if NailgunTask.killall: NailgunTask.killall(log) return ret
def __init__(self, context): NailgunTask.__init__(self, context, workdir=context.config.get('scala-compile', 'nailgun_dir')) # Set up the zinc utils. color = not context.options.no_color self._zinc_utils = ZincUtils(context=context, nailgun_task=self, color=color) # The rough number of source files to build in each compiler pass. self._partition_size_hint = (context.options.scala_compile_partition_size_hint if context.options.scala_compile_partition_size_hint != -1 else context.config.getint('scala-compile', 'partition_size_hint', default=1000)) # Set up dep checking if needed. if context.options.scala_check_missing_deps: JvmDependencyCache.init_product_requirements(self) self._opts = context.config.getlist('scala-compile', 'args') if context.options.scala_compile_warnings: self._opts.extend(context.config.getlist('scala-compile', 'warning_args')) else: self._opts.extend(context.config.getlist('scala-compile', 'no_warning_args')) # Various output directories. workdir = context.config.get('scala-compile', 'workdir') self._classes_dir = os.path.join(workdir, 'classes') self._analysis_dir = os.path.join(workdir, 'analysis') safe_mkdir(self._classes_dir) safe_mkdir(self._analysis_dir) self._analysis_file = os.path.join(self._analysis_dir, 'global_analysis.valid') self._invalid_analysis_file = os.path.join(self._analysis_dir, 'global_analysis.invalid') self._resources_dir = os.path.join(workdir, 'resources') # The ivy confs for which we're building. self._confs = context.config.getlist('scala-compile', 'confs') self.context.products.require_data('exclusives_groups') self._local_artifact_cache_spec = \ context.config.getlist('scala-compile', 'local_artifact_caches2', default=[]) self._remote_artifact_cache_spec = \ context.config.getlist('scala-compile', 'remote_artifact_caches2', default=[]) # A temporary, but well-known, dir to munge analysis files in before caching. It must be # well-known so we know where to find the files when we retrieve them from the cache. self._analysis_tmpdir = os.path.join(self._analysis_dir, 'artifact_cache_tmpdir') # If we are compiling scala libraries with circular deps on java libraries we need to make sure # those cycle deps are present. self._inject_java_cycles() # Sources present in the last analysis that have since been deleted. # Generated lazily, so do not access directly. Call self._get_deleted_sources(). self._deleted_sources = None
def __init__(self, context): self._profile = context.config.get('checkstyle', 'profile') workdir = context.config.get('checkstyle', 'nailgun_dir') NailgunTask.__init__(self, context, workdir=workdir) self._configuration_file = context.config.get('checkstyle', 'configuration') self._work_dir = context.config.get('checkstyle', 'workdir') self._properties = context.config.getdict('checkstyle', 'properties') self._confs = context.config.getlist('checkstyle', 'confs')
def __init__(self, context, strict=False, verbose=True): NailgunTask.__init__(self, context) self.strict = strict self.verbose = verbose for info in INFO_FOR_COMPILER.values(): config = info['config'] bootstrap_tools = context.config.getlist(config, 'bootstrap-tools', default=[':%s' % config]) self._jvm_tool_bootstrapper.register_jvm_tool(config, bootstrap_tools)
def __init__(self, context): self._profile = context.config.get('checkstyle', 'profile') workdir = context.config.get('checkstyle', 'nailgun_dir') NailgunTask.__init__(self, context, workdir=workdir) self._configuration_file = context.config.get('checkstyle', 'configuration') self._work_dir = context.config.get('checkstyle', 'workdir') self._properties = context.config.getdict('checkstyle', 'properties') self._confs = context.config.getlist('checkstyle', 'confs') self.context.products.require_data('exclusives_groups')
def __init__(self, context): CodeGen.__init__(self, context) NailgunTask.__init__(self, context) # TODO(John Sirois): kill if not needed by prepare_gen self._classpath_by_compiler = {} active_compilers = set(map(lambda t: t.compiler, context.targets(predicate=self.is_gentarget))) for compiler, tools in self._all_possible_antlr_bootstrap_tools(): if compiler in active_compilers: self._jvm_tool_bootstrapper.register_jvm_tool(compiler, tools)
def setup_parser(cls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) option_group.add_option( mkflag("warnings"), mkflag("warnings", negate=True), dest="java_compile_warnings", default=True, action="callback", callback=mkflag.set_bool, help="[%default] Compile java code with all configured warnings " "enabled.")
def run(self, lock): # Update the reporting settings, now that we have flags etc. def is_console_task(): for phase in self.phases: for goal in phase.goals(): if issubclass(goal.task_type, ConsoleTask): return True return False update_reporting(self.options, is_console_task(), self.run_tracker) if self.options.dry_run: print '****** Dry Run ******' context = Context( self.config, self.options, self.run_tracker, self.targets, requested_goals=self.requested_goals, lock=lock) # TODO: Time to get rid of this hack. if self.options.recursive_directory: context.log.warn( '--all-recursive is deprecated, use a target spec with the form [dir]:: instead') for dir in self.options.recursive_directory: self.add_target_recursive(dir) if self.options.target_directory: context.log.warn('--all is deprecated, use a target spec with the form [dir]: instead') for dir in self.options.target_directory: self.add_target_directory(dir) unknown = [] for phase in self.phases: if not phase.goals(): unknown.append(phase) if unknown: print('Unknown goal(s): %s' % ' '.join(phase.name for phase in unknown)) print('') return Phase.execute(context, 'goals') ret = Phase.attempt(context, self.phases) if self.options.cleanup_nailguns or self.config.get('nailgun', 'autokill', default = False): if log: log.debug('auto-killing nailguns') if NailgunTask.killall: NailgunTask.killall(log) return ret
def __init__(self, context, workdir=None): NailgunTask.__init__(self, context, workdir=context.config.get( 'scala-compile', 'nailgun_dir')) self._flatten = \ context.options.scala_compile_flatten if context.options.scala_compile_flatten is not None else \ context.config.getbool('scala-compile', 'default_to_flatten') # We use the scala_compile_color flag if it is explicitly set on the command line. self._color = \ context.options.scala_compile_color if context.options.scala_compile_color is not None else \ context.config.getbool('scala-compile', 'color', default=True) self._compile_profile = context.config.get( 'scala-compile', 'compile-profile') # The target scala version. self._zinc_profile = context.config.get('scala-compile', 'zinc-profile') # All scala targets implicitly depend on the selected scala runtime. scaladeps = [] for spec in context.config.getlist('scala-compile', 'scaladeps'): scaladeps.extend(context.resolve(spec)) for target in context.targets(is_scala): target.update_dependencies(scaladeps) self._workdir = context.config.get( 'scala-compile', 'workdir') if workdir is None else workdir self._incremental_classes_dir = os.path.join(self._workdir, 'incremental.classes') self._flat_classes_dir = os.path.join(self._workdir, 'classes') self._analysis_cache_dir = os.path.join(self._workdir, 'analysis_cache') self._resources_dir = os.path.join(self._workdir, 'resources') self._main = context.config.get('scala-compile', 'main') self._args = context.config.getlist('scala-compile', 'args') self._jvm_args = context.config.getlist('scala-compile', 'jvm_args') if context.options.scala_compile_warnings: self._args.extend( context.config.getlist('scala-compile', 'warning_args')) else: self._args.extend( context.config.getlist('scala-compile', 'no_warning_args')) self._confs = context.config.getlist('scala-compile', 'confs') self._depfile_dir = os.path.join(self._workdir, 'depfiles') artifact_cache_spec = context.config.getlist('scala-compile', 'artifact_caches') self.setup_artifact_cache(artifact_cache_spec)
def __init__(self, context): classpath = context.config.getlist('ivy', 'classpath') nailgun_dir = context.config.get('ivy-resolve', 'nailgun_dir') NailgunTask.__init__(self, context, classpath=classpath, workdir=nailgun_dir) self._ivy_settings = context.config.get('ivy', 'ivy_settings') self._cachedir = context.options.ivy_resolve_cache or context.config.get('ivy', 'cache_dir') self._confs = context.config.getlist('ivy-resolve', 'confs') self._transitive = context.config.getbool('ivy-resolve', 'transitive') self._args = context.config.getlist('ivy-resolve', 'args') self._profile = context.config.get('ivy-resolve', 'profile') self._template_path = os.path.join('ivy_resolve', 'ivy.mustache') self._work_dir = context.config.get('ivy-resolve', 'workdir') self._classpath_file = os.path.join(self._work_dir, 'classpath') self._classpath_dir = os.path.join(self._work_dir, 'mapped') self._outdir = context.options.ivy_resolve_outdir or os.path.join(self._work_dir, 'reports') self._open = context.options.ivy_resolve_open self._report = self._open or context.options.ivy_resolve_report self._ivy_utils = IvyUtils(context, self._cachedir) def parse_override(override): match = re.match(r'^([^#]+)#([^=]+)=([^\s]+)$', override) if not match: raise TaskError('Invalid dependency override: %s' % override) org, name, rev_or_url = match.groups() def fmt_message(message, template): return message % dict( overridden='%s#%s;%s' % (template.org, template.module, template.version), rev=rev_or_url, url=rev_or_url ) def replace_rev(template): context.log.info(fmt_message('Overrode %(overridden)s with rev %(rev)s', template)) return template.extend(version=rev_or_url, url=None, force=True) def replace_url(template): context.log.info(fmt_message('Overrode %(overridden)s with snapshot at %(url)s', template)) return template.extend(version='SNAPSHOT', url=rev_or_url, force=True) replace = replace_url if re.match(r'^\w+://.+', rev_or_url) else replace_rev return (org, name), replace self._overrides = {} if context.options.ivy_resolve_overrides: self._overrides.update(parse_override(o) for o in context.options.ivy_resolve_overrides)
def setup_parser(subcls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) option_group.add_option(mkflag('warnings'), mkflag('warnings', negate=True), dest=subcls._language+'_compile_warnings', default=True, action='callback', callback=mkflag.set_bool, help='[%default] Compile with all configured warnings enabled.') option_group.add_option(mkflag('partition-size-hint'), dest=subcls._language+'_partition_size_hint', action='store', type='int', default=-1, help='Roughly how many source files to attempt to compile together. Set to a large number ' 'to compile all sources together. Set this to 0 to compile target-by-target. ' 'Default is set in pants.ini.') option_group.add_option(mkflag('missing-deps'), dest=subcls._language+'_missing_deps', choices=['off', 'warn', 'fatal'], default='warn', help='[%default] One of off, warn, fatal. ' 'Check for missing dependencies in ' + subcls._language + 'code. ' 'Reports actual dependencies A -> B where there is no ' 'transitive BUILD file dependency path from A to B.' 'If fatal, missing deps are treated as a build error.') option_group.add_option(mkflag('missing-direct-deps'), dest=subcls._language+'_missing_direct_deps', choices=['off', 'warn', 'fatal'], default='off', help='[%default] One of off, warn, fatal. ' 'Check for missing direct dependencies in ' + subcls._language + ' code. ' 'Reports actual dependencies A -> B where there is no direct ' 'BUILD file dependency path from A to B. ' 'This is a very strict check, as in practice it is common to rely on ' 'transitive, non-direct dependencies, e.g., due to type inference or when ' 'the main target in a BUILD file is modified to depend on other targets in ' 'the same BUILD file as an implementation detail. It may still be useful ' 'to set it to fatal temorarily, to detect these.') option_group.add_option(mkflag('unnecessary-deps'), dest=subcls._language+'_unnecessary_deps', choices=['off', 'warn', 'fatal'], default='off', help='[%default] One of off, warn, fatal. ' 'Check for declared dependencies in ' + subcls._language + ' code ' 'that are not needed. This is a very strict check. For example, ' 'generated code will often legitimately have BUILD dependencies that ' 'are unused in practice.')
def __init__(self, context): classpath = context.config.getlist("ivy", "classpath") nailgun_dir = context.config.get("ivy-resolve", "nailgun_dir") NailgunTask.__init__(self, context, classpath=classpath, workdir=nailgun_dir) self._ivy_settings = context.config.get("ivy", "ivy_settings") self._cachedir = context.options.ivy_resolve_cache or context.config.get("ivy", "cache_dir") self._confs = context.config.getlist("ivy-resolve", "confs") self._transitive = context.config.getbool("ivy-resolve", "transitive") self._args = context.config.getlist("ivy-resolve", "args") self._profile = context.config.get("ivy-resolve", "profile") self._template_path = os.path.join("ivy_resolve", "ivy.mustache") self._work_dir = context.config.get("ivy-resolve", "workdir") self._classpath_file = os.path.join(self._work_dir, "classpath") self._classpath_dir = os.path.join(self._work_dir, "mapped") self._outdir = context.options.ivy_resolve_outdir or os.path.join(self._work_dir, "reports") self._open = context.options.ivy_resolve_open self._report = self._open or context.options.ivy_resolve_report self._ivy_utils = IvyUtils(context, self._cachedir) def parse_override(override): match = re.match(r"^([^#]+)#([^=]+)=([^\s]+)$", override) if not match: raise TaskError("Invalid dependency override: %s" % override) org, name, rev_or_url = match.groups() def fmt_message(message, template): return message % dict( overridden="%s#%s;%s" % (template.org, template.module, template.version), rev=rev_or_url, url=rev_or_url, ) def replace_rev(template): context.log.info(fmt_message("Overrode %(overridden)s with rev %(rev)s", template)) return template.extend(version=rev_or_url, url=None, force=True) def replace_url(template): context.log.info(fmt_message("Overrode %(overridden)s with snapshot at %(url)s", template)) return template.extend(version="SNAPSHOT", url=rev_or_url, force=True) replace = replace_url if re.match(r"^\w+://.+", rev_or_url) else replace_rev return (org, name), replace self._overrides = {} if context.options.ivy_resolve_overrides: self._overrides.update(parse_override(o) for o in context.options.ivy_resolve_overrides)
def __init__(self, context): CodeGen.__init__(self, context) NailgunTask.__init__(self, context) # TODO(John Sirois): kill if not needed by prepare_gen self._classpath_by_compiler = {} active_compilers = set( map(lambda t: t.compiler, context.targets(predicate=self.is_gentarget))) for compiler, tools in self._all_possible_antlr_bootstrap_tools(): if compiler in active_compilers: self._jvm_tool_bootstrapper.register_jvm_tool(compiler, tools)
def setup_parser(cls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) option_group.add_option(mkflag("warnings"), mkflag("warnings", negate=True), dest="java_compile_warnings", default=True, action="callback", callback=mkflag.set_bool, help="[%default] Compile java code with all configured warnings " "enabled.") option_group.add_option(mkflag("partition-size-hint"), dest="java_compile_partition_size_hint", action="store", type="int", default=-1, help="Roughly how many source files to attempt to compile together. Set to a large number to compile "\ "all sources together. Set this to 0 to compile target-by-target. Default is set in pants.ini.")
def setup_parser(cls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) option_group.add_option(mkflag("warnings"), mkflag("warnings", negate=True), dest="java_compile_warnings", default=True, action="callback", callback=mkflag.set_bool, help="[%default] Compile java code with all configured warnings " "enabled.") option_group.add_option(mkflag("flatten"), mkflag("flatten", negate=True), dest="java_compile_flatten", action="callback", callback=mkflag.set_bool, help="[%default] Compile java code for all dependencies in a " "single compilation.")
def __init__(self, context): NailgunTask.__init__(self, context, workdir=context.config.get( 'java-compile', 'nailgun_dir')) if context.options.java_compile_partition_size_hint != -1: self._partition_size_hint = context.options.java_compile_partition_size_hint else: self._partition_size_hint = context.config.getint( 'java-compile', 'partition_size_hint', default=1000) workdir = context.config.get('java-compile', 'workdir') self._classes_dir = os.path.join(workdir, 'classes') self._resources_dir = os.path.join(workdir, 'resources') self._depfile_dir = os.path.join(workdir, 'depfiles') self._deps = Dependencies(self._classes_dir) self._jmake_profile = context.config.get('java-compile', 'jmake-profile') self._compiler_profile = context.config.get('java-compile', 'compiler-profile') self._opts = context.config.getlist('java-compile', 'args') self._jvm_args = context.config.getlist('java-compile', 'jvm_args') self._javac_opts = [] if context.options.java_compile_args: for arg in context.options.java_compile_args: self._javac_opts.extend(shlex.split(arg)) else: self._javac_opts.extend( context.config.getlist('java-compile', 'javac_args', default=[])) if context.options.java_compile_warnings: self._opts.extend( context.config.getlist('java-compile', 'warning_args')) else: self._opts.extend( context.config.getlist('java-compile', 'no_warning_args')) self._confs = context.config.getlist('java-compile', 'confs') # The artifact cache to read from/write to. artifact_cache_spec = context.config.getlist('java-compile', 'artifact_caches', default=[]) self.setup_artifact_cache(artifact_cache_spec)
def __init__(self, context): NailgunTask.__init__(self, context, workdir=context.config.get( 'scala-compile', 'nailgun_dir')) # Set up the zinc utils. color = not context.options.no_color self._zinc_utils = ZincUtils(context=context, nailgun_task=self, color=color) # The rough number of source files to build in each compiler pass. self._partition_size_hint = ( context.options.scala_compile_partition_size_hint if context.options.scala_compile_partition_size_hint != -1 else context.config.getint( 'scala-compile', 'partition_size_hint', default=1000)) # Set up dep checking if needed. if context.options.scala_check_missing_deps: JvmDependencyCache.init_product_requirements(self) self._opts = context.config.getlist('scala-compile', 'args') if context.options.scala_compile_warnings: self._opts.extend( context.config.getlist('scala-compile', 'warning_args')) else: self._opts.extend( context.config.getlist('scala-compile', 'no_warning_args')) # Various output directories. workdir = context.config.get('scala-compile', 'workdir') self._resources_dir = os.path.join(workdir, 'resources') self._artifact_factory = ZincArtifactFactory(workdir, self.context, self._zinc_utils) # The ivy confs for which we're building. self._confs = context.config.getlist('scala-compile', 'confs') # The artifact cache to read from/write to. artifact_cache_spec = context.config.getlist('scala-compile', 'artifact_caches', default=[]) self.setup_artifact_cache(artifact_cache_spec) # If we are compiling scala libraries with circular deps on java libraries we need to make sure # those cycle deps are present. self._inject_java_cycles()
def __init__(self, context): workdir = context.config.get('checkstyle', 'nailgun_dir') NailgunTask.__init__(self, context, workdir=workdir) self._checkstyle_bootstrap_key = 'checkstyle' bootstrap_tools = context.config.getlist('checkstyle', 'bootstrap-tools', default=[':twitter-checkstyle']) self._bootstrap_utils.register_jvm_build_tools(self._checkstyle_bootstrap_key, bootstrap_tools) self._configuration_file = context.config.get('checkstyle', 'configuration') self._work_dir = context.config.get('checkstyle', 'workdir') self._properties = context.config.getdict('checkstyle', 'properties') self._confs = context.config.getlist('checkstyle', 'confs') self.context.products.require_data('exclusives_groups')
def __init__(self, context, output_dir=None, classpath=None, main=None, args=None, confs=None): self._profile = context.config.get('scala-compile', 'profile') workdir = context.config.get('scala-compile', 'nailgun_dir') NailgunTask.__init__(self, context, workdir=workdir) self._compiler_classpath = classpath self._output_dir = output_dir or context.config.get('scala-compile', 'workdir') self._main = main or context.config.get('scala-compile', 'main') self._args = args or context.config.getlist('scala-compile', 'args') if context.options.scala_compile_warnings: self._args.extend(context.config.getlist('scala-compile', 'warning_args')) else: self._args.extend(context.config.getlist('scala-compile', 'no_warning_args')) self._confs = confs or context.config.getlist('scala-compile', 'confs') self._depfile = os.path.join(self._output_dir, 'dependencies')
def __init__(self, context): workdir = context.config.get('checkstyle', 'nailgun_dir') NailgunTask.__init__(self, context, workdir=workdir) self._checkstyle_bootstrap_key = 'checkstyle' bootstrap_tools = context.config.getlist( 'checkstyle', 'bootstrap-tools', default=[':twitter-checkstyle']) self._bootstrap_utils.register_jvm_build_tools( self._checkstyle_bootstrap_key, bootstrap_tools) self._configuration_file = context.config.get('checkstyle', 'configuration') self._work_dir = context.config.get('checkstyle', 'workdir') self._properties = context.config.getdict('checkstyle', 'properties') self._confs = context.config.getlist('checkstyle', 'confs') self.context.products.require_data('exclusives_groups')
def __init__(self, context): NailgunTask.__init__(self, context, workdir=context.config.get("scala-compile", "nailgun_dir")) # Set up the zinc utils. # Command line switch overrides color setting set in pants.ini color = ( context.options.scala_compile_color if context.options.scala_compile_color is not None else context.config.getbool("scala-compile", "color", default=True) ) self._zinc_utils = ZincUtils(context=context, java_runner=self.runjava, color=color) # The rough number of source files to build in each compiler pass. self._partition_size_hint = ( context.options.scala_compile_partition_size_hint if context.options.scala_compile_partition_size_hint != -1 else context.config.getint("scala-compile", "partition_size_hint", default=1000) ) # Set up dep checking if needed. if context.options.scala_check_missing_deps: JvmDependencyCache.init_product_requirements(self) self._opts = context.config.getlist("scala-compile", "args") if context.options.scala_compile_warnings: self._opts.extend(context.config.getlist("scala-compile", "warning_args")) else: self._opts.extend(context.config.getlist("scala-compile", "no_warning_args")) # Various output directories. workdir = context.config.get("scala-compile", "workdir") self._resources_dir = os.path.join(workdir, "resources") self._artifact_factory = ZincArtifactFactory(workdir, self.context, self._zinc_utils) # The ivy confs for which we're building. self._confs = context.config.getlist("scala-compile", "confs") # The artifact cache to read from/write to. artifact_cache_spec = context.config.getlist("scala-compile", "artifact_caches") self.setup_artifact_cache(artifact_cache_spec) # If we are compiling scala libraries with circular deps on java libraries we need to make sure # those cycle deps are present. self._inject_java_cycles()
def __init__(self, context): NailgunTask.__init__(self, context, workdir=context.config.get('java-compile', 'nailgun_dir')) if context.options.java_compile_partition_size_hint != -1: self._partition_size_hint = context.options.java_compile_partition_size_hint else: self._partition_size_hint = context.config.getint('java-compile', 'partition_size_hint', default=1000) workdir = context.config.get('java-compile', 'workdir') self._classes_dir = os.path.join(workdir, 'classes') self._resources_dir = os.path.join(workdir, 'resources') self._depfile_dir = os.path.join(workdir, 'depfiles') self._depfile = os.path.join(self._depfile_dir, 'global_depfile') safe_mkdir(self._classes_dir) safe_mkdir(self._depfile_dir) self._jmake_profile = context.config.get('java-compile', 'jmake-profile') self._compiler_profile = context.config.get('java-compile', 'compiler-profile') self._opts = context.config.getlist('java-compile', 'args') self._jvm_args = context.config.getlist('java-compile', 'jvm_args') self._javac_opts = [] if context.options.java_compile_args: for arg in context.options.java_compile_args: self._javac_opts.extend(shlex.split(arg)) else: self._javac_opts.extend(context.config.getlist('java-compile', 'javac_args', default=[])) if context.options.java_compile_warnings: self._opts.extend(context.config.getlist('java-compile', 'warning_args')) else: self._opts.extend(context.config.getlist('java-compile', 'no_warning_args')) self._confs = context.config.getlist('java-compile', 'confs') self.context.products.require_data('exclusives_groups') artifact_cache_spec = context.config.getlist('java-compile', 'artifact_caches2', default=[]) self.setup_artifact_cache(artifact_cache_spec) # A temporary, but well-known, dir to munge analysis files in before caching. It must be # well-known so we know where to find the files when we retrieve them from the cache. self._depfile_tmpdir = os.path.join(self._depfile_dir, 'depfile_tmpdir')
def __init__(self, context): NailgunTask.__init__(self, context, workdir=context.config.get('java-compile', 'nailgun_dir')) workdir = context.config.get('java-compile', 'workdir') self._classes_dir = os.path.join(workdir, 'classes') self._resources_dir = os.path.join(workdir, 'resources') self._dependencies_file = os.path.join(workdir, 'dependencies') self._jmake_profile = context.config.get('java-compile', 'jmake-profile') self._compiler_profile = context.config.get('java-compile', 'compiler-profile') self._args = context.config.getlist('java-compile', 'args') if context.options.java_compile_warnings: self._args.extend(context.config.getlist('java-compile', 'warning_args')) else: self._args.extend(context.config.getlist('java-compile', 'no_warning_args')) self._confs = context.config.getlist('java-compile', 'confs')
def setup_parser(cls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) flag = mkflag('override') option_group.add_option( flag, action='append', dest='ivy_resolve_overrides', help='''Specifies a jar dependency override in the form: [org]#[name]=(revision|url) For example, to specify 2 overrides: %(flag)s=com.foo#bar=0.1.2 \\ %(flag)s=com.baz#spam=file:///tmp/spam.jar ''' % dict(flag=flag)) report = mkflag("report") option_group.add_option( report, mkflag("report", negate=True), dest="ivy_resolve_report", action="callback", callback=mkflag.set_bool, default=False, help="[%default] Generate an ivy resolve html report") option_group.add_option( mkflag("open"), mkflag("open", negate=True), dest="ivy_resolve_open", default=False, action="callback", callback=mkflag.set_bool, help="[%%default] Attempt to open the generated ivy resolve report " "in a browser (implies %s)." % report) option_group.add_option( mkflag("outdir"), dest="ivy_resolve_outdir", help="Emit ivy report outputs in to this directory.") option_group.add_option(mkflag("cache"), dest="ivy_resolve_cache", help="Use this directory as the ivy cache, instead of the " \ "default specified in pants.ini.")
def setup_parser(subcls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) option_group.add_option( mkflag('missing-deps'), dest=subcls._language + '_missing_deps', choices=['off', 'warn', 'fatal'], # TODO(Benjy): Change to fatal after we iron out all outstanding missing deps. default='warn', help='[%default] One of off, warn, fatal. ' 'Check for missing dependencies in ' + subcls._language + 'code. ' 'Reports actual dependencies A -> B where there is no ' 'transitive BUILD file dependency path from A to B.' 'If fatal, missing deps are treated as a build error.') option_group.add_option( mkflag('missing-direct-deps'), dest=subcls._language + '_missing_direct_deps', choices=['off', 'warn', 'fatal'], default='off', help='[%default] One of off, warn, fatal. ' 'Check for missing direct dependencies in ' + subcls._language + ' code. ' 'Reports actual dependencies A -> B where there is no direct ' 'BUILD file dependency path from A to B. ' 'This is a very strict check, as in practice it is common to rely on ' 'transitive, non-direct dependencies, e.g., due to type inference or when ' 'the main target in a BUILD file is modified to depend on other targets in ' 'the same BUILD file as an implementation detail. It may still be useful ' 'to set it to fatal temorarily, to detect these.') option_group.add_option( mkflag('unnecessary-deps'), dest=subcls._language + '_unnecessary_deps', choices=['off', 'warn', 'fatal'], default='off', help='[%default] One of off, warn, fatal. ' 'Check for declared dependencies in ' + subcls._language + ' code ' 'that are not needed. This is a very strict check. For example, ' 'generated code will often legitimately have BUILD dependencies that ' 'are unused in practice.')
def __init__(self, context, workdir=None): NailgunTask.__init__(self, context, workdir=context.config.get( 'scala-compile', 'nailgun_dir')) # Set up the zinc utils. # Command line switch overrides color setting set in pants.ini color = context.options.scala_compile_color if context.options.scala_compile_color is not None else \ context.config.getbool('scala-compile', 'color', default=True) self._zinc_utils = ZincUtils(context=context, java_runner=self.runjava, color=color) # The rough number of source files to build in each compiler pass. self._partition_size_hint = \ context.options.scala_compile_partition_size_hint \ if context.options.scala_compile_partition_size_hint != -1 else \ context.config.getint('scala-compile', 'partition_size_hint') # Set up dep checking if needed. if context.options.scala_check_missing_deps: JvmDependencyCache.init_product_requirements(self) # Various output directories. self._buildroot = get_buildroot() workdir = context.config.get('scala-compile', 'workdir') if workdir is None else workdir self._resources_dir = os.path.join(workdir, 'resources') self._artifact_factory = ZincArtifactFactory(workdir, self.context, self._zinc_utils) # The ivy confs for which we're building. self._confs = context.config.getlist('scala-compile', 'confs') # The artifact cache to read from/write to. artifact_cache_spec = context.config.getlist('scala-compile', 'artifact_caches') self.setup_artifact_cache(artifact_cache_spec)
def __init__(self, context, confs=None): classpath = context.config.getlist('ivy', 'classpath') nailgun_dir = context.config.get('ivy-resolve', 'nailgun_dir') NailgunTask.__init__(self, context, classpath=classpath, workdir=nailgun_dir) self._cachedir = context.options.ivy_resolve_cache or context.config.get( 'ivy', 'cache_dir') self._confs = confs or context.config.getlist('ivy-resolve', 'confs') self._work_dir = context.config.get('ivy-resolve', 'workdir') self._classpath_dir = os.path.join(self._work_dir, 'mapped') self._outdir = context.options.ivy_resolve_outdir or os.path.join( self._work_dir, 'reports') self._open = context.options.ivy_resolve_open self._report = self._open or context.options.ivy_resolve_report self._ivy_bootstrap_key = 'ivy' ivy_bootstrap_tools = context.config.getlist('ivy-resolve', 'bootstrap-tools', ':xalan') self._bootstrap_utils.register_jvm_build_tools(self._ivy_bootstrap_key, ivy_bootstrap_tools) self._ivy_utils = IvyUtils(config=context.config, options=context.options, log=context.log) context.products.require_data('exclusives_groups') # Typically this should be a local cache only, since classpaths aren't portable. artifact_cache_spec = context.config.getlist('ivy-resolve', 'artifact_caches', default=[]) self.setup_artifact_cache(artifact_cache_spec)
def execute(self, targets): NailgunTask.killall( everywhere=self.context.options.ng_killall_everywhere)
def _run(): """ To add additional paths to sys.path, add a block to the config similar to the following: [main] roots: ['src/python/twitter/pants_internal/test/',] """ version = get_version() if len(sys.argv) == 2 and sys.argv[1] == _VERSION_OPTION: _do_exit(version) root_dir = get_buildroot() if not os.path.exists(root_dir): _exit_and_fail('PANTS_BUILD_ROOT does not point to a valid path: %s' % root_dir) if len(sys.argv) < 2 or (len(sys.argv) == 2 and sys.argv[1] in _HELP_ALIASES): _help(version, root_dir) command_class, command_args = _parse_command(root_dir, sys.argv[1:]) parser = optparse.OptionParser(version=version) RcFile.install_disable_rc_option(parser) parser.add_option(_LOG_EXIT_OPTION, action='store_true', default=False, dest='log_exit', help='Log an exit message on success or failure.') config = Config.load() # TODO: This can be replaced once extensions are enabled with # https://github.com/pantsbuild/pants/issues/5 roots = config.getlist('parse', 'roots', default=[]) sys.path.extend(map(lambda root: os.path.join(root_dir, root), roots)) # XXX(wickman) This should be in the command goal, not un pants_exe.py! run_tracker = RunTracker.from_config(config) report = initial_reporting(config, run_tracker) run_tracker.start(report) url = run_tracker.run_info.get_info('report_url') if url: run_tracker.log(Report.INFO, 'See a report at: %s' % url) else: run_tracker.log(Report.INFO, '(To run a reporting server: ./pants server)') command = command_class(run_tracker, root_dir, parser, command_args) try: if command.serialized(): def onwait(pid): print('Waiting on pants process %s to complete' % _process_info(pid), file=sys.stderr) return True runfile = os.path.join(root_dir, '.pants.run') lock = Lock.acquire(runfile, onwait=onwait) else: lock = Lock.unlocked() try: result = command.run(lock) _do_exit(result) except KeyboardInterrupt: command.cleanup() raise finally: lock.release() finally: run_tracker.end() # Must kill nailguns only after run_tracker.end() is called, because there may still # be pending background work that needs a nailgun. if (hasattr(command.options, 'cleanup_nailguns') and command.options.cleanup_nailguns) \ or config.get('nailgun', 'autokill', default=False): NailgunTask.killall(None)
def setup_parser(subcls, option_group, args, mkflag): NailgunTask.setup_parser(option_group, args, mkflag) option_group.add_option(mkflag('warnings'), mkflag('warnings', negate=True), dest=subcls._language+'_compile_warnings', default=True, action='callback', callback=mkflag.set_bool, help='[%default] Compile with all configured warnings enabled.') option_group.add_option(mkflag('partition-size-hint'), dest=subcls._language+'_partition_size_hint', action='store', type='int', default=-1, help='Roughly how many source files to attempt to compile together. ' 'Set to a large number to compile all sources together. Set this ' 'to 0 to compile target-by-target. Default is set in pants.ini.') option_group.add_option(mkflag('missing-deps'), dest=subcls._language+'_missing_deps', choices=['off', 'warn', 'fatal'], default='warn', help='[%default] One of off, warn, fatal. ' 'Check for missing dependencies in ' + subcls._language + 'code. ' 'Reports actual dependencies A -> B where there is no ' 'transitive BUILD file dependency path from A to B.' 'If fatal, missing deps are treated as a build error.') option_group.add_option(mkflag('missing-direct-deps'), dest=subcls._language+'_missing_direct_deps', choices=['off', 'warn', 'fatal'], default='off', help='[%default] One of off, warn, fatal. ' 'Check for missing direct dependencies in ' + subcls._language + ' code. Reports actual dependencies A -> B where there is no ' 'direct BUILD file dependency path from A to B. This is a very ' 'strict check, as in practice it is common to rely on transitive, ' 'non-direct dependencies, e.g., due to type inference or when the ' 'main target in a BUILD file is modified to depend on other ' 'targets in the same BUILD file as an implementation detail. It ' 'may still be useful to set it to fatal temorarily, to detect ' 'these.') option_group.add_option(mkflag('unnecessary-deps'), dest=subcls._language+'_unnecessary_deps', choices=['off', 'warn', 'fatal'], default='off', help='[%default] One of off, warn, fatal. Check for declared ' 'dependencies in ' + subcls._language + ' code that are not ' 'needed. This is a very strict check. For example, generated code ' 'will often legitimately have BUILD dependencies that are unused ' 'in practice.') option_group.add_option(mkflag('delete-scratch'), mkflag('delete-scratch', negate=True), dest=subcls._language+'_delete_scratch', default=True, action='callback', callback=mkflag.set_bool, help='[%default] Leave intermediate scratch files around, ' 'for debugging build problems.')
def __init__(self, context): classpath = context.config.getlist('ivy', 'classpath') nailgun_dir = context.config.get('ivy-resolve', 'nailgun_dir') NailgunTask.__init__(self, context, classpath=classpath, workdir=nailgun_dir) self._ivy_settings = context.config.get('ivy', 'ivy_settings') self._cachedir = context.config.get('ivy', 'cache_dir') self._confs = context.config.getlist('ivy-resolve', 'confs') self._transitive = context.config.getbool('ivy-resolve', 'transitive') self._args = context.config.getlist('ivy-resolve', 'args') self._profile = context.config.get('ivy-resolve', 'profile') self._template_path = os.path.join('ivy_resolve', 'ivy.mk') self._work_dir = context.config.get('ivy-resolve', 'workdir') self._classpath_file = os.path.join(self._work_dir, 'classpath') self._classpath_dir = os.path.join(self._work_dir, 'mapped') self._outdir = context.options.ivy_resolve_outdir or os.path.join( self._work_dir, 'reports') self._open = context.options.ivy_resolve_open self._report = self._open or context.options.ivy_resolve_report self._ivy_utils = IvyUtils(context, self._cachedir) def parse_override(override): match = re.match(r'^([^#]+)#([^=]+)=([^\s]+)$', override) if not match: raise TaskError('Invalid dependency override: %s' % override) org, name, rev_or_url = match.groups() def fmt_message(message, template): return message % dict( overridden='%s#%s;%s' % (template.org, template.module, template.version), rev=rev_or_url, url=rev_or_url) def replace_rev(template): context.log.info( fmt_message('Overrode %(overridden)s with rev %(rev)s', template)) return template.extend(version=rev_or_url, url=None, force=True) def replace_url(template): context.log.info( fmt_message( 'Overrode %(overridden)s with snapshot at %(url)s', template)) return template.extend(version='SNAPSHOT', url=rev_or_url, force=True) replace = replace_url if re.match(r'^\w+://.+', rev_or_url) else replace_rev return (org, name), replace self._overrides = {} if context.options.ivy_resolve_overrides: self._overrides.update( parse_override(o) for o in context.options.ivy_resolve_overrides)
def cleanup(self): # TODO: Make this more selective? Only kill nailguns that affect state? E.g., checkstyle # may not need to be killed. NailgunTask.killall(log) sys.exit(1)