Bug 1790446 - Add build script to preprocess CMake config.h templates. r=dandarnell
Right now config.h.in is rewritten when the RNP source is updated. This has caused problems when new lines are added to it. Depends on D157151 Differential Revision: https://phabricator.services.mozilla.com/D157152 --HG-- extra : rebase_source : d7a684d7086dd3054fc0e0056f1ae5804eee256f extra : histedit_source : 3ed504cc8654589fda22146e4a08554d1fe43d62
This commit is contained in:
Родитель
f2e7148ccd
Коммит
d87891f46e
|
@ -0,0 +1,103 @@
|
|||
# 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/.
|
||||
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from buildconfig import topsrcdir, topobjdir
|
||||
from mozbuild.backend.configenvironment import PartialConfigEnvironment
|
||||
|
||||
|
||||
def define_type(string):
|
||||
vals = string.split("=", 1)
|
||||
if len(vals) == 1:
|
||||
vals.append(1)
|
||||
elif vals[1].isdecimal():
|
||||
vals[1] = int(vals[1])
|
||||
return tuple(vals)
|
||||
|
||||
|
||||
def process_cmake_define_file(output, input_file, extra_defines):
|
||||
"""Creates the given config header. A config header is generated by
|
||||
taking the corresponding source file and replacing some #define/#undef
|
||||
occurences:
|
||||
"#undef NAME" is turned into "#define NAME VALUE"
|
||||
"#cmakedefine NAME" is turned into "#define NAME VALUE"
|
||||
"#define NAME" is unchanged
|
||||
"#define NAME ORIGINAL_VALUE" is turned into "#define NAME VALUE"
|
||||
"#undef UNKNOWN_NAME" is turned into "/* #undef UNKNOWN_NAME */"
|
||||
"#cmakedefine UNKNOWN_NAME" is turned into "/* #undef UNKNOWN_NAME */"
|
||||
Whitespaces are preserved.
|
||||
"""
|
||||
|
||||
path = os.path.abspath(input_file)
|
||||
|
||||
config = PartialConfigEnvironment(topobjdir)
|
||||
|
||||
defines = dict(config.defines.iteritems())
|
||||
defines.update(extra_defines)
|
||||
|
||||
with open(path, "r") as input_file:
|
||||
r = re.compile(
|
||||
r'^\s*#\s*(?P<cmd>[a-z]+)(?:\s+(?P<name>\S+)(?:\s+(?P<value>("[^"]+"|\S+)))?)?',
|
||||
re.U,
|
||||
)
|
||||
for line in input_file:
|
||||
m = r.match(line)
|
||||
if m:
|
||||
cmd = m.group("cmd")
|
||||
name = m.group("name")
|
||||
value = m.group("value")
|
||||
if name:
|
||||
if cmd == "define":
|
||||
if value and name in defines:
|
||||
line = (
|
||||
line[: m.start("value")]
|
||||
+ str(defines[name])
|
||||
+ line[m.end("value") :]
|
||||
)
|
||||
elif cmd in ("undef", "cmakedefine"):
|
||||
if name in defines:
|
||||
line = (
|
||||
line[: m.start("cmd")]
|
||||
+ "define"
|
||||
+ line[m.end("cmd") : m.end("name")]
|
||||
+ " "
|
||||
+ str(defines[name])
|
||||
+ line[m.end("name") :]
|
||||
)
|
||||
else:
|
||||
line = (
|
||||
"/* #undef "
|
||||
+ line[m.start("name") : m.end("name")]
|
||||
+ " */"
|
||||
+ line[m.end("name") :]
|
||||
)
|
||||
|
||||
output.write(line)
|
||||
|
||||
|
||||
def main(output, *argv):
|
||||
parser = argparse.ArgumentParser(description="Process define files.")
|
||||
|
||||
parser.add_argument("input", help="Input define file.")
|
||||
parser.add_argument(
|
||||
"-D",
|
||||
type=define_type,
|
||||
action="append",
|
||||
dest="extra_defines",
|
||||
default=[],
|
||||
help="Additional defines not set at configure time.",
|
||||
)
|
||||
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
return process_cmake_define_file(output, args.input, args.extra_defines)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(*sys.argv))
|
|
@ -36,15 +36,23 @@ if CONFIG["CC_TYPE"] == "clang-cl":
|
|||
"/EHs",
|
||||
]
|
||||
|
||||
DEFINES["_GNU_SOURCE"] = True
|
||||
|
||||
DEFINES["HAVE_BZLIB_H"] = True
|
||||
DEFINES["HAVE_ZLIB_H"] = True
|
||||
DEFINES["MOZ_RNP_DIST_INFO"] = rnp_dist_info
|
||||
|
||||
CONFIGURE_DEFINE_FILES += [
|
||||
rnp_defines = {
|
||||
"HAVE_BZLIB_H": True,
|
||||
"HAVE_ZLIB_H": True,
|
||||
"CRYPTO_BACKEND_BOTAN": True,
|
||||
"ENABLE_AEAD": True,
|
||||
"ENABLE_TWOFISH": True,
|
||||
"ENABLE_BRAINPOOL": True,
|
||||
}
|
||||
GeneratedFile(
|
||||
"src/lib/config.h",
|
||||
]
|
||||
script="/comm/python/rocbuild/process_cmake_define_files.py",
|
||||
inputs=["src/lib/config.h.in"],
|
||||
flags=[
|
||||
"-D%s=%s" % (k, "1" if v is True else v)
|
||||
for k, v in rnp_defines.items()
|
||||
],
|
||||
)
|
||||
|
||||
LOCAL_INCLUDES = [
|
||||
"include",
|
||||
|
|
|
@ -18,13 +18,6 @@ COMPILE_FLAGS["OS_CXXFLAGS"] = []
|
|||
COMPILE_FLAGS["OS_INCLUDES"] = []
|
||||
COMPILE_FLAGS["CLANG_PLUGIN"] = []
|
||||
|
||||
DEFINES["RNP_NO_DEPRECATED"] = True
|
||||
DEFINES["CRYPTO_BACKEND_BOTAN"] = True
|
||||
DEFINES["ENABLE_AEAD"] = True
|
||||
DEFINES["ENABLE_TWOFISH"] = True
|
||||
DEFINES["ENABLE_BRAINPOOL"] = True
|
||||
|
||||
|
||||
if CONFIG["COMPILE_ENVIRONMENT"]:
|
||||
COMPILE_FLAGS["MOZ_HARDENING_CFLAGS"] = []
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче