aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeVersionProperties.java
blob: 5da51a5b41831ff5229264fb2634710f95faf2c6 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// 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;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Strings;

import javax.annotation.Nullable;

/**
 * A tuple containing information about a version of xcode and its properties. 
 */
public class XcodeVersionProperties {
  @VisibleForTesting public static final String DEFAULT_IOS_SDK_VERSION = "8.4";
  @VisibleForTesting public static final String DEFAULT_WATCHOS_SDK_VERSION = "2.0";
  @VisibleForTesting public static final String DEFAULT_MACOSX_SDK_VERSION = "10.10";
  @VisibleForTesting public static final String DEFAULT_TVOS_SDK_VERSION = "1.0";

  private final Optional<DottedVersion> xcodeVersion;
  private final DottedVersion defaultIosSdkVersion;
  private final DottedVersion defaultWatchosSdkVersion;
  private final DottedVersion defaultTvosSdkVersion;
  private final DottedVersion defaultMacosxSdkVersion;

  /**
   * Creates and returns a tuple representing no known xcode property information (defaults are
   * used where applicable).
   */
  // TODO(bazel-team): The xcode version should be a well-defined value, either specified by the
  // user, evaluated on the local system, or set to a sensible default.
  // Unfortunately, until the local system evaluation hook is created, this constraint would break
  // some users.
  public static XcodeVersionProperties unknownXcodeVersionProperties() {
    return new XcodeVersionProperties(null);
  }

  /**
   * Constructor for when only the xcode version is specified, but no property information
   * is specified.
   */
  XcodeVersionProperties(DottedVersion xcodeVersion) {
    this(xcodeVersion, null, null, null, null);
  }

  /**
   * General constructor. Some (nullable) properties may be left unspecified. In these cases,
   * a semi-sensible default will be assigned to the property value. 
   */
  XcodeVersionProperties(DottedVersion xcodeVersion,
      @Nullable String defaultIosSdkVersion,
      @Nullable String defaultWatchosSdkVersion,
      @Nullable String defaultTvosSdkVersion,
      @Nullable String defaultMacosxSdkVersion) {
    this.xcodeVersion = Optional.fromNullable(xcodeVersion);
    this.defaultIosSdkVersion = (Strings.isNullOrEmpty(defaultIosSdkVersion))
        ? DottedVersion.fromString(DEFAULT_IOS_SDK_VERSION)
        : DottedVersion.fromString(defaultIosSdkVersion);
    this.defaultWatchosSdkVersion = (Strings.isNullOrEmpty(defaultWatchosSdkVersion))
        ? DottedVersion.fromString(DEFAULT_WATCHOS_SDK_VERSION)
        : DottedVersion.fromString(defaultWatchosSdkVersion);
    this.defaultTvosSdkVersion = (Strings.isNullOrEmpty(defaultTvosSdkVersion))
        ? DottedVersion.fromString(DEFAULT_TVOS_SDK_VERSION)
        : DottedVersion.fromString(defaultTvosSdkVersion);
    this.defaultMacosxSdkVersion = (Strings.isNullOrEmpty(defaultMacosxSdkVersion))
        ? DottedVersion.fromString(DEFAULT_MACOSX_SDK_VERSION)
        : DottedVersion.fromString(defaultMacosxSdkVersion);
  }

  /**
   * Returns the xcode version, or {@link Optional#absent} if the xcode version is unknown.
   */
  public Optional<DottedVersion> getXcodeVersion() {
    return xcodeVersion;
  }

  /**
   * Returns the default ios sdk version to use if this xcode version is in use.
   */
  public DottedVersion getDefaultIosSdkVersion() {
    return defaultIosSdkVersion;
  }

  /**
   * Returns the default watchos sdk version to use if this xcode version is in use.
   */
  public DottedVersion getDefaultWatchosSdkVersion() {
    return defaultWatchosSdkVersion;
  }

  /**
   * Returns the default tvos sdk version to use if this xcode version is in use.
   */
  public DottedVersion getDefaultTvosSdkVersion() {
    return defaultTvosSdkVersion;
  }
  
  /**
   * Returns the default macosx sdk version to use if this xcode version is in use.
   */
  public DottedVersion getDefaultMacosxSdkVersion() {
    return defaultMacosxSdkVersion;
  }
}