From ece8d5fc1adbbb924122b9f1201a877839da2d27 Mon Sep 17 00:00:00 2001 From: plf Date: Wed, 20 Jun 2018 04:14:38 -0700 Subject: C++: Re-writes cc_import in Skylark. I will put cc_import.bzl in Bazel in a follow up CL. RELNOTES:none PiperOrigin-RevId: 201332133 --- .../com/google/devtools/build/lib/rules/cpp/BUILD | 21 +- .../cpp/CcImportBaseConfiguredTargetTest.java | 352 +++++++++++++++++++++ .../rules/cpp/CcImportConfiguredTargetTest.java | 303 +----------------- 3 files changed, 376 insertions(+), 300 deletions(-) create mode 100644 src/test/java/com/google/devtools/build/lib/rules/cpp/CcImportBaseConfiguredTargetTest.java (limited to 'src/test/java/com/google') diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD b/src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD index c3b8be1ac1..035d5eb9a9 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/BUILD @@ -12,7 +12,10 @@ filegroup( java_test( name = "cpp-rules-tests", - srcs = glob(["*.java"]) + ["proto/CcProtoLibraryTest.java"], + srcs = glob( + ["*.java"], + exclude = ["CcImportBaseConfiguredTargetTest.java"], + ) + ["proto/CcProtoLibraryTest.java"], resources = [ "//tools/cpp:crosstool_utils", "//tools/cpp:lib_cc_configure", @@ -20,6 +23,7 @@ java_test( tags = ["rules"], test_class = "com.google.devtools.build.lib.AllTests", deps = [ + ":CcImportBaseConfiguredTargetTest", "//src/main/java/com/google/devtools/build/lib:bazel-main", "//src/main/java/com/google/devtools/build/lib:bazel-rules", "//src/main/java/com/google/devtools/build/lib:build-base", @@ -82,6 +86,21 @@ java_library( ], ) +java_library( + name = "CcImportBaseConfiguredTargetTest", + srcs = ["CcImportBaseConfiguredTargetTest.java"], + deps = [ + "//src/main/java/com/google/devtools/build/lib:build-base", + "//src/main/java/com/google/devtools/build/lib/actions", + "//src/main/java/com/google/devtools/build/lib/rules/cpp", + "//src/test/java/com/google/devtools/build/lib:actions_testutil", + "//src/test/java/com/google/devtools/build/lib:analysis_testutil", + "//src/test/java/com/google/devtools/build/lib:packages_testutil", + "//third_party:junit4", + "//third_party:truth", + ], +) + test_suite( name = "windows_tests", tags = [ diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcImportBaseConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcImportBaseConfiguredTargetTest.java new file mode 100644 index 0000000000..548bf8e09f --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcImportBaseConfiguredTargetTest.java @@ -0,0 +1,352 @@ +// Copyright 2015 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. +// Copyright 2006 Google Inc. All rights reserved. + +package com.google.devtools.build.lib.rules.cpp; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; +import com.google.devtools.build.lib.analysis.util.AnalysisMock; +import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; +import com.google.devtools.build.lib.packages.util.MockCcSupport; +import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** "White-box" unit test of cc_import rule. */ +@RunWith(JUnit4.class) +public abstract class CcImportBaseConfiguredTargetTest extends BuildViewTestCase { + protected String skylarkImplementationLoadStatement = ""; + + @Before + public void setSkylarkImplementationLoadStatement() { + setIsSkylarkImplementation(); + } + + protected abstract void setIsSkylarkImplementation(); + + @Test + public void testCcImportRule() throws Exception { + scratch.file( + "third_party/BUILD", + skylarkImplementationLoadStatement, + "cc_import(", + " name = 'a_import',", + " static_library = 'A.a',", + " shared_library = 'A.so',", + " interface_library = 'A.ifso',", + " hdrs = ['a.h'],", + " alwayslink = 1,", + " system_provided = 0,", + ")"); + getConfiguredTarget("//third_party:a_import"); + } + + @Test + public void testWrongCcImportDefinitions() throws Exception { + checkError( + "a", + "foo", + "does not produce any cc_import static_library files " + "(expected .a, .lib or .pic.a)", + skylarkImplementationLoadStatement, + "cc_import(", + " name = 'foo',", + " static_library = 'libfoo.so',", + ")"); + checkError( + "b", + "foo", + "does not produce any cc_import shared_library files (expected .so, .dylib or .dll)", + skylarkImplementationLoadStatement, + "cc_import(", + " name = 'foo',", + " shared_library = 'libfoo.a',", + ")"); + checkError( + "c", + "foo", + "does not produce any cc_import interface_library files " + + "(expected .ifso, .tbd, .lib, .so or .dylib)", + skylarkImplementationLoadStatement, + "cc_import(", + " name = 'foo',", + " shared_library = 'libfoo.dll',", + " interface_library = 'libfoo.a',", + ")"); + checkError( + "d", + "foo", + "'shared_library' shouldn't be specified when 'system_provided' is true", + skylarkImplementationLoadStatement, + "cc_import(", + " name = 'foo',", + " shared_library = 'libfoo.so',", + " system_provided = 1,", + ")"); + checkError( + "e", + "foo", + "'shared_library' should be specified when 'system_provided' is false", + skylarkImplementationLoadStatement, + "cc_import(", + " name = 'foo',", + " interface_library = 'libfoo.ifso',", + " system_provided = 0,", + ")"); + } + + @Test + public void testWrongCcImportDefinitionsOnWindows() throws Exception { + AnalysisMock.get() + .ccSupport() + .setupCrosstool( + mockToolsConfig, + MockCcSupport.COPY_DYNAMIC_LIBRARIES_TO_BINARY_CONFIGURATION, + MockCcSupport.TARGETS_WINDOWS_CONFIGURATION); + useConfiguration(); + checkError( + "a", + "foo", + "'interface library' must be specified when using cc_import for shared library on Windows", + skylarkImplementationLoadStatement, + "cc_import(", + " name = 'foo',", + " shared_library = 'libfoo.dll',", + ")"); + } + + @Test + public void testCcImportWithStaticLibrary() throws Exception { + ConfiguredTarget target = + scratchConfiguredTarget( + "a", + "foo", + skylarkImplementationLoadStatement, + "cc_import(name = 'foo', static_library = 'libfoo.a')"); + Iterable libraries = + LinkerInputs.toNonSolibArtifacts( + target + .get(CcLinkingInfo.PROVIDER) + .getCcLinkParamsStore() + .getCcLinkParams(false, false) + .getLibraries()); + assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); + + libraries = + LinkerInputs.toNonSolibArtifacts( + target + .get(CcLinkingInfo.PROVIDER) + .getCcLinkParamsStore() + .getCcLinkParams(false, true) + .getLibraries()); + assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); + + libraries = + LinkerInputs.toNonSolibArtifacts( + target + .get(CcLinkingInfo.PROVIDER) + .getCcLinkParamsStore() + .getCcLinkParams(true, false) + .getLibraries()); + assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); + + libraries = + LinkerInputs.toNonSolibArtifacts( + target + .get(CcLinkingInfo.PROVIDER) + .getCcLinkParamsStore() + .getCcLinkParams(true, true) + .getLibraries()); + assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); + } + + @Test + public void testCcImportWithSharedLibrary() throws Exception { + useConfiguration("--cpu=k8"); + ConfiguredTarget target = + scratchConfiguredTarget( + "a", + "foo", + skylarkImplementationLoadStatement, + "cc_import(name = 'foo', shared_library = 'libfoo.so')"); + CcLinkParams ccLinkParams = + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, false); + Iterable libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); + Iterable dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); + assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); + assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) + .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); + + ccLinkParams = + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, true); + libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); + dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); + assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); + assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) + .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); + + ccLinkParams = + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, false); + libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); + dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); + assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); + assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) + .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); + + ccLinkParams = + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, true); + libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); + dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); + assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); + assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) + .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); + } + + @Test + public void testCcImportWithInterfaceSharedLibrary() throws Exception { + useConfiguration("--cpu=k8"); + ConfiguredTarget target = + scratchConfiguredTarget( + "b", + "foo", + skylarkImplementationLoadStatement, + "cc_import(name = 'foo', shared_library = 'libfoo.so'," + + " interface_library = 'libfoo.ifso')"); + CcLinkParams ccLinkParams = + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, false); + Iterable libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); + Iterable dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); + assertThat(artifactsToStrings(libraries)).containsExactly("src b/libfoo.ifso"); + assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) + .containsExactly("bin _solib_k8/_U_S_Sb_Cfoo___Ub/libfoo.so"); + + ccLinkParams = + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, true); + libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); + dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); + assertThat(artifactsToStrings(libraries)).containsExactly("src b/libfoo.ifso"); + assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) + .containsExactly("bin _solib_k8/_U_S_Sb_Cfoo___Ub/libfoo.so"); + + ccLinkParams = + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, false); + libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); + dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); + assertThat(artifactsToStrings(libraries)).containsExactly("src b/libfoo.ifso"); + assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) + .containsExactly("bin _solib_k8/_U_S_Sb_Cfoo___Ub/libfoo.so"); + + ccLinkParams = + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, true); + libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); + dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); + assertThat(artifactsToStrings(libraries)).containsExactly("src b/libfoo.ifso"); + assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) + .containsExactly("bin _solib_k8/_U_S_Sb_Cfoo___Ub/libfoo.so"); + } + + @Test + public void testCcImportWithBothStaticAndSharedLibraries() throws Exception { + useConfiguration("--cpu=k8"); + ConfiguredTarget target = + scratchConfiguredTarget( + "a", + "foo", + skylarkImplementationLoadStatement, + "cc_import(name = 'foo', static_library = 'libfoo.a', shared_library = 'libfoo.so')"); + CcLinkParams ccLinkParams = + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, false); + Iterable libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); + Iterable dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); + assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); + assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) + .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); + + ccLinkParams = + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, true); + libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); + dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); + assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); + assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) + .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); + + ccLinkParams = + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, false); + libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); + dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); + assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); + assertThat(artifactsToStrings(dynamicLibrariesForRuntime)).isEmpty(); + + ccLinkParams = + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, true); + libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); + dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); + assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); + assertThat(artifactsToStrings(dynamicLibrariesForRuntime)).isEmpty(); + } + + @Test + public void testCcImportWithAlwaysLinkStaticLibrary() throws Exception { + ConfiguredTarget target = + scratchConfiguredTarget( + "a", + "foo", + skylarkImplementationLoadStatement, + "cc_import(name = 'foo', static_library = 'libfoo.a', alwayslink = 1)"); + LibraryToLink libraryToLink = + target + .get(CcLinkingInfo.PROVIDER) + .getCcLinkParamsStore() + .getCcLinkParams(false, false) + .getLibraries() + .toList() + .get(0); + assertThat(libraryToLink.getArtifactCategory()) + .isEqualTo(ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY); + } + + @Test + public void testCcImportSystemProvidedIsTrue() throws Exception { + ConfiguredTarget target = + scratchConfiguredTarget( + "a", + "foo", + skylarkImplementationLoadStatement, + "cc_import(name = 'foo', interface_library = 'libfoo.ifso', system_provided = 1)"); + CcLinkParams ccLinkParams = + target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, false); + Iterable libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); + Iterable dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); + assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.ifso"); + assertThat(artifactsToStrings(dynamicLibrariesForRuntime)).isEmpty(); + } + + @Test + public void testCcImportProvideHeaderFiles() throws Exception { + Iterable headers = + scratchConfiguredTarget( + "a", + "foo", + skylarkImplementationLoadStatement, + "cc_import(name = 'foo', static_library = 'libfoo.a', hdrs = ['foo.h'])") + .get(CcCompilationInfo.PROVIDER) + .getCcCompilationContext() + .getDeclaredIncludeSrcs(); + assertThat(artifactsToStrings(headers)).containsExactly("src a/foo.h"); + } +} diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcImportConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcImportConfiguredTargetTest.java index 0f6ce9bc9d..938cbea33a 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcImportConfiguredTargetTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcImportConfiguredTargetTest.java @@ -15,307 +15,12 @@ package com.google.devtools.build.lib.rules.cpp; -import static com.google.common.truth.Truth.assertThat; - -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.util.AnalysisMock; -import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; -import com.google.devtools.build.lib.packages.util.MockCcSupport; -import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink; -import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** - * "White-box" unit test of cc_import rule. - */ +/** "White-box" unit test of cc_import rule. */ @RunWith(JUnit4.class) -public class CcImportConfiguredTargetTest extends BuildViewTestCase { - - @Test - public void testCcImportRule() throws Exception { - scratch.file( - "third_party/BUILD", - "cc_import(", - " name = 'a_import',", - " static_library = 'A.a',", - " shared_library = 'A.so',", - " interface_library = 'A.ifso',", - " hdrs = ['a.h'],", - " alwayslink = 1,", - " system_provided = 0,", - ")"); - getConfiguredTarget("//third_party:a_import"); - } - - @Test - public void testWrongCcImportDefinitions() throws Exception { - checkError("a", "foo", - "'//a:libfoo.so' does not produce any cc_import static_library files " - + "(expected .a, .lib or .pic.a)", - "cc_import(", - " name = 'foo',", - " static_library = 'libfoo.so',", - ")" - ); - checkError("b", "foo", - "'//b:libfoo.a' does not produce any cc_import shared_library files " - + "(expected .so, .dylib or .dll)", - "cc_import(", - " name = 'foo',", - " shared_library = 'libfoo.a',", - ")" - ); - checkError( - "c", - "foo", - "'//c:libfoo.a' does not produce any cc_import interface_library files " - + "(expected .ifso, .tbd, .lib, .so or .dylib)", - "cc_import(", - " name = 'foo',", - " shared_library = 'libfoo.dll',", - " interface_library = 'libfoo.a',", - ")"); - checkError("d", "foo", - "'shared_library' shouldn't be specified when 'system_provided' is true", - "cc_import(", - " name = 'foo',", - " shared_library = 'libfoo.so',", - " system_provided = 1,", - ")" - ); - checkError("e", "foo", - "'shared_library' should be specified when 'system_provided' is false", - "cc_import(", - " name = 'foo',", - " interface_library = 'libfoo.ifso',", - " system_provided = 0,", - ")" - ); - } - - @Test - public void testWrongCcImportDefinitionsOnWindows() throws Exception { - AnalysisMock.get() - .ccSupport() - .setupCrosstool( - mockToolsConfig, - MockCcSupport.COPY_DYNAMIC_LIBRARIES_TO_BINARY_CONFIGURATION, - MockCcSupport.TARGETS_WINDOWS_CONFIGURATION); - useConfiguration(); - checkError("a", "foo", - "'interface library' must be specified when using cc_import for shared library on Windows", - "cc_import(", - " name = 'foo',", - " shared_library = 'libfoo.dll',", - ")" - ); - } - - @Test - public void testCcImportWithStaticLibrary() throws Exception { - ConfiguredTarget target = - scratchConfiguredTarget("a", "foo", "cc_import(name = 'foo', static_library = 'libfoo.a')"); - Iterable libraries = - LinkerInputs.toNonSolibArtifacts( - target - .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsStore() - .getCcLinkParams(false, false) - .getLibraries()); - assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); - - libraries = - LinkerInputs.toNonSolibArtifacts( - target - .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsStore() - .getCcLinkParams(false, true) - .getLibraries()); - assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); - - libraries = - LinkerInputs.toNonSolibArtifacts( - target - .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsStore() - .getCcLinkParams(true, false) - .getLibraries()); - assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); - - libraries = - LinkerInputs.toNonSolibArtifacts( - target - .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsStore() - .getCcLinkParams(true, true) - .getLibraries()); - assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); - } - - @Test - public void testCcImportWithSharedLibrary() throws Exception { - useConfiguration("--cpu=k8"); - ConfiguredTarget target = - scratchConfiguredTarget( - "a", "foo", "cc_import(name = 'foo', shared_library = 'libfoo.so')"); - CcLinkParams ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, false); - Iterable libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); - Iterable dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); - assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); - assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) - .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); - - ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, true); - libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); - dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); - assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); - assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) - .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); - - ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, false); - libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); - dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); - assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); - assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) - .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); - - ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, true); - libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); - dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); - assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); - assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) - .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); - } - - @Test - public void testCcImportWithInterfaceSharedLibrary() throws Exception { - useConfiguration("--cpu=k8"); - ConfiguredTarget target = - scratchConfiguredTarget( - "b", - "foo", - "cc_import(name = 'foo', shared_library = 'libfoo.so'," - + " interface_library = 'libfoo.ifso')"); - CcLinkParams ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, false); - Iterable libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); - Iterable dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); - assertThat(artifactsToStrings(libraries)).containsExactly("src b/libfoo.ifso"); - assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) - .containsExactly("bin _solib_k8/_U_S_Sb_Cfoo___Ub/libfoo.so"); - - ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, true); - libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); - dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); - assertThat(artifactsToStrings(libraries)).containsExactly("src b/libfoo.ifso"); - assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) - .containsExactly("bin _solib_k8/_U_S_Sb_Cfoo___Ub/libfoo.so"); - - ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, false); - libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); - dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); - assertThat(artifactsToStrings(libraries)).containsExactly("src b/libfoo.ifso"); - assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) - .containsExactly("bin _solib_k8/_U_S_Sb_Cfoo___Ub/libfoo.so"); - - ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, true); - libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); - dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); - assertThat(artifactsToStrings(libraries)).containsExactly("src b/libfoo.ifso"); - assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) - .containsExactly("bin _solib_k8/_U_S_Sb_Cfoo___Ub/libfoo.so"); - } - - @Test - public void testCcImportWithBothStaticAndSharedLibraries() throws Exception { - useConfiguration("--cpu=k8"); - ConfiguredTarget target = - scratchConfiguredTarget( - "a", - "foo", - "cc_import(name = 'foo', static_library = 'libfoo.a', shared_library = 'libfoo.so')"); - CcLinkParams ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, false); - Iterable libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); - Iterable dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); - assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); - assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) - .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); - - ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, true); - libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); - dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); - assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.so"); - assertThat(artifactsToStrings(dynamicLibrariesForRuntime)) - .containsExactly("bin _solib_k8/_U_S_Sa_Cfoo___Ua/libfoo.so"); - - ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, false); - libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); - dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); - assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); - assertThat(artifactsToStrings(dynamicLibrariesForRuntime)).isEmpty(); - - ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(true, true); - libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); - dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); - assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.a"); - assertThat(artifactsToStrings(dynamicLibrariesForRuntime)).isEmpty(); - } - - @Test - public void testCcImportWithAlwaysLinkStaticLibrary() throws Exception { - ConfiguredTarget target = - scratchConfiguredTarget( - "a", "foo", "cc_import(name = 'foo', static_library = 'libfoo.a', alwayslink = 1)"); - LibraryToLink libraryToLink = - target - .get(CcLinkingInfo.PROVIDER) - .getCcLinkParamsStore() - .getCcLinkParams(false, false) - .getLibraries() - .toList() - .get(0); - assertThat(libraryToLink.getArtifactCategory()) - .isEqualTo(ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY); - } - - @Test - public void testCcImportSystemProvidedIsTrue() throws Exception { - ConfiguredTarget target = - scratchConfiguredTarget( - "a", - "foo", - "cc_import(name = 'foo', interface_library = 'libfoo.ifso', system_provided = 1)"); - CcLinkParams ccLinkParams = - target.get(CcLinkingInfo.PROVIDER).getCcLinkParamsStore().getCcLinkParams(false, false); - Iterable libraries = LinkerInputs.toNonSolibArtifacts(ccLinkParams.getLibraries()); - Iterable dynamicLibrariesForRuntime = ccLinkParams.getDynamicLibrariesForRuntime(); - assertThat(artifactsToStrings(libraries)).containsExactly("src a/libfoo.ifso"); - assertThat(artifactsToStrings(dynamicLibrariesForRuntime)).isEmpty(); - } - - @Test - public void testCcImportProvideHeaderFiles() throws Exception { - Iterable headers = - scratchConfiguredTarget( - "a", - "foo", - "cc_import(name = 'foo', static_library = 'libfoo.a', hdrs = ['foo.h'])") - .get(CcCompilationInfo.PROVIDER) - .getCcCompilationContext() - .getDeclaredIncludeSrcs(); - assertThat(artifactsToStrings(headers)).containsExactly("src a/foo.h"); - } +public class CcImportConfiguredTargetTest extends CcImportBaseConfiguredTargetTest { + @Override + protected void setIsSkylarkImplementation() {} } -- cgit v1.2.3