gwenhywfar  5.10.1
buildctx_bdeps.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Mon Feb 08 2021
3  copyright : (C) 2021 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * Please see toplevel file COPYING for license details *
8  ***************************************************************************/
9 
10 #ifdef HAVE_CONFIG_H
11 # include <config.h>
12 #endif
13 
14 #define DISABLE_DEBUGLOG
15 
16 
17 #include "gwenbuild/buildctx/buildctx_p.h"
19 
20 #include <gwenhywfar/debug.h>
21 #include <gwenhywfar/text.h>
22 #include <gwenhywfar/directory.h>
23 
24 #include <unistd.h>
25 #include <ctype.h>
26 
27 
28 
29 static void _setupDepsForCmd(GWB_BUILD_CMD *bcmd, GWB_BUILD_CMD_LIST2 *targetCmdList);
30 static void _setBuildCmdInFiles(GWB_BUILD_CONTEXT *bctx);
31 static void _fileListSetBuildCmd(GWB_FILE_LIST2 *fileList, GWB_BUILD_CMD *bcmd);
32 static int _cmdIsInList(const GWB_BUILD_CMD_LIST2 *sourceCmdList, const GWB_BUILD_CMD *cmd);
33 
34 static void _clearDeps(GWB_BUILD_CONTEXT *bctx);
35 static void _clearDepsInCommands(GWB_BUILD_CONTEXT *bctx);
36 static void _clearDepsInFiles(GWB_BUILD_CONTEXT *bctx);
37 
38 
39 
40 
41 
43 {
44  _clearDeps(bctx);
45  _setBuildCmdInFiles(bctx);
46  return 0;
47 }
48 
49 
50 
51 int GWB_BuildCtx_FillWaitingQueue(GWB_BUILD_CONTEXT *bctx, const char *builderName)
52 {
53  int rv;
54 
55  rv=GWB_BuildCtx_AddBuildCmdsByBuilderNameToList(bctx->commandList, builderName, bctx->waitingQueue);
56  if (rv<0) {
57  DBG_INFO(NULL, "here (%d)", rv);
58  return rv;
59  }
60 
61 #if 0
62  DBG_ERROR(NULL, "Got this queue:");
63  GWBUILD_Debug_PrintBuildCmdList2("Waiting Queue", bctx->waitingQueue, 2);
64 #endif
65 
66  return 0;
67 }
68 
69 
70 
71 int GWB_BuildCtx_AddBuildCmdsForFileToList(const GWB_FILE *file, GWB_BUILD_CMD_LIST2 *targetCmdList)
72 {
73  GWB_BUILD_CMD *bcmd;
74 
75  bcmd=GWB_File_GetBuildCmd(file);
76  if (bcmd) {
78  GWB_BuildCmd_List2_PushBack(targetCmdList, bcmd);
79  _setupDepsForCmd(bcmd, targetCmdList);
80  }
81  else {
82  const char *sBuilderName;
83  const char *sFolder;
84  const char *sFileName;
85 
86  sBuilderName=GWB_BuildCmd_GetBuilderName(bcmd);
87  sFileName=GWB_File_GetName(file);
88  sFolder=GWB_File_GetFolder(file);
89  DBG_ERROR(NULL, "Builder \"%s\" for selected file \"%s\" in folder \"%s\" has no build commands",
90  sBuilderName?sBuilderName:"<no name>",
91  sFileName?sFileName:"<no name>",
92  sFolder?sFolder:".");
93  }
94  }
95 
96  return 0;
97 }
98 
99 
100 
101 int GWB_BuildCtx_AddBuildCmdsByBuilderNameToList(const GWB_BUILD_CMD_LIST2 *sourceCmdList,
102  const char *builderName,
103  GWB_BUILD_CMD_LIST2 *targetCmdList)
104 {
105  if (sourceCmdList) {
106  GWB_BUILD_CMD_LIST2_ITERATOR *it;
107 
108  it=GWB_BuildCmd_List2_First(sourceCmdList);
109  if (it) {
110  if (builderName && *builderName) {
111  GWB_BUILD_CMD *bcmd;
112 
113  bcmd=GWB_BuildCmd_List2Iterator_Data(it);
114  while(bcmd) {
115  const char *s;
116 
118  if (s && strcasecmp(s, builderName)==0) {
119  if (!_cmdIsInList(targetCmdList, bcmd)) {
120  if (GWB_BuildCmd_GetCurrentCommand(bcmd)) {
121  GWB_BuildCmd_List2_PushBack(targetCmdList, bcmd);
122  _setupDepsForCmd(bcmd, targetCmdList);
123  }
124  }
125  }
126  bcmd=GWB_BuildCmd_List2Iterator_Next(it);
127  }
128  GWB_BuildCmd_List2Iterator_free(it);
129  }
130  else {
131  GWB_BUILD_CMD *bcmd;
132 
133  bcmd=GWB_BuildCmd_List2Iterator_Data(it);
134  while(bcmd) {
136  if (!_cmdIsInList(targetCmdList, bcmd)) {
137  if (GWB_BuildCmd_GetCurrentCommand(bcmd)) {
138  GWB_BuildCmd_List2_PushBack(targetCmdList, bcmd);
139  _setupDepsForCmd(bcmd, targetCmdList);
140  }
141  }
142  }
143  bcmd=GWB_BuildCmd_List2Iterator_Next(it);
144  }
145  GWB_BuildCmd_List2Iterator_free(it);
146  }
147  }
148  }
149  return 0;
150 }
151 
152 
153 
155 {
156  _clearDepsInCommands(bctx);
157  _clearDepsInFiles(bctx);
158 }
159 
160 
161 
163 {
164  if (bctx->commandList) {
165  GWB_BUILD_CMD_LIST2_ITERATOR *it;
166 
167  it=GWB_BuildCmd_List2_First(bctx->commandList);
168  if (it) {
169  GWB_BUILD_CMD *bcmd;
170 
171  bcmd=GWB_BuildCmd_List2Iterator_Data(it);
172  while(bcmd) {
174  bcmd=GWB_BuildCmd_List2Iterator_Next(it);
175  }
176  GWB_BuildCmd_List2Iterator_free(it);
177  }
178  }
179 }
180 
181 
182 
184 {
185  if (bctx->fileList) {
186  GWB_FILE_LIST2_ITERATOR *it;
187 
188  it=GWB_File_List2_First(bctx->fileList);
189  if (it) {
190  GWB_FILE *file;
191 
192  file=GWB_File_List2Iterator_Data(it);
193  while(file) {
195  file=GWB_File_List2Iterator_Next(it);
196  }
197  GWB_File_List2Iterator_free(it);
198  }
199  }
200 }
201 
202 
203 
204 
205 void _setupDepsForCmd(GWB_BUILD_CMD *bcmd, GWB_BUILD_CMD_LIST2 *targetCmdList)
206 {
207  GWB_FILE_LIST2 *fileList;
208 
209  fileList=GWB_BuildCmd_GetInFileList2(bcmd);
210  if (fileList) {
211  GWB_FILE_LIST2_ITERATOR *it;
212 
213  it=GWB_File_List2_First(fileList);
214  if (it) {
215  GWB_FILE *file;
216 
217  file=GWB_File_List2Iterator_Data(it);
218  while(file) {
219  GWB_BUILD_CMD *fileBuildCmd;
220 
221  fileBuildCmd=GWB_File_GetBuildCmd(file);
222  if (fileBuildCmd) {
223  GWB_File_AddWaitingBuildCmd(file, bcmd);
225  if (!_cmdIsInList(targetCmdList, fileBuildCmd)) {
226  if (GWB_BuildCmd_GetCurrentCommand(fileBuildCmd)) {
227  GWB_BuildCmd_List2_PushBack(targetCmdList, fileBuildCmd);
228  _setupDepsForCmd(fileBuildCmd, targetCmdList); /* recursion! */
229  }
230  }
231  }
232 
233  file=GWB_File_List2Iterator_Next(it);
234  }
235  GWB_File_List2Iterator_free(it);
236  }
237  }
238 }
239 
240 
241 
243 {
244  if (bctx->commandList) {
245  GWB_BUILD_CMD_LIST2_ITERATOR *it;
246 
247  it=GWB_BuildCmd_List2_First(bctx->commandList);
248  if (it) {
249  GWB_BUILD_CMD *bcmd;
250 
251  bcmd=GWB_BuildCmd_List2Iterator_Data(it);
252  while(bcmd) {
254  bcmd=GWB_BuildCmd_List2Iterator_Next(it);
255  }
256  GWB_BuildCmd_List2Iterator_free(it);
257  }
258  }
259 }
260 
261 
262 
263 void _fileListSetBuildCmd(GWB_FILE_LIST2 *fileList, GWB_BUILD_CMD *bcmd)
264 {
265  if (fileList) {
266  GWB_FILE_LIST2_ITERATOR *it;
267 
268  it=GWB_File_List2_First(fileList);
269  if (it) {
270  GWB_FILE *file;
271 
272  file=GWB_File_List2Iterator_Data(it);
273  while(file) {
274  GWB_File_SetBuildCmd(file, bcmd);
275  file=GWB_File_List2Iterator_Next(it);
276  }
277  GWB_File_List2Iterator_free(it);
278  }
279  }
280 }
281 
282 
283 
284 int _cmdIsInList(const GWB_BUILD_CMD_LIST2 *sourceCmdList, const GWB_BUILD_CMD *cmd)
285 {
286  GWB_BUILD_CMD_LIST2_ITERATOR *it;
287 
288  it=GWB_BuildCmd_List2_First(sourceCmdList);
289  if (it) {
290  GWB_BUILD_CMD *bcmd;
291 
292  bcmd=GWB_BuildCmd_List2Iterator_Data(it);
293  while(bcmd) {
294  if (bcmd==cmd) {
295  GWB_BuildCmd_List2Iterator_free(it);
296  return 1;
297  }
298  bcmd=GWB_BuildCmd_List2Iterator_Next(it);
299  }
300  GWB_BuildCmd_List2Iterator_free(it);
301  }
302 
303  return 0;
304 }
305 
306 
307 
308 
309 
310 
GWB_FILE_LIST2 * GWB_BuildCmd_GetInFileList2(const GWB_BUILD_CMD *bcmd)
Definition: buildcmd.c:255
static int _cmdIsInList(const GWB_BUILD_CMD_LIST2 *sourceCmdList, const GWB_BUILD_CMD *cmd)
void GWB_File_SetBuildCmd(GWB_FILE *f, GWB_BUILD_CMD *bcmd)
Definition: file.c:277
static void _setupDepsForCmd(GWB_BUILD_CMD *bcmd, GWB_BUILD_CMD_LIST2 *targetCmdList)
struct GWB_FILE GWB_FILE
Definition: file.h:18
struct GWB_BUILD_CONTEXT GWB_BUILD_CONTEXT
Definition: buildctx.h:16
#define NULL
Definition: binreloc.c:300
int GWB_BuildCtx_FillWaitingQueue(GWB_BUILD_CONTEXT *bctx, const char *builderName)
static void _setBuildCmdInFiles(GWB_BUILD_CONTEXT *bctx)
void GWBUILD_Debug_PrintBuildCmdList2(const char *sName, const GWB_BUILD_CMD_LIST2 *buildCmdList2, int indent)
Definition: gwenbuild.c:436
GWB_BUILD_CMD * GWB_File_GetBuildCmd(const GWB_FILE *f)
Definition: file.c:270
static void _clearDepsInFiles(GWB_BUILD_CONTEXT *bctx)
const char * GWB_File_GetFolder(const GWB_FILE *f)
Definition: file.c:127
const char * GWB_File_GetName(const GWB_FILE *f)
Definition: file.c:146
int GWB_BuildCtx_AddBuildCmdsForFileToList(const GWB_FILE *file, GWB_BUILD_CMD_LIST2 *targetCmdList)
GWB_FILE_LIST2 * GWB_BuildCmd_GetOutFileList2(const GWB_BUILD_CMD *bcmd)
Definition: buildcmd.c:270
void GWB_BuildCmd_SetBlockingFiles(GWB_BUILD_CMD *bcmd, int i)
Definition: buildcmd.c:231
#define GWB_BUILD_CMD_FLAGS_AUTO
Definition: buildcmd.h:27
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
GWB_BUILD_SUBCMD * GWB_BuildCmd_GetCurrentCommand(const GWB_BUILD_CMD *bcmd)
Definition: buildcmd.c:306
int GWB_BuildCtx_SetupDependencies(GWB_BUILD_CONTEXT *bctx)
struct GWB_BUILD_CMD GWB_BUILD_CMD
Definition: buildcmd.h:20
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:181
int GWB_BuildCmd_IncBlockingFiles(GWB_BUILD_CMD *bcmd)
Definition: buildcmd.c:238
void GWB_File_ClearWaitingBuildCmds(GWB_FILE *f)
Definition: file.c:262
static void _clearDeps(GWB_BUILD_CONTEXT *bctx)
const char * GWB_BuildCmd_GetBuilderName(const GWB_BUILD_CMD *bcmd)
Definition: buildcmd.c:148
uint32_t GWB_BuildCmd_GetFlags(const GWB_BUILD_CMD *bcmd)
Definition: buildcmd.c:120
static void _fileListSetBuildCmd(GWB_FILE_LIST2 *fileList, GWB_BUILD_CMD *bcmd)
static void _clearDepsInCommands(GWB_BUILD_CONTEXT *bctx)
void GWB_File_AddWaitingBuildCmd(GWB_FILE *f, GWB_BUILD_CMD *bcmd)
Definition: file.c:253
int GWB_BuildCtx_AddBuildCmdsByBuilderNameToList(const GWB_BUILD_CMD_LIST2 *sourceCmdList, const char *builderName, GWB_BUILD_CMD_LIST2 *targetCmdList)