Skip to content

Commit

Permalink
if --experimental_apple_mandatory_minimum_version is specified, make …
Browse files Browse the repository at this point in the history
…Apple rules only add the minimum version of the OS to the output directory name if the configuration is behind an AppleBinaryTransition, or if a minimum_os flag (such as --ios_minimum_os) is specified on the command line.

This is necessary so that the only time the minimum OS version affects the output directory name is when it's explicitly specified and therefore is accessible without looking at the xcode_config rule.

Progress towards bazelbuild#3424.

RELNOTES: None.
PiperOrigin-RevId: 171641295
  • Loading branch information
lberki authored and hlopko committed Oct 10, 2017
1 parent d8a5753 commit 95ee9cb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,19 @@ public DefaultProvisioningProfileConverter() {
)
public boolean targetUsesAppleCrosstool;

/**
* Returns whether the minimum OS version is explicitly set for the current platform.
*/
public boolean isMinimumOsVersionExplicitlySet() {
switch (applePlatformType) {
case IOS: return iosMinimumOs != null;
case MACOS: return macosMinimumOs != null;
case TVOS: return tvosMinimumOs != null;
case WATCHOS: return watchosMinimumOs != null;
default: throw new IllegalStateException();
}
}

/**
* Returns the architecture implied by these options.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,10 @@ public String getOutputDirectoryName() {
if (!appleSplitCpu.isEmpty()) {
components.add(applePlatformType.toString().toLowerCase());
components.add(appleSplitCpu);
components.add("min" + getMinimumOsForPlatformType(applePlatformType));

if (!isMandatoryMinimumVersion() || options.isMinimumOsVersionExplicitlySet()) {
components.add("min" + getMinimumOsForPlatformType(applePlatformType));
}
}
if (shouldDistinguishOutputDirectory()) {
components.add(configurationDistinguisher.getFileSystemName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.actions.SymlinkAction;
import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher;
import com.google.devtools.build.lib.rules.apple.ApplePlatform;
import com.google.devtools.build.lib.rules.apple.ApplePlatform.PlatformType;
Expand All @@ -37,6 +38,7 @@
import com.google.devtools.build.lib.rules.objc.ObjcCommandLineOptions.ObjcCrosstoolMode;
import com.google.devtools.build.lib.syntax.SkylarkDict;
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -80,6 +82,35 @@ Iterable<String> requiredAttributes(Scratch scratch, String packageDir,
private static final ImmutableSet<String> COCOA_FEATURE_FLAGS =
ImmutableSet.of(COCOA_FRAMEWORK_FLAG);

@Test
public void testOutputDirectoryWithMandatoryMinimumVersion() throws Exception {
scratch.file("a/BUILD",
"apple_binary(name='a', platform_type='ios', deps=['b'], minimum_os_version='7.0')",
"objc_library(name='b', srcs=['b.c'])");

useConfiguration(
"--experimental_apple_mandatory_minimum_version",
"ios_cpus=i386");
ConfiguredTarget a = getConfiguredTarget("//a:a");
ConfiguredTarget b = getDirectPrerequisite(a, "//a:b");

PathFragment aPath = a.getConfiguration().getOutputDirectory(RepositoryName.MAIN).getExecPath();
PathFragment bPath = b.getConfiguration().getOutputDirectory(RepositoryName.MAIN).getExecPath();

assertThat(aPath.getPathString()).doesNotMatch("-min[0-9]");
assertThat(bPath.getPathString()).contains("-min7.0-");
}

@Test
public void testMandatoryMinimumVersionEnforced() throws Exception {
scratch.file("a/BUILD", "apple_binary(name='a', platform_type='ios')");

useConfiguration("--experimental_apple_mandatory_minimum_version");
reporter.removeHandler(failFastHandler);
getConfiguredTarget("//a:a");
assertContainsEvent("This attribute must be explicitly specified");
}

@Test
public void testMandatoryMinimumOsVersionUnset() throws Exception {
RULE_TYPE.scratchTarget(scratch,
Expand Down

0 comments on commit 95ee9cb

Please sign in to comment.