Commit Graph

9 Commits

Author SHA1 Message Date
Arnout Vandecappelle
b8288a5f43 genrandconfig: pass outputdir and buildrootdir as arguments
The --instance argument is just an artifact of genrandconfig's
history as part of autobuild-run. It is much more logical to pass
the output directory and the buildroot directory as arguments, with
sane defaults.

This also allows us to remove the hack of creating a symlink in the
instance directory if it doesn't exist yet.

Note that the default outputdir 'output' doesn't work yet, because in
that case Buildroot will put the config file in the buildroot directory
instead of the output directory. This will be fixed in a follow-up
patch.

After this change, the script should be called from autobuild-run as:

    subprocess.call([os.path.join(srcdir, "utils/genrandconfig"),
                     "-o", outputdir, "-b", srcdir,
                     "--toolchains-url", kwargs['toolchains_url']],
                    stdout=devnull, stderr=log)

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2017-07-25 22:44:19 +02:00
Arnout Vandecappelle
9633b6ddd2 genrandconfig: calculate buildrootdir in __main__
This prepares for passing buildrootdir as an argument.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2017-07-25 22:44:07 +02:00
Arnout Vandecappelle
2dc209be36 genrandconfig: calculate outputdir in __main__
This prepares for passing outputdir as an argument.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2017-07-25 22:43:50 +02:00
Arnout Vandecappelle
d7b05d5b7d genrandconfig: verbose output and use stderr
The output of genrandconfig is currently very terse, which is annoying
for debugging the script or generally seeing what is going on. Also the
timing information added by log_write isn't very useful when the script
is used stand-alone.

In the new setup, (verbose) output goes to stdout and error output goes
to stderr. Also the "INFO: generate the configuration" message is
eliminated - it should go in the autobuild-run script.

We also add an explicit message when a toolchain can't be used after
the first defconfig, otherwise autobuild-run will just silently
restart.

Note that, since the output of make is no longer redirected to
/dev/null, we get one more message on stderr that will be recorded in
the autobuilder's log file: KCONFIG_SEED=0xXXXXXXXX.

This approach allows us to optimise the error handling to use
exceptions, where appropriate, which can be caught at the top level and
converted to an error message to stderr. This, in turn, allows us to use
subprocess.check_call, which eliminates a lot of conditions.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2017-07-25 22:43:30 +02:00
Arnout Vandecappelle
e8c6d52c89 genrandconfig: move instantiation of SystemInfo down
The SystemInfo class is instantiated globally and passed down to all
functions, but it is really only used in fixup_config. So instead,
instantiate it there.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2017-07-25 22:42:59 +02:00
Arnout Vandecappelle
22978c7399 genrandconfig: replace kwargs with explicit arguments
kwargs is a left-over from the use of docopt, it's better to use
argparse's Namespace object directly.

In addition, most functions use just one or two fields of args, so
these can just as well be passed directly as arguments to the function.
Particularly for outputdir it doesn't make sense to reconstruct it all
the time.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2017-07-25 22:42:45 +02:00
Arnout Vandecappelle
30f7fec0a8 genrandconfig: fix (some) pep8 warnings
Warnings fixed:
E731 do not assign a lambda expression, use a def
 -> urlopen_closing is defined with a def. urlopen is not used
    elsewhere so inlined.
E302 expected 2 blank lines
E501 line too long
 -> long lines due to a long string are NOT split
E701 multiple statements on one line (colon)
E722 do not use bare except'
 -> use "except Exception", so KeyInterrupt and SystemExit are still
    passed. We never intended to catch those.
E741 ambiguous variable name 'l'
 -> variable name is replaced with the much more descriptive
    toolchains_csv
E271 multiple spaces after keyword
E231 missing whitespace after ','

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2017-07-25 22:42:15 +02:00
Arnout Vandecappelle
59419cdac1 genrandconfig: use subprocess.check_output instead of Popen
Popen is more complicated and more difficult to understand.

check_output raises an exception if the exit code is non-zero, but
that's probably what we want if ldd can't be executed.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2017-07-25 22:41:57 +02:00
Arnout Vandecappelle
86ca7a04a8 utils/genrandconfig: new script
This script will be used by the autobuild-run script to generate the
configuration to test. It is put in the utils directory because it can
also be called directly to allow users to test things.

For now, it is a direct copy of the relevant functions from the
autobuild-run script. The only changes are:
- unneeded import statements are removed;
- code/decode wrappers are limited to decode_byte_list;
- __main__ handling is added.

For now, the only supported arguments are the ones needed for
autobuild-run.  Follow-up patches will refactor things and also change
the way the script is called. In this version, it can be called from the
autobuild-run script as:

  subprocess.call([os.path.join(srcdir, "utils/genrandconfig"),
                   "-i", str(kwargs['instance']),
                   "--toolchains-url", kwargs['toolchains_url']],
                  stdout=log, stderr=log)

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2017-07-25 22:41:35 +02:00