#4265 assigned enhancement

Add rtems_get_build_hash()

Reported by: Sebastian Huber Owned by: Sebastian Huber
Priority: normal Milestone: 6.1
Component: rtems Version: 6
Severity: normal Keywords: qualification
Cc: Blocked By:


Add a function to report a hash value of the build environment in the test suite results.

/* Generated from spec:/rtems/config/if/get-build-hash */

 * @ingroup RTEMSAPIConfig
 * @brief Gets the RTEMS build hash.
 * The build hash is calculated from all key-value pairs of the build
 * environment.  Local file system paths in the values do not contribute to the
 * hash value.
 * @return Returns the pointer to the RTEMS build hash.
 * @par Notes
 * The build hash can be used to distinguish test suite results obtained from
 * different build environments.
 * @par Constraints
 * @parblock
 * The following constraints apply to this directive:
 * * The directive may be called from within any runtime context.
 * * The directive will not cause the calling task to be preempted.
 * @endparblock
const char *rtems_get_build_hash( void );

Change History (6)

comment:1 Changed on Feb 24, 2021 at 4:01:12 AM by Chris Johns

Is there a list that defines all key-value pairs in the build environment?

comment:2 Changed on Feb 24, 2021 at 7:04:45 AM by Sebastian Huber

Yes, you can iterate over conf.env:

  • wscript

    diff --git a/wscript b/wscript
    index 6626fafb74..84b845dce4 100755
    a b def get_compiler(conf, cp, variant): 
    13591359    return value
     1362def _generate_build_hash(conf):
     1363    import hashlib
     1364    import base64
     1366    build_hash = ""
     1367    for key in sorted(conf.env):
     1368        build_hash = build_hash + key + str(conf.env[key])
     1369    for discard in [
     1370        conf.env.PREFIX,
     1371        conf.bldnode.make_node(conf.env.VARIANT).abspath(),
     1372        conf.path.abspath(),
     1373    ]:
     1374        build_hash = build_hash.replace(discard, "")
     1375    state = hashlib.sha256()
     1376    state.update(build_hash.encode("utf-8"))
     1377    conf.define("RTEMS_BUILD_HASH", base64.urlsafe_b64encode(state.digest()))
     1378    conf.write_config_header(
     1379        conf.env.VARIANT + "/cpukit/include/rtems/build-hash.h"
     1380    )
    13621383def configure_variant(conf, cp, bsp_map, path_list, top_group, variant):
    13631384    conf.msg("Configure board support package (BSP)", variant, color="YELLOW")
    def configure_variant(conf, cp, bsp_map, path_list, top_group, variant): 
    13911412        conf.fatal("No such base BSP: '{}'".format(variant))
    13921413    bsp_item.configure(conf, cic)
    1394     options = set([o[0].upper() for o in cp.items(variant)])
     1415    options = set(o[0].upper() for o in cp.items(variant))
    13951416    for o in options.difference(cic.options):
    13961417        conf.msg("Unknown configuration option", o.upper(), color="RED")
     1418    _generate_build_hash(conf)
    13991421def check_forbidden_options(ctx, opts):

An alternative would be to explicitly add (or remove) build options.

comment:3 Changed on Feb 25, 2021 at 12:32:31 AM by Chris Johns

This captures a user's environment variables?

comment:4 Changed on Feb 25, 2021 at 7:22:20 AM by Sebastian Huber

There are always means to sabotage something. We don't recommend the use of environment variables and a waf configure warns about them. I will add a note that environment variables are not recommended and not used for the build hash.

comment:5 Changed on Feb 25, 2021 at 3:13:58 PM by Sebastian Huber

As discussed on the mailing list I tried the following approach. Iterate over all start files and libraries generated by the build and then create a hash of all executable sections. Then we recompile one object with a command line define with the build hash and replace this object in librtemscpu.a. Unfortunately, this exceeds my waf skills at the moment. I think it is feasible, but you really have to know how to adjust the waf tasks through meta programming.

comment:6 Changed on Jun 18, 2021 at 9:24:45 AM by Sebastian Huber

Keywords: qualification added
Note: See TracTickets for help on using tickets.