Java tutorial
/* * Copyright 2017-present Facebook, Inc. * * 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.facebook.buck.cxx; import com.facebook.buck.core.model.Flavor; import com.facebook.buck.core.model.RuleType; import com.facebook.buck.core.toolchain.ToolchainProvider; import com.facebook.buck.cxx.toolchain.CxxBuckConfig; import com.facebook.buck.cxx.toolchain.CxxPlatformsProvider; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSortedSet; import java.util.Optional; public class CxxBinaryImplicitFlavors { private final ToolchainProvider toolchainProvider; private final CxxBuckConfig cxxBuckConfig; public CxxBinaryImplicitFlavors(ToolchainProvider toolchainProvider, CxxBuckConfig cxxBuckConfig) { this.toolchainProvider = toolchainProvider; this.cxxBuckConfig = cxxBuckConfig; } public ImmutableSortedSet<Flavor> addImplicitFlavorsForRuleTypes(ImmutableSortedSet<Flavor> argDefaultFlavors, RuleType... types) { Optional<Flavor> platformFlavor = getCxxPlatformsProvider().getUnresolvedCxxPlatforms() .getFlavor(argDefaultFlavors); for (RuleType type : types) { ImmutableMap<String, Flavor> libraryDefaults = cxxBuckConfig.getDefaultFlavorsForRuleType(type); if (!platformFlavor.isPresent()) { platformFlavor = Optional.ofNullable(libraryDefaults.get(CxxBuckConfig.DEFAULT_FLAVOR_PLATFORM)); } } if (platformFlavor.isPresent()) { return ImmutableSortedSet.of(platformFlavor.get()); } else { // To avoid changing the output path of binaries built without a flavor, // we'll default to no flavor, which implicitly builds the default platform. return ImmutableSortedSet.of(); } } private CxxPlatformsProvider getCxxPlatformsProvider() { return toolchainProvider.getByName(CxxPlatformsProvider.DEFAULT_NAME, CxxPlatformsProvider.class); } }