// Copyright 2014 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.cpp; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.analysis.config.BuildConfiguration.LabelConverter; import com.google.devtools.build.lib.analysis.config.CompilationMode; import com.google.devtools.build.lib.analysis.config.FragmentOptions; import com.google.devtools.build.lib.analysis.config.PerLabelOptions; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.rules.cpp.CppConfiguration.DynamicMode; import com.google.devtools.build.lib.rules.cpp.CppConfiguration.StripMode; import com.google.devtools.build.lib.util.OS; import com.google.devtools.common.options.Converter; import com.google.devtools.common.options.EnumConverter; import com.google.devtools.common.options.Option; import com.google.devtools.common.options.OptionDocumentationCategory; import com.google.devtools.common.options.OptionEffectTag; import com.google.devtools.common.options.OptionMetadataTag; import com.google.devtools.common.options.OptionsParsingException; import java.util.LinkedHashSet; import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.Set; /** Command-line options for C++. */ public class CppOptions extends FragmentOptions { /** * Converts a comma-separated list of compilation mode settings to a properly typed List. */ public static class FissionOptionConverter implements Converter> { @Override public List convert(String input) throws OptionsParsingException { ImmutableSet.Builder modes = ImmutableSet.builder(); if (input.equals("yes")) { // Special case: enable all modes. modes.add(CompilationMode.values()); } else if (!input.equals("no")) { // "no" is another special case that disables all modes. CompilationMode.Converter modeConverter = new CompilationMode.Converter(); for (String mode : Splitter.on(',').split(input)) { modes.add(modeConverter.convert(mode)); } } return modes.build().asList(); } @Override public String getTypeDescription() { return "a set of compilation modes"; } } /** * Converter for {@link DynamicMode} */ public static class DynamicModeConverter extends EnumConverter { public DynamicModeConverter() { super(DynamicMode.class, "dynamic mode"); } } /** * Converter for the --strip option. */ public static class StripModeConverter extends EnumConverter { public StripModeConverter() { super(StripMode.class, "strip mode"); } } private static final String LIBC_RELATIVE_LABEL = ":everything"; /** * Converts a String, which is a package label into a label that can be used for a LibcTop object. */ public static class LibcTopLabelConverter implements Converter