diff options
Diffstat (limited to 'src/test')
9 files changed, 264 insertions, 74 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java index 4cc1620711..1b18643978 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java +++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java @@ -478,7 +478,7 @@ public abstract class MockCcSupport { + "artifact_name_pattern {" + " category_name: 'static_library'" + " prefix: 'lib'" - + " extension: '.tweaked.a'" + + " extension: '.lib'" + "}"; public static final String STATIC_LINK_AS_DOT_A_CONFIGURATION = diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java index 32821eec44..f94c047667 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java @@ -45,7 +45,6 @@ import com.google.devtools.build.lib.rules.cpp.transitions.LipoDataTransitionRul import com.google.devtools.build.lib.rules.platform.PlatformRules; import com.google.devtools.build.lib.rules.repository.CoreWorkspaceRules; import com.google.devtools.build.lib.util.FileType; -import com.google.devtools.build.lib.util.OsUtils; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.PathFragment; @@ -134,7 +133,7 @@ public class CcCommonTest extends BuildViewTestCase { public void testEmptyBinary() throws Exception { ConfiguredTarget emptybin = getConfiguredTarget("//empty:emptybinary"); assertThat(baseNamesOf(getFilesToBuild(emptybin))) - .isEqualTo("emptybinary" + OsUtils.executableExtension()); + .isEqualTo("emptybinary"); } private List<String> getCopts(String target) throws Exception { diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java index dd864bc08c..6dfc222072 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java @@ -17,6 +17,7 @@ package com.google.devtools.build.lib.rules.cpp; import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.fail; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; @@ -29,6 +30,7 @@ import com.google.devtools.build.lib.actions.util.ActionsTestUtil; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.OutputGroupInfo; +import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesProvider; import com.google.devtools.build.lib.analysis.util.AnalysisMock; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; @@ -37,6 +39,7 @@ import com.google.devtools.build.lib.packages.util.MockCcSupport; import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData; import com.google.devtools.build.lib.testutil.TestRuleClassProvider; import com.google.devtools.build.lib.util.FileType; +import com.google.devtools.build.lib.util.StringUtil; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig; import com.google.protobuf.TextFormat; @@ -64,15 +67,34 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { @Before public final void createFiles() throws Exception { - scratch.file("hello/BUILD", - "cc_library(name = 'hello',", - " srcs = ['hello.cc'])", - "cc_library(name = 'hello_static',", - " srcs = ['hello.cc'],", - " linkstatic = 1)"); - scratch.file("hello/hello.cc", - "#include <stdio.h>", - "int hello_world() { printf(\"Hello, world!\\n\"); }"); + scratch.file( + "hello/BUILD", + "cc_library(", + " name = 'hello',", + " srcs = ['hello.cc'],", + ")", + "cc_library(", + " name = 'hello_static',", + " srcs = ['hello.cc'],", + " linkstatic = 1,", + ")", + "cc_library(", + " name = 'hello_alwayslink',", + " srcs = ['hello.cc'],", + " alwayslink = 1,", + ")", + "cc_binary(", + " name = 'hello_bin',", + " srcs = ['hello_main.cc'],", + ")"); + scratch.file( + "hello/hello.cc", + "#include <stdio.h>", + "int hello_world() { printf(\"Hello, world!\\n\"); }"); + scratch.file( + "hello/hello_main.cc", + "#include <stdio.h>", + "int main() { printf(\"Hello, world!\\n\"); }"); } private CppCompileAction getCppCompileAction(String label) throws Exception { @@ -100,6 +122,38 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { .isNull(); } + public void checkWrongExtensionInArtifactNamePattern( + String categoryName, ImmutableList<String> correctExtensions) throws Exception { + AnalysisMock.get() + .ccSupport() + .setupCrosstool( + mockToolsConfig, + MockCcSupport.COPY_DYNAMIC_LIBRARIES_TO_BINARY_CONFIGURATION, + MockCcSupport.TARGETS_WINDOWS_CONFIGURATION, + "supports_interface_shared_objects: true", + "artifact_name_pattern {" + + " category_name: '" + + categoryName + + "'" + + " prefix: ''" + + " extension: '.wrong_ext'" + + "}"); + + try { + useConfiguration(); + fail("Should fail"); + } catch (InvalidConfigurationException e) { + assertThat(e) + .hasMessageThat() + .contains( + String.format( + "Unrecognized file extension '.wrong_ext', allowed " + + "extensions are %s, please check artifact_name_pattern configuration for %s " + + "in your CROSSTOOL.", + StringUtil.joinEnglishList(correctExtensions, "or", "'"), categoryName)); + } + } + @Test public void testDefinesAndMakeVariables() throws Exception { ConfiguredTarget l = scratchConfiguredTarget("a", "l", @@ -347,7 +401,7 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { useConfiguration("--features=" + Link.LinkTargetType.STATIC_LIBRARY.getActionName()); ConfiguredTarget hello = getConfiguredTarget("//hello:hello"); Artifact archive = - FileType.filter(getFilesToBuild(hello), FileType.of(".tweaked.a")).iterator().next(); + FileType.filter(getFilesToBuild(hello), FileType.of(".lib")).iterator().next(); CppLinkAction action = (CppLinkAction) getGeneratingAction(archive); @@ -363,12 +417,123 @@ public class CcLibraryConfiguredTargetTest extends BuildViewTestCase { "artifact_name_pattern {" + " category_name: 'object_file'" + " prefix: ''" - + " extension: '.test.o'" + + " extension: '.obj'" + "}"); useConfiguration(); ConfiguredTarget hello = getConfiguredTarget("//hello:hello"); - assertThat(artifactByPath(getFilesToBuild(hello), ".a", ".test.o")).isNotNull(); + assertThat(artifactByPath(getFilesToBuild(hello), ".a", ".obj")).isNotNull(); + } + + @Test + public void testWindowsFileNamePatternsCanBeSpecifiedInToolchain() throws Exception { + AnalysisMock.get() + .ccSupport() + .setupCrosstool( + mockToolsConfig, + MockCcSupport.COPY_DYNAMIC_LIBRARIES_TO_BINARY_CONFIGURATION, + MockCcSupport.TARGETS_WINDOWS_CONFIGURATION, + "needsPic: false", + "supports_interface_shared_objects: true", + "artifact_name_pattern {" + + " category_name: 'object_file'" + + " prefix: ''" + + " extension: '.obj'" + + "}", + "artifact_name_pattern {" + + " category_name: 'static_library'" + + " prefix: ''" + + " extension: '.lib'" + + "}", + "artifact_name_pattern {" + + " category_name: 'alwayslink_static_library'" + + " prefix: ''" + + " extension: '.lo.lib'" + + "}", + "artifact_name_pattern {" + + " category_name: 'executable'" + + " prefix: ''" + + " extension: '.exe'" + + "}", + "artifact_name_pattern {" + + " category_name: 'dynamic_library'" + + " prefix: ''" + + " extension: '.dll'" + + "}", + "artifact_name_pattern {" + + " category_name: 'interface_library'" + + " prefix: ''" + + " extension: '.if.lib'" + + "}"); + + useConfiguration(); + + ConfiguredTarget hello = getConfiguredTarget("//hello:hello"); + Artifact helloObj = getBinArtifact("_objs/hello/hello/hello.obj", "//hello:hello"); + CppCompileAction helloObjAction = (CppCompileAction) getGeneratingAction(helloObj); + assertThat(helloObjAction).isNotNull(); + + Artifact helloLib = + FileType.filter(getFilesToBuild(hello), CppFileTypes.ARCHIVE).iterator().next(); + assertThat(helloLib.getExecPathString()).endsWith("hello.lib"); + + ConfiguredTarget helloAlwaysLink = getConfiguredTarget("//hello:hello_alwayslink"); + Artifact helloLibAlwaysLink = + FileType.filter(getFilesToBuild(helloAlwaysLink), CppFileTypes.ALWAYS_LINK_LIBRARY) + .iterator() + .next(); + assertThat(helloLibAlwaysLink.getExecPathString()).endsWith("hello_alwayslink.lo.lib"); + + ConfiguredTarget helloBin = getConfiguredTarget("//hello:hello_bin"); + Artifact helloBinExe = getFilesToBuild(helloBin).iterator().next(); + assertThat(helloBinExe.getExecPathString()).endsWith("hello_bin.exe"); + + assertThat( + artifactsToStrings( + getOutputGroup(hello, CcLinkingHelper.DYNAMIC_LIBRARY_OUTPUT_GROUP_NAME))) + .containsExactly("bin hello/hello.dll", "bin hello/hello.if.lib"); + } + + @Test + public void testWrongObjectFileArtifactNamePattern() throws Exception { + checkWrongExtensionInArtifactNamePattern( + "object_file", + ArtifactCategory.OBJECT_FILE.getAllowedExtensions()); + } + + @Test + public void testWrongStaticLibraryArtifactNamePattern() throws Exception { + checkWrongExtensionInArtifactNamePattern( + "static_library", + ArtifactCategory.STATIC_LIBRARY.getAllowedExtensions()); + } + + @Test + public void testWrongAlwayslinkStaticLibraryArtifactNamePattern() throws Exception { + checkWrongExtensionInArtifactNamePattern( + "alwayslink_static_library", + ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY.getAllowedExtensions()); + } + + @Test + public void testWrongExecutableArtifactNamePattern() throws Exception { + checkWrongExtensionInArtifactNamePattern( + "executable", + ArtifactCategory.EXECUTABLE.getAllowedExtensions()); + } + + @Test + public void testWrongDynamicLibraryArtifactNamePattern() throws Exception { + checkWrongExtensionInArtifactNamePattern( + "dynamic_library", + ArtifactCategory.DYNAMIC_LIBRARY.getAllowedExtensions()); + } + + @Test + public void testWrongInterfaceLibraryArtifactNamePattern() throws Exception { + checkWrongExtensionInArtifactNamePattern( + "interface_library", + ArtifactCategory.INTERFACE_LIBRARY.getAllowedExtensions()); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java index a780425d10..f8c29e00e8 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java @@ -1742,7 +1742,7 @@ public class CcToolchainFeaturesTest extends FoundationTestCase { "artifact_name_pattern {", "category_name: 'static_library'", "prefix: 'foo'", - "extension: 'bar'}"); + "extension: '.a'}"); toolchainFeatures.getArtifactNameForCategory(ArtifactCategory.DYNAMIC_LIBRARY, "output_name"); fail("Should throw InvalidConfigurationException."); } catch (InvalidConfigurationException e) { @@ -1754,4 +1754,32 @@ public class CcToolchainFeaturesTest extends FoundationTestCase { ArtifactCategory.DYNAMIC_LIBRARY.toString().toLowerCase())); } } + + @Test + public void testGetArtifactNameExtensionForCategory() throws Exception { + CcToolchainFeatures toolchainFeatures = + buildFeatures( + "artifact_name_pattern {", + " category_name: 'object_file'", + " prefix: ''", + " extension: '.obj'", + "}", + "artifact_name_pattern {", + " category_name: 'executable'", + " prefix: ''", + " extension: ''", + "}", + "artifact_name_pattern {", + " category_name: 'static_library'", + " prefix: ''", + " extension: '.a'", + "}"); + assertThat(toolchainFeatures.getArtifactNameExtensionForCategory(ArtifactCategory.OBJECT_FILE)) + .isEqualTo(".obj"); + assertThat(toolchainFeatures.getArtifactNameExtensionForCategory(ArtifactCategory.EXECUTABLE)) + .isEmpty(); + assertThat( + toolchainFeatures.getArtifactNameExtensionForCategory(ArtifactCategory.STATIC_LIBRARY)) + .isEqualTo(".a"); + } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java index fda3b53507..4c3680d974 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java @@ -53,7 +53,6 @@ import com.google.devtools.build.lib.rules.cpp.Link.LinkerOrArchiver; import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink; import com.google.devtools.build.lib.testutil.TestUtils; import com.google.devtools.build.lib.util.OS; -import com.google.devtools.build.lib.util.OsUtils; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.Path; @@ -179,8 +178,7 @@ public class CppLinkActionTest extends BuildViewTestCase { scratch.file("x/some-other-dir/qux.so"); ConfiguredTarget configuredTarget = getConfiguredTarget("//x:foo"); - CppLinkAction linkAction = (CppLinkAction) getGeneratingAction(configuredTarget, "x/foo" - + OsUtils.executableExtension()); + CppLinkAction linkAction = (CppLinkAction) getGeneratingAction(configuredTarget, "x/foo"); List<String> arguments = linkAction.getLinkCommandLine().arguments(); @@ -206,7 +204,7 @@ public class CppLinkActionTest extends BuildViewTestCase { ConfiguredTarget configuredTarget = getConfiguredTarget("//x:foo"); CppLinkAction linkAction = (CppLinkAction) - getGeneratingAction(configuredTarget, "x/foo" + OsUtils.executableExtension()); + getGeneratingAction(configuredTarget, "x/foo"); Iterable<? extends VariableValue> runtimeLibrarySearchDirectories = linkAction @@ -238,9 +236,8 @@ public class CppLinkActionTest extends BuildViewTestCase { ConfiguredTarget configuredTarget = getConfiguredTarget("//x:a"); String cpu = CrosstoolConfigurationHelper.defaultCpu(); - String extension = OsUtils.executableExtension(); CppLinkAction linkAction = - (CppLinkAction) getGeneratingAction(configuredTarget, "x/a" + extension); + (CppLinkAction) getGeneratingAction(configuredTarget, "x/a"); assertThat(artifactsToStrings(linkAction.getInputs())) .contains("bin _solib_" + cpu + "/libx_Sliba.ifso"); assertThat(linkAction.getArguments()) @@ -251,7 +248,7 @@ public class CppLinkActionTest extends BuildViewTestCase { .contains("bin _solib_" + cpu + "/libx_Sliba.so"); configuredTarget = getConfiguredTarget("//x:b"); - linkAction = (CppLinkAction) getGeneratingAction(configuredTarget, "x/b" + extension); + linkAction = (CppLinkAction) getGeneratingAction(configuredTarget, "x/b"); assertThat(artifactsToStrings(linkAction.getInputs())).contains("bin x/_objs/b/x/a.pic.o"); runfilesProvider = configuredTarget.getProvider(RunfilesProvider.class); assertThat(artifactsToStrings(runfilesProvider.getDefaultRunfiles().getArtifacts())) @@ -809,7 +806,7 @@ public class CppLinkActionTest extends BuildViewTestCase { for (LinkTargetType linkType : targetTypesToTest) { scratch.deleteFile("dummyRuleContext/BUILD"); - Artifact output = scratchArtifact("output." + linkType.getExtension()); + Artifact output = scratchArtifact("output." + linkType.getDefaultExtension()); CppLinkActionBuilder builder = createLinkBuilder( diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java index bc463b09ab..874bf638a0 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java @@ -25,7 +25,6 @@ import com.google.devtools.build.lib.packages.util.MockCcSupport; import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables.LibraryToLinkValue; import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables.VariableValue; import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType; -import com.google.devtools.build.lib.util.OsUtils; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; @@ -106,7 +105,7 @@ public class LinkBuildVariablesTest extends LinkBuildVariablesTestCase { CcToolchainVariables variables = getLinkBuildVariables(target, Link.LinkTargetType.EXECUTABLE); String variableValue = getVariableValue(variables, LinkBuildVariables.LINKER_PARAM_FILE.getVariableName()); - assertThat(variableValue).matches(".*bin/x/bin" + OsUtils.executableExtension() + "-2.params$"); + assertThat(variableValue).matches(".*bin/x/bin" + "-2.params$"); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoLangToolchainTest.java b/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoLangToolchainTest.java index 5bc6ce32ae..262cb7de5d 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoLangToolchainTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoLangToolchainTest.java @@ -22,7 +22,6 @@ import com.google.common.eventbus.EventBus; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; import com.google.devtools.build.lib.cmdline.Label; -import com.google.devtools.build.lib.util.OsUtils; import org.junit.Test; import org.junit.runner.RunWith; @@ -56,7 +55,7 @@ public class ProtoLangToolchainTest extends BuildViewTestCase { assertThat(toolchain.commandLine()).isEqualTo("cmd-line"); assertThat(toolchain.pluginExecutable().getExecutable().getRootRelativePathString()) - .isEqualTo("x/plugin" + OsUtils.executableExtension()); + .isEqualTo("x/plugin"); TransitiveInfoCollection runtimes = toolchain.runtime(); assertThat(runtimes.getLabel()).isEqualTo(Label.parseAbsolute("//x:runtime")); diff --git a/src/test/py/bazel/bazel_windows_cpp_test.py b/src/test/py/bazel/bazel_windows_cpp_test.py index 71d8231dc2..1b85d5f1df 100644 --- a/src/test/py/bazel/bazel_windows_cpp_test.py +++ b/src/test/py/bazel/bazel_windows_cpp_test.py @@ -140,8 +140,8 @@ class BazelWindowsCppTest(test_base.TestBase): # TODO(pcloudy): change suffixes to .lib and .dll after making DLL # extensions correct on # Windows. - import_library = os.path.join(bazel_bin, 'libA.ifso') - shared_library = os.path.join(bazel_bin, 'libA.so') + import_library = os.path.join(bazel_bin, 'A.if.lib') + shared_library = os.path.join(bazel_bin, 'A.dll') def_file = os.path.join(bazel_bin, 'A.def') self.assertTrue(os.path.exists(import_library)) self.assertTrue(os.path.exists(shared_library)) @@ -161,8 +161,8 @@ class BazelWindowsCppTest(test_base.TestBase): # TODO(pcloudy): change suffixes to .lib and .dll after making DLL # extensions correct on # Windows. - import_library = os.path.join(bazel_bin, 'libB.ifso') - shared_library = os.path.join(bazel_bin, 'libB.so') + import_library = os.path.join(bazel_bin, 'B.if.lib') + shared_library = os.path.join(bazel_bin, 'B.dll') def_file = os.path.join(bazel_bin, 'B.def') self.assertTrue(os.path.exists(import_library)) self.assertTrue(os.path.exists(shared_library)) @@ -176,7 +176,7 @@ class BazelWindowsCppTest(test_base.TestBase): '--features=no_windows_export_all_symbols' ]) self.AssertExitCode(exit_code, 1, stderr) - self.assertIn('output \'libB.ifso\' was not created', ''.join(stderr)) + self.assertIn('output \'B.if.lib\' was not created', ''.join(stderr)) def testBuildCcBinaryWithDependenciesDynamicallyLinked(self): self.createProjectFiles() @@ -191,15 +191,15 @@ class BazelWindowsCppTest(test_base.TestBase): # extensions correct on # Windows. # a_import_library - self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'libA.ifso'))) + self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'A.if.lib'))) # a_shared_library - self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'libA.so'))) + self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'A.dll'))) # a_def_file self.assertFalse(os.path.exists(os.path.join(bazel_bin, 'A.def'))) # b_import_library - self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'libB.ifso'))) + self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'B.if.lib'))) # b_shared_library - self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'libB.so'))) + self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'B.dll'))) # b_def_file self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'B.def'))) # c_exe @@ -220,11 +220,11 @@ class BazelWindowsCppTest(test_base.TestBase): exit_code, _, stderr = self.RunBazel(['build', '//main:main']) self.AssertExitCode(exit_code, 0, stderr) - # Test if libA.so and libB.so are copied to the directory of main.exe + # Test if A.dll and B.dll are copied to the directory of main.exe main_bin = os.path.join(bazel_bin, 'main/main.exe') self.assertTrue(os.path.exists(main_bin)) - self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'main/libA.so'))) - self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'main/libB.so'))) + self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'main/A.dll'))) + self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'main/B.dll'))) # Run the binary to see if it runs successfully exit_code, stdout, stderr = self.RunProgram([main_bin]) @@ -245,12 +245,12 @@ class BazelWindowsCppTest(test_base.TestBase): ]) # //main:main depends on both //lib:A and //:A, - # their dlls are both called libA.so, + # their dlls are both called A.dll, # so there should be a conflict error exit_code, _, stderr = self.RunBazel(['build', '//main:main']) self.AssertExitCode(exit_code, 1, stderr) self.assertIn( - 'ERROR: file \'main/libA.so\' is generated by these conflicting ' + 'ERROR: file \'main/A.dll\' is generated by these conflicting ' 'actions:', ''.join(stderr)) def testBuildDifferentCcBinariesDependOnConflictDLLs(self): @@ -282,7 +282,7 @@ class BazelWindowsCppTest(test_base.TestBase): exit_code, _, stderr = self.RunBazel(['build', '//main:other_main']) self.AssertExitCode(exit_code, 1, stderr) self.assertIn( - 'ERROR: file \'main/libA.so\' is generated by these conflicting ' + 'ERROR: file \'main/A.dll\' is generated by these conflicting ' 'actions:', ''.join(stderr)) def testDynamicLinkingMSVCRT(self): @@ -337,7 +337,7 @@ class BazelWindowsCppTest(test_base.TestBase): 'main/BUILD', [ 'cc_binary(', - ' name = "main.so",', + ' name = "main.dll",', ' srcs = ["main.cc"],', ' deps = ["//:B"],', # Transitively depends on //:A ' linkstatic = 1,' @@ -348,19 +348,19 @@ class BazelWindowsCppTest(test_base.TestBase): bazel_bin = self.getBazelInfo('bazel-bin') exit_code, _, stderr = self.RunBazel([ - 'build', '//main:main.so', '--output_groups=default,interface_library' + 'build', '//main:main.dll', '--output_groups=default,interface_library' ]) self.AssertExitCode(exit_code, 0, stderr) - main_library = os.path.join(bazel_bin, 'main/main.so') - main_interface = os.path.join(bazel_bin, 'main/main.ifso') - def_file = os.path.join(bazel_bin, 'main/main.so.def') + main_library = os.path.join(bazel_bin, 'main/main.dll') + main_interface = os.path.join(bazel_bin, 'main/main.dll.if.lib') + def_file = os.path.join(bazel_bin, 'main/main.dll.def') self.assertTrue(os.path.exists(main_library)) self.assertTrue(os.path.exists(main_interface)) self.assertTrue(os.path.exists(def_file)) - # libA.so and libB.so should not be copied. - self.assertFalse(os.path.exists(os.path.join(bazel_bin, 'main/libA.so'))) - self.assertFalse(os.path.exists(os.path.join(bazel_bin, 'main/libB.so'))) + # A.dll and B.dll should not be copied. + self.assertFalse(os.path.exists(os.path.join(bazel_bin, 'main/A.dll'))) + self.assertFalse(os.path.exists(os.path.join(bazel_bin, 'main/B.dll'))) self.AssertFileContentContains(def_file, 'hello_A') self.AssertFileContentContains(def_file, 'hello_B') self.AssertFileContentContains(def_file, 'hello_C') @@ -371,7 +371,7 @@ class BazelWindowsCppTest(test_base.TestBase): 'main/BUILD', [ 'cc_binary(', - ' name = "main.so",', + ' name = "main.dll",', ' srcs = ["main.cc"],', ' deps = ["//:B"],', # Transitively depends on //:A ' linkstatic = 0,' @@ -382,19 +382,19 @@ class BazelWindowsCppTest(test_base.TestBase): bazel_bin = self.getBazelInfo('bazel-bin') exit_code, _, stderr = self.RunBazel([ - 'build', '//main:main.so', '--output_groups=default,interface_library' + 'build', '//main:main.dll', '--output_groups=default,interface_library' ]) self.AssertExitCode(exit_code, 0, stderr) - main_library = os.path.join(bazel_bin, 'main/main.so') - main_interface = os.path.join(bazel_bin, 'main/main.ifso') - def_file = os.path.join(bazel_bin, 'main/main.so.def') + main_library = os.path.join(bazel_bin, 'main/main.dll') + main_interface = os.path.join(bazel_bin, 'main/main.dll.if.lib') + def_file = os.path.join(bazel_bin, 'main/main.dll.def') self.assertTrue(os.path.exists(main_library)) self.assertTrue(os.path.exists(main_interface)) self.assertTrue(os.path.exists(def_file)) - # libA.so and libB.so should be copied. - self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'main/libA.so'))) - self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'main/libB.so'))) + # A.dll and B.dll should be copied. + self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'main/A.dll'))) + self.assertTrue(os.path.exists(os.path.join(bazel_bin, 'main/B.dll'))) # hello_A and hello_B should not be exported. self.AssertFileContentNotContains(def_file, 'hello_A') self.AssertFileContentNotContains(def_file, 'hello_B') @@ -406,7 +406,7 @@ class BazelWindowsCppTest(test_base.TestBase): 'main/BUILD', [ 'cc_binary(', - ' name = "main.so",', + ' name = "main.dll",', ' srcs = ["main.cc"],', ' deps = ["//:B"],', # Transitively depends on //:A ' linkstatic = 1,' @@ -416,12 +416,12 @@ class BazelWindowsCppTest(test_base.TestBase): bazel_bin = self.getBazelInfo('bazel-bin') exit_code, _, stderr = self.RunBazel( - ['build', '//main:main.so', '--output_groups=def_file']) + ['build', '//main:main.dll', '--output_groups=def_file']) self.AssertExitCode(exit_code, 0, stderr) # Although windows_export_all_symbols is not specified for this target, # we should still be able to get the DEF file by def_file output group. - def_file = os.path.join(bazel_bin, 'main/main.so.def') + def_file = os.path.join(bazel_bin, 'main/main.dll.def') self.assertTrue(os.path.exists(def_file)) self.AssertFileContentContains(def_file, 'hello_A') self.AssertFileContentContains(def_file, 'hello_B') @@ -441,7 +441,6 @@ class BazelWindowsCppTest(test_base.TestBase): self.ScratchFile('WORKSPACE') self.ScratchFile('lib.cc', ['void hello() {}']) self.ScratchFile('my_lib.def', [ - 'LIBRARY liblib.so', 'EXPORTS', ' ?hello@@YAXXZ', ]) @@ -453,7 +452,7 @@ class BazelWindowsCppTest(test_base.TestBase): ')', '', 'cc_binary(', - ' name = "lib.so",', + ' name = "lib_dy.dll",', ' srcs = ["lib.cc"],', ' win_def_file = "my_lib.def",', ' linkshared = 1,', @@ -468,13 +467,13 @@ class BazelWindowsCppTest(test_base.TestBase): ]) bazel_bin = self.getBazelInfo('bazel-bin') - lib_ifso = os.path.join(bazel_bin, 'liblib.ifso') + lib_if = os.path.join(bazel_bin, 'lib.if.lib') lib_def = os.path.join(bazel_bin, 'lib.def') - self.assertTrue(os.path.exists(lib_ifso)) + self.assertTrue(os.path.exists(lib_if)) self.assertFalse(os.path.exists(lib_def)) # Test specifying DEF file in cc_binary - exit_code, _, stderr = self.RunBazel(['build', '//:lib.so', '-s']) + exit_code, _, stderr = self.RunBazel(['build', '//:lib_dy.dll', '-s']) self.AssertExitCode(exit_code, 0, stderr) self.assertIn('/DEF:my_lib.def', ''.join(stderr)) @@ -483,9 +482,9 @@ class BazelWindowsCppTest(test_base.TestBase): self.ScratchFile('BUILD', [ 'cc_import(', ' name = "a_import",', - ' static_library = "A.a",', - ' shared_library = "A.so",', - ' interface_library = "A.ifso",', + ' static_library = "A.lib",', + ' shared_library = "A.dll",', + ' interface_library = "A.if.lib",', ' hdrs = ["a.h"],', ' alwayslink = 1,', ')', diff --git a/src/test/shell/bazel/bazel_windows_example_test.sh b/src/test/shell/bazel/bazel_windows_example_test.sh index b36d30148e..45215dee23 100755 --- a/src/test/shell/bazel/bazel_windows_example_test.sh +++ b/src/test/shell/bazel/bazel_windows_example_test.sh @@ -63,11 +63,15 @@ function assert_binary_run_from_subdir() { # function test_cpp() { local cpp_pkg=examples/cpp - assert_build_output ./bazel-bin/${cpp_pkg}/libhello-lib.a ${cpp_pkg}:hello-world - assert_build_output ./bazel-bin/${cpp_pkg}/hello-world.pdb ${cpp_pkg}:hello-world --output_groups=pdb_file - assert_build_output ./bazel-bin/${cpp_pkg}/hello-world.pdb -c dbg ${cpp_pkg}:hello-world --output_groups=pdb_file + assert_build_output \ + ./bazel-bin/${cpp_pkg}/hello-lib.lib ${cpp_pkg}:hello-world + assert_build_output ./bazel-bin/${cpp_pkg}/hello-world.pdb \ + ${cpp_pkg}:hello-world --output_groups=pdb_file + assert_build_output ./bazel-bin/${cpp_pkg}/hello-world.pdb -c dbg \ + ${cpp_pkg}:hello-world --output_groups=pdb_file assert_build -c opt ${cpp_pkg}:hello-world --output_groups=pdb_file - test -f ./bazel-bin/${cpp_pkg}/hello-world.pdb && fail "PDB file should not be generated in OPT mode" + test -f ./bazel-bin/${cpp_pkg}/hello-world.pdb \ + && fail "PDB file should not be generated in OPT mode" assert_build ${cpp_pkg}:hello-world ./bazel-bin/${cpp_pkg}/hello-world foo >& $TEST_log \ || fail "./bazel-bin/${cpp_pkg}/hello-world foo execution failed" |