Repository: randombit/botan
Pull request #3642 (2023-07-25 11:29:27)

Add compiler and architecture information to XML report
In the PDF test report generated for the BSI, we want to show the used compiler and target architecture information.

This adds the required information to the XML report as properties, allowing it to be easily extracted if we generate the BSI test report form the XML report.


Patch:
diff --git a/src/build-data/buildh.in b/src/build-data/buildh.in
index 67a6293b6..4802e0bf0 100644
--- a/src/build-data/buildh.in
+++ b/src/build-data/buildh.in
@@ -97,6 +97,7 @@
 #define BOTAN_HAS_SANITIZER_%{i|upper}
 %{endfor}
 
+#define BOTAN_TARGET_ARCH "%{arch}"
 #define BOTAN_TARGET_ARCH_IS_%{arch|upper}
 %{if endian}
 #define BOTAN_TARGET_CPU_IS_%{endian|upper}_ENDIAN
diff --git a/src/scripts/ci_build.py b/src/scripts/ci_build.py
index 0710e6e73..a1910acb5 100755
--- a/src/scripts/ci_build.py
+++ b/src/scripts/ci_build.py
@@ -522,23 +522,6 @@ def have_prog(prog):
                 return True
     return False
 
-def validate_make_tool(make_tool, build_jobs):
-    if make_tool == '':
-        return validate_make_tool('make', build_jobs)
-
-    if make_tool not in ['nmake', 'jom', 'make']:
-        raise Exception("Don't know about %s as a make tool" % (make_tool))
-
-    # Hack to work around jom occasionally failing to install
-    # https://github.com/randombit/botan/issues/3629
-    if make_tool == 'jom' and not have_prog('jom'):
-        return ['nmake']
-
-    if make_tool in ['make', 'jom']:
-        return [make_tool, '-j%d' % (build_jobs)]
-    else:
-        return [make_tool]
-
 def main(args=None):
     """
     Parse options, do the things
@@ -652,9 +635,14 @@ def main(args=None):
 
         cmds.append([py_interp, os.path.join(root_dir, 'configure.py')] + config_flags)
 
-        make_cmd = validate_make_tool(options.make_tool, options.build_jobs)
+        if options.make_tool == '':
+            options.make_tool = 'make'
+
+        make_cmd = [options.make_tool]
         if build_dir != '.':
             make_cmd = ['indir:%s' % build_dir] + make_cmd
+        if options.build_jobs > 1 and options.make_tool != 'nmake':
+            make_cmd += ['-j%d' % (options.build_jobs)]
 
         make_cmd += ['-k']
 


Test patch:
diff --git a/src/tests/runner/test_xml_reporter.cpp b/src/tests/runner/test_xml_reporter.cpp
index 4fcbe8d2e..5bb59a073 100644
--- a/src/tests/runner/test_xml_reporter.cpp
+++ b/src/tests/runner/test_xml_reporter.cpp
@@ -9,17 +9,54 @@
 
 #if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM)
 
+   #include <botan/build.h>
    #include <botan/version.h>
    #include <botan/internal/loadstor.h>
 
    #include <iomanip>
    #include <numeric>
+   #include <sstream>
    #include <time.h>
 
 namespace Botan_Tests {
 
 namespace {
 
+std::string full_compiler_version_string() {
+   #if defined(BOTAN_BUILD_COMPILER_IS_CLANG) || defined(BOTAN_BUILD_COMPILER_IS_GCC)
+   return __VERSION__;
+   #elif defined(BOTAN_BUILD_COMPILER_IS_MSVC)
+   // See https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros
+   //    If the version number of the Microsoft C/C++ compiler is 15.00.20706.01,
+   //    the _MSC_FULL_VER macro evaluates to 150020706.
+   constexpr int major = _MSC_FULL_VER / 10000000;
+   constexpr int minor = (_MSC_FULL_VER % 10000000) / 100000;
+   constexpr int patch = _MSC_FULL_VER % 100000;
+   constexpr int build = _MSC_BUILD;
+
+   std::ostringstream oss;
+
+   oss << std::setfill('0') << std::setw(2) << major << "." << std::setw(2) << minor << "." << std::setw(5) << patch
+       << "." << std::setw(2) << build << std::endl;
+
+   return oss.str();
+   #else
+   return "unknown";
+   #endif
+}
+
+std::string full_compiler_name_string() {
+   #if defined(BOTAN_BUILD_COMPILER_IS_CLANG)
+   return "clang";
+   #elif defined(BOTAN_BUILD_COMPILER_IS_GCC)
+   return "gcc";
+   #elif defined(BOTAN_BUILD_COMPILER_IS_MSVC)
+   return "Microsoft Visual C++";
+   #else
+   return "unknown";
+   #endif
+}
+
 std::tm* localtime(const time_t* timer, std::tm* buffer) {
    #if defined(BOTAN_BUILD_COMPILER_IS_MSVC) || defined(BOTAN_TARGET_OS_IS_MINGW) || \
       defined(BOTAN_TARGET_OS_IS_CYGWIN) || defined(BOTAN_TARGET_OS_IS_WINDOWS)
@@ -53,6 +90,9 @@ std::string format(const std::chrono::nanoseconds& dur) {
 
 XmlReporter::XmlReporter(const Test_Options& opts, std::string output_dir) :
       Reporter(opts), m_output_dir(std::move(output_dir)) {
+   set_property("architecture", BOTAN_TARGET_ARCH);
+   set_property("compiler", full_compiler_name_string());
+   set_property("compiler_version", full_compiler_version_string());
    set_property("timestamp", format(std::chrono::system_clock::now()));
    auto custom_props = opts.report_properties();
    for(const auto& prop : custom_props) {