Skip to content

Commit

Permalink
Refactor BUILD.gn so can easily be embedded in other projects
Browse files Browse the repository at this point in the history
1.
BUILD.gn: Don't use the extra Chromium clang warnings

Also removes the unused .gn secondary_sources.

2.

Move fuzzers in test/ instead of testing/

This frees up testing/ to be the git subtree of Chromium's src/testing/
that contains test.gni, gtest, gmock and libfuzzer

3.

DEPS: get the whole testing/ subtree of Chromium

4.

BUILD.gn: Simplify the standalone gtest targets

These targets definitions are inspired from ANGLE's and add a variable
that is the path of the googletest directory so that it can be made
overridable in future commits.

6.

BUILD.gn: Add overridable variables for deps dirs

This avoids hardcoded paths to dependencies that make it hard to
integrate SPIRV-Tools in other GN projects.
  • Loading branch information
Kangz authored and dneto0 committed Aug 3, 2018
1 parent c8e7bb1 commit 2d9a325
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 499 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ compile_commands.json
/out
/TAGS
/third_party/llvm-build/
/testing/libfuzzer/
/testing
/tools/clang/
/utils/clang-format-diff.py

Expand Down
2 changes: 1 addition & 1 deletion .gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

buildconfig = "//build/config/BUILDCONFIG.gn"
secondary_source = "//build/secondary/"

default_args = {
clang_use_chrome_plugins = false
use_custom_libcxx = false
}
108 changes: 28 additions & 80 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/spirv_tools.gni")

import("//testing/test.gni")
import("//build_overrides/build.gni")

if (build_with_chromium) {
spirv_headers = "//third_party/spirv-headers/src"
} else {
spirv_headers = "external/spirv-headers"
}
spirv_headers = spirv_tools_spirv_headers_dir

template("spvtools_core_tables") {
assert(defined(invoker.version), "Need version in $target_name generation.")
Expand Down Expand Up @@ -589,86 +587,42 @@ group("SPIRV-Tools") {
}

if (!build_with_chromium) {
static_library("gtest") {
testonly = true

defines = [
# In order to allow regex matches in gtest to be shared between Windows
# and other systems, we tell gtest to always use its internal engine.
"GTEST_HAS_POSIX_RE=0",
googletest_dir = spirv_tools_googletest_dir

# Enables C++11 features.
"GTEST_LANG_CXX11=1",

# Prevents gtest from including both <tr1/tuple> and <tuple>.
"GTEST_HAS_TR1_TUPLE=0",
config("gtest_config") {
include_dirs = [
"${googletest_dir}/googletest",
"${googletest_dir}/googletest/include",
]
}

static_library("gtest") {
testonly = true
sources = [
"external/googletest/googletest/include/gtest/gtest-death-test.h",
"external/googletest/googletest/include/gtest/gtest-message.h",
"external/googletest/googletest/include/gtest/gtest-param-test.h",
"external/googletest/googletest/include/gtest/gtest-printers.h",
"external/googletest/googletest/include/gtest/gtest-spi.h",
"external/googletest/googletest/include/gtest/gtest-test-part.h",
"external/googletest/googletest/include/gtest/gtest-typed-test.h",
"external/googletest/googletest/include/gtest/gtest.h",
"external/googletest/googletest/include/gtest/gtest_pred_impl.h",
"external/googletest/googletest/include/gtest/internal/gtest-death-test-internal.h",
"external/googletest/googletest/include/gtest/internal/gtest-filepath.h",
"external/googletest/googletest/include/gtest/internal/gtest-internal.h",
"external/googletest/googletest/include/gtest/internal/gtest-linked_ptr.h",
"external/googletest/googletest/include/gtest/internal/gtest-param-util-generated.h",
"external/googletest/googletest/include/gtest/internal/gtest-param-util.h",
"external/googletest/googletest/include/gtest/internal/gtest-port.h",
"external/googletest/googletest/include/gtest/internal/gtest-string.h",
"external/googletest/googletest/include/gtest/internal/gtest-tuple.h",
"external/googletest/googletest/include/gtest/internal/gtest-type-util.h",
"external/googletest/googletest/src/gtest-death-test.cc",
"external/googletest/googletest/src/gtest-filepath.cc",
"external/googletest/googletest/src/gtest-internal-inl.h",
"external/googletest/googletest/src/gtest-port.cc",
"external/googletest/googletest/src/gtest-printers.cc",
"external/googletest/googletest/src/gtest-test-part.cc",
"external/googletest/googletest/src/gtest-typed-test.cc",
"external/googletest/googletest/src/gtest.cc",
"${googletest_dir}/googletest/src/gtest-all.cc",
]
public_configs = [ ":gtest_config" ]
}

config("gmock_config") {
include_dirs = [
"external/googletest/googletest/include",
"external/googletest/googletest/",
"${googletest_dir}/googlemock",
"${googletest_dir}/googlemock/include",
"${googletest_dir}/googletest/include",
]

configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
if (is_clang) {
# TODO: Can remove this if/when the issue is fixed.
# https://github.com/google/googletest/issues/533
cflags = [ "-Wno-inconsistent-missing-override" ]
}
}

static_library("gmock") {
testonly = true
sources = [
"external/googletest/googlemock/include/gmock/gmock-actions.h",
"external/googletest/googlemock/include/gmock/gmock-cardinalities.h",
"external/googletest/googlemock/include/gmock/gmock-generated-actions.h",
"external/googletest/googlemock/include/gmock/gmock-generated-function-mockers.h",
"external/googletest/googlemock/include/gmock/gmock-generated-matchers.h",
"external/googletest/googlemock/include/gmock/gmock-generated-nice-strict.h",
"external/googletest/googlemock/include/gmock/gmock-matchers.h",
"external/googletest/googlemock/include/gmock/gmock-spec-builders.h",
"external/googletest/googlemock/include/gmock/gmock.h",
"external/googletest/googlemock/include/gmock/internal/gmock-generated-internal-utils.h",
"external/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h",
"external/googletest/googlemock/include/gmock/internal/gmock-port.h",
"external/googletest/googlemock/src/gmock-cardinalities.cc",
"external/googletest/googlemock/src/gmock-internal-utils.cc",
"external/googletest/googlemock/src/gmock-matchers.cc",
"external/googletest/googlemock/src/gmock-spec-builders.cc",
"external/googletest/googlemock/src/gmock.cc",
]

include_dirs = [
"external/googletest/googletest/include",
"external/googletest/googlemock/include",
"${googletest_dir}/googlemock/src/gmock-all.cc",
]
public_configs = [ ":gmock_config" ]
}
}

Expand Down Expand Up @@ -754,13 +708,7 @@ test("spvtools_test") {
":gmock",
":gtest",
]

sources += [ "external/googletest/googletest/src/gtest_main.cc" ]

include_dirs = [
"external/googletest/googletest/include",
"external/googletest/googlemock/include",
]
sources += [ "${googletest_dir}/googletest/src/gtest_main.cc" ]
}

configs += [
Expand All @@ -769,11 +717,11 @@ test("spvtools_test") {
]
}

if (!build_with_chromium) {
if (spirv_tools_standalone) {
group("fuzzers") {
testonly = true
deps = [
"//testing/fuzzers",
"test/fuzzers",
]
}
}
8 changes: 4 additions & 4 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ vars = {
'clang_revision': 'abe5e4f9dc0f1df848c7a0efa05256253e77a7b7',
'effcee_revision': '04b624799f5a9dbaf3fa1dbed2ba9dce2fc8dcf2',
'googletest_revision': '98a0d007d7092b72eea0e501bb9ad17908a1a036',
'libfuzzer_revision': 'c24c2cd3f4d6130e815b6baff8165e4df440d442',
'testing_revision': '340252637e2e7c72c0901dcbeeacfff419e19b59',
're2_revision': '6cf8ccd82dbaab2668e9b13596c68183c9ecd13f',
'spirv_headers_revision': 'ff684ffc6a35d2a58f0f63108877d0064ea33feb',
}
Expand All @@ -35,9 +35,9 @@ deps = {
'external/re2':
Var('github') + '/google/re2.git@' + Var('re2_revision'),

'testing/libfuzzer':
Var('chromium_git') + '/chromium/src/testing/libfuzzer@' +
Var('libfuzzer_revision'),
'testing':
Var('chromium_git') + '/chromium/src/testing@' +
Var('testing_revision'),

'tools/clang':
Var('chromium_git') + '/chromium/src/tools/clang@' + Var('clang_revision')
Expand Down
25 changes: 25 additions & 0 deletions build_overrides/spirv_tools.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2018 Google Inc. 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.

# These are variables that are overridable by projects that include
# SPIRV-Tools. The values in this file are the defaults for when we are
# building from SPIRV-Tools' repository.

# Whether we are building from SPIRV-Tools' repository.
# MUST be set to false in other projects.
spirv_tools_standalone = true

# The path to SPIRV-Tools' dependencies
spirv_tools_googletest_dir = "//external/googletest"
spirv_tools_spirv_headers_dir = "//external/spirv-headers"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 2d9a325

Please sign in to comment.