diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java index f990245c9946fe..c33bbd227630d6 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java @@ -518,6 +518,17 @@ public FragmentOptions getExec() { return exec; } + @Override + public AppleCommandLineOptions getNormalized() { + AppleCommandLineOptions result = (AppleCommandLineOptions) clone(); + result.catalystCpus = dedupAndSort(result.catalystCpus); + result.iosMultiCpus = dedupAndSort(result.iosMultiCpus); + result.macosCpus = dedupAndSort(result.macosCpus); + result.tvosCpus = dedupAndSort(result.tvosCpus); + result.watchosCpus = dedupAndSort(result.watchosCpus); + return result; + } + void serialize(SerializationContext context, CodedOutputStream out) throws IOException, SerializationException { context.serialize(this, out); diff --git a/src/test/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptionsTest.java b/src/test/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptionsTest.java new file mode 100644 index 00000000000000..5cfd9aa28c6e42 --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptionsTest.java @@ -0,0 +1,105 @@ +// Copyright 2023 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.devtools.build.lib.analysis.util.OptionsTestCase; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public final class AppleCommandLineOptionsTest extends OptionsTestCase { + + private static final String IOS_CPUS_PREFIX = "--ios_multi_cpus="; + private static final String WATCHOS_CPUS_PREFIX = "--watchos_cpus="; + private static final String MACOS_CPUS_PREFIX = "--macos_cpus="; + private static final String TVOS_CPUS_PREFIX = "--tvos_cpus="; + private static final String CATALYST_CPUS_PREFIX = "--catalyst_cpus="; + + @Override + protected Class getOptionsClass() { + return AppleCommandLineOptions.class; + } + + @Test + public void testIosCpus_ordering() throws Exception { + AppleCommandLineOptions one = createWithPrefix(IOS_CPUS_PREFIX, "foo", "bar"); + AppleCommandLineOptions two = createWithPrefix(IOS_CPUS_PREFIX, "bar", "foo"); + assertSame(one, two); + } + + @Test + public void testIosCpus_duplicates() throws Exception { + AppleCommandLineOptions one = createWithPrefix(IOS_CPUS_PREFIX, "foo", "foo"); + AppleCommandLineOptions two = createWithPrefix(IOS_CPUS_PREFIX, "foo"); + assertSame(one, two); + } + + @Test + public void testWatchosCpus_ordering() throws Exception { + AppleCommandLineOptions one = createWithPrefix(WATCHOS_CPUS_PREFIX, "foo", "bar"); + AppleCommandLineOptions two = createWithPrefix(WATCHOS_CPUS_PREFIX, "bar", "foo"); + assertSame(one, two); + } + + @Test + public void testWatchosCpus_duplicates() throws Exception { + AppleCommandLineOptions one = createWithPrefix(WATCHOS_CPUS_PREFIX, "foo", "foo"); + AppleCommandLineOptions two = createWithPrefix(WATCHOS_CPUS_PREFIX, "foo"); + assertSame(one, two); + } + + @Test + public void testMacosCpus_ordering() throws Exception { + AppleCommandLineOptions one = createWithPrefix(MACOS_CPUS_PREFIX, "foo", "bar"); + AppleCommandLineOptions two = createWithPrefix(MACOS_CPUS_PREFIX, "bar", "foo"); + assertSame(one, two); + } + + @Test + public void testMacosCpus_duplicates() throws Exception { + AppleCommandLineOptions one = createWithPrefix(MACOS_CPUS_PREFIX, "foo", "foo"); + AppleCommandLineOptions two = createWithPrefix(MACOS_CPUS_PREFIX, "foo"); + assertSame(one, two); + } + + @Test + public void testTvosCpus_ordering() throws Exception { + AppleCommandLineOptions one = createWithPrefix(TVOS_CPUS_PREFIX, "foo", "bar"); + AppleCommandLineOptions two = createWithPrefix(TVOS_CPUS_PREFIX, "bar", "foo"); + assertSame(one, two); + } + + @Test + public void testTvosCpus_duplicates() throws Exception { + AppleCommandLineOptions one = createWithPrefix(TVOS_CPUS_PREFIX, "foo", "foo"); + AppleCommandLineOptions two = createWithPrefix(TVOS_CPUS_PREFIX, "foo"); + assertSame(one, two); + } + + @Test + public void testCatalystCpus_ordering() throws Exception { + AppleCommandLineOptions one = createWithPrefix(CATALYST_CPUS_PREFIX, "foo", "bar"); + AppleCommandLineOptions two = createWithPrefix(CATALYST_CPUS_PREFIX, "bar", "foo"); + assertSame(one, two); + } + + @Test + public void testCatalystCpus_duplicates() throws Exception { + AppleCommandLineOptions one = createWithPrefix(CATALYST_CPUS_PREFIX, "foo", "foo"); + AppleCommandLineOptions two = createWithPrefix(CATALYST_CPUS_PREFIX, "foo"); + assertSame(one, two); + } +}