def __init__(self, context, options, workdir, analysis_tools,
                 compile_task_name, sources_predicate):
        super(JvmCompileGlobalStrategy,
              self).__init__(context, options, workdir, analysis_tools,
                             compile_task_name, sources_predicate)

        # Various working directories.
        # NB: These are grandfathered in with non-strategy-specific names, but to prevent
        # collisions within the buildcache, strategies should use strategy-specific subdirectories.
        self._analysis_dir = os.path.join(workdir, 'analysis')
        self._classes_dir = os.path.join(workdir, 'classes')

        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._target_sources_dir = os.path.join(workdir, 'target_sources')

        # The rough number of source files to build in each compiler pass.
        self._partition_size_hint = options.partition_size_hint

        # Set up dep checking if needed.
        def munge_flag(flag):
            flag_value = getattr(options, flag, None)
            return None if flag_value == 'off' else flag_value

        check_missing_deps = munge_flag('missing_deps')
        check_missing_direct_deps = munge_flag('missing_direct_deps')
        check_unnecessary_deps = munge_flag('unnecessary_deps')

        if check_missing_deps or check_missing_direct_deps or check_unnecessary_deps:
            target_whitelist = options.missing_deps_whitelist
            # 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, target_whitelist)
        else:
            self._dep_analyzer = None

        # Computed lazily as needed.
        self._upstream_class_to_path = None

        # If non-zero, and we have fewer than this number of locally-changed targets,
        # then we partition them separately, to preserve stability in the face of repeated
        # compilations.
        self._changed_targets_heuristic_limit = options.changed_targets_heuristic_limit

        # Sources (relative to buildroot) present in the last analysis that have since been deleted.
        # Populated in prepare_compile().
        self._deleted_sources = None
Exemple #2
0
    def __init__(self, context, workdir, minimum_version=None, jdk=False):
        # TODO(John Sirois): XXX plumb minimum_version via config or flags
        super(JvmCompile, self).__init__(context,
                                         workdir,
                                         minimum_version=minimum_version,
                                         jdk=jdk)
        concrete_class = type(self)
        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)

        # Global workdir.
        self._pants_workdir = context.config.getdefault('pants_workdir')

        # Various working directories.
        self._classes_dir = os.path.join(self.workdir, 'classes')
        self._resources_dir = os.path.join(self.workdir, 'resources')
        self._analysis_dir = os.path.join(self.workdir, 'analysis')
        self._target_sources_dir = os.path.join(self.workdir, 'target_sources')

        self._delete_scratch = get_lang_specific_option('delete_scratch')

        safe_mkdir(self._classes_dir)
        safe_mkdir(self._analysis_dir)
        safe_mkdir(self._target_sources_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')

        # A temporary, but well-known, dir in which 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')

        # We can't create analysis tools until after construction.
        self._lazy_analysis_tools = None

        # Compiler options.
        self._args = context.config.getlist(config_section, 'args')
        if get_lang_specific_option('compile_warnings'):
            self._args.extend(
                context.config.getlist(config_section, 'warning_args'))
        else:
            self._args.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 options for running the compiler.
        self._jvm_options = context.config.getlist(config_section, 'jvm_args')

        # The ivy confs for which we're building.
        self._confs = context.config.getlist(config_section,
                                             'confs',
                                             default=['default'])

        # Runtime dependencies.
        runtime_deps = context.config.getlist(config_section,
                                              'runtime-deps',
                                              default=[])
        if runtime_deps:
            self._runtime_deps_key = self._language + '-runtime-deps'
            self.register_jvm_tool(self._runtime_deps_key, runtime_deps)
        else:
            self._runtime_deps_key = None

        # 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

        # If non-zero, and we have fewer than this number of locally-changed targets,
        # then we partition them separately, to preserve stability in the face of repeated
        # compilations.
        self._locally_changed_targets_heuristic_limit = context.config.getint(
            config_section, 'locally_changed_targets_heuristic_limit', 0)

        self._class_to_jarfile = None  # Computed lazily as needed.

        self.context.products.require_data('exclusives_groups')
        self.setup_artifact_cache_from_config(config_section=config_section)

        # Sources (relative to buildroot) present in the last analysis that have since been deleted.
        # Populated in prepare_execute().
        self._deleted_sources = None

        # Map of target -> list of sources (relative to buildroot), for all targets in all chunks.
        # Populated in prepare_execute().
        self._sources_by_target = None
Exemple #3
0
    def __init__(self, *args, **kwargs):
        super(JvmCompile, self).__init__(*args, **kwargs)

        # Various working directories.
        self._classes_dir = os.path.join(self.workdir, 'classes')
        self._resources_dir = os.path.join(self.workdir, 'resources')
        self._analysis_dir = os.path.join(self.workdir, 'analysis')
        self._target_sources_dir = os.path.join(self.workdir, 'target_sources')

        self._delete_scratch = self.get_options().delete_scratch

        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')

        # A temporary, but well-known, dir in which 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')

        # We can't create analysis tools until after construction.
        self._lazy_analysis_tools = None

        # The rough number of source files to build in each compiler pass.
        self._partition_size_hint = self.get_options().partition_size_hint

        # JVM options for running the compiler.
        self._jvm_options = self.get_options().jvm_options

        # The ivy confs for which we're building.
        self._confs = self.get_options().confs

        self._args = list(self.get_options().args)
        if self.get_options().warnings:
            self._args.extend(self.get_options().warning_args)
        else:
            self._args.extend(self.get_options().no_warning_args)

        # Set up dep checking if needed.
        def munge_flag(flag):
            flag_value = getattr(self.get_options(), flag, None)
            return None if flag_value == 'off' else flag_value

        check_missing_deps = munge_flag('missing_deps')
        check_missing_direct_deps = munge_flag('missing_direct_deps')
        check_unnecessary_deps = munge_flag('unnecessary_deps')

        if check_missing_deps or check_missing_direct_deps or check_unnecessary_deps:
            target_whitelist = self.get_options().missing_deps_whitelist
            # 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, target_whitelist)
        else:
            self._dep_analyzer = None

        # If non-zero, and we have fewer than this number of locally-changed targets,
        # then we partition them separately, to preserve stability in the face of repeated
        # compilations.
        self._changed_targets_heuristic_limit = self.get_options(
        ).changed_targets_heuristic_limit

        self._upstream_class_to_path = None  # Computed lazily as needed.
        self.setup_artifact_cache()

        # Sources (relative to buildroot) present in the last analysis that have since been deleted.
        # Populated in prepare_execute().
        self._deleted_sources = None

        # Map of target -> list of sources (relative to buildroot), for all targets in all chunks.
        # Populated in prepare_execute().
        self._sources_by_target = None