f43be0
# HG changeset patch
f43be0
# User Rob Lemley <rob@thunderbird.net>
f43be0
# Date 1662997034 0
f43be0
#      Mon Sep 12 15:37:14 2022 +0000
f43be0
# Node ID 17dc6bb322b5d40299bba0a90d59c0593137d4f6
f43be0
# Parent  c9e44c0a569253884961ad2e18fae23f5ed0f6dc
f43be0
Bug 1790446 - Get RNP version during configure and set in config.h. r=dandarnell
f43be0
f43be0
f43be0
f43be0
f43be0
Depends on D157152
f43be0
f43be0
Differential Revision: https://phabricator.services.mozilla.com/D157153
f43be0
f43be0
diff --git a/comm/third_party/openpgp.configure b/comm/third_party/openpgp.configure
f43be0
--- a/comm/third_party/openpgp.configure
f43be0
+++ b/comm/third_party/openpgp.configure
f43be0
@@ -86,10 +86,42 @@ with only_when("--enable-compile-environ
f43be0
     set_config("MZLA_LIBRNP", depends_if(in_tree_librnp)(lambda _: True))
f43be0
     set_define("MZLA_LIBRNP", depends_if(in_tree_librnp)(lambda _: True))
f43be0
 
f43be0
 
f43be0
 with only_when(in_tree_librnp):
f43be0
+
f43be0
+    @depends(build_environment, c_compiler)
f43be0
+    @imports(_from="textwrap", _import="dedent")
f43be0
+    @imports(_from="os.path", _import="join")
f43be0
+    def rnp_version_string(build_env, compiler):
f43be0
+        log.info("Determining librnp version from version.h.")
f43be0
+        include_path = join(
f43be0
+            build_env.topsrcdir, "comm", "third_party", "rnp", "src", "lib"
f43be0
+        )
f43be0
+        check = dedent(
f43be0
+            """\
f43be0
+        #include "version.h"
f43be0
+        RNP_VERSION_STRING_FULL
f43be0
+        """
f43be0
+        )
f43be0
+        result = try_preprocess(
f43be0
+            compiler.wrapper
f43be0
+            + [compiler.compiler]
f43be0
+            + compiler.flags
f43be0
+            + ["-I", include_path],
f43be0
+            "C",
f43be0
+            check,
f43be0
+        )
f43be0
+        if result:
f43be0
+            rnp_version = result.splitlines()[-1]
f43be0
+            rnp_version = rnp_version.replace('"', "")
f43be0
+        else:
f43be0
+            raise FatalCheckError("Unable to determine RNP version string.")
f43be0
+        return rnp_version
f43be0
+
f43be0
+    set_config("MZLA_LIBRNP_FULL_VERSION", rnp_version_string)
f43be0
+
f43be0
     # JSON-C --with-system-json
f43be0
     system_lib_option(
f43be0
         "--with-system-jsonc",
f43be0
         help="Use system JSON-C for librnp (located with pkgconfig)",
f43be0
     )
f43be0
diff --git a/comm/third_party/rnp/moz.build b/third_party/rnp/moz.b/commuild
f43be0
--- a/comm/third_party/rnp/moz.build
f43be0
+++ b/comm/third_party/rnp/moz.build
f43be0
@@ -41,10 +41,12 @@ rnp_defines = {
f43be0
     "HAVE_ZLIB_H": True,
f43be0
     "CRYPTO_BACKEND_BOTAN": True,
f43be0
     "ENABLE_AEAD": True,
f43be0
     "ENABLE_TWOFISH": True,
f43be0
     "ENABLE_BRAINPOOL": True,
f43be0
+    "PACKAGE_BUGREPORT": '"https://bugzilla.mozilla.org/enter_bug.cgi?product=Thunderbird"',
f43be0
+    "PACKAGE_STRING": '"rnp {}"'.format(CONFIG["MZLA_LIBRNP_FULL_VERSION"])
f43be0
 }
f43be0
 GeneratedFile(
f43be0
     "src/lib/config.h",
f43be0
     script="/comm/python/rocbuild/process_cmake_define_files.py",
f43be0
     inputs=["src/lib/config.h.in"],