aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/apple/cpp/AppleCcToolchain.java
blob: b1836b4c7e3b99d23b95dbb505cc4971ce43445d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2016 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.apple.cpp;

import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
import com.google.devtools.build.lib.rules.apple.DottedVersion;
import com.google.devtools.build.lib.rules.apple.Platform;
import com.google.devtools.build.lib.rules.cpp.CcToolchain;

import java.util.Map;

/**
 * Implementation for apple_cc_toolchain rule.
 */
public class AppleCcToolchain extends CcToolchain {

  // TODO(bazel-team): Compute default based on local Xcode instead of hardcoded 7.2.
  private static final DottedVersion DEFAULT_XCODE_VERSION = DottedVersion.fromString("7.2");

  private static final String XCODE_VERSION_KEY = "xcode_version";
  private static final String IOS_SDK_VERSION_KEY = "ios_sdk_version";
  private static final String MACOSX_SDK_VERSION_KEY = "macosx_sdk_version";
  private static final String TVOS_SDK_VERSION_KEY = "appletvos_sdk_version";
  private static final String WATCHOS_SDK_VERSION_KEY = "watchos_sdk_version";

  @Override
  protected Map<String, String> getBuildVariables(RuleContext ruleContext) {
    AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class);
    
    return ImmutableMap.<String, String>builder()
        .put(XCODE_VERSION_KEY,
            appleConfiguration.getXcodeVersion().or(DEFAULT_XCODE_VERSION).toString())
        .put(IOS_SDK_VERSION_KEY,
            appleConfiguration.getSdkVersionForPlatform(Platform.IOS_SIMULATOR).toString())
        .put(MACOSX_SDK_VERSION_KEY,
            appleConfiguration.getSdkVersionForPlatform(Platform.MACOS_X).toString())
        .put(TVOS_SDK_VERSION_KEY,
            appleConfiguration.getSdkVersionForPlatform(Platform.TVOS_SIMULATOR).toString())
        .put(WATCHOS_SDK_VERSION_KEY,
            appleConfiguration.getSdkVersionForPlatform(Platform.WATCHOS_SIMULATOR).toString())
        .build();
  }
}