30 Commits

Author SHA1 Message Date
Mehmet Basaran 71075d441a UBUNTU: [Packaging] update annotations scripts
BugLink: https://bugs.launchpad.net/bugs/1786013
Signed-off-by: Mehmet Basaran <mehmet.basaran@canonical.com>
2025-06-15 10:34:06 +03:00
Stefan Bader 91137688a1 UBUNTU: [Packaging] update annotations scripts
BugLink: https://bugs.launchpad.net/bugs/1786013
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2025-05-19 11:20:39 +02:00
Roxana Nicolescu 782e3646d1 UBUNTU: [Packaging] update annotations scripts
BugLink: https://bugs.launchpad.net/bugs/1786013
Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
2024-05-01 15:52:58 +02:00
Andrea Righi 63a035ca10 UBUNTU: [Packaging] update annotations scripts
BugLink: https://bugs.launchpad.net/bugs/1786013
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:41:09 +01:00
Andrea Righi 0b411127d2 UBUNTU: [Packaging] update annotations scripts
BugLink: https://bugs.launchpad.net/bugs/1786013
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:41:04 +01:00
Andrea Righi 81311e5461 UBUNTU: [Packaging] update annotations scripts
BugLink: https://bugs.launchpad.net/bugs/1786013
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:45 +01:00
Andrea Righi 4795aa23f8 UBUNTU: [Packaging] annotations: never drop configs that have notes different than the parent
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:41 +01:00
Andrea Righi b967072613 UBUNTU: [Packaging] kconfig/annotations.py: support older way of merging dicts
BugLink: https://bugs.launchpad.net/bugs/2020531

The '|=' update operator for merging dicts is available starting in
python 3.9 however in focal we have python 3.8, which causes the
annotation parsing script to crash.

Support also the old way of merging dicts available since python 3.5
that uses dict unpacking, e.g. dict1 = {**dict1, **dict2}

Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:41 +01:00
Andrea Righi 281ad73637 UBUNTU: [Packaging] annotations: prevent duplicate include lines
Includes are always parsed recursively, but when we save them (e.g.,
when the annotations file is updated) we should always save only the
top-level includes, without repeating the recursive ones.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:33 +01:00
Andrea Righi 7ecfc3dd9d UBUNTU: [Packaging] annotations: various code cleanups
kconfig: Fix pylint violations

Fix the following:
R0205: Class 'Config' inherits from object, can be safely removed from bases in python3 (useless-object-inheritance)
E1101: Instance of 'Config' has no '_parse' member (no-member)
W0613: Unused argument 'arch' (unused-argument)
W0613: Unused argument 'flavour' (unused-argument)
W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
R0201: Method could be a function (no-self-use)
E1101: Instance of 'Config' has no 'config' member (no-member)
W0707: Consider explicitly re-raising using the 'from' keyword (raise-missing-from)
W0105: String statement has no effect (pointless-string-statement)
W0123: Use of eval (eval-used)
W0102: Dangerous default value [] as argument (dangerous-default-value)
R1723: Unnecessary "elif" after "break" (no-else-break)
R1705: Unnecessary "elif" after "return" (no-else-return)
R1704: Redefining argument with the local name 'arch' (redefined-argument-from-local)

Signed-off-by: Juerg Haefliger <juergh@proton.me>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:26 +01:00
Juerg Haefliger f1781299e3 UBUNTU: [Packaging] annotations: Check validity of FLAVOUR_DEP
FLAVOUR_DEP is used to map flavors from the main annotations file to
flavors from includes. Currently, there is no check that any of the
listed flavors exists or is valid so the resulting behavior is
(probably) undefined/unexpected. Add a sanity check to verify the
FLAVOUR_DEP flavors.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:26 +01:00
Juerg Haefliger 007607d60c UBUNTU: [Packaging] annotations: Write out annotations with notes first
When writing the annotations file, separate them  into two groups: With
and without a note. Write the group with notes first and separate the
other group with a visual marker.

The idea is that all configs that are set/modified manually should have
an annotation note and putting them at the top of the annotations file
should make it easier to figure out what the config of this kernel is
about.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:26 +01:00
Juerg Haefliger e011f2959f UBUNTU: [Packaging] annotations: Fail on invalid lines
Currently, invalid lines are silently ignored, which is not good.
Fix this by raising an exception if the line can't be parsed. While at
it, remove one level of nesting by using if-continue.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:26 +01:00
Juerg Haefliger 7e9800b36e UBUNTU: [Packaging] annotations: Handle tabs in annotations file
Handle tabs in the annotations file by replacing them with spaces.
While at make the parsing more robust by removing leading and trailing
whitespaces and ignoring empty lines.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:26 +01:00
Juerg Haefliger 7a79eea193 UBUNTU: [Packaging] annotations: Clean up policy writes
The logic to determine if policy lines need to be written to the output
file is a little convoluted. Basically, if there is no 'policy' key in
a config, there is nothing to do, so put that check at the beginning of
the loop.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:26 +01:00
Juerg Haefliger 0bd2d18b70 UBUNTU: [Packaging] annotations: Fix linter errors
Fix the following flake8 errors:
  - E127 continuation line over-indented for visual indent
  - E722 do not use bare 'except'
  - E203 whitespace before ':'
  - E201 whitespace after '{'
  - E202 whitespace before '}'
  - E713 test for membership should be 'not in'

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:26 +01:00
Juerg Haefliger 7329f4be77 UBUNTU: [Packaging] annotations: Preserve single-line annotation rules
Currently, rules with notes are written out as separate lines, i. e.,
one line for the policy and one line for the note, followed by an
empty line. The parser now supports single line rules so preserve that
style when writting out the rules.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:26 +01:00
Juerg Haefliger 0c9146f650 UBUNTU: [Packaging] annotations: Handle single-line annoation rules
The old annotations file allowed single-line rules such as:
CONFIG_FOO  policy<'amd64': 'n'> note<LP: #123456>

The new annotations parser doesn't support that, so add it.

Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:26 +01:00
Andrea Righi 82d666f0e3 UBUNTU: [Packaging]: annotations: fix _remove_entry() logic
Drop unnecessary delete statements and fix the code to properly remove
the entry in _remove_entry().

Reported-by: Juerg Haefliger <juerg.haefliger@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:25 +01:00
Andrea Righi cce5a4b5a8 UBUNTU: [Packaging] annotations: do not drop undefined configs in derivatives
Prevent dropping configs that are undefined across all the supported
architectures in annotations that have includes, because we may want to
use them to override configs imported from other annotations.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:25 +01:00
Andrea Righi ae281486dd UBUNTU: [Packaging] annotations: make sure to always drop undefined configs
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:22 +01:00
Andrea Righi 93592077df UBUNTU: [Packaging] annotations: remove configs that are undefined across all arches/flavours
Sometimes certain config options are removed in new kernels, so when
annotations is updated these options result to be undefined across all
architectures and flavours, in this case it's much more clean to simply
drop them from annotations (considering that the kernel doesn't support
them anymore).

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:14 +01:00
Andrea Righi 92ef1ebdb8 UBUNTU: [Packaging] annotations: unify same rule across all flavour within the same arch
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:12 +01:00
Andrea Righi f2df6ca302 UBUNTU: [Packaging] annotations: catch syntax errors in annotations
Trigger a syntax error when a policy or note rule is not properly
closed.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:08 +01:00
Andrea Righi ac91298460 UBUNTU: [Packaging] annotations: properly support multiple levels of inclusion
Moreover, do some refactoring to optimize parsing.

Reported-by: Masahiro Yamada <masahiro.yamada@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:08 +01:00
Andrea Righi d7fd5426bd UBUNTU: [Packaging] annotations: properly merge configs with includes
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:08 +01:00
Andrea Righi 0ab043100c UBUNTU: [Packaging] annotations: support flavour inheritance
Allow to define flavour inheritance relationship in the annotations
file, such as:

 # FLAVOUR_DEP: {'amd64-lowlatency': 'amd64-generic', 'arm64-lowlatency': 'arm64-generic', 'arm64-lowlatency-64k': 'arm64-lowlatency-64k'}

In this case, for example, -lowlatency flavours inherits the config
values from -generic (both for amd64 and arm64) and -lowlatency-64
inherits the value from -generic-64k (only on arm64).

This allows to strongly reduce the size of annotations and helps to
read and review changes in annotations.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:08 +01:00
Andrea Righi 50af9ecfd5 UBUNTU: [Packaging] annotations: allow to set note to config options directly
Allow to set a note to config options without changing their values.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:08 +01:00
Andrea Righi 708e12fa46 UBUNTU: [Packaging] annotations: set and delete configs from command line
Allow to set and delete config options from command line using the
'annotations' script (instead of manually editing the annotations file).

This also provides an interface to manage the annotations file from
other scripts.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:07 +01:00
Andrea Righi b9c9629053 UBUNTU: [Packaging] introduce annotations script
Add a script to manage annotations and .config.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
2024-03-11 09:40:05 +01:00