Changeset 2612
- Timestamp:
- Jul 29, 2012, 8:18:00 PM (13 years ago)
- Location:
- trunk/src/kObjCache
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kObjCache/Makefile.kmk
r2413 r2612 30 30 kObjCache_TEMPLATE = BIN 31 31 kObjCache_SOURCES = kObjCache.c 32 kObjCache_LIBS = $(LIB_KUTIL) 32 kObjCache_LIBS = \ 33 $(LIB_KDEP) \ 34 $(LIB_KUTIL) 33 35 34 36 include $(KBUILD_PATH)/subfooter.kmk -
trunk/src/kObjCache/kObjCache.c
r2568 r2612 5 5 6 6 /* 7 * Copyright (c) 2007-201 1knut st. osmundsen <bird-kBuild-spamx@anduin.net>7 * Copyright (c) 2007-2012 knut st. osmundsen <bird-kBuild-spamx@anduin.net> 8 8 * 9 9 * This file is part of kBuild. … … 80 80 #include "crc32.h" 81 81 #include "md5.h" 82 #include "kDep.h" 82 83 83 84 … … 110 111 #endif 111 112 113 #define MY_IS_BLANK(a_ch) ((a_ch) == ' ' || (a_ch) == '\t') 114 112 115 113 116 /******************************************************************************* … … 129 132 static char *CalcRelativeName(const char *pszPath, const char *pszDir); 130 133 static FILE *FOpenFileInDir(const char *pszName, const char *pszDir, const char *pszMode); 131 static int UnlinkFileInDir(const char *pszName, const char *pszDir);132 static int RenameFileInDir(const char *pszOldName, const char *pszNewName, const char *pszDir);133 static int DoesFileInDirExist(const char *pszName, const char *pszDir);134 static int UnlinkFileInDir(const char *pszName, const char *pszDir); 135 static int RenameFileInDir(const char *pszOldName, const char *pszNewName, const char *pszDir); 136 static int DoesFileInDirExist(const char *pszName, const char *pszDir); 134 137 static void *ReadFileInDir(const char *pszName, const char *pszDir, size_t *pcbFile); 135 138 … … 757 760 758 761 762 /** 763 * Dependency collector state. 764 */ 765 typedef struct KOCDEP 766 { 767 /** The statemachine for processing the preprocessed code stream. */ 768 enum KOCDEPSTATE 769 { 770 kOCDepState_Invalid = 0, 771 kOCDepState_NeedNewLine, 772 kOCDepState_NeedHash, 773 kOCDepState_NeedLine_l, 774 kOCDepState_NeedLine_l_HaveSpace, 775 kOCDepState_NeedLine_i, 776 kOCDepState_NeedLine_n, 777 kOCDepState_NeedLine_e, 778 kOCDepState_NeedSpaceBeforeDigit, 779 kOCDepState_NeedFirstDigit, 780 kOCDepState_NeedMoreDigits, 781 kOCDepState_NeedQuote, 782 kOCDepState_NeedEndQuote 783 } enmState; 784 /** Current offset into the filename buffer. */ 785 uint32_t offFilename; 786 /** The amount of space currently allocated for the filename buffer. */ 787 uint32_t cbFilenameAlloced; 788 /** Pointer to the filename buffer. */ 789 char *pszFilename; 790 /** The current dependency file. */ 791 PDEP pCurDep; 792 } KOCDEP; 793 /** Pointer to a KOCDEP. */ 794 typedef KOCDEP *PKOCDEP; 795 796 797 /** 798 * Initializes the dependency collector state. 799 * 800 * @param pDepState The dependency collector state. 801 */ 802 static void kOCDepInit(PKOCDEP pDepState) 803 { 804 pDepState->enmState = kOCDepState_NeedHash; 805 pDepState->offFilename = 0; 806 pDepState->cbFilenameAlloced = 0; 807 pDepState->pszFilename = NULL; 808 pDepState->pCurDep = NULL; 809 } 810 811 812 /** 813 * Deletes the dependency collector state, releasing all resources. 814 * 815 * @param pDepState The dependency collector state. 816 */ 817 static void kOCDepDelete(PKOCDEP pDepState) 818 { 819 pDepState->enmState = kOCDepState_Invalid; 820 free(pDepState->pszFilename); 821 pDepState->pszFilename = NULL; 822 depCleanup(); 823 } 824 825 826 /** 827 * Unescapes a string in place. 828 * 829 * @returns The new string length. 830 * @param psz The string to unescape (input and output). 831 */ 832 static size_t kOCDepUnescape(char *psz) 833 { 834 char *pszSrc = psz; 835 char *pszDst = psz; 836 char ch; 837 838 while ((ch = *pszSrc++) != '\0') 839 { 840 if (ch == '\\') 841 { 842 char ch2 = *pszSrc; 843 if (ch2) 844 { 845 pszSrc++; 846 ch = ch2; 847 } 848 /* else: cannot happen / just ignore */ 849 } 850 *pszDst++ = ch; 851 } 852 853 *pszDst = '\0'; 854 return pszDst - psz; 855 } 856 857 858 /** 859 * Checks if the character at @a offChar is escaped or not. 860 * 861 * @returns 1 if escaped, 0 if not. 862 * @param pach The string (not terminated). 863 * @param offChar The offset of the character in question. 864 */ 865 static int kOCDepIsEscaped(char *pach, size_t offChar) 866 { 867 while (offChar > 0 && pach[offChar - 1] == '\\') 868 { 869 if ( offChar == 1 870 || pach[offChar - 2] != '\\') 871 return 1; 872 offChar -= 2; 873 } 874 return 0; 875 } 876 877 878 /** 879 * This consumes the preprocessor output and generate dependencies from it. 880 * 881 * The trick is to look at the line directives and which files get listed there. 882 * 883 * @returns The new state. This is a convenience for saving code space and it 884 * isn't really meant to be of any use to the caller. 885 * @param pDepState The dependency collector state. 886 * @param pszInput The input. 887 * @param cchInput The input length. 888 */ 889 static enum KOCDEPSTATE 890 kOCDepConsumer(PKOCDEP pDepState, const char *pszInput, size_t cchInput) 891 { 892 enum KOCDEPSTATE enmState = pDepState->enmState; 893 const char *psz; 894 895 while (cchInput > 0) 896 { 897 switch (enmState) 898 { 899 case kOCDepState_NeedNewLine: 900 psz = (const char *)memchr(pszInput, '\n', cchInput); 901 if (!psz) 902 return enmState; 903 psz++; 904 cchInput -= psz - pszInput; 905 pszInput = psz; 906 907 case kOCDepState_NeedHash: 908 while (cchInput > 0 && MY_IS_BLANK(*pszInput)) 909 cchInput--, pszInput++; 910 if (!cchInput) 911 return pDepState->enmState = kOCDepState_NeedHash; 912 913 if (*pszInput != '#') 914 break; 915 pszInput++; 916 cchInput--; 917 enmState = kOCDepState_NeedLine_l; 918 919 case kOCDepState_NeedLine_l: 920 case kOCDepState_NeedLine_l_HaveSpace: 921 while (cchInput > 0 && MY_IS_BLANK(*pszInput)) 922 { 923 enmState = kOCDepState_NeedLine_l_HaveSpace; 924 cchInput--, pszInput++; 925 } 926 if (!cchInput) 927 return pDepState->enmState = enmState; 928 929 if (*pszInput != 'l') 930 { 931 /* # <digit> "<file>" */ 932 if (enmState != kOCDepState_NeedLine_l_HaveSpace || !isdigit(*pszInput)) 933 break; 934 pszInput++; 935 cchInput--; 936 enmState = kOCDepState_NeedMoreDigits; 937 continue; 938 } 939 pszInput++; 940 if (!--cchInput) 941 return pDepState->enmState = kOCDepState_NeedLine_i; 942 943 case kOCDepState_NeedLine_i: 944 if (*pszInput != 'i') 945 break; 946 pszInput++; 947 if (!--cchInput) 948 return pDepState->enmState = kOCDepState_NeedLine_n; 949 950 case kOCDepState_NeedLine_n: 951 if (*pszInput != 'n') 952 break; 953 pszInput++; 954 if (!--cchInput) 955 return pDepState->enmState = kOCDepState_NeedLine_e; 956 957 case kOCDepState_NeedLine_e: 958 if (*pszInput != 'e') 959 break; 960 pszInput++; 961 if (!--cchInput) 962 return pDepState->enmState = kOCDepState_NeedSpaceBeforeDigit; 963 964 case kOCDepState_NeedSpaceBeforeDigit: 965 if (!MY_IS_BLANK(*pszInput)) 966 break; 967 pszInput++; 968 cchInput--; 969 970 case kOCDepState_NeedFirstDigit: 971 while (cchInput > 0 && MY_IS_BLANK(*pszInput)) 972 cchInput--, pszInput++; 973 if (!cchInput) 974 return pDepState->enmState = kOCDepState_NeedFirstDigit; 975 976 if (!isdigit(*pszInput)) 977 break; 978 pszInput++; 979 cchInput--; 980 981 case kOCDepState_NeedMoreDigits: 982 while (cchInput > 0 && isdigit(*pszInput)) 983 cchInput--, pszInput++; 984 if (!cchInput) 985 return pDepState->enmState = kOCDepState_NeedMoreDigits; 986 987 case kOCDepState_NeedQuote: 988 while (cchInput > 0 && MY_IS_BLANK(*pszInput)) 989 cchInput--, pszInput++; 990 if (!cchInput) 991 return pDepState->enmState = kOCDepState_NeedQuote; 992 993 if (*pszInput != '"') 994 break; 995 pszInput++; 996 cchInput--; 997 998 case kOCDepState_NeedEndQuote: 999 { 1000 uint32_t off = pDepState->offFilename; 1001 for (;;) 1002 { 1003 char ch; 1004 1005 if (!cchInput) 1006 { 1007 pDepState->offFilename = off; 1008 return pDepState->enmState = kOCDepState_NeedEndQuote; 1009 } 1010 1011 if (off + 1 >= pDepState->cbFilenameAlloced) 1012 { 1013 if (!pDepState->cbFilenameAlloced) 1014 pDepState->cbFilenameAlloced = 32; 1015 else 1016 pDepState->cbFilenameAlloced *= 2; 1017 pDepState->pszFilename = (char *)xrealloc(pDepState->pszFilename, pDepState->cbFilenameAlloced); 1018 } 1019 pDepState->pszFilename[off] = ch = *pszInput++; 1020 cchInput--; 1021 1022 if ( ch == '"' 1023 && ( off == 0 1024 || pDepState->pszFilename[off - 1] != '\\' 1025 || !kOCDepIsEscaped(pDepState->pszFilename, off))) 1026 { 1027 /* Done, unescape and add the file. */ 1028 size_t cchFilename; 1029 1030 pDepState->pszFilename[off] = '\0'; 1031 cchFilename = kOCDepUnescape(pDepState->pszFilename); 1032 1033 if ( !pDepState->pCurDep 1034 || cchFilename != pDepState->pCurDep->cchFilename 1035 || strcmp(pDepState->pszFilename, pDepState->pCurDep->szFilename)) 1036 pDepState->pCurDep = depAdd(pDepState->pszFilename, cchFilename); 1037 pDepState->offFilename = 0; 1038 break; 1039 } 1040 1041 off++; 1042 } 1043 } 1044 } 1045 1046 /* next newline */ 1047 enmState = kOCDepState_NeedNewLine; 1048 } 1049 1050 return pDepState->enmState = enmState; 1051 } 1052 1053 1054 /** 1055 * Writes the dependencies to the specified file. 1056 * 1057 * @param pDepState The dependency collector state. 1058 * @param pszFilename The name of the dependency file. 1059 * @param pszObjFile The object file name, relative to @a pszObjDir. 1060 * @param pszObjDir The object file directory. 1061 * @param fFixCase Whether to fix the case of dependency files. 1062 * @param fQuiet Whether to be quiet about the dependencies. 1063 * @param fGenStubs Whether to generate stubs. 1064 */ 1065 static void kOCDepWriteToFile(PKOCDEP pDepState, const char *pszFilename, const char *pszObjFile, const char *pszObjDir, 1066 int fFixCase, int fQuiet, int fGenStubs) 1067 { 1068 char *pszObjFileAbs; 1069 FILE *pFile = fopen(pszFilename, "w"); 1070 if (!pFile) 1071 FatalMsg("Failed to open dependency file '%s': %s\n", pszFilename, strerror(errno)); 1072 1073 depOptimize(fFixCase, fQuiet); 1074 1075 pszObjFileAbs = MakePathFromDirAndFile(pszObjFile, pszObjDir); 1076 fprintf(pFile, "%s:", pszObjFileAbs); 1077 free(pszObjFileAbs); 1078 depPrint(pFile); 1079 if (fGenStubs) 1080 depPrintStubs(pFile); 1081 1082 if (fclose(pFile) != 0) 1083 FatalMsg("Failed to write dependency file '%s': %s\n", pszFilename, strerror(errno)); 1084 } 1085 759 1086 760 1087 761 1088 762 1089 /** A checksum list entry. 763 * We keep a list checksums (of precompiler output) that matches, The planned 764 * matching algorithm doesn't require the precompiler output to be indentical, 765 * only to produce the same object files. 1090 * We keep a list checksums (of preprocessor output) that matches. 1091 * 1092 * The matching algorithm doesn't require the preprocessor output to be 1093 * indentical, only to produce the same object files. 766 1094 */ 767 1095 typedef struct KOCSUM … … 783 1111 784 1112 /** 785 * Temporary context record used when calculating 786 * the checksum of some data. 1113 * Temporary context record used when calculating the checksum of some data. 787 1114 */ 788 1115 typedef struct KOCSUMCTX … … 1080 1407 /** Set if the object needs to be (re)compiled. */ 1081 1408 unsigned fNeedCompiling; 1082 /** Whether the pre compiler runs in piped mode. If clear it's file1409 /** Whether the preprocessor runs in piped mode. If clear it's file 1083 1410 * mode (it could be redirected stdout, but that's essentially the 1084 1411 * same from our point of view). */ 1085 1412 unsigned fPipedPreComp; 1086 /** Whether the compiler runs in piped mode (pre compiler output on stdin). */1413 /** Whether the compiler runs in piped mode (preprocessor output on stdin). */ 1087 1414 unsigned fPipedCompile; 1088 /** The name of the pipe that we're feeding the pre compiled output to the1415 /** The name of the pipe that we're feeding the preprocessed output to the 1089 1416 * compiler via. This is a Windows thing. */ 1090 1417 char *pszNmPipeCompile; 1418 /** Name of the dependency file (generated from #line statements in the 1419 * preprocessor output). */ 1420 char *pszMakeDepFilename; 1421 /** Whether to fix the case of the make depedencies. */ 1422 int fMakeDepFixCase; 1423 /** Whether to do the make dependencies quietly. */ 1424 int fMakeDepQuiet; 1425 /** Whether to generate stubs for headers files. */ 1426 int fMakeDepGenStubs; 1427 /** The dependency collector state. */ 1428 KOCDEP DepState; 1091 1429 /** Cache entry key that's used for some quick digest validation. */ 1092 1430 uint32_t uKey; … … 1095 1433 struct KOCENTRYDATA 1096 1434 { 1097 /** The name of file containing the pre compiler output. */1435 /** The name of file containing the preprocessor output. */ 1098 1436 char *pszCppName; 1099 /** Pointer to the pre compiler output. */1437 /** Pointer to the preprocessor output. */ 1100 1438 char *pszCppMapping; 1101 /** The size of the pre compiler output. 0 if not determined. */1439 /** The size of the preprocessor output. 0 if not determined. */ 1102 1440 size_t cbCpp; 1103 /** The pre compiler output checksums that will produce the cached object. */1441 /** The preprocessor output checksums that will produce the cached object. */ 1104 1442 KOCSUM SumHead; 1105 1443 /** The number of milliseconds spent precompiling. */ … … 1117 1455 uint32_t cMsCompile; 1118 1456 /** @todo need a list of additional output files for MSC. */ 1457 /** @todo need compiler output (warnings). */ 1119 1458 1120 1459 /** The target os/arch identifier. */ … … 1148 1487 pEntry = xmallocz(sizeof(*pEntry)); 1149 1488 1489 kOCDepInit(&pEntry->DepState); 1490 1150 1491 kOCSumInit(&pEntry->New.SumHead); 1151 1492 kOCSumInit(&pEntry->Old.SumHead); … … 1181 1522 free(pEntry->pszAbsPath); 1182 1523 free(pEntry->pszNmPipeCompile); 1524 free(pEntry->pszMakeDepFilename); 1525 1526 kOCDepDelete(&pEntry->DepState); 1183 1527 1184 1528 kOCSumDeleteChain(&pEntry->New.SumHead); … … 1635 1979 1636 1980 /** 1637 * Sets the pre compiler output filename.1638 * We don't generally care if thismatches the old name or not.1981 * Sets the preprocessor output filename. We don't generally care if this 1982 * matches the old name or not. 1639 1983 * 1640 1984 * @param pEntry The cache entry. 1641 * @param pszCppName The pre compiler output filename.1985 * @param pszCppName The preprocessor output filename. 1642 1986 */ 1643 1987 static void kOCEntrySetCppName(PKOCENTRY pEntry, const char *pszCppName) … … 1649 1993 1650 1994 /** 1651 * Sets the piped mode of the pre compiler and compiler.1995 * Sets the piped mode of the preprocessor and compiler. 1652 1996 * 1653 1997 * @param pEntry The cache entry. 1654 * @param fRedirPreCompStdOut Whether the pre compiler is in piped mode.1998 * @param fRedirPreCompStdOut Whether the preprocessor is in piped mode. 1655 1999 * @param fRedirCompileStdIn Whether the compiler is in piped mode. 1656 2000 * @param pszNmPipeCompile The name of the named pipe to use to feed … … 1663 2007 pEntry->fPipedCompile = fRedirCompileStdIn || pszNmPipeCompile; 1664 2008 pEntry->pszNmPipeCompile = xstrdup(pszNmPipeCompile); 2009 } 2010 2011 2012 /** 2013 * Sets the dependency file. 2014 * 2015 * @param pEntry The cache entry. 2016 * @param pszMakeDepFilename The dependency filename. 2017 * @param fMakeDepFixCase Whether to fix the case of dependency files. 2018 * @param fMakeDepQuiet Whether to be quiet about the dependencies. 2019 * @param fMakeDepGenStubs Whether to generate stubs. 2020 */ 2021 static void kOCEntrySetDepFilename(PKOCENTRY pEntry, const char *pszMakeDepFilename, 2022 int fMakeDepFixCase, int fMakeDepQuiet, int fMakeDepGenStubs) 2023 { 2024 pEntry->pszMakeDepFilename = xstrdup(pszMakeDepFilename); 2025 pEntry->fMakeDepFixCase = fMakeDepFixCase; 2026 pEntry->fMakeDepQuiet = fMakeDepQuiet; 2027 pEntry->fMakeDepGenStubs = fMakeDepGenStubs; 1665 2028 } 1666 2029 … … 1825 2188 # endif 1826 2189 if (pid == -1) 1827 FatalDie("pre compile- _spawnvp failed: %s\n", strerror(errno));2190 FatalDie("preprocess - _spawnvp failed: %s\n", strerror(errno)); 1828 2191 1829 2192 #else … … 1832 2195 { 1833 2196 execvp(papszArgv[0], (char **)papszArgv); 1834 FatalDie("pre compile- execvp failed: %s\n", strerror(errno));2197 FatalDie("preprocess - execvp failed: %s\n", strerror(errno)); 1835 2198 } 1836 2199 if (pid == -1) 1837 FatalDie("pre compile- fork() failed: %s\n", strerror(errno));2200 FatalDie("preprocess - fork() failed: %s\n", strerror(errno)); 1838 2201 #endif 1839 2202 … … 1903 2266 * 1904 2267 * @param pEntry The cache entry. 1905 * @param p FDsWhere to store the two file descriptors.2268 * @param paFDs Where to store the two file descriptors. 1906 2269 * @param pszMsg The operation message for info/error messages. 1907 2270 * @param pszPipeName The pipe name if it is supposed to be named. (Windows only.) 1908 2271 */ 1909 static void kOCEntryCreatePipe(PKOCENTRY pEntry, int *p FDs, const char *pszPipeName, const char *pszMsg)1910 { 1911 p FDs[0] = pFDs[1] = -1;2272 static void kOCEntryCreatePipe(PKOCENTRY pEntry, int *paFDs, const char *pszPipeName, const char *pszMsg) 2273 { 2274 paFDs[0] = paFDs[1] = -1; 1912 2275 #if defined(__WIN__) 1913 2276 if (pszPipeName) … … 1925 2288 FatalDie("%s - CreateNamedPipe(%s) failed: %d\n", pszMsg, pszPipeName, GetLastError()); 1926 2289 1927 p FDs[1 /* write */] = _open_osfhandle((intptr_t)hPipe, _O_WRONLY | _O_TEXT | _O_NOINHERIT);1928 if (p FDs[1 /* write */] == -1)2290 paFDs[1 /* write */] = _open_osfhandle((intptr_t)hPipe, _O_WRONLY | _O_TEXT | _O_NOINHERIT); 2291 if (paFDs[1 /* write */] == -1) 1929 2292 FatalDie("%s - _open_osfhandle failed: %d\n", pszMsg, strerror(errno)); 1930 2293 } 1931 else if (_pipe(pFDs, 0, _O_NOINHERIT | _O_BINARY) < 0) 2294 else if ( _pipe(paFDs, 256*1024, _O_NOINHERIT | _O_BINARY) < 0 2295 && _pipe(paFDs, 0, _O_NOINHERIT | _O_BINARY) < 0) 1932 2296 #else 1933 if (pipe(p FDs) < 0)2297 if (pipe(paFDs) < 0) 1934 2298 #endif 1935 2299 FatalDie("%s - pipe failed: %s\n", pszMsg, strerror(errno)); 1936 2300 #if !defined(__WIN__) 1937 fcntl(p FDs[0], F_SETFD, FD_CLOEXEC);1938 fcntl(p FDs[1], F_SETFD, FD_CLOEXEC);2301 fcntl(paFDs[0], F_SETFD, FD_CLOEXEC); 2302 fcntl(paFDs[1], F_SETFD, FD_CLOEXEC); 1939 2303 #endif 1940 2304 … … 2041 2405 2042 2406 /** 2043 * Reads the output from the pre compiler.2407 * Reads the output from the preprocessor. 2044 2408 * 2045 2409 * @param pEntry The cache entry. New.cbCpp and New.pszCppMapping will be updated. … … 2060 2424 } 2061 2425 2062 InfoMsg(3, "pre compiled file is %lu bytes long\n", (unsigned long)pWhich->cbCpp);2426 InfoMsg(3, "preprocessed file is %lu bytes long\n", (unsigned long)pWhich->cbCpp); 2063 2427 return 0; 2064 2428 } … … 2066 2430 2067 2431 /** 2068 * Worker for kOCEntryPre Compileand calculates the checksum of2069 * the pre compiler output.2432 * Worker for kOCEntryPreProcess and calculates the checksum of 2433 * the preprocessor output. 2070 2434 * 2071 2435 * @param pEntry The cache entry. NewSum will be updated. … … 2082 2446 2083 2447 /** 2084 * This consumes the pre compiler output and checksums it.2448 * This consumes the preprocessor output and checksums it. 2085 2449 * 2086 2450 * @param pEntry The cache entry. 2087 * @param fdIn The pre compiler output pipe.2451 * @param fdIn The preprocessor output pipe. 2088 2452 * @param fdOut The compiler input pipe, -1 if no compiler. 2089 2453 */ 2090 static void kOCEntryPre CompileConsumer(PKOCENTRY pEntry, int fdIn)2454 static void kOCEntryPreProcessConsumer(PKOCENTRY pEntry, int fdIn) 2091 2455 { 2092 2456 KOCSUMCTX Ctx; … … 2111 2475 if (errno == EINTR) 2112 2476 continue; 2113 FatalDie(" precompile- read(%d,,%ld) failed: %s\n",2477 FatalDie("PreProcess - read(%d,,%ld) failed: %s\n", 2114 2478 fdIn, (long)cbLeft, strerror(errno)); 2115 2479 } … … 2120 2484 psz[cbRead] = '\0'; 2121 2485 kOCSumUpdate(&pEntry->New.SumHead, &Ctx, psz, cbRead); 2486 if (pEntry->pszMakeDepFilename) 2487 kOCDepConsumer(&pEntry->DepState, psz, cbRead); 2122 2488 2123 2489 /* … … 2146 2512 2147 2513 /** 2148 * Run the pre compiler and calculate the checksum of the output.2514 * Run the preprocessor and calculate the checksum of the output. 2149 2515 * 2150 2516 * @param pEntry The cache entry. 2151 * @param papszArgvPreComp The argument vector for executing precompiler. The cArgvPreComp'th argument must be NULL. 2517 * @param papszArgvPreComp The argument vector for executing preprocessor. 2518 * The cArgvPreComp'th argument must be NULL. 2152 2519 * @param cArgvPreComp The number of arguments. 2153 2520 */ 2154 static void kOCEntryPre Compile(PKOCENTRY pEntry, const char * const *papszArgvPreComp, unsigned cArgvPreComp)2155 { 2156 /* 2157 * If we're executing the pre compiler in piped mode, it's relatively simple.2521 static void kOCEntryPreProcess(PKOCENTRY pEntry, const char * const *papszArgvPreComp, unsigned cArgvPreComp) 2522 { 2523 /* 2524 * If we're executing the preprocessor in piped mode, it's relatively simple. 2158 2525 */ 2159 2526 if (pEntry->fPipedPreComp) 2160 kOCEntrySpawnProducer(pEntry, papszArgvPreComp, cArgvPreComp, "pre compile",2161 kOCEntryPre CompileConsumer);2527 kOCEntrySpawnProducer(pEntry, papszArgvPreComp, cArgvPreComp, "preprocess", 2528 kOCEntryPreProcessConsumer); 2162 2529 else 2163 2530 { 2164 2531 /* 2165 * Rename the old pre compiled output to '-old' so the precompiler won't2532 * Rename the old preprocessed output to '-old' so the preprocessor won't 2166 2533 * overwrite it when we execute it. 2167 2534 */ … … 2187 2554 */ 2188 2555 InfoMsg(3, "precompiling -> '%s'...\n", pEntry->New.pszCppName); 2189 kOCEntrySpawn(pEntry, &pEntry->New.cMsCpp, papszArgvPreComp, cArgvPreComp, "pre compile", NULL);2556 kOCEntrySpawn(pEntry, &pEntry->New.cMsCpp, papszArgvPreComp, cArgvPreComp, "preprocess", NULL); 2190 2557 kOCEntryReadCppOutput(pEntry, &pEntry->New, 0 /* fatal */); 2191 2558 kOCEntryCalcChecksum(pEntry); 2192 } 2559 if (pEntry->pszMakeDepFilename) 2560 kOCDepConsumer(&pEntry->DepState, pEntry->New.pszCppMapping, pEntry->New.cbCpp); 2561 } 2562 2563 if (pEntry->pszMakeDepFilename) 2564 kOCDepWriteToFile(&pEntry->DepState, pEntry->pszMakeDepFilename, pEntry->New.pszObjName, pEntry->pszDir, 2565 pEntry->fMakeDepFixCase, pEntry->fMakeDepQuiet, pEntry->fMakeDepGenStubs); 2193 2566 } 2194 2567 … … 2196 2569 /** 2197 2570 * Worker function for kOCEntryTeeConsumer and kOCEntryCompileIt that 2198 * writes the pre compiler output to disk.2571 * writes the preprocessor output to disk. 2199 2572 * 2200 2573 * @param pEntry The cache entry. … … 2257 2630 2258 2631 /** 2259 * kOCEntrySpawnConsumer callback that passes the pre compiler2260 * output to thecompiler and writes it to the disk (latter only when necesary).2632 * kOCEntrySpawnConsumer callback that passes the preprocessor output to the 2633 * compiler and writes it to the disk (latter only when necesary). 2261 2634 * 2262 2635 * @param pEntry The cache entry. … … 2346 2719 * kOCEntrySpawnTee callback that works sort of like 'tee'. 2347 2720 * 2348 * It will calculate the pre compiled output checksum and2721 * It will calculate the preprocessed output checksum and 2349 2722 * write it to disk while the compiler is busy compiling it. 2350 2723 * 2351 2724 * @param pEntry The cache entry. 2352 * @param fdIn The input handle (connected to the pre compiler).2725 * @param fdIn The input handle (connected to the preprocessor). 2353 2726 * @param fdOut The output handle (connected to the compiler). 2354 2727 */ … … 2367 2740 cbLeft = cbAlloc; 2368 2741 pEntry->New.pszCppMapping = psz = xmalloc(cbAlloc); 2369 InfoMsg(3, "pre compiler|compile - starting passhtru...\n");2742 InfoMsg(3, "preprocessor|compile - starting passhtru...\n"); 2370 2743 for (;;) 2371 2744 { … … 2380 2753 if (errno == EINTR) 2381 2754 continue; 2382 FatalDie("pre compile|compile - read(%d,,%ld) failed: %s\n",2755 FatalDie("preprocess|compile - read(%d,,%ld) failed: %s\n", 2383 2756 fdIn, (long)cbLeft, strerror(errno)); 2384 2757 } 2385 InfoMsg(3, "pre compiler|compile - read %d\n", cbRead);2758 InfoMsg(3, "preprocessor|compile - read %d\n", cbRead); 2386 2759 2387 2760 /* … … 2390 2763 psz[cbRead] = '\0'; 2391 2764 kOCSumUpdate(&pEntry->New.SumHead, &Ctx, psz, cbRead); 2765 if (pEntry->pszMakeDepFilename) 2766 kOCDepConsumer(&pEntry->DepState, psz, cbRead); 2767 2392 2768 #ifdef __WIN__ 2393 2769 if ( !fConnectedToCompiler 2394 2770 && !(fConnectedToCompiler = ConnectNamedPipe((HANDLE)_get_osfhandle(fdOut), NULL))) 2395 FatalDie("pre compile|compile - ConnectNamedPipe failed: %d\n", GetLastError());2771 FatalDie("preprocess|compile - ConnectNamedPipe failed: %d\n", GetLastError()); 2396 2772 #endif 2397 2773 do … … 2402 2778 if (errno == EINTR) 2403 2779 continue; 2404 FatalDie("pre compile|compile - write(%d,,%ld) failed: %s\n", fdOut, cbRead, strerror(errno));2780 FatalDie("preprocess|compile - write(%d,,%ld) failed: %s\n", fdOut, cbRead, strerror(errno)); 2405 2781 } 2406 2782 psz += cbWritten; … … 2421 2797 } 2422 2798 } 2423 InfoMsg(3, "pre compiler|compile - done passhtru\n");2799 InfoMsg(3, "preprocessor|compile - done passhtru\n"); 2424 2800 2425 2801 close(fdIn); … … 2430 2806 2431 2807 /* 2432 * Write the pre compiler output to disk and free the memory it2808 * Write the preprocessor output to disk and free the memory it 2433 2809 * occupies while the compiler is busy compiling. 2434 2810 */ … … 2441 2817 * 2442 2818 * @param pEntry The cache entry. 2443 * @param papszArgvPreComp The argument vector for executing precompiler. The cArgvPreComp'th argument must be NULL. 2819 * @param papszArgvPreComp The argument vector for executing preprocessor. 2820 * The cArgvPreComp'th argument must be NULL. 2444 2821 * @param cArgvPreComp The number of arguments. 2445 2822 */ 2446 static void kOCEntryPre CompileAndCompile(PKOCENTRY pEntry, const char * const *papszArgvPreComp, unsigned cArgvPreComp)2823 static void kOCEntryPreProcessAndCompile(PKOCENTRY pEntry, const char * const *papszArgvPreComp, unsigned cArgvPreComp) 2447 2824 { 2448 2825 if ( pEntry->fPipedCompile … … 2462 2839 2463 2840 /* 2464 * Do the actual compile and write the pre compiler output to disk.2841 * Do the actual compile and write the preprocessor output to disk. 2465 2842 */ 2466 2843 kOCEntrySpawnTee(pEntry, papszArgvPreComp, cArgvPreComp, 2467 2844 (const char * const *)pEntry->New.papszArgvCompile, pEntry->New.cArgvCompile, 2468 "precompile|compile", kOCEntryTeeConsumer); 2845 "preprocess|compile", kOCEntryTeeConsumer); 2846 if (pEntry->pszMakeDepFilename) 2847 kOCDepWriteToFile(&pEntry->DepState, pEntry->pszMakeDepFilename, pEntry->New.pszObjName, pEntry->pszDir, 2848 pEntry->fMakeDepFixCase, pEntry->fMakeDepQuiet, pEntry->fMakeDepGenStubs); 2469 2849 } 2470 2850 else 2471 2851 { 2472 kOCEntryPre Compile(pEntry, papszArgvPreComp, cArgvPreComp);2852 kOCEntryPreProcess(pEntry, papszArgvPreComp, cArgvPreComp); 2473 2853 kOCEntryCompileIt(pEntry); 2474 2854 } … … 2563 2943 /** 2564 2944 * Worker for kOCEntryCompareOldAndNewOutput() that compares the 2565 * pre compiled output using a fast but not very good method.2945 * preprocessed output using a fast but not very good method. 2566 2946 * 2567 2947 * @returns 1 if matching, 0 if not matching. … … 2613 2993 * possible that we will omit this header from the dependencies 2614 2994 * when using VCC. This might not be a problem, since it seems 2615 * we'll have to use the pre compiler output to generate the deps2995 * we'll have to use the preprocessor output to generate the deps 2616 2996 * anyway. 2617 2997 */ … … 2779 3159 /** 2780 3160 * Worker for kOCEntryCompileIfNeeded that compares the 2781 * pre compiled output.3161 * preprocessed output. 2782 3162 * 2783 3163 * @returns 1 if matching, 0 if not matching. … … 2810 3190 2811 3191 /* 2812 * Check if the pre compiler output differ in any significant way?3192 * Check if the preprocessor output differ in any significant way? 2813 3193 */ 2814 3194 if (!kOCSumHasEqualInChain(&pEntry->Old.SumHead, &pEntry->New.SumHead)) … … 2957 3337 /** The checksum of the compile argument vector. */ 2958 3338 KOCSUM SumCompArgv; 2959 /** The list of pre compiler output checksums that's . */3339 /** The list of preprocessor output checksums that's . */ 2960 3340 KOCSUM SumHead; 2961 3341 } KOCDIGEST; … … 3832 4212 " <-t|--target <target-name>>\n" 3833 4213 " [-r|--redir-stdout] [-p|--passthru] [--named-pipe-compile <pipename>]\n" 3834 " --kObjCache-cpp <filename> <pre compiler + args>\n"4214 " --kObjCache-cpp <filename> <preprocessor + args>\n" 3835 4215 " --kObjCache-cc <object> <compiler + args>\n" 3836 4216 " [--kObjCache-both [args]]\n" … … 3871 4251 const char *pszNmPipeCompile = NULL; 3872 4252 4253 const char *pszMakeDepFilename = NULL; 4254 int fMakeDepFixCase = 0; 4255 int fMakeDepGenStubs = 0; 4256 int fMakeDepQuiet = 0; 4257 3873 4258 const char *pszTarget = NULL; 3874 4259 … … 3911 4296 { 3912 4297 if (++i >= argc) 3913 return SyntaxError("--kObjCache-cc requires an pre compiler output filename!\n");4298 return SyntaxError("--kObjCache-cc requires an preprocessor output filename!\n"); 3914 4299 pszObjName = argv[i]; 3915 4300 } … … 3975 4360 fRedirCompileStdIn = 0; 3976 4361 } 4362 else if (!strcmp(argv[i], "-m") || !strcmp(argv[i], "--make-dep-file")) 4363 { 4364 if (i + 1 >= argc) 4365 return SyntaxError("%s requires a filename!\n", argv[i]); 4366 pszMakeDepFilename = argv[++i]; 4367 } 4368 else if (!strcmp(argv[i], "--make-dep-fix-case")) 4369 fMakeDepFixCase = 1; 4370 else if (!strcmp(argv[i], "--make-dep-gen-stubs")) 4371 fMakeDepGenStubs = 1; 4372 else if (!strcmp(argv[i], "--make-dep-quiet")) 4373 fMakeDepQuiet = 1; 3977 4374 else if (!strcmp(argv[i], "-p") || !strcmp(argv[i], "--passthru")) 3978 4375 fRedirPreCompStdOut = fRedirCompileStdIn = 1; … … 3992 4389 { 3993 4390 printf("kObjCache - kBuild version %d.%d.%d ($Revision$)\n" 3994 "Copyright (c) 2007-201 1knut st. osmundsen\n",4391 "Copyright (c) 2007-2012 knut st. osmundsen\n", 3995 4392 KBUILD_VERSION_MAJOR, KBUILD_VERSION_MINOR, KBUILD_VERSION_PATCH); 3996 4393 return 0; … … 4006 4403 return SyntaxError("No compiler arguments (--kObjCache-cc)!\n"); 4007 4404 if (!cArgvPreComp) 4008 return SyntaxError("No pre compiler arguments (--kObjCache-cc)!\n");4405 return SyntaxError("No preprocessor arguments (--kObjCache-cc)!\n"); 4009 4406 4010 4407 /* … … 4048 4445 kOCEntrySetCppName(pEntry, pszPreCompName); 4049 4446 kOCEntrySetPipedMode(pEntry, fRedirPreCompStdOut, fRedirCompileStdIn, pszNmPipeCompile); 4447 kOCEntrySetDepFilename(pEntry, pszMakeDepFilename, fMakeDepFixCase, fMakeDepQuiet, fMakeDepGenStubs); 4050 4448 4051 4449 /* … … 4062 4460 kObjCacheUnlock(pCache); 4063 4461 InfoMsg(1, "doing full compile\n"); 4064 kOCEntryPre CompileAndCompile(pEntry, papszArgvPreComp, cArgvPreComp);4462 kOCEntryPreProcessAndCompile(pEntry, papszArgvPreComp, cArgvPreComp); 4065 4463 kObjCacheLock(pCache); 4066 4464 } … … 4068 4466 { 4069 4467 /* 4070 * Do the pre compile(don't need to lock the cache file for this).4468 * Do the preprocess (don't need to lock the cache file for this). 4071 4469 */ 4072 4470 kObjCacheUnlock(pCache); 4073 kOCEntryPre Compile(pEntry, papszArgvPreComp, cArgvPreComp);4471 kOCEntryPreProcess(pEntry, papszArgvPreComp, cArgvPreComp); 4074 4472 4075 4473 /*
Note:
See TracChangeset
for help on using the changeset viewer.