Skip to content

Commit 02b1b78

Browse files
Googlercopybara-github
Googler
authored andcommitted
Normalize various apple cpu flags so it is treated as a set.
See 3a8da92 for why we should normalize. RELNOTES: None. PiperOrigin-RevId: 507505855 Change-Id: Ib430b1dd59b18c1331b98166e6b13a8311821213
1 parent a4269eb commit 02b1b78

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java

+11
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,17 @@ public FragmentOptions getExec() {
518518
return exec;
519519
}
520520

521+
@Override
522+
public AppleCommandLineOptions getNormalized() {
523+
AppleCommandLineOptions result = (AppleCommandLineOptions) clone();
524+
result.catalystCpus = dedupAndSort(result.catalystCpus);
525+
result.iosMultiCpus = dedupAndSort(result.iosMultiCpus);
526+
result.macosCpus = dedupAndSort(result.macosCpus);
527+
result.tvosCpus = dedupAndSort(result.tvosCpus);
528+
result.watchosCpus = dedupAndSort(result.watchosCpus);
529+
return result;
530+
}
531+
521532
void serialize(SerializationContext context, CodedOutputStream out)
522533
throws IOException, SerializationException {
523534
context.serialize(this, out);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2023 The Bazel Authors. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.devtools.build.lib.rules.apple;
16+
17+
import com.google.devtools.build.lib.analysis.util.OptionsTestCase;
18+
import org.junit.Test;
19+
import org.junit.runner.RunWith;
20+
import org.junit.runners.JUnit4;
21+
22+
@RunWith(JUnit4.class)
23+
public final class AppleCommandLineOptionsTest extends OptionsTestCase<AppleCommandLineOptions> {
24+
25+
private static final String IOS_CPUS_PREFIX = "--ios_multi_cpus=";
26+
private static final String WATCHOS_CPUS_PREFIX = "--watchos_cpus=";
27+
private static final String MACOS_CPUS_PREFIX = "--macos_cpus=";
28+
private static final String TVOS_CPUS_PREFIX = "--tvos_cpus=";
29+
private static final String CATALYST_CPUS_PREFIX = "--catalyst_cpus=";
30+
31+
@Override
32+
protected Class<AppleCommandLineOptions> getOptionsClass() {
33+
return AppleCommandLineOptions.class;
34+
}
35+
36+
@Test
37+
public void testIosCpus_ordering() throws Exception {
38+
AppleCommandLineOptions one = createWithPrefix(IOS_CPUS_PREFIX, "foo", "bar");
39+
AppleCommandLineOptions two = createWithPrefix(IOS_CPUS_PREFIX, "bar", "foo");
40+
assertSame(one, two);
41+
}
42+
43+
@Test
44+
public void testIosCpus_duplicates() throws Exception {
45+
AppleCommandLineOptions one = createWithPrefix(IOS_CPUS_PREFIX, "foo", "foo");
46+
AppleCommandLineOptions two = createWithPrefix(IOS_CPUS_PREFIX, "foo");
47+
assertSame(one, two);
48+
}
49+
50+
@Test
51+
public void testWatchosCpus_ordering() throws Exception {
52+
AppleCommandLineOptions one = createWithPrefix(WATCHOS_CPUS_PREFIX, "foo", "bar");
53+
AppleCommandLineOptions two = createWithPrefix(WATCHOS_CPUS_PREFIX, "bar", "foo");
54+
assertSame(one, two);
55+
}
56+
57+
@Test
58+
public void testWatchosCpus_duplicates() throws Exception {
59+
AppleCommandLineOptions one = createWithPrefix(WATCHOS_CPUS_PREFIX, "foo", "foo");
60+
AppleCommandLineOptions two = createWithPrefix(WATCHOS_CPUS_PREFIX, "foo");
61+
assertSame(one, two);
62+
}
63+
64+
@Test
65+
public void testMacosCpus_ordering() throws Exception {
66+
AppleCommandLineOptions one = createWithPrefix(MACOS_CPUS_PREFIX, "foo", "bar");
67+
AppleCommandLineOptions two = createWithPrefix(MACOS_CPUS_PREFIX, "bar", "foo");
68+
assertSame(one, two);
69+
}
70+
71+
@Test
72+
public void testMacosCpus_duplicates() throws Exception {
73+
AppleCommandLineOptions one = createWithPrefix(MACOS_CPUS_PREFIX, "foo", "foo");
74+
AppleCommandLineOptions two = createWithPrefix(MACOS_CPUS_PREFIX, "foo");
75+
assertSame(one, two);
76+
}
77+
78+
@Test
79+
public void testTvosCpus_ordering() throws Exception {
80+
AppleCommandLineOptions one = createWithPrefix(TVOS_CPUS_PREFIX, "foo", "bar");
81+
AppleCommandLineOptions two = createWithPrefix(TVOS_CPUS_PREFIX, "bar", "foo");
82+
assertSame(one, two);
83+
}
84+
85+
@Test
86+
public void testTvosCpus_duplicates() throws Exception {
87+
AppleCommandLineOptions one = createWithPrefix(TVOS_CPUS_PREFIX, "foo", "foo");
88+
AppleCommandLineOptions two = createWithPrefix(TVOS_CPUS_PREFIX, "foo");
89+
assertSame(one, two);
90+
}
91+
92+
@Test
93+
public void testCatalystCpus_ordering() throws Exception {
94+
AppleCommandLineOptions one = createWithPrefix(CATALYST_CPUS_PREFIX, "foo", "bar");
95+
AppleCommandLineOptions two = createWithPrefix(CATALYST_CPUS_PREFIX, "bar", "foo");
96+
assertSame(one, two);
97+
}
98+
99+
@Test
100+
public void testCatalystCpus_duplicates() throws Exception {
101+
AppleCommandLineOptions one = createWithPrefix(CATALYST_CPUS_PREFIX, "foo", "foo");
102+
AppleCommandLineOptions two = createWithPrefix(CATALYST_CPUS_PREFIX, "foo");
103+
assertSame(one, two);
104+
}
105+
}

0 commit comments

Comments
 (0)