Skip to content

Commit

Permalink
[gn build] Make ninja check-lld also run LLD's unit tests
Browse files Browse the repository at this point in the history
And add build files for gtest.

With this, the build files for //lld are complete.

Differential Revision: https://reviews.llvm.org/D55838

llvm-svn: 349704
  • Loading branch information
nico committed Dec 20, 2018
1 parent 87b2268 commit a2abcf6
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 2 deletions.
3 changes: 1 addition & 2 deletions llvm/utils/gn/secondary/lld/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ group("test") {
":lit_site_cfg",
":lit_unit_site_cfg",
"//lld/tools/lld:symlinks",
"//lld/unittests",
"//llvm/tools/llc",
"//llvm/tools/llvm-ar:symlinks",
"//llvm/tools/llvm-as",
Expand All @@ -101,8 +102,6 @@ group("test") {
"//llvm/utils/not",
]
testonly = true

# FIXME: Add dep on "//lld/unittests" target once it exists.
}

# This is the action that runs all of lld's tests, check-lld.
Expand Down
7 changes: 7 additions & 0 deletions llvm/utils/gn/secondary/lld/unittests/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
group("unittests") {
deps = [
"DriverTests",
"MachOTests",
]
testonly = true
}
15 changes: 15 additions & 0 deletions llvm/utils/gn/secondary/lld/unittests/DriverTests/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
executable("DriverTests") {
# test/Unit/lit.cfg expects unittests in LLD_BINARY_DIR/unittest
output_dir = target_out_dir

configs += [ "//llvm/utils/gn/build:lld_code" ]
deps = [
"//lld/lib/Driver",
"//lld/lib/ReaderWriter/MachO",
"//llvm/utils/unittest/UnitTestMain",
]
sources = [
"DarwinLdDriverTest.cpp",
]
testonly = true
}
19 changes: 19 additions & 0 deletions llvm/utils/gn/secondary/lld/unittests/MachOTests/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
executable("MachOTests") {
# test/Unit/lit.cfg expects unittests in LLD_BINARY_DIR/unittest
output_dir = target_out_dir

configs += [ "//llvm/utils/gn/build:lld_code" ]
deps = [
"//lld/lib/Driver",
"//lld/lib/ReaderWriter/MachO",
"//lld/lib/ReaderWriter/YAML",
"//llvm/utils/unittest/UnitTestMain",
]
sources = [
"MachONormalizedFileBinaryReaderTests.cpp",
"MachONormalizedFileBinaryWriterTests.cpp",
"MachONormalizedFileToAtomsTests.cpp",
"MachONormalizedFileYAMLTests.cpp",
]
testonly = true
}
40 changes: 40 additions & 0 deletions llvm/utils/gn/secondary/llvm/utils/unittest/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import("//llvm/utils/gn/build/libs/pthread/enable.gni")

# Used to push the gtest include directories to things depending on :googletest.
config("googletest_config") {
include_dirs = [
"googlemock/include",
"googletest/include",
]

# LLVM requires C++11 but gtest doesn't correctly detect the availability
# of C++11 on MSVC, so we force it on.
defines = [
"GTEST_LANG_CXX11",
"GTEST_HAS_TR1_TUPLE=0",
]
if (host_os == "win") {
defines += [ "GTEST_OS_WINDOWS" ]
}
if (!llvm_enable_threads) {
defines += [ "GTEST_HAS_PTHREAD=0" ]
}
defines += [ "GTEST_HAS_RTTI=0" ]
}

static_library("gtest") {
deps = [
"//llvm/lib/Support",
]
include_dirs = [
"googletest", # For including src/gtest.cc
"googlemock", # For including src/gmock.cc
]
public_configs = [ ":googletest_config" ]
configs -= [ "//llvm/utils/gn/build:warn_covered_switch_default" ]
sources = [
"googlemock/src/gmock-all.cc",
"googletest/src/gtest-all.cc",
]
testonly = true
}
25 changes: 25 additions & 0 deletions llvm/utils/gn/secondary/llvm/utils/unittest/UnitTestMain/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
source_set("UnitTestMain") {
deps = [
"//llvm/lib/Support",
]

# Make targets depending on this also depend on gtest, to get the gtest
# include_dir.
public_deps = [
"..:gtest",
]
sources = [
"TestMain.cpp",
]
testonly = true
}

# Nothing depends on this target, but llvm-config expects it to exist when
# it runs with `--link-static --system-libs`, so humor it.
static_library("gtest_main") {
deps = [
":UnitTestMain",
]
complete_static_lib = true
testonly = true
}

0 comments on commit a2abcf6

Please sign in to comment.