Skip to content

Commit 607c002

Browse files
committed
* Fix: Now produced files are tracked as dependency for rules (run, configure). cc is under consideration.
1 parent 42084e3 commit 607c002

File tree

10 files changed

+159
-24
lines changed

10 files changed

+159
-24
lines changed

deps.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ bool deps_cur_is_outdated(struct node *n, struct deps *d) {
111111
}
112112
return strcmp(val, d->resource) != 0;
113113
}
114+
case DEPS_TYPE_FILE_NOT_EXISTS: {
115+
struct akpath_stat st;
116+
if (path_stat(d->resource, &st) || st.ftype == AKPATH_NOT_EXISTS) {
117+
return true;
118+
}
119+
break;
120+
}
114121
case DEPS_TYPE_OUTDATED:
115122
return true;
116123
}
@@ -152,6 +159,10 @@ static int _deps_add(struct deps *d, char type, char flags, const char *resource
152159
path_normalize(resource, buf[0]);
153160
resource = buf[0];
154161
serial = 0;
162+
} else if (type == DEPS_TYPE_FILE_NOT_EXISTS) {
163+
path_normalize(resource, buf[0]);
164+
resource = buf[0];
165+
serial = 0;
155166
}
156167

157168
long int off = ftell(d->file);

deps.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
#include <stdint.h>
1010
#endif
1111

12-
#define DEPS_TYPE_FILE 102 // f
13-
#define DEPS_TYPE_FILE_OUTDATED 111 // x
14-
#define DEPS_TYPE_NODE_VALUE 118 // v
15-
#define DEPS_TYPE_ENV 101 // e
16-
#define DEPS_TYPE_SYS_ENV 115 // s
17-
#define DEPS_TYPE_ALIAS 97 // a
18-
#define DEPS_TYPE_OUTDATED 120 // o
12+
#define DEPS_TYPE_FILE 102 // f
13+
#define DEPS_TYPE_FILE_OUTDATED 111 // x
14+
#define DEPS_TYPE_NODE_VALUE 118 // v
15+
#define DEPS_TYPE_ENV 101 // e
16+
#define DEPS_TYPE_SYS_ENV 115 // s
17+
#define DEPS_TYPE_ALIAS 97 // a
18+
#define DEPS_TYPE_OUTDATED 120 // o
19+
#define DEPS_TYPE_FILE_NOT_EXISTS 110 // n
1920

2021
#define DEPS_OPEN_TRUNCATE 0x01U
2122
#define DEPS_OPEN_READONLY 0x02U

dist/autark.c

Lines changed: 55 additions & 8 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 "4a8a474"
5+
#define META_REVISION "42084e3"
66

77
#define MACRO_MAX_RECURSIVE_CALLS 128
88

@@ -572,6 +572,8 @@ void utils_split_values_add(const char *v, struct xstr *xstr);
572572

573573
int utils_fd_make_non_blocking(int fd);
574574

575+
int64_t utils_current_time_ms(void);
576+
575577
//----------------------- Vlist
576578

577579
struct vlist_iter {
@@ -885,13 +887,14 @@ const char* env_libdir(void);
885887
#include <stdint.h>
886888
#endif
887889

888-
#define DEPS_TYPE_FILE 102 // f
889-
#define DEPS_TYPE_FILE_OUTDATED 111 // x
890-
#define DEPS_TYPE_NODE_VALUE 118 // v
891-
#define DEPS_TYPE_ENV 101 // e
892-
#define DEPS_TYPE_SYS_ENV 115 // s
893-
#define DEPS_TYPE_ALIAS 97 // a
894-
#define DEPS_TYPE_OUTDATED 120 // o
890+
#define DEPS_TYPE_FILE 102 // f
891+
#define DEPS_TYPE_FILE_OUTDATED 111 // x
892+
#define DEPS_TYPE_NODE_VALUE 118 // v
893+
#define DEPS_TYPE_ENV 101 // e
894+
#define DEPS_TYPE_SYS_ENV 115 // s
895+
#define DEPS_TYPE_ALIAS 97 // a
896+
#define DEPS_TYPE_OUTDATED 120 // o
897+
#define DEPS_TYPE_FILE_NOT_EXISTS 110 // n
895898

896899
#define DEPS_OPEN_TRUNCATE 0x01U
897900
#define DEPS_OPEN_READONLY 0x02U
@@ -1111,6 +1114,8 @@ struct node* node_by_product(struct node*, const char *prod, char pathbuf[PATH_M
11111114

11121115
struct node* node_by_product_raw(struct node*, const char *prod);
11131116

1117+
void node_products_add_as_deps(struct node *n, struct deps *deps);
1118+
11141119
void node_product_add(struct node*, const char *prod, char pathbuf[PATH_MAX]);
11151120

11161121
void node_product_add_raw(struct node*, const char *prod);
@@ -2396,6 +2401,7 @@ int map_iter_next(struct map_iter *iter) {
23962401
#include <errno.h>
23972402
#include <fcntl.h>
23982403
#include <stdio.h>
2404+
#include <time.h>
23992405
#endif
24002406

24012407
struct value utils_file_as_buf(const char *path, ssize_t buflen_max) {
@@ -2586,6 +2592,20 @@ int utils_fd_make_non_blocking(int fd) {
25862592
}
25872593
return 0;
25882594
}
2595+
2596+
int64_t utils_current_time_ms(void) {
2597+
struct timespec ts;
2598+
#if defined(CLOCK_REALTIME)
2599+
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
2600+
akfatal(errno, "", 0);
2601+
}
2602+
#else
2603+
struct timeval tv;
2604+
gettimeofday(&tv, NULL);
2605+
return (int64_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
2606+
#endif
2607+
return (int64_t) ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
2608+
}
25892609
#ifndef _AMALGAMATE_
25902610
#include "paths.h"
25912611
#include "xstr.h"
@@ -3607,6 +3627,13 @@ bool deps_cur_is_outdated(struct node *n, struct deps *d) {
36073627
}
36083628
return strcmp(val, d->resource) != 0;
36093629
}
3630+
case DEPS_TYPE_FILE_NOT_EXISTS: {
3631+
struct akpath_stat st;
3632+
if (path_stat(d->resource, &st) || st.ftype == AKPATH_NOT_EXISTS) {
3633+
return true;
3634+
}
3635+
break;
3636+
}
36103637
case DEPS_TYPE_OUTDATED:
36113638
return true;
36123639
}
@@ -3648,6 +3675,10 @@ static int _deps_add(struct deps *d, char type, char flags, const char *resource
36483675
path_normalize(resource, buf[0]);
36493676
resource = buf[0];
36503677
serial = 0;
3678+
} else if (type == DEPS_TYPE_FILE_NOT_EXISTS) {
3679+
path_normalize(resource, buf[0]);
3680+
resource = buf[0];
3681+
serial = 0;
36513682
}
36523683

36533684
long int off = ftell(d->file);
@@ -4765,6 +4796,8 @@ static void _run_on_resolve(struct node_resolve *r) {
47654796
deps_add(&deps, DEPS_TYPE_FILE, 'f', path, 0);
47664797
}
47674798

4799+
node_products_add_as_deps(n, &deps);
4800+
47684801
deps_close(&deps);
47694802
}
47704803

@@ -5147,6 +5180,8 @@ static void _configure_on_resolve(struct node_resolve *r) {
51475180
deps_add(&deps, DEPS_TYPE_FILE, 's', src, 0);
51485181
}
51495182

5183+
node_products_add_as_deps(n, &deps);
5184+
51505185
deps_close(&deps);
51515186

51525187
ulist_destroy_keep(&rlist);
@@ -9291,6 +9326,18 @@ struct node* node_by_product_raw(struct node *n, const char *prod) {
92919326
return map_get(s->products, prod);
92929327
}
92939328

9329+
void node_products_add_as_deps(struct node *n, struct deps *deps) {
9330+
struct map_iter it;
9331+
struct sctx *s = n->ctx;
9332+
map_iter_init(s->products, &it);
9333+
int64_t ts = utils_current_time_ms();
9334+
while (map_iter_next(&it)) {
9335+
if (it.val == n) {
9336+
deps_add(deps, DEPS_TYPE_FILE, 0, it.key, ts);
9337+
}
9338+
}
9339+
}
9340+
92949341
struct node* node_find_direct_child(struct node *n, int type, const char *val) {
92959342
if (n) {
92969343
for (struct node *nn = n->child; nn; nn = nn->next) {

dist/build.sh

Lines changed: 50 additions & 9 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=4a8a474
9+
META_REVISION=42084e3
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 "4a8a474"
65+
#define META_REVISION "42084e3"
6666
#define MACRO_MAX_RECURSIVE_CALLS 128
6767
#endif
6868
#define _AMALGAMATE_
@@ -481,6 +481,7 @@ int utils_copy_file(const char *src, const char *dst);
481481
int utils_rename_file(const char *src, const char *dst);
482482
void utils_split_values_add(const char *v, struct xstr *xstr);
483483
int utils_fd_make_non_blocking(int fd);
484+
int64_t utils_current_time_ms(void);
484485
//----------------------- Vlist
485486
struct vlist_iter {
486487
const char *item;
@@ -704,13 +705,14 @@ const char* env_libdir(void);
704705
#include <limits.h>
705706
#include <stdint.h>
706707
#endif
707-
#define DEPS_TYPE_FILE 102 // f
708-
#define DEPS_TYPE_FILE_OUTDATED 111 // x
709-
#define DEPS_TYPE_NODE_VALUE 118 // v
710-
#define DEPS_TYPE_ENV 101 // e
711-
#define DEPS_TYPE_SYS_ENV 115 // s
712-
#define DEPS_TYPE_ALIAS 97 // a
713-
#define DEPS_TYPE_OUTDATED 120 // o
708+
#define DEPS_TYPE_FILE 102 // f
709+
#define DEPS_TYPE_FILE_OUTDATED 111 // x
710+
#define DEPS_TYPE_NODE_VALUE 118 // v
711+
#define DEPS_TYPE_ENV 101 // e
712+
#define DEPS_TYPE_SYS_ENV 115 // s
713+
#define DEPS_TYPE_ALIAS 97 // a
714+
#define DEPS_TYPE_OUTDATED 120 // o
715+
#define DEPS_TYPE_FILE_NOT_EXISTS 110 // n
714716
#define DEPS_OPEN_TRUNCATE 0x01U
715717
#define DEPS_OPEN_READONLY 0x02U
716718
#define DEPS_BUF_SZ 262144
@@ -879,6 +881,7 @@ void node_env_set(struct node*, const char *key, const char *val);
879881
void node_env_set_node(struct node*, const char *key, unsigned tag);
880882
struct node* node_by_product(struct node*, const char *prod, char pathbuf[PATH_MAX]);
881883
struct node* node_by_product_raw(struct node*, const char *prod);
884+
void node_products_add_as_deps(struct node *n, struct deps *deps);
882885
void node_product_add(struct node*, const char *prod, char pathbuf[PATH_MAX]);
883886
void node_product_add_raw(struct node*, const char *prod);
884887
void node_reset(struct node *n);
@@ -2011,6 +2014,7 @@ int map_iter_next(struct map_iter *iter) {
20112014
#include <errno.h>
20122015
#include <fcntl.h>
20132016
#include <stdio.h>
2017+
#include <time.h>
20142018
#endif
20152019
struct value utils_file_as_buf(const char *path, ssize_t buflen_max) {
20162020
struct value ret = { 0 };
@@ -2190,6 +2194,19 @@ int utils_fd_make_non_blocking(int fd) {
21902194
}
21912195
return 0;
21922196
}
2197+
int64_t utils_current_time_ms(void) {
2198+
struct timespec ts;
2199+
#if defined(CLOCK_REALTIME)
2200+
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
2201+
akfatal(errno, "", 0);
2202+
}
2203+
#else
2204+
struct timeval tv;
2205+
gettimeofday(&tv, NULL);
2206+
return (int64_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
2207+
#endif
2208+
return (int64_t) ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
2209+
}
21932210
#ifndef _AMALGAMATE_
21942211
#include "paths.h"
21952212
#include "xstr.h"
@@ -3095,6 +3112,13 @@ bool deps_cur_is_outdated(struct node *n, struct deps *d) {
30953112
}
30963113
return strcmp(val, d->resource) != 0;
30973114
}
3115+
case DEPS_TYPE_FILE_NOT_EXISTS: {
3116+
struct akpath_stat st;
3117+
if (path_stat(d->resource, &st) || st.ftype == AKPATH_NOT_EXISTS) {
3118+
return true;
3119+
}
3120+
break;
3121+
}
30983122
case DEPS_TYPE_OUTDATED:
30993123
return true;
31003124
}
@@ -3134,6 +3158,10 @@ static int _deps_add(struct deps *d, char type, char flags, const char *resource
31343158
path_normalize(resource, buf[0]);
31353159
resource = buf[0];
31363160
serial = 0;
3161+
} else if (type == DEPS_TYPE_FILE_NOT_EXISTS) {
3162+
path_normalize(resource, buf[0]);
3163+
resource = buf[0];
3164+
serial = 0;
31373165
}
31383166
long int off = ftell(d->file);
31393167
if (off < 0) {
@@ -4124,6 +4152,7 @@ static void _run_on_resolve(struct node_resolve *r) {
41244152
const char *path = *(const char**) ulist_get(&ctx->consumes_foreach, i);
41254153
deps_add(&deps, DEPS_TYPE_FILE, 'f', path, 0);
41264154
}
4155+
node_products_add_as_deps(n, &deps);
41274156
deps_close(&deps);
41284157
}
41294158
static bool _run_setup_foreach(struct node *n) {
@@ -4459,6 +4488,7 @@ static void _configure_on_resolve(struct node_resolve *r) {
44594488
char *src = *(char**) ulist_get(&ctx->sources, i);
44604489
deps_add(&deps, DEPS_TYPE_FILE, 's', src, 0);
44614490
}
4491+
node_products_add_as_deps(n, &deps);
44624492
deps_close(&deps);
44634493
ulist_destroy_keep(&rlist);
44644494
}
@@ -8226,6 +8256,17 @@ struct node* node_by_product_raw(struct node *n, const char *prod) {
82268256
struct sctx *s = n->ctx;
82278257
return map_get(s->products, prod);
82288258
}
8259+
void node_products_add_as_deps(struct node *n, struct deps *deps) {
8260+
struct map_iter it;
8261+
struct sctx *s = n->ctx;
8262+
map_iter_init(s->products, &it);
8263+
int64_t ts = utils_current_time_ms();
8264+
while (map_iter_next(&it)) {
8265+
if (it.val == n) {
8266+
deps_add(deps, DEPS_TYPE_FILE, 0, it.key, ts);
8267+
}
8268+
}
8269+
}
82298270
struct node* node_find_direct_child(struct node *n, int type, const char *val) {
82308271
if (n) {
82318272
for (struct node *nn = n->child; nn; nn = nn->next) {

node_configure.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ static void _configure_on_resolve(struct node_resolve *r) {
239239
deps_add(&deps, DEPS_TYPE_FILE, 's', src, 0);
240240
}
241241

242+
node_products_add_as_deps(n, &deps);
243+
242244
deps_close(&deps);
243245

244246
ulist_destroy_keep(&rlist);

node_run.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ static void _run_on_resolve(struct node_resolve *r) {
217217
deps_add(&deps, DEPS_TYPE_FILE, 'f', path, 0);
218218
}
219219

220+
node_products_add_as_deps(n, &deps);
221+
220222
deps_close(&deps);
221223
}
222224

script.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,18 @@ struct node* node_by_product_raw(struct node *n, const char *prod) {
958958
return map_get(s->products, prod);
959959
}
960960

961+
void node_products_add_as_deps(struct node *n, struct deps *deps) {
962+
struct map_iter it;
963+
struct sctx *s = n->ctx;
964+
map_iter_init(s->products, &it);
965+
int64_t ts = utils_current_time_ms();
966+
while (map_iter_next(&it)) {
967+
if (it.val == n) {
968+
deps_add(deps, DEPS_TYPE_FILE, 0, it.key, ts);
969+
}
970+
}
971+
}
972+
961973
struct node* node_find_direct_child(struct node *n, int type, const char *val) {
962974
if (n) {
963975
for (struct node *nn = n->child; nn; nn = nn->next) {

script.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ struct node* node_by_product(struct node*, const char *prod, char pathbuf[PATH_M
128128

129129
struct node* node_by_product_raw(struct node*, const char *prod);
130130

131+
void node_products_add_as_deps(struct node *n, struct deps *deps);
132+
131133
void node_product_add(struct node*, const char *prod, char pathbuf[PATH_MAX]);
132134

133135
void node_product_add_raw(struct node*, const char *prod);

0 commit comments

Comments
 (0)