// Copyright 2015 The Bazel Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.google.devtools.build.lib.rules.objc; import com.google.common.base.Joiner; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.analysis.config.BuildConfiguration.Fragment; import com.google.devtools.build.lib.analysis.config.BuildOptions; import com.google.devtools.build.lib.analysis.config.ConfigurationEnvironment; import com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory; import com.google.devtools.build.lib.analysis.config.FragmentOptions; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; import java.util.Collections; import java.util.List; /** * A J2ObjC transpiler configuration fragment containing J2ObjC translation flags. * This configuration fragment is used by Java rules that can be transpiled * (specifically, J2ObjCAspects thereof). */ @Immutable public class J2ObjcConfiguration extends Fragment { /** * Always-on flags for J2ObjC translation. These flags are always used when invoking the J2ObjC * transpiler, and cannot be overriden by user-specified flags in {@link * J2ObjcCommandLineOptions}. See http://j2objc.org/docs/j2objc.html for flag documentation. */ private static final ImmutableList J2OBJC_ALWAYS_ON_TRANSLATION_FLAGS = ImmutableList.of( "-encoding", "UTF-8", "--doc-comments", "-XcombineJars"); /** * Default flags for J2ObjC translation. These flags are used by default when invoking the J2ObjC * transpiler, but can be overriden by user-specified flags in {@link J2ObjcCommandLineOptions}. * See http://j2objc.org/docs/j2objc.html for flag documentation. */ private static final ImmutableList J2OBJC_DEFAULT_TRANSLATION_FLAGS = ImmutableList.of("-g"); /** * Disallowed flags for J2ObjC translation. See http://j2objc.org/docs/j2objc.html for flag * documentation. */ static final ImmutableList J2OBJC_BLACKLISTED_TRANSLATION_FLAGS = ImmutableList.of("--prefixes", "--prefix", "-x"); static final String INVALID_TRANSLATION_FLAGS_MSG_TEMPLATE = "J2Objc translation flags: %s not supported. Unsupported flags are: %s"; /** * Configuration loader for {@link J2ObjcConfiguration}. */ public static class Loader implements ConfigurationFragmentFactory { @Override public Fragment create(ConfigurationEnvironment env, BuildOptions buildOptions) { return new J2ObjcConfiguration(buildOptions.get(J2ObjcCommandLineOptions.class)); } @Override public Class creates() { return J2ObjcConfiguration.class; } @Override public ImmutableSet> requiredOptions() { return ImmutableSet.>of(J2ObjcCommandLineOptions.class); } } private final List translationFlags; private final boolean removeDeadCode; private final boolean experimentalJ2ObjcHeaderMap; private final Optional