Notice: We have migrated to GitLab launching 2024-05-01 see here:

#4265 closed enhancement (wontfix)

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 (7)

comment:1 Changed on 02/24/21 at 04:01:12 by Chris Johns

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

comment:2 Changed on 02/24/21 at 07:04:45 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 02/25/21 at 00:32:31 by Chris Johns

This captures a user's environment variables?

comment:4 Changed on 02/25/21 at 07:22:20 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 02/25/21 at 15:13:58 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 06/18/21 at 09:24:45 by Sebastian Huber

Keywords: qualification added

comment:7 Changed on 11/23/21 at 13:52:54 by Sebastian Huber

Resolution: wontfix
Status: assignedclosed

The rtems_get_build_hash() was dropped in favour of #4269.

Note: See TracTickets for help on using tickets.