tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

gen_moz_build.py (2585B)


      1 #!/usr/bin/env python3
      2 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
      3 # vim: set filetype=python:
      4 # This Source Code Form is subject to the terms of the Mozilla Public
      5 # License, v. 2.0. If a copy of the MPL was not distributed with this
      6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      7 
      8 import os
      9 import json
     10 
     11 
     12 def gen_includes(export_prefix, path_prefix):
     13    result = ""
     14 
     15    exports = []
     16    for f in os.listdir(path_prefix):
     17        # Explicitly ignore the "{gtest,gmock}/internal/custom" paths, as we
     18        # replace files in them for custom configurations.
     19        if f == "custom":
     20            continue
     21 
     22        path = os.path.join(path_prefix, f)
     23        if os.path.isfile(path):
     24            if os.path.splitext(f)[1] != ".h":
     25                continue
     26            exports.append(path)
     27        else:
     28            result += gen_includes(export_prefix + "." + f, path)
     29 
     30    if exports:
     31        result += "%s += [\n" % export_prefix
     32        for export in sorted(exports):
     33            result += "    %s,\n" % json.dumps(export)
     34        result += "]\n"
     35 
     36    return result
     37 
     38 
     39 if __name__ == "__main__":
     40    GTEST_PATH = "googletest/include/gtest"
     41    GMOCK_PATH = "googlemock/include/gmock"
     42 
     43    exports = "\n".join(
     44        [
     45            # Normal include paths used by most code
     46            gen_includes("EXPORTS.gtest", GTEST_PATH),
     47            gen_includes("EXPORTS.gmock", GMOCK_PATH),
     48            # webrtc.org unit tests use this include path
     49            gen_includes("EXPORTS.testing.gtest.include.gtest", GTEST_PATH),
     50            gen_includes("EXPORTS.testing.gmock.include.gmock", GMOCK_PATH),
     51        ]
     52    )
     53    exports = exports.replace("\n", "\n    ")
     54 
     55    mozbuild = f"""\
     56 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
     57 # vim: set filetype=python:
     58 # This Source Code Form is subject to the terms of the Mozilla Public
     59 # License, v. 2.0. If a copy of the MPL was not distributed with this
     60 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
     61 
     62 # !!! THIS FILE IS AUTOGENERATED USING gen_moz_build.py DO NOT EDIT !!!
     63 
     64 with Files("**"):
     65    BUG_COMPONENT = ("Testing", "GTest")
     66    SCHEDULES.exclusive = ["gtest"]
     67 
     68 if CONFIG["ENABLE_TESTS"]:
     69 
     70    {exports}
     71 
     72    SOURCES += [
     73        "googlemock/src/gmock-all.cc",
     74        "googletest/src/gtest-all.cc",
     75    ]
     76 
     77    Library("gtest")
     78 
     79    LOCAL_INCLUDES += [
     80        "googlemock",
     81        "googletest",
     82    ]
     83 
     84    if CONFIG["OS_ARCH"] == "WINNT":
     85        DEFINES["UNICODE"] = True
     86 
     87    FINAL_LIBRARY = "xul-gtest"
     88 """
     89 
     90    with open("moz.build", "w") as f:
     91        f.write(mozbuild)