commit 3b81c2969575294f831d652bc0d0d6c7bcf1dea3
parent b1f43d35294c8f5ebcfb095714c3ea6e169e4231
Author: Remy Noulin <loader2x@gmail.com>
Date: Tue, 24 Dec 2019 13:26:19 +0100
add header file dependencies to c file dependencies to recompile when a header is updated
Update dependency dates after all modified files are found, before this
commit not all c files were recompiled
src/sheepy.c | 49 ++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 42 insertions(+), 7 deletions(-)
Diffstat:
| M | src/sheepy.c | | | 49 | ++++++++++++++++++++++++++++++++++++++++++------- |
1 file changed, 42 insertions(+), 7 deletions(-)
diff --git a/src/sheepy.c b/src/sheepy.c
@@ -683,7 +683,7 @@ int MAIN(int ARGC, char** ARGV) {
createAllocateSmallArray(mainDepFiles);
iter(mainFile, l) {
castS(L, l)
- // TODO improve main function detecttion
+ // TODO improve main function detection
if (hasG(L, "main") && (hasG(L, "int") || hasG(L, "define")) && !sheepyParams.compileLib) {
// main function detected
// compile the executable if requested
@@ -981,12 +981,30 @@ int MAIN(int ARGC, char** ARGV) {
//puts("--- cDependencies");
createAllocateSmallDict(cDependencies);
if (lenG(dependencies) > 0) {
- const char *k;
+ char *k;
iter(dependencies, depArray) {
- k = iterKeyG(dependencies);
+ k = (char*)iterKeyG(dependencies);
if (isC(k) || isCP(k)) {
- cast(smallArrayt *, deps, dupG(depArray))
cast(smallArrayt *, depsOrig, depArray)
+ // add dependencies from header file to c dependency list
+ // to recompile when a header is updated
+ if (isC(k)) {
+ setS(k, -1, 'h');
+ if (hasG(dependencies, k)) {
+ appendNFreeG(depsOrig, getNDupG(dependencies, rtSmallArrayt, k));
+ }
+ setS(k, -1, 'c');
+ }
+ elif (isCP(k)) {
+ setS(k, -1, 'h');
+ if (hasG(dependencies, k)) {
+ appendNFreeG(depsOrig, getNDupG(dependencies, rtSmallArrayt, k));
+ }
+ setS(k, -1, 'p');
+ }
+ // update depArray pointer in dependencies because it might have been updated
+ setPG(dependencies, k, depsOrig);
+ cast(smallArrayt *, deps, dupG(depArray))
// for each dep, append dep array to c dep array
// TODO check if the array is empty?
forEachSmallArray(depsOrig, dep) {
@@ -1000,7 +1018,7 @@ int MAIN(int ARGC, char** ARGV) {
// uniquify deps
uniqG(deps, unusedV);
// add array to cDependencies
- setG(cDependencies, k, deps);
+ setNFreeG(cDependencies, k, deps);
}
}
}
@@ -1014,6 +1032,7 @@ int MAIN(int ARGC, char** ARGV) {
// check if h and c (not all of them are in the list) files are modified
if (lenG(cDependencies) > 0) {
const char *k;
+ createSmallArray(copyAllHeaderDatesToDep);
iter(cDependencies, depValue) {
k = iterKeyG(cDependencies);
cast(smallArrayt *, hDeps, depValue)
@@ -1048,7 +1067,12 @@ int MAIN(int ARGC, char** ARGV) {
//puts("DIFFERENT DATES RECOMPILE");
addFileToCompile(actualDir, k, buildCPath, toCompile);
// copy header dates to not recompile unecesserarily next time
- copyHeaderDates(actualDir, hDeps, buildPath);
+ // change dep files after all modified files are found
+ createSmallArray(headerInfo);
+ pushG (&headerInfo, actualDir);
+ pushNFreeG(&headerInfo, dupG(hDeps));
+ pushG (&headerInfo, buildPath);
+ pushG (©AllHeaderDatesToDep, &headerInfo);
free(buildCPath);
continue;
// else puts("C AND O HAVE SAME DATE SKIP COMPILATION - CHECK IF H FILES ARE UPDATED");
@@ -1061,7 +1085,12 @@ int MAIN(int ARGC, char** ARGV) {
//puts(buildCPath);
addFileToCompile(actualDir, k, buildCPath, toCompile);
// copy header dates to not recompile unecesserarily next time
- copyHeaderDates(actualDir, hDeps, buildPath);
+ // change dep files after all modified files are found
+ createSmallArray(headerInfo);
+ pushG (&headerInfo, actualDir);
+ pushNFreeG(&headerInfo, dupG(hDeps));
+ pushG (&headerInfo, buildPath);
+ pushG (©AllHeaderDatesToDep, &headerInfo);
free(buildCPath);
continue;
}
@@ -1157,6 +1186,12 @@ int MAIN(int ARGC, char** ARGV) {
finishG(dep);
}
}
+ // copy all header dates to dep files in build directory
+ iter(©AllHeaderDatesToDep, HeaderInfo) {
+ cast(smallArrayt*, headerInfo, HeaderInfo);
+ copyHeaderDates(/*actualDir*/getG(headerInfo, rtChar, 0), /*hDeps*/getG(headerInfo, rtSmallArrayt, 1), /*buildPath*/getG(headerInfo, rtChar, 2));
+ }
+ freeG(©AllHeaderDatesToDep);
}
// add all c file to compile list