gwenhywfar  5.10.1
buildctx.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 
19 #include "gwenbuild/buildctx/buildctx_p.h"
20 
21 #include <gwenhywfar/debug.h>
22 #include <gwenhywfar/text.h>
23 #include <gwenhywfar/directory.h>
24 
25 #include <unistd.h>
26 #include <ctype.h>
27 
28 
29 
31 {
32  GWB_BUILD_CONTEXT *bctx;
33 
35  bctx->commandList=GWB_BuildCmd_List2_new();
36  bctx->fileList=GWB_File_List2_new();
37 
38  return bctx;
39 }
40 
41 
42 
44 {
45  if (bctx) {
46  GWB_BuildCmd_List2_free(bctx->waitingQueue);
47  GWB_BuildCmd_List2_free(bctx->runningQueue);
48  GWB_BuildCmd_List2_free(bctx->finishedQueue);
49 
50  GWB_BuildCmd_List2_FreeAll(bctx->commandList);
51  GWB_File_List2_FreeAll(bctx->fileList);
52 
53  free(bctx->initialSourceDir);
54 
55  GWEN_FREE_OBJECT(bctx);
56  }
57 }
58 
59 
60 
62 {
63  return bctx->initialSourceDir;
64 }
65 
66 
67 
69 {
70  free(bctx->initialSourceDir);
71  bctx->initialSourceDir=s?strdup(s):NULL;
72 }
73 
74 
75 
76 GWB_BUILD_CMD_LIST2 *GWB_BuildCtx_GetCommandList(const GWB_BUILD_CONTEXT *bctx)
77 {
78  return bctx->commandList;
79 }
80 
81 
82 
84 {
85  GWB_BuildCmd_List2_PushBack(bctx->commandList, cmd);
86 }
87 
88 
89 
90 GWB_FILE_LIST2 *GWB_BuildCtx_GetFileList(const GWB_BUILD_CONTEXT *bctx)
91 {
92  return bctx->fileList;
93 }
94 
95 
96 
98 {
99  GWB_File_SetId(file, ++(bctx->lastFileId));
100  GWB_File_List2_PushBack(bctx->fileList, file);
101 }
102 
103 
104 
105 GWB_FILE *GWB_BuildCtx_GetFileByPathAndName(const GWB_BUILD_CONTEXT *bctx, const char *folder, const char *fname)
106 {
107  return GWB_File_List2_GetFileByPathAndName(bctx->fileList, folder, fname);
108 }
109 
110 
111 
113 {
114  GWB_FILE *storedFile;
115 
117  if (storedFile)
118  GWB_BuildCmd_AddInFile(bcmd, storedFile);
119  else {
120  GWB_FILE *fileCopy;
121 
122  fileCopy=GWB_File_dup(file);
123  GWB_BuildCmd_AddInFile(bcmd, fileCopy);
124  GWB_BuildCtx_AddFile(bctx, fileCopy);
125  }
126 }
127 
128 
129 
130 void GWB_BuildCtx_AddInFilesToCtxAndCmd(GWB_BUILD_CONTEXT *bctx, GWB_BUILD_CMD *bcmd, GWB_FILE_LIST2 *fileList)
131 {
132  GWB_FILE_LIST2_ITERATOR *it;
133 
134  it=GWB_File_List2_First(fileList);
135  if (it) {
136  GWB_FILE *file;
137 
138  file=GWB_File_List2Iterator_Data(it);
139  while(file) {
140  GWB_BuildCtx_AddInFileToCtxAndCmd(bctx, bcmd, file);
141  file=GWB_File_List2Iterator_Next(it);
142  }
143  GWB_File_List2Iterator_free(it);
144  }
145 }
146 
147 
148 
150 {
151  GWB_FILE *storedFile;
152 
154  if (storedFile)
155  GWB_BuildCmd_AddOutFile(bcmd, storedFile);
156  else {
157  GWB_FILE *fileCopy;
158 
159  fileCopy=GWB_File_dup(file);
160  GWB_BuildCmd_AddOutFile(bcmd, fileCopy);
161  GWB_BuildCtx_AddFile(bctx, fileCopy);
162  }
163 }
164 
165 
166 
167 void GWB_BuildCtx_AddOutFilesToCtxAndCmd(GWB_BUILD_CONTEXT *bctx, GWB_BUILD_CMD *bcmd, GWB_FILE_LIST2 *fileList)
168 {
169  GWB_FILE_LIST2_ITERATOR *it;
170 
171  it=GWB_File_List2_First(fileList);
172  if (it) {
173  GWB_FILE *file;
174 
175  file=GWB_File_List2Iterator_Data(it);
176  while(file) {
177  GWB_BuildCtx_AddOutFileToCtxAndCmd(bctx, bcmd, file);
178  file=GWB_File_List2Iterator_Next(it);
179  }
180  GWB_File_List2Iterator_free(it);
181  }
182 }
183 
184 
185 
186 void GWB_BuildCtx_Dump(const GWB_BUILD_CONTEXT *bctx, int indent)
187 {
188  int i;
189 
190  for(i=0; i<indent; i++)
191  fprintf(stderr, " ");
192  fprintf(stderr, "BuildCtx:\n");
193 
194  GWBUILD_Debug_PrintBuildCmdList2("commandList", bctx->commandList, indent+2);
195  GWBUILD_Debug_PrintFileList2("fileList", bctx->fileList, indent+2);
196 }
197 
198 
199 
200 
201 
202 
GWB_BUILD_CONTEXT * GWB_BuildCtx_new()
Definition: buildctx.c:30
struct GWB_FILE GWB_FILE
Definition: file.h:18
struct GWB_BUILD_CONTEXT GWB_BUILD_CONTEXT
Definition: buildctx.h:16
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:61
#define NULL
Definition: binreloc.c:300
GWB_FILE * GWB_File_dup(const GWB_FILE *oldFile)
Definition: file.c:50
void GWB_BuildCtx_free(GWB_BUILD_CONTEXT *bctx)
Definition: buildctx.c:43
void GWB_File_SetId(GWB_FILE *f, uint32_t i)
Definition: file.c:92
void GWBUILD_Debug_PrintBuildCmdList2(const char *sName, const GWB_BUILD_CMD_LIST2 *buildCmdList2, int indent)
Definition: gwenbuild.c:436
GWB_FILE * GWB_BuildCtx_GetFileByPathAndName(const GWB_BUILD_CONTEXT *bctx, const char *folder, const char *fname)
Definition: buildctx.c:105
const char * GWB_File_GetFolder(const GWB_FILE *f)
Definition: file.c:127
const char * GWB_BuildCtx_GetInitialSourceDir(const GWB_BUILD_CONTEXT *bctx)
Definition: buildctx.c:61
const char * GWB_File_GetName(const GWB_FILE *f)
Definition: file.c:146
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:55
GWB_FILE_LIST2 * GWB_BuildCtx_GetFileList(const GWB_BUILD_CONTEXT *bctx)
Definition: buildctx.c:90
void GWB_BuildCmd_AddInFile(GWB_BUILD_CMD *bcmd, GWB_FILE *file)
Definition: buildcmd.c:262
void GWB_BuildCtx_SetInitialSourceDir(GWB_BUILD_CONTEXT *bctx, const char *s)
Definition: buildctx.c:68
void GWBUILD_Debug_PrintFileList2(const char *sName, const GWB_FILE_LIST2 *fileList2, int indent)
Definition: gwenbuild.c:334
void GWB_BuildCtx_AddInFilesToCtxAndCmd(GWB_BUILD_CONTEXT *bctx, GWB_BUILD_CMD *bcmd, GWB_FILE_LIST2 *fileList)
Definition: buildctx.c:130
void GWB_File_List2_FreeAll(GWB_FILE_LIST2 *fileList2)
Definition: file.c:284
void GWB_BuildCtx_AddCommand(GWB_BUILD_CONTEXT *bctx, GWB_BUILD_CMD *cmd)
Definition: buildctx.c:83
void GWB_BuildCtx_AddOutFilesToCtxAndCmd(GWB_BUILD_CONTEXT *bctx, GWB_BUILD_CMD *bcmd, GWB_FILE_LIST2 *fileList)
Definition: buildctx.c:167
void GWB_BuildCmd_List2_FreeAll(GWB_BUILD_CMD_LIST2 *cmdList)
Definition: buildcmd.c:548
GWB_FILE * GWB_File_List2_GetFileByPathAndName(const GWB_FILE_LIST2 *fileList, const char *folder, const char *fname)
Definition: file.c:353
void GWB_BuildCtx_AddFile(GWB_BUILD_CONTEXT *bctx, GWB_FILE *file)
Definition: buildctx.c:97
struct GWB_BUILD_CMD GWB_BUILD_CMD
Definition: buildcmd.h:20
GWB_BUILD_CMD_LIST2 * GWB_BuildCtx_GetCommandList(const GWB_BUILD_CONTEXT *bctx)
Definition: buildctx.c:76
void GWB_BuildCmd_AddOutFile(GWB_BUILD_CMD *bcmd, GWB_FILE *file)
Definition: buildcmd.c:277
void GWB_BuildCtx_AddInFileToCtxAndCmd(GWB_BUILD_CONTEXT *bctx, GWB_BUILD_CMD *bcmd, GWB_FILE *file)
Definition: buildctx.c:112
void GWB_BuildCtx_Dump(const GWB_BUILD_CONTEXT *bctx, int indent)
Definition: buildctx.c:186
void GWB_BuildCtx_AddOutFileToCtxAndCmd(GWB_BUILD_CONTEXT *bctx, GWB_BUILD_CMD *bcmd, GWB_FILE *file)
Definition: buildctx.c:149