LogoLogo
Open TrustInSoft CI
  • Overview
  • Introduction tutorial
    • Prepare the demo project
    • Set up the continuous analysis
    • Find the root cause of the undefined behavior
    • Prove the absence of undefined behaviors
    • Go beyond your test suite
  • C++ tutorial
    • Prerequisites
    • Identifiers, constructors and calling conventions
    • Learn more
  • Configuration files
    • Build preparation stage
    • Analyses configuration
    • Tips: Switching from a Global configuration to a Committed configuration
    • Tips: Generalize analyses for several architectures
    • Tips: Factorize options between several analyses
  • Get help
  • Changelog
  • Glossary
  • FAQ
  • REFERENCE
    • Supported architectures
    • Add a status badge
    • GitHub organizations
    • CWE coverage
Powered by GitBook
On this page
  • With the include option
  • With a Build preparation script
  1. Configuration files

Tips: Factorize options between several analyses

PreviousTips: Generalize analyses for several architecturesNextGet help

Last updated 3 years ago

This tip can only be achieved with a Committed configuration. See the section to learn more about the different kinds of configuration.

All examples in this section can be replayed with our repository, used for our . Feel free to fork this repository to try it by yourself.

With the include option

The "include" option allows to inline another configuration object(s) where the "include" option is.

The "include" option requires one or several paths to other existing files. These files should only only a single configuration object:

  "include": "another_config.json"
  // or
  "include": [ "another_config_1.json", "another_config_2.json" ]

For each option in the included configuration:

  • If the option has not been declared before the "include", it will be added to the parent configuration.

  • If the option has already been declared before the special option "include":

    • If the option type is a list of values (such as "cpp-extra-args" or "files"), the value of the option in the included configuration will be concatenated to the existing one of the parent configuration.

    • Otherwise, the value of the option in the included configuration will replace the value in the main configuration.

For any option declared after the "include" option in the parent configuration, the value of the option will either be added, be concatenated or will replace the one declared in the included configuration by following the same rules as above.

The type of options can be checked in the .

In the case of several included configuration, the first configuration to include is processed according to the above rules. Then the resulting configuration will be considered as the parent one for the second configuration to include, and so on...

For a better clarity and readability of your analysis configuration objects, it is recommended to write any "include"option first and then the other options.

In this case, any option that is declared several times will either replace the included configuration value or be concatenated according to the option type.

.trustinsoft/config.json
[
  {
    "include": "common.json",
    "name": "Test shift values 7 and -3",
    "cpp-extra-args": "-DFOO" // will be appended to "-I ."
  },
  {
    "include": "common.json",
    "name": "Test from program inputs",
    "main": "main_with_input", // will overwrite "main": "main"
    "val-program-name": "a.out",
    "val-args": "|People of Earth, your attention please|7"
  }
]
.trustinsoft/common.json
{
    "prefix_path": "..",
    "files": [ "caesar.c", "main.c" ],
    "cpp-extra-args": "-I .",
    "main": "main"
}

With a Build preparation script

First, rename your existing .trustinsoft/config.json file into .trustinsoft/orig_config.json (or any other name, but make sure to modify the INPUT_FILE variable in the Build preparation script below).

Then, remove all the options you want to factorize for all the configuration objects.

.trustinsoft/config.json
[
  {
    "name": "Test shift values 7 and -3",
  },
  {
    "name": "Test from program inputs",
    "main": "main_with_input",
    "val-program-name": "a.out",
    "val-args": "|People of Earth, your attention please|7"
  }
]

/* Options to factorize:

   "files": [ "caesar.c", "main.c" ]
   "cpp-extra-args": "-I ."
   "prefix_path": ".."
*/

Then, create the .trustinsoft/prepare.sh script (or adapt your existing one with the following script):

.trustinsoft/prepare.sh
#!/bin/bash

set -e

readonly INPUT_FILE="orig_config.json"
readonly COMMON_OPTIONS='{
   "files": [ "caesar.c", "main.c" ],
   "cpp-extra-args": "-I .",
   "prefix_path": ".."
}'

test -e "$INPUT_FILE" || { echo "$INPUT_FILE not found"; exit 1; }

minify --type js "$INPUT_FILE" \
  | jq --argjson common "$COMMON_OPTIONS" 'map($common + .)' \
  > config.json

Finally, update the COMMON_OPTIONS variable to add the options to add to each analysis configuration of .trustinsoft/orig_config.json, commit, push the changes and that's all.

TheCOMMON_OPTIONS are concatenated in each analysis configuration before any options of your .trustinsoft/orig_config.json, hence any duplicated option will either be concatenated to the previous one (for options like"files" or"cpp-extra-args") or will replace the previous one (for options like"main"or"val-args").

Since the allows to generate the .trustinsoft/config.json file, it can also be used to add options to any analysis configuration on the fly.

See the section for the exact rules when a same option is given several times.

Configuration files
demo-caesar
Introduction tutorial
TrustInSoft Analyzer documentation
Build preparation stage
With the include option