Commit 919ce7ef authored by Nika Layzell's avatar Nika Layzell
Browse files

Bug 1761511 - Part 1: Set up moz.yaml vendoring for gtest, r=ahal,tjr

This doesn't actually vendor the library in, but sets up the basic
configuration to allow it to be vendored in.

The latest commit on the main branch, rather than the latest tag, is used as
recommended by the googletest documentation.

Differential Revision: https://phabricator.services.mozilla.com/D142608
parent cb02113c
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
Copyright 2008, Google Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

    * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
    * Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+21 −0
Original line number Diff line number Diff line
diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h
--- a/googletest/include/gtest/gtest.h
+++ b/googletest/include/gtest/gtest.h
@@ -70,6 +70,8 @@
 #include "gtest/gtest-test-part.h"
 #include "gtest/gtest-typed-test.h"
 
+#include "mozilla/Attributes.h"
+
 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
 /* class A needs to have dll-interface to be used by clients of class B */)
 
@@ -491,7 +493,7 @@ class GTEST_API_ Test {
   //
   // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
   // Instead, use the TEST or TEST_F macro.
-  virtual void TestBody() = 0;
+  MOZ_CAN_RUN_SCRIPT virtual void TestBody() = 0;
 
   // Sets up, executes, and tears down the test.
   void Run();
+88 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import os
import json


def gen_includes(export_prefix, path_prefix):
    result = ""

    exports = []
    for f in os.listdir(path_prefix):
        # Explicitly ignore the "{gtest,gmock}/internal/custom" paths, as we
        # replace files in them for custom configurations.
        if f == "custom":
            continue

        path = os.path.join(path_prefix, f)
        if os.path.isfile(path):
            if os.path.splitext(f)[1] != ".h":
                continue
            exports.append(path)
        else:
            result += gen_includes(export_prefix + "." + f, path)

    if exports:
        result += "%s += [\n" % export_prefix
        for export in sorted(exports):
            result += "    %s,\n" % json.dumps(export)
        result += "]\n"

    return result


if __name__ == "__main__":
    GTEST_PATH = "googletest/include/gtest"
    GMOCK_PATH = "googlemock/include/gmock"

    exports = "\n".join(
        [
            # Normal include paths used by most code
            gen_includes("EXPORTS.gtest", GTEST_PATH),
            gen_includes("EXPORTS.gmock", GMOCK_PATH),
            # webrtc.org unit tests use this include path
            gen_includes("EXPORTS.testing.gtest.include.gtest", GTEST_PATH),
            gen_includes("EXPORTS.testing.gmock.include.gmock", GMOCK_PATH),
        ]
    )
    exports = exports.replace("\n", "\n    ")

    mozbuild = f"""\
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# !!! THIS FILE IS AUTOGENERATED USING gen_moz_build.py DO NOT EDIT !!!

with Files("**"):
    BUG_COMPONENT = ("Testing", "GTest")
    SCHEDULES.exclusive = ["gtest"]

if CONFIG["ENABLE_TESTS"]:

    {exports}

    SOURCES += [
        "googlemock/src/gmock-all.cc",
        "googletest/src/gtest-all.cc",
    ]

    Library("gtest")

    LOCAL_INCLUDES += [
        "googlemock",
        "googletest",
    ]

    FINAL_LIBRARY = "xul-gtest"
"""

    with open("moz.build", "w") as f:
        f.write(mozbuild)
+53 −0
Original line number Diff line number Diff line
schema: 1

bugzilla:
  product: Testing
  component: GTest

origin:
  name: googletest
  description: Google Testing and Mocking Framework

  url: https://google.github.io/googletest/

  release: commit v0

  revision: v0

  license: BSD-3-Clause
  license-file: LICENSE

vendoring:
  url: https://github.com/google/googletest
  source-hosting: github
  tracking: commit

  exclude:
    - .github/
    - ci/
    - docs/
    - googlemock/docs/
    - googlemock/samples/
    - googlemock/scripts/
    - googlemock/test/
    - googletest/docs/
    - googletest/samples/
    - googletest/scripts/
    - googletest/test/
    # Customization points, replaced by headers in testing/gtest/mozilla/
    - googlemock/include/gmock/internal/custom
    - googletest/include/gtest/internal/custom

  keep:
    - gen_moz_build.py

  skip-vendoring-steps:
    - update-moz-build # Handled by gen_moz_build.py

  update-actions:
    - action: run-script
      script: "{yaml_dir}/gen_moz_build.py"
      cwd: "{yaml_dir}"

  patches:
    - "*.patch"
+12 −0
Original line number Diff line number Diff line
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -3932,7 +3932,7 @@ class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
     const char* sep = "";
     // Workaround spurious C4189 on MSVC<=15.7 when k is empty.
     (void)sep;
-    const char* dummy[] = {"", (*os << sep << "#" << k, sep = ", ")...};
+    const char* dummy[] = {"", (static_cast<void>(*os << sep << "#" << k), sep = ", ")...};
     (void)dummy;
     *os << ") ";
   }
Loading