Skip to content

Commit

Permalink
parser: drop last leaf in links
Browse files Browse the repository at this point in the history
If links are used, ref will point to the parent instead of itself.

This means that the following example:

    rev-1x = {

    };
    rev-1.0 = {
        ref = "#../rev-1x";
    }

is changed in this way:

    rev-1x = {

    };
    rev-1.0 = {
        ref = "#./rev-1x";
    }

Signed-off-by: Stefano Babic <[email protected]>
  • Loading branch information
sbabic committed Dec 5, 2018
1 parent 62e03dc commit f1b36de
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 44 deletions.
8 changes: 8 additions & 0 deletions corelib/parsing_library.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ bool set_find_path(const char **nodes, const char *newpath, char **tmp)
return false;
}
count = count_string_array(nodes);
/*
* Count is surely > 0, decrementing is safe
* Do not consider the last leaf with "ref"
* This means that "#./link" is searched
* starting from the parent of "ref"
*/
count--;

ref = strdup(newpath);
if (!ref) {
ERROR("No memory: failed for %lu bytes",
Expand Down
87 changes: 43 additions & 44 deletions doc/source/sw-description.rst
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,16 @@ the section with `-e stable,<rev number>`.
...
);
scripts: (
...
...
);
}
rev-1.3: {
hardware-compatibility: ["1.3"];
images: (
...
...
);
scripts: (
...
...
);
}

Expand Down Expand Up @@ -399,74 +399,73 @@ the section with `-e stable,<rev number>`.
If each of them requires an own section, it is the way to do. Anyway, it is more probable
than revisions can be grouped together, for example board with the same major revision
number could have the same installation instructions. This leads in the example to 3 groups
for rev1.X, rev2.X and rev3.X. Links allow to group section together. When a string is found
for rev1.X, rev2.X and rev3.X. Links allow to group section together. When a "ref" is found
when SWUpdate searches for a group (images, files, script, bootenv), it replaces the current path
in the tree with the value of the string. In this way, the example above can be written in this way:

::

software =
{
version = "0.1.0";
version = "0.1.0";

myboard = {
myboard = {
stable = {

hardware-compatibility: ["1.0", "1.2", "2.0", "1.3, "3.0", "3.1"];
rev-1x: {
images: (
...
);
scripts: (
...
);
}
hardware-compatibility: ["1.0", "1.2", "2.0", "1.3, "3.0", "3.1"];
rev-1x: {
images: (
...
);
scripts: (
...
);
}
rev1.0 = {
ref = "#../rev-1x";
ref = "#./rev-1x";
}
rev1.2 = {
ref = "#../rev-1x";
ref = "#./rev-1x";
}
rev1.3 = {
ref = "#../rev-1x";
ref = "#./rev-1x";
}
rev-2x: {
images: (
...
);
scripts: (
...
);
}
rev-2x: {
images: (
...
);
scripts: (
...
);
}
rev2.0 = {
ref = "#../rev-2x";
ref = "#./rev-2x";
}

rev-3x:
{
images: (
...
);
scripts: (
...
);
rev-3x: {
images: (
...
);
scripts: (
...
);
}
rev3.0 = {
ref = "#../rev-3x";
ref = "#./rev-3x";
}
rev3.1 = {
ref = "#../rev-3x";
ref = "#./rev-3x";
}
}
}
}
}

The link can be absolute or relative. The keyword *"ref"* is used to indicate a link. If this is found, SWUpdate
will traverse the tree and replaces the current path with the values find in the string pointed by "ref". There are
simple rules for a link:

- it must start with the character '#'
- "." points to the current level in the tree
- "." points to the current level in the tree, that means the parent of "ref"
- ".." points to the parent level in the tree
- "/" is used as filed separator in the link

Expand All @@ -483,7 +482,7 @@ The path `software.myboard.stable.common.images` is then replaced by
software =
{
version = {
ref = "#../commonversion";
ref = "#./commonversion";
}

hardware-compatibility = ["rev10", "rev11", "rev20"];
Expand All @@ -496,7 +495,7 @@ The path `software.myboard.stable.common.images` is then replaced by
common:{
images =
{
ref = "#../../trythis";
ref = "#./../trythis";
}
};

Expand Down Expand Up @@ -525,15 +524,15 @@ The path `software.myboard.stable.common.images` is then replaced by
};
pdm3rev11 =
{
ref = "#../pdm3rev10";
ref = "#./pdm3rev10";
}
pdm3rev20 =
{
ref = "#../pdm3rev10";
ref = "#./pdm3rev10";
}
pdm3rev40 =
{
ref = "#../common";
ref = "#./common";
}
};
};
Expand Down

0 comments on commit f1b36de

Please sign in to comment.