Changeset 1045 in kBuild for trunk/src/kObjCache/kObjCache.c
- Timestamp:
- Jun 9, 2007 4:44:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kObjCache/kObjCache.c
r1044 r1045 1091 1091 free(pEntry->Old.pszObjName); 1092 1092 1093 free(pEntry->New.pszTarget); 1094 free(pEntry->Old.pszTarget); 1095 1093 1096 while (pEntry->New.cArgvCompile > 0) 1094 1097 free(pEntry->New.papszArgvCompile[--pEntry->New.cArgvCompile]); … … 1104 1107 1105 1108 /** 1109 * Calculates the checksum of an compiler argument vector. 1110 * 1111 * @param pEntry The cache entry. 1112 * @param papszArgv The argument vector. 1113 * @param cArgc The number of entries in the vector. 1114 * @param pszIgnorePath Path to ignore when encountered at the end of arguments. 1115 * (Not quite safe for simple file names, but what the heck.) 1116 * @param pSum Where to store the check sum. 1117 */ 1118 static void kOCEntryCalcArgvSum(PKOCENTRY pEntry, const char * const *papszArgv, unsigned cArgc, 1119 const char *pszIgnorePath, PKOCSUM pSum) 1120 { 1121 size_t cchIgnorePath = strlen(pszIgnorePath); 1122 KOCSUMCTX Ctx; 1123 unsigned i; 1124 1125 kOCSumInitWithCtx(pSum, &Ctx); 1126 for (i = 0; i < cArgc; i++) 1127 { 1128 size_t cch = strlen(papszArgv[i]); 1129 if ( cch < cchIgnorePath 1130 || !ArePathsIdentical(papszArgv[i] + cch - cchIgnorePath, pszIgnorePath, cch)) 1131 kOCSumUpdate(pSum, &Ctx, papszArgv[i], cch + 1); 1132 } 1133 kOCSumFinalize(pSum, &Ctx); 1134 } 1135 1136 1137 /** 1106 1138 * Reads and parses the cache file. 1107 1139 * … … 1114 1146 if (pFile) 1115 1147 { 1116 InfoMsg( 1, "reading cache file...\n");1148 InfoMsg(4, "reading cache entry...\n"); 1117 1149 1118 1150 /* … … 1122 1154 || strcmp(g_szLine, "magic=kObjCache-1\n")) 1123 1155 { 1124 InfoMsg( 1, "bad cache file (magic)\n");1156 InfoMsg(2, "bad cache file (magic)\n"); 1125 1157 pEntry->fNeedCompiling = 1; 1126 1158 } … … 1231 1263 if (!fBad && fBadBeforeMissing) 1232 1264 { 1233 InfoMsg( 1, "bad cache file (no end)\n");1265 InfoMsg(2, "bad cache file (no end)\n"); 1234 1266 fBad = 1; 1235 1267 } … … 1244 1276 fBad = 1; 1245 1277 if (!fBad) 1246 {1247 KOCSUMCTX Ctx;1248 KOCSUM Sum;1249 1250 kOCSumInitWithCtx(&Sum, &Ctx);1251 1278 for (i = 0; i < pEntry->Old.cArgvCompile; i++) 1252 {1253 1279 if ((fBad = !pEntry->Old.papszArgvCompile[i])) 1254 1280 break; 1255 kOCSumUpdate(&Sum, &Ctx, pEntry->Old.papszArgvCompile[i], strlen(pEntry->Old.papszArgvCompile[i]) + 1); 1256 } 1257 kOCSumFinalize(&Sum, &Ctx); 1258 if (!fBad) 1259 fBad = !kOCSumIsEqual(&pEntry->Old.SumCompArgv, &Sum); 1281 if (!fBad) 1282 { 1283 KOCSUM Sum; 1284 kOCEntryCalcArgvSum(pEntry, (const char * const *)pEntry->Old.papszArgvCompile, 1285 pEntry->Old.cArgvCompile, pEntry->Old.pszObjName, &Sum); 1286 fBad = !kOCSumIsEqual(&pEntry->Old.SumCompArgv, &Sum); 1260 1287 } 1261 1288 if (fBad) 1262 InfoMsg( 1, "bad cache file (%s)\n", fBadBeforeMissing ? g_szLine : "missing stuff");1289 InfoMsg(2, "bad cache file (%s)\n", fBadBeforeMissing ? g_szLine : "missing stuff"); 1263 1290 else if (ferror(pFile)) 1264 1291 { 1265 InfoMsg( 1, "cache file read error\n");1292 InfoMsg(2, "cache file read error\n"); 1266 1293 fBad = 1; 1267 1294 } … … 1276 1303 if (stat(pszPath, &st) != 0) 1277 1304 { 1278 InfoMsg( 1, "failed to stat object file: %s\n", strerror(errno));1305 InfoMsg(2, "failed to stat object file: %s\n", strerror(errno)); 1279 1306 fBad = 1; 1280 1307 } … … 1291 1318 else 1292 1319 { 1293 InfoMsg( 1, "no cache file\n");1320 InfoMsg(2, "no cache file\n"); 1294 1321 pEntry->fNeedCompiling = 1; 1295 1322 } … … 1308 1335 unsigned i; 1309 1336 1310 InfoMsg( 1, "writing cache entry '%s'...\n", pEntry->pszName);1337 InfoMsg(4, "writing cache entry '%s'...\n", pEntry->pszName); 1311 1338 pFile = FOpenFileInDir(pEntry->pszName, pEntry->pszDir, "wb"); 1312 1339 if (!pFile) … … 1382 1409 static int kOCEntryCheck(PKOCENTRY pEntry) 1383 1410 { 1384 return pEntry->fNeedCompiling; 1411 return !pEntry->fNeedCompiling; 1412 } 1413 1414 1415 /** 1416 * Sets the object name and compares it with the old name if present. 1417 * 1418 * @param pEntry The cache entry. 1419 * @param pszObjName The new object name. 1420 */ 1421 static void kOCEntrySetCompileObjName(PKOCENTRY pEntry, const char *pszObjName) 1422 { 1423 assert(!pEntry->New.pszObjName); 1424 pEntry->New.pszObjName = CalcRelativeName(pszObjName, pEntry->pszDir); 1425 1426 if ( !pEntry->fNeedCompiling 1427 && ( !pEntry->Old.pszObjName 1428 || strcmp(pEntry->New.pszObjName, pEntry->Old.pszObjName))) 1429 { 1430 InfoMsg(2, "object file name differs\n"); 1431 pEntry->fNeedCompiling = 1; 1432 } 1433 1434 if ( !pEntry->fNeedCompiling 1435 && !DoesFileInDirExist(pEntry->New.pszObjName, pEntry->pszDir)) 1436 { 1437 InfoMsg(2, "object file doesn't exist\n"); 1438 pEntry->fNeedCompiling = 1; 1439 } 1385 1440 } 1386 1441 … … 1392 1447 * @param papszArgvCompile The new argument vector for compilation. 1393 1448 * @param cArgvCompile The number of arguments in the vector. 1449 * 1450 * @remark Must call kOCEntrySetCompileObjName before this function! 1394 1451 */ 1395 1452 static void kOCEntrySetCompileArgv(PKOCENTRY pEntry, const char * const *papszArgvCompile, unsigned cArgvCompile) 1396 1453 { 1397 KOCSUMCTX Ctx;1398 1454 unsigned i; 1399 1455 1400 1456 /* call me only once! */ 1401 1457 assert(!pEntry->New.cArgvCompile); 1402 1403 /* 1404 * Copy the argument vector and calculate the checksum while doing so. 1458 /* call kOCEntrySetCompilerObjName first! */ 1459 assert(pEntry->New.pszObjName); 1460 1461 /* 1462 * Copy the argument vector and calculate the checksum. 1405 1463 */ 1406 1464 pEntry->New.cArgvCompile = cArgvCompile; 1407 1465 pEntry->New.papszArgvCompile = xmalloc((cArgvCompile + 1) * sizeof(pEntry->New.papszArgvCompile[0])); 1408 kOCSumInitWithCtx(&pEntry->New.SumCompArgv, &Ctx);1409 1466 for (i = 0; i < cArgvCompile; i++) 1410 {1411 1467 pEntry->New.papszArgvCompile[i] = xstrdup(papszArgvCompile[i]); 1412 kOCSumUpdate(&pEntry->New.SumCompArgv, &Ctx, papszArgvCompile[i], strlen(papszArgvCompile[i]) + 1);1413 }1414 kOCSumFinalize(&pEntry->New.SumCompArgv, &Ctx);1415 1468 pEntry->New.papszArgvCompile[i] = NULL; /* for exev/spawnv */ 1416 kOCSumInfo(&pEntry->New.SumCompArgv, 1, "comp-argv"); 1469 1470 kOCEntryCalcArgvSum(pEntry, papszArgvCompile, cArgvCompile, pEntry->New.pszObjName, &pEntry->New.SumCompArgv); 1471 kOCSumInfo(&pEntry->New.SumCompArgv, 4, "comp-argv"); 1417 1472 1418 1473 /* … … 1422 1477 && !kOCSumIsEqual(&pEntry->New.SumCompArgv, &pEntry->Old.SumCompArgv)) 1423 1478 { 1424 InfoMsg(1, "compiler args differs\n"); 1425 pEntry->fNeedCompiling = 1; 1426 } 1427 } 1428 1429 1430 /** 1431 * Sets the object name and compares it with the old name if present. 1432 * 1433 * @param pEntry The cache entry. 1434 * @param pszObjName The new object name. 1435 */ 1436 static void kOCEntrySetCompileObjName(PKOCENTRY pEntry, const char *pszObjName) 1437 { 1438 assert(!pEntry->New.pszObjName); 1439 pEntry->New.pszObjName = CalcRelativeName(pszObjName, pEntry->pszDir); 1440 1441 if ( !pEntry->fNeedCompiling 1442 && ( !pEntry->Old.pszObjName 1443 || strcmp(pEntry->New.pszObjName, pEntry->Old.pszObjName))) 1444 { 1445 InfoMsg(1, "object file name differs\n"); 1446 pEntry->fNeedCompiling = 1; 1447 } 1448 1449 if ( !pEntry->fNeedCompiling 1450 && !DoesFileInDirExist(pEntry->New.pszObjName, pEntry->pszDir)) 1451 { 1452 InfoMsg(1, "object file doesn't exist\n"); 1479 InfoMsg(2, "compiler args differs\n"); 1453 1480 pEntry->fNeedCompiling = 1; 1454 1481 } … … 1471 1498 || strcmp(pEntry->New.pszTarget, pEntry->Old.pszTarget))) 1472 1499 { 1473 InfoMsg( 1, "target differs\n");1500 InfoMsg(2, "target differs\n"); 1474 1501 pEntry->fNeedCompiling = 1; 1475 1502 } … … 1687 1714 int iStatus = -1; 1688 1715 pid_t pidWait; 1689 InfoMsg(3, "%s - wait-child (%ld)\n", pszMsg, (long)pid);1716 InfoMsg(3, "%s - wait-child %ld\n", pszMsg, (long)pid); 1690 1717 1691 1718 #ifdef __WIN__ … … 1841 1868 FatalDie("failed to open/read '%s' in '%s': %s\n", 1842 1869 pWhich->pszCppName, pEntry->pszDir, strerror(errno)); 1843 InfoMsg( 1, "failed to open/read '%s' in '%s': %s\n",1870 InfoMsg(2, "failed to open/read '%s' in '%s': %s\n", 1844 1871 pWhich->pszCppName, pEntry->pszDir, strerror(errno)); 1845 1872 return -1; 1846 1873 } 1847 1874 1848 InfoMsg( 1, "precompiled file is %lu bytes long\n", (unsigned long)pWhich->cbCpp);1875 InfoMsg(3, "precompiled file is %lu bytes long\n", (unsigned long)pWhich->cbCpp); 1849 1876 return 0; 1850 1877 } … … 1863 1890 kOCSumUpdate(&pEntry->New.SumHead, &Ctx, pEntry->New.pszCppMapping, pEntry->New.cbCpp); 1864 1891 kOCSumFinalize(&pEntry->New.SumHead, &Ctx); 1865 kOCSumInfo(&pEntry->New.SumHead, 1, "cpp (file)");1892 kOCSumInfo(&pEntry->New.SumHead, 4, "cpp (file)"); 1866 1893 } 1867 1894 … … 1926 1953 pEntry->New.cbCpp = cbAlloc - cbLeft; 1927 1954 kOCSumFinalize(&pEntry->New.SumHead, &Ctx); 1928 kOCSumInfo(&pEntry->New.SumHead, 1, "cpp (pipe)");1955 kOCSumInfo(&pEntry->New.SumHead, 4, "cpp (pipe)"); 1929 1956 } 1930 1957 … … 1961 1988 memcpy(psz + cch, "-old", sizeof("-old")); 1962 1989 1963 InfoMsg( 1, "renaming '%s' to '%s' in '%s'\n", pEntry->Old.pszCppName, psz, pEntry->pszDir);1990 InfoMsg(3, "renaming '%s' to '%s' in '%s'\n", pEntry->Old.pszCppName, psz, pEntry->pszDir); 1964 1991 UnlinkFileInDir(psz, pEntry->pszDir); 1965 1992 if (RenameFileInDir(pEntry->Old.pszCppName, psz, pEntry->pszDir)) … … 1973 2000 * Precompile it and calculate the checksum on the output. 1974 2001 */ 1975 InfoMsg( 1, "precompiling -> '%s'...\n", pEntry->New.pszCppName);2002 InfoMsg(3, "precompiling -> '%s'...\n", pEntry->New.pszCppName); 1976 2003 kOCEntrySpawn(pEntry, papszArgvPreComp, cArgvPreComp, "precompile", NULL); 1977 2004 kOCEntryReadCppOutput(pEntry, &pEntry->New, 0 /* fatal */); … … 2103 2130 && !pEntry->New.pszCppMapping) 2104 2131 kOCEntryReadCppOutput(pEntry, &pEntry->New, 0 /* fatal */); 2105 InfoMsg( 1, "compiling -> '%s'...\n", pEntry->New.pszObjName);2132 InfoMsg(3, "compiling -> '%s'...\n", pEntry->New.pszObjName); 2106 2133 kOCEntrySpawnConsumer(pEntry, (const char * const *)pEntry->New.papszArgvCompile, pEntry->New.cArgvCompile, 2107 2134 "compile", kOCEntryCompileProducer); … … 2111 2138 if (pEntry->fPipedPreComp) 2112 2139 kOCEntryWriteCppOutput(pEntry, 1 /* free it */); 2113 InfoMsg( 1, "compiling -> '%s'...\n", pEntry->New.pszObjName);2140 InfoMsg(3, "compiling -> '%s'...\n", pEntry->New.pszObjName); 2114 2141 kOCEntrySpawn(pEntry, (const char * const *)pEntry->New.papszArgvCompile, pEntry->New.cArgvCompile, "compile", NULL); 2115 2142 } … … 2154 2181 fdIn, (long)cbLeft, strerror(errno)); 2155 2182 } 2156 InfoMsg( 2, "precompiler|compile - read %d\n", cbRead);2183 InfoMsg(3, "precompiler|compile - read %d\n", cbRead); 2157 2184 2158 2185 /* … … 2188 2215 } 2189 2216 } 2190 InfoMsg( 2, "precompiler|compile - done passhtru\n");2217 InfoMsg(3, "precompiler|compile - done passhtru\n"); 2191 2218 2192 2219 close(fdIn); … … 2194 2221 pEntry->New.cbCpp = cbAlloc - cbLeft; 2195 2222 kOCSumFinalize(&pEntry->New.SumHead, &Ctx); 2196 kOCSumInfo(&pEntry->New.SumHead, 1, "cpp (tee)");2223 kOCSumInfo(&pEntry->New.SumHead, 4, "cpp (tee)"); 2197 2224 2198 2225 /* … … 2591 2618 if (!kOCSumHasEqualInChain(&pEntry->Old.SumHead, &pEntry->New.SumHead)) 2592 2619 { 2593 InfoMsg( 1, "no checksum match - comparing output\n");2620 InfoMsg(2, "no checksum match - comparing output\n"); 2594 2621 if (!kOCEntryCompareOldAndNewOutput(pEntry)) 2595 2622 pEntry->fNeedCompiling = 1; … … 2986 3013 int fBad = 0; 2987 3014 3015 InfoMsg(4, "reading cache file...\n"); 3016 2988 3017 /* 2989 3018 * Rewind the file & stream, and associate a temporary buffer … … 3002 3031 || strcmp(g_szLine, "magic=kObjCache-v0.1.0\n")) 3003 3032 { 3004 InfoMsg( 1, "bad cache file (magic)\n");3033 InfoMsg(2, "bad cache file (magic)\n"); 3005 3034 fBad = 1; 3006 3035 } … … 3008 3037 || strncmp(g_szLine, "generation=", sizeof("generation=") - 1)) 3009 3038 { 3010 InfoMsg( 1, "bad cache file (generation)\n");3039 InfoMsg(2, "bad cache file (generation)\n"); 3011 3040 fBad = 1; 3012 3041 } … … 3014 3043 && pCache->uGeneration == atol(&g_szLine[sizeof("generation=") - 1])) 3015 3044 { 3016 InfoMsg( 1, "drop re-read unmodified cache file\n");3045 InfoMsg(3, "drop re-read unmodified cache file\n"); 3017 3046 fBad = 0; 3018 3047 } … … 3155 3184 if ((fBad = pCache->paDigests[i].pszTarget == NULL)) 3156 3185 break; 3186 InfoMsg(4, "digest-%u: %s\n", i, pCache->paDigests[i].pszAbsPath 3187 ? pCache->paDigests[i].pszAbsPath : pCache->paDigests[i].pszRelPath); 3157 3188 } 3158 3189 if (fBad) 3159 InfoMsg( 1, "bad cache file (%s)\n", fBadBeforeMissing ? g_szLine : "missing stuff");3190 InfoMsg(2, "bad cache file (%s)\n", fBadBeforeMissing ? g_szLine : "missing stuff"); 3160 3191 else if (ferror(pCache->pFile)) 3161 3192 { 3162 InfoMsg( 1, "cache file read error\n");3193 InfoMsg(2, "cache file read error\n"); 3163 3194 fBad = 1; 3164 3195 } … … 3263 3294 #endif 3264 3295 FatalDie("file truncation failed: %s\n", strerror(errno)); 3265 InfoMsg( 1, "wrote '%s' in '%s', %d bytes\n", pCache->pszName, pCache->pszDir, cb);3296 InfoMsg(4, "wrote '%s' in '%s', %d bytes\n", pCache->pszName, pCache->pszDir, cb); 3266 3297 } 3267 3298 … … 3368 3399 kObjCacheRead(pCache); 3369 3400 else 3401 { 3370 3402 pCache->fNewCache = 1; 3403 InfoMsg(2, "the cache file is empty\n"); 3404 } 3371 3405 } 3372 3406 … … 3438 3472 3439 3473 pCache->fDirty = 1; 3474 InfoMsg(3, "removing entry '%s'; %d left.\n", kOCEntryAbsPath(pEntry), pCache->cDigests); 3440 3475 } 3441 3476 } … … 3482 3517 * Create a new digest. 3483 3518 */ 3484 i = pCache->cDigests++; 3485 kOCDigestInitFromEntry(&pCache->paDigests[i], pEntry); 3519 kOCDigestInitFromEntry(&pCache->paDigests[pCache->cDigests], pEntry); 3520 pCache->cDigests++; 3521 InfoMsg(4, "Inserted digest #%u: %s\n", pCache->cDigests - 1, kOCEntryAbsPath(pEntry)); 3486 3522 3487 3523 pCache->fDirty = 1; … … 3521 3557 3522 3558 /* bad entry, purge it. */ 3559 InfoMsg(3, "removing bad digest '%s'\n", kOCDigestAbsPath(pDigest, pCache->pszDir)); 3523 3560 kOCDigestPurge(pDigest); 3524 3561 … … 3770 3807 pEntry = kOCEntryCreate(pszEntryFile); 3771 3808 kOCEntryRead(pEntry); 3809 kOCEntrySetCompileObjName(pEntry, pszObjName); 3772 3810 kOCEntrySetCompileArgv(pEntry, papszArgvCompile, cArgvCompile); 3773 kOCEntrySetCompileObjName(pEntry, pszObjName);3774 3811 kOCEntrySetTarget(pEntry, pszTarget); 3775 3812 kOCEntrySetCppName(pEntry, pszPreCompName); … … 3788 3825 */ 3789 3826 kObjCacheUnlock(pCache); 3827 InfoMsg(1, "doing full compile\n"); 3790 3828 kOCEntryPreCompileAndCompile(pEntry, papszArgvPreComp, cArgvPreComp); 3791 3829 kObjCacheLock(pCache); … … 3811 3849 if (pUseEntry) 3812 3850 { 3851 InfoMsg(1, "using cache entry '%s'\n", kOCEntryAbsPath(pUseEntry)); 3813 3852 kOCEntryCopy(pEntry, pUseEntry); 3814 3853 kOCEntryDestroy(pUseEntry); … … 3817 3856 { 3818 3857 kObjCacheUnlock(pCache); 3858 InfoMsg(1, "recompiling\n"); 3819 3859 kOCEntryCompileIt(pEntry); 3820 3860 kObjCacheLock(pCache); … … 3822 3862 } 3823 3863 else 3864 { 3865 InfoMsg(1, "no need to recompile\n"); 3824 3866 kObjCacheLock(pCache); 3867 } 3825 3868 } 3826 3869
Note:
See TracChangeset
for help on using the changeset viewer.