Skip to content

Commit 688d2f6

Browse files
committed
* set-force removed
1 parent c05460d commit 688d2f6

File tree

10 files changed

+24
-72
lines changed

10 files changed

+24
-72
lines changed

.gdbinit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cd ./autark-cache/tests
2-
file ./test10
2+
file ./test6
33
#file ./autark-cache/autark
44
#set environment CC=clang
55
#set environment IWNET_RUN_TESTS=1

README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -581,19 +581,6 @@ set {
581581
}
582582
```
583583

584-
## set-force
585-
586-
Please note that the `set` directive assigns a variable under the given name during the init `build` phase.
587-
If you use multiple set expressions for the same variable name, only the last one will take effect.
588-
This happens because set expression values are evaluated during the `init` phase, while the `build` and `setup` phases
589-
are executed afterward - using the values cached from `init`.
590-
591-
This behavior often causes confusion in `macros` that are invoked multiple times and contain
592-
`set` directives in their bodies.
593-
594-
To ensure the variable is correctly updated across all build and setup phases, use `set-force`.
595-
Unlike set, it is executed for every phase and does not cache its results.
596-
597584
# env {...}
598585

599586
Similar to `set`, but sets an **environment variable** for the build process

dist/autark.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define CONFIG_H
33

44
#define META_VERSION "0.9.0"
5-
#define META_REVISION "4edc652"
5+
#define META_REVISION "c05460d"
66

77
#endif
88
#define _AMALGAMATE_
@@ -3840,14 +3840,8 @@ static struct unit* _unit_for_set(struct node *n, struct node *nn, const char **
38403840

38413841
static void _set_init(struct node *n);
38423842

3843-
static bool _set_is_force(struct node *n) {
3844-
return strcmp(n->value, "set-force") == 0;
3845-
}
3846-
38473843
static void _set_setup(struct node *n) {
3848-
if (_set_is_force(n)) {
3849-
_set_init(n);
3850-
}
3844+
_set_init(n);
38513845
if (n->child && strcmp(n->value, "env") == 0) {
38523846
const char *v = _set_value_get(n);
38533847
if (v) {
@@ -3871,7 +3865,7 @@ static void _set_init(struct node *n) {
38713865
return;
38723866
}
38733867
struct node *nn = unit_env_get_node(unit, key);
3874-
if (nn) {
3868+
if (nn && nn != n) {
38753869
n->recur_next.n = nn;
38763870
}
38773871
unit_env_set_node(unit, key, n);
@@ -3884,7 +3878,7 @@ static const char* _set_value_get(struct node *n) {
38843878
n->recur_next.active = true;
38853879

38863880
struct node_foreach *fe = node_find_parent_foreach(n);
3887-
if (fe || _set_is_force(n)) {
3881+
if (fe) {
38883882
if ((uintptr_t) n->impl != (uintptr_t) -1) {
38893883
free(n->impl);
38903884
}
@@ -3953,9 +3947,7 @@ int node_set_setup(struct node *n) {
39533947
n->setup = _set_setup;
39543948
n->value_get = _set_value_get;
39553949
n->dispose = _set_dispose;
3956-
if (_set_is_force(n)) {
3957-
n->build = _set_build;
3958-
}
3950+
n->build = _set_build;
39593951
return 0;
39603952
}
39613953
#ifndef _AMALGAMATE_
@@ -8327,7 +8319,7 @@ static unsigned _rule_type(const char *key, unsigned *flags) {
83278319
return NODE_TYPE_SUBST;
83288320
} else if (strcmp(key, "^") == 0) {
83298321
return NODE_TYPE_JOIN;
8330-
} else if (strcmp(key, "set") == 0 || strcmp(key, "env") == 0 || strcmp(key, "set-force") == 0) {
8322+
} else if (strcmp(key, "set") == 0 || strcmp(key, "env") == 0) {
83318323
return NODE_TYPE_SET;
83328324
} else if (strcmp(key, "check") == 0) {
83338325
return NODE_TYPE_CHECK;

dist/build.sh

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# https://github.com/Softmotions/autark
77

88
META_VERSION=0.9.0
9-
META_REVISION=4edc652
9+
META_REVISION=c05460d
1010
cd "$(cd "$(dirname "$0")"; pwd -P)"
1111

1212
prev_arg=""
@@ -62,7 +62,7 @@ cat <<'a292effa503b' > ${AUTARK_HOME}/autark.c
6262
#ifndef CONFIG_H
6363
#define CONFIG_H
6464
#define META_VERSION "0.9.0"
65-
#define META_REVISION "4edc652"
65+
#define META_REVISION "c05460d"
6666
#endif
6767
#define _AMALGAMATE_
6868
#define _XOPEN_SOURCE 700
@@ -3298,13 +3298,8 @@ static struct unit* _unit_for_set(struct node *n, struct node *nn, const char **
32983298
return unit_peek();
32993299
}
33003300
static void _set_init(struct node *n);
3301-
static bool _set_is_force(struct node *n) {
3302-
return strcmp(n->value, "set-force") == 0;
3303-
}
33043301
static void _set_setup(struct node *n) {
3305-
if (_set_is_force(n)) {
3306-
_set_init(n);
3307-
}
3302+
_set_init(n);
33083303
if (n->child && strcmp(n->value, "env") == 0) {
33093304
const char *v = _set_value_get(n);
33103305
if (v) {
@@ -3327,7 +3322,7 @@ static void _set_init(struct node *n) {
33273322
return;
33283323
}
33293324
struct node *nn = unit_env_get_node(unit, key);
3330-
if (nn) {
3325+
if (nn && nn != n) {
33313326
n->recur_next.n = nn;
33323327
}
33333328
unit_env_set_node(unit, key, n);
@@ -3338,7 +3333,7 @@ static const char* _set_value_get(struct node *n) {
33383333
}
33393334
n->recur_next.active = true;
33403335
struct node_foreach *fe = node_find_parent_foreach(n);
3341-
if (fe || _set_is_force(n)) {
3336+
if (fe) {
33423337
if ((uintptr_t) n->impl != (uintptr_t) -1) {
33433338
free(n->impl);
33443339
}
@@ -3398,9 +3393,7 @@ int node_set_setup(struct node *n) {
33983393
n->setup = _set_setup;
33993394
n->value_get = _set_value_get;
34003395
n->dispose = _set_dispose;
3401-
if (_set_is_force(n)) {
3402-
n->build = _set_build;
3403-
}
3396+
n->build = _set_build;
34043397
return 0;
34053398
}
34063399
#ifndef _AMALGAMATE_
@@ -7337,7 +7330,7 @@ static unsigned _rule_type(const char *key, unsigned *flags) {
73377330
return NODE_TYPE_SUBST;
73387331
} else if (strcmp(key, "^") == 0) {
73397332
return NODE_TYPE_JOIN;
7340-
} else if (strcmp(key, "set") == 0 || strcmp(key, "env") == 0 || strcmp(key, "set-force") == 0) {
7333+
} else if (strcmp(key, "set") == 0 || strcmp(key, "env") == 0) {
73417334
return NODE_TYPE_SET;
73427335
} else if (strcmp(key, "check") == 0) {
73437336
return NODE_TYPE_CHECK;

dist/docs/index.html

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -823,20 +823,6 @@ <h1 id="set-">set {...}</h1>
823823
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a><span class="dt"> }</span></span>
824824
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a><span class="dt"> ... # values</span></span>
825825
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a><span class="dt">}</span></span></code></pre></div>
826-
<h2 id="set-force">set-force</h2>
827-
<p>Please note that the <code>set</code> directive assigns a variable
828-
under the given name during the init <code>build</code> phase. If you
829-
use multiple set expressions for the same variable name, only the last
830-
one will take effect. This happens because set expression values are
831-
evaluated during the <code>init</code> phase, while the
832-
<code>build</code> and <code>setup</code> phases are executed afterward
833-
- using the values cached from <code>init</code>.</p>
834-
<p>This behavior often causes confusion in <code>macros</code> that are
835-
invoked multiple times and contain <code>set</code> directives in their
836-
bodies.</p>
837-
<p>To ensure the variable is correctly updated across all build and
838-
setup phases, use <code>set-force</code>. Unlike set, it is executed for
839-
every phase and does not cache its results.</p>
840826
<h1 id="env-">env {...}</h1>
841827
<p>Similar to <code>set</code>, but sets an <strong>environment
842828
variable</strong> for the build process using <code>setenv(3)</code> at

node_set.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,8 @@ static struct unit* _unit_for_set(struct node *n, struct node *nn, const char **
2525

2626
static void _set_init(struct node *n);
2727

28-
static bool _set_is_force(struct node *n) {
29-
return strcmp(n->value, "set-force") == 0;
30-
}
31-
3228
static void _set_setup(struct node *n) {
33-
if (_set_is_force(n)) {
34-
_set_init(n);
35-
}
29+
_set_init(n);
3630
if (n->child && strcmp(n->value, "env") == 0) {
3731
const char *v = _set_value_get(n);
3832
if (v) {
@@ -56,7 +50,7 @@ static void _set_init(struct node *n) {
5650
return;
5751
}
5852
struct node *nn = unit_env_get_node(unit, key);
59-
if (nn) {
53+
if (nn && nn != n) {
6054
n->recur_next.n = nn;
6155
}
6256
unit_env_set_node(unit, key, n);
@@ -69,7 +63,7 @@ static const char* _set_value_get(struct node *n) {
6963
n->recur_next.active = true;
7064

7165
struct node_foreach *fe = node_find_parent_foreach(n);
72-
if (fe || _set_is_force(n)) {
66+
if (fe) {
7367
if ((uintptr_t) n->impl != (uintptr_t) -1) {
7468
free(n->impl);
7569
}
@@ -138,8 +132,6 @@ int node_set_setup(struct node *n) {
138132
n->setup = _set_setup;
139133
n->value_get = _set_value_get;
140134
n->dispose = _set_dispose;
141-
if (_set_is_force(n)) {
142-
n->build = _set_build;
143-
}
135+
n->build = _set_build;
144136
return 0;
145137
}

script.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static unsigned _rule_type(const char *key, unsigned *flags) {
7474
return NODE_TYPE_SUBST;
7575
} else if (strcmp(key, "^") == 0) {
7676
return NODE_TYPE_JOIN;
77-
} else if (strcmp(key, "set") == 0 || strcmp(key, "env") == 0 || strcmp(key, "set-force") == 0) {
77+
} else if (strcmp(key, "set") == 0 || strcmp(key, "env") == 0) {
7878
return NODE_TYPE_SET;
7979
} else if (strcmp(key, "check") == 0) {
8080
return NODE_TYPE_CHECK;

tests/data/test10/Autark

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
macro {
22
M_ECHO
3-
set-force {
3+
set {
44
JOIN
55
^{&{1} ' ' &{2}}
66
}

tests/data/test10/Autark.dump

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Autark:0x100 {
2-
set-force:0x4 {
2+
set:0x4 {
33
JOIN:0x1
44
^:0x8 {
55
foo bar:0x1
@@ -21,7 +21,7 @@ Autark:0x100 {
2121
JOIN:0x1
2222
}
2323
}
24-
set-force:0x4 {
24+
set:0x4 {
2525
JOIN:0x1
2626
^:0x8 {
2727
baz gaz:0x1

tests/test10.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ int main(void) {
1212
struct sctx *sctx;
1313
akassert(script_open("../../tests/data/test10/Autark", &sctx) == 0);
1414
script_build(sctx);
15+
1516
akassert(
1617
strcmp(
1718
"Autark:9 init: foo bar\n"
@@ -21,6 +22,7 @@ int main(void) {
2122
"Autark:7 echo: last\n"
2223
"Autark:13 echo: JOIN baz gaz last\n",
2324
xstr_ptr(xstr)) == 0);
25+
2426
xstr_clear(xstr);
2527
script_dump(sctx, xstr);
2628
script_close(&sctx);

0 commit comments

Comments
 (0)