-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.h
More file actions
215 lines (157 loc) · 5.78 KB
/
Copy pathscript.h
File metadata and controls
215 lines (157 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#ifndef SCRIPT_H
#define SCRIPT_H
#ifndef _AMALGAMATE_
#include "ulist.h"
#include "xstr.h"
#include "deps.h"
#include "map.h"
#include <stdbool.h>
#endif
// value types
#define NODE_TYPE_VALUE 0x01U
#define NODE_TYPE_SUBST 0x02U
#define NODE_TYPE_SET 0x04U
#define NODE_TYPE_JOIN 0x08U
#define NODE_TYPE_BASENAME 0x10U
#define NODE_TYPE_DIR 0x20U
#define NODE_TYPE_FIND 0x40U
// eof value types
#define NODE_TYPE_SCRIPT 0x100U
#define NODE_TYPE_BAG 0x200U
#define NODE_TYPE_META 0x400U
#define NODE_TYPE_CHECK 0x800U
#define NODE_TYPE_INCLUDE 0x1000U
#define NODE_TYPE_IF 0x2000U
#define NODE_TYPE_RUN 0x4000U
#define NODE_TYPE_CC 0x8000U
#define NODE_TYPE_CONFIGURE 0x10000U
#define NODE_TYPE_FOREACH 0x20000U
#define NODE_TYPE_IN_SOURCES 0x40000U
#define NODE_TYPE_OPTION 0x80000U
#define NODE_TYPE_ERROR 0x100000U
#define NODE_TYPE_ECHO 0x200000U
#define NODE_TYPE_INSTALL 0x400000U
#define NODE_TYPE_MACRO 0x800000U
#define NODE_TYPE_CALL 0x1000000U
#define NODE_FLG_BOUND 0x01U
#define NODE_FLG_INIT 0x02U
#define NODE_FLG_SETUP 0x04U
// Vacant: 0x08U
#define NODE_FLG_BUILT 0x10U // Node built
#define NODE_FLG_POST_BUILT 0x20U // Node post-built
#define NODE_FLG_IN_CACHE 0x40U
#define NODE_FLG_IN_SRC 0x80U
#define NODE_FLG_NO_CWD 0x100U
#define NODE_FLG_NEGATE 0x200U
#define NODE_FLG_IN_ANY (NODE_FLG_IN_SRC | NODE_FLG_IN_CACHE | NODE_FLG_NO_CWD)
#define node_is_init(n__) (((n__)->flags & NODE_FLG_INIT) != 0)
#define node_is_setup(n__) (((n__)->flags & NODE_FLG_SETUP) != 0)
#define node_is_built(n__) (((n__)->flags & NODE_FLG_BUILT) != 0)
#define node_is_post_built(n__) (((n__)->flags & NODE_FLG_POST_BUILT) != 0)
#define node_is_value(n__) ((n__)->type == NODE_TYPE_VALUE)
#define node_is_can_be_value(n__) ((n__)->type >= NODE_TYPE_VALUE && (n__)->type <= NODE_TYPE_FIND)
#define node_is_rule(n__) !node_is_value(n__)
#define NODE_PRINT_INDENT 2
struct node_foreach {
char *name;
char *value;
char *items;
unsigned access_cnt;
};
struct node {
unsigned type;
unsigned flags;
unsigned flags_owner; /// Extra flaghs set by owner node
unsigned index; /// Own index in env::nodes
unsigned lnum; /// Node line number
const char *name; /// Internal node name
const char *vfile; /// Node virtual file
const char *value; /// Key or value
struct node *child;
struct node *next;
struct node *parent;
// Recursive set
struct {
struct node *n;
bool active;
} recur_next;
struct sctx *ctx;
struct unit *unit;
const char* (*value_get)(struct node*);
void (*init)(struct node*);
void (*setup)(struct node*);
void (*build)(struct node*);
void (*post_build)(struct node*);
void (*dispose)(struct node*);
void *impl;
};
struct sctx {
struct node *root; /// Project root script node (Autark)
struct ulist nodes; /// ulist<struct node*>
struct map *products; /// Products of nodes (product name -> node)
};
int script_open(const char *file, struct sctx **out);
int script_include(struct node *parent, const char *file, struct node **out);
void script_build(struct sctx*);
void script_close(struct sctx**);
void script_dump(struct sctx*, struct xstr *out);
const char* node_env_get(struct node*, const char *key);
void node_env_set(struct node*, const char *key, const char *val);
void node_env_set_node(struct node*, const char *key, unsigned tag);
struct node* node_by_product(struct node*, const char *prod, char pathbuf[PATH_MAX]);
struct node* node_by_product_raw(struct node*, const char *prod);
void node_products_add_as_deps(struct node *n, struct deps *deps);
void node_product_add(struct node*, const char *prod, char pathbuf[PATH_MAX]);
void node_product_add_raw(struct node*, const char *prod);
void node_reset(struct node *n);
const char* node_value(struct node *n);
#define NODE_VISIT_CHILD_SKIP INT_MAX
int node_visit(struct node *n, int lvl, void *ctx, int (*visitor)(struct node*, int, void*));
void node_module_setup(struct node *n, unsigned flags);
void node_init(struct node *n);
void node_setup(struct node *n);
void node_build(struct node *n);
void node_post_build(struct node *n);
struct node* node_find_direct_child(struct node *n, int type, const char *val);
struct node* node_find_prev_sibling(struct node *n);
struct node* node_find_parent_of_type(struct node *n, int type);
struct node_foreach* node_find_parent_foreach(struct node *n);
bool node_is_value_may_be_dep_saved(struct node *n, unsigned skip_type);
struct node* node_consumes_resolve(
struct node *n,
struct node *npaths,
struct ulist *paths,
void (*on_resolved)(const char *path, void *opq),
void *opq);
void node_add_unit_deps(struct node *n, struct deps*);
struct node_resolve {
struct node *n;
const char *path;
void *user_data;
void (*on_init)(struct node_resolve*);
void (*on_env_value)(struct node_resolve*, const char *key, const char *val);
void (*on_resolve)(struct node_resolve*);
const char *deps_path_tmp;
const char *env_path_tmp;
struct ulist resolve_outdated; // struct resolve_outdated
struct ulist node_val_deps; // struct node*
struct pool *pool;
unsigned mode;
int num_deps; // Number of dependencies
bool force_outdated;
};
struct resolve_outdated {
char type;
char flags;
char *path;
};
#define NODE_RESOLVE_ENV_ALWAYS 0x01U
void node_resolve(struct node_resolve*);
__attribute__((noreturn))
void node_fatal(int rc, struct node *n, const char *fmt, ...);
void node_info(struct node *n, const char *fmt, ...);
void node_warn(struct node *n, const char *fmt, ...);
int node_error(int rc, struct node *n, const char *fmt, ...);
struct node* node_clone_and_register(struct node*);
int node_bind(struct node*);
#endif