Changeset 2894 in kBuild
- Timestamp:
- Sep 8, 2016 1:27:56 PM (8 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kWorker/Makefile.kmk
r2878 r2894 33 33 kWorker_DEFS.debug = K_STRICT 34 34 kWorker_DEFS.release = NASSERT 35 kWorker_SOURCES = kWorker.c 35 kWorker_SOURCES = \ 36 kWorker.c \ 37 ../kmk/kmkbuiltin/kDepObj.c 38 kWorker_INCS = \ 39 ../kmk/ \ 40 ../kmk/kmkbuiltin 36 41 kWorker_LIBS = \ 37 42 $(kStuff_1_TARGET) \ … … 56 61 crc32.c \ 57 62 md5.c \ 58 kbuild_version.c 63 kbuild_version.c \ 64 kDep.c 59 65 kWorkerLib_SOURCES.win = \ 60 66 nt_fullpath.c \ 67 nt_fullpath_cached.c \ 61 68 quoted_spawn.c \ 62 69 nt/nthlpcore.c \ -
trunk/src/kWorker/kWorker.c
r2892 r2894 53 53 #include "quote_argv.h" 54 54 #include "md5.h" 55 56 #include "../kmk/kmkbuiltin.h" 55 57 56 58 … … 6894 6896 6895 6897 /** 6898 * Does the post command part of a job (optional). 6899 * 6900 * @returns The exit code of the job. 6901 * @param cPostCmdArgs Number of post command arguments (includes cmd). 6902 * @param papszPostCmdArgs The post command and its argument. 6903 */ 6904 static int kSubmitHandleJobPostCmd(KU32 cPostCmdArgs, const char **papszPostCmdArgs) 6905 { 6906 const char *pszCmd = papszPostCmdArgs[0]; 6907 6908 /* Allow the kmk builtin prefix. */ 6909 static const char s_szKmkBuiltinPrefix[] = "kmk_builtin_"; 6910 if (kHlpStrNComp(pszCmd, s_szKmkBuiltinPrefix, sizeof(s_szKmkBuiltinPrefix) - 1) == 0) 6911 pszCmd += sizeof(s_szKmkBuiltinPrefix) - 1; 6912 6913 /* Command switch. */ 6914 if (kHlpStrComp(pszCmd, "kDepObj") == 0) 6915 return kmk_builtin_kDepObj(cPostCmdArgs, (char **)papszPostCmdArgs, NULL); 6916 6917 return kwErrPrintfRc(42 + 5 , "Unknown post command: '%s'\n", pszCmd); 6918 } 6919 6920 6921 /** 6896 6922 * Part 2 of the "JOB" command handler. 6897 6923 * 6898 6924 * @returns The exit code of the job. 6899 * @param pszExecutable The executable to execute.6900 * @param pszCwd The current working directory of the job.6901 * @param cArgs The number of arguments.6902 * @param papszArgs The argument vector.6925 * @param pszExecutable The executable to execute. 6926 * @param pszCwd The current working directory of the job. 6927 * @param cArgs The number of arguments. 6928 * @param papszArgs The argument vector. 6903 6929 * @param fWatcomBrainDamange Whether to apply watcom rules while quoting. 6904 * @param cEnvVars The number of environment variables. 6905 * @param papszEnvVars The enviornment vector. 6930 * @param cEnvVars The number of environment variables. 6931 * @param papszEnvVars The enviornment vector. 6932 * @param cPostCmdArgs Number of post command arguments (includes cmd). 6933 * @param papszPostCmdArgs The post command and its argument. 6906 6934 */ 6907 6935 static int kSubmitHandleJobUnpacked(const char *pszExecutable, const char *pszCwd, 6908 6936 KU32 cArgs, const char **papszArgs, KBOOL fWatcomBrainDamange, 6909 KU32 cEnvVars, const char **papszEnvVars) 6937 KU32 cEnvVars, const char **papszEnvVars, 6938 KU32 cPostCmdArgs, const char **papszPostCmdArgs) 6910 6939 { 6911 6940 int rcExit; … … 6972 7001 break; 6973 7002 } 7003 7004 /* 7005 * Do the post command, if present. 7006 */ 7007 if (cPostCmdArgs && rcExit == 0) 7008 rcExit = kSubmitHandleJobPostCmd(cPostCmdArgs, papszPostCmdArgs); 6974 7009 } 6975 7010 else … … 7063 7098 if (papszEnvVars) 7064 7099 { 7065 KU32 i;7066 7100 for (i = 0; i < cEnvVars; i++) 7067 7101 { … … 7078 7112 } 7079 7113 papszEnvVars[cEnvVars] = 0; 7114 7115 /* Flags (currently just watcom argument brain damanage). */ 7080 7116 if (cbMsg >= sizeof(KU8)) 7081 7117 { 7082 7118 KBOOL fWatcomBrainDamange = *pszMsg++; 7083 7119 cbMsg--; 7084 if (cbMsg == 0) 7120 7121 /* Post command argument count (can be zero). */ 7122 if (cbMsg >= sizeof(KU32)) 7085 7123 { 7086 /* 7087 * The next step. 7088 */ 7089 rcExit = kSubmitHandleJobUnpacked(pszExecutable, pszCwd, 7090 cArgs, papszArgs, fWatcomBrainDamange, 7091 cEnvVars, papszEnvVars); 7124 KU32 cPostCmdArgs; 7125 kHlpMemCopy(&cPostCmdArgs, pszMsg, sizeof(cPostCmdArgs)); 7126 pszMsg += sizeof(cPostCmdArgs); 7127 cbMsg -= sizeof(cPostCmdArgs); 7128 7129 if (cPostCmdArgs >= 0 && cPostCmdArgs < 32) 7130 { 7131 char const *apszPostCmdArgs[32+1]; 7132 for (i = 0; i < cPostCmdArgs; i++) 7133 { 7134 apszPostCmdArgs[i] = pszMsg; 7135 cbTmp = kHlpStrLen(pszMsg) + 1; 7136 pszMsg += cbTmp; 7137 if ( cbTmp < cbMsg 7138 || (cbTmp == cbMsg && i + 1 == cPostCmdArgs)) 7139 cbMsg -= cbTmp; 7140 else 7141 { 7142 cbMsg = KSIZE_MAX; 7143 break; 7144 } 7145 } 7146 if (cbMsg == 0) 7147 { 7148 apszPostCmdArgs[cPostCmdArgs] = NULL; 7149 7150 /* 7151 * The next step. 7152 */ 7153 rcExit = kSubmitHandleJobUnpacked(pszExecutable, pszCwd, 7154 cArgs, papszArgs, fWatcomBrainDamange, 7155 cEnvVars, papszEnvVars, 7156 cPostCmdArgs, apszPostCmdArgs); 7157 } 7158 else if (cbMsg == KSIZE_MAX) 7159 kwErrPrintf("Detected bogus message unpacking post command and its arguments!\n"); 7160 else 7161 kwErrPrintf("Message has %u bytes unknown trailing bytes\n", cbMsg); 7162 } 7163 else 7164 kwErrPrintf("Bogus post command argument count: %u %#x\n", cPostCmdArgs, cPostCmdArgs); 7092 7165 } 7093 7166 else 7094 kwErrPrintf(" Message has %u bytes unknown trailing bytes\n", cbMsg);7167 kwErrPrintf("Detected bogus message looking for the post command argument count!\n"); 7095 7168 } 7096 7169 else … … 7281 7354 rcExit = kSubmitHandleJobUnpacked(argv[i], pszCwd, 7282 7355 argc - i, &argv[i], fWatcomBrainDamange, 7283 cEnvVars, environ); 7356 cEnvVars, environ, 7357 0, NULL); 7284 7358 KW_LOG(("rcExit=%d\n", rcExit)); 7285 7359 kwSandboxCleanupLate(&g_Sandbox); -
trunk/src/kmk/kmkbuiltin/kDepObj.c
r2856 r2894 28 28 *******************************************************************************/ 29 29 #define MSCFAKES_NO_WINDOWS_H 30 #include "config.h"31 30 #include <stdio.h> 32 31 #include <stdlib.h> … … 36 35 #include <ctype.h> 37 36 #include <stdarg.h> 38 #ifdef HAVE_ALLOCA_H39 # include <alloca.h>40 #endif41 37 #if !defined(_MSC_VER) 42 38 # include <unistd.h> … … 54 50 * Defined Constants And Macros * 55 51 *******************************************************************************/ 56 /*#define DEBUG*/ 57 #ifdef DEBUG 52 #if 0 58 53 # define dprintf(a) printf a 59 54 # define dump(pb, cb, offBase) depHexDump(pb,cb,offBase) … … 576 571 * @param cbSyms Size of the symbol section. 577 572 */ 578 int kDepObjCOFFParseCV8SymbolSection(const KU8 *pbSyms, K SIZEcbSyms)573 int kDepObjCOFFParseCV8SymbolSection(const KU8 *pbSyms, KU32 cbSyms) 579 574 { 580 575 char const * pchStrTab = NULL; … … 765 760 int rc; 766 761 767 printf("COFF file!\n");762 dprintf(("COFF file!\n")); 768 763 769 764 for (iSHdr = 0; iSHdr < cSHdrs; iSHdr++) … … 784 779 return rc; 785 780 } 786 printf("#%d: %.8s\n", iSHdr, paSHdrs[iSHdr].Name);781 dprintf(("#%d: %.8s\n", iSHdr, paSHdrs[iSHdr].Name)); 787 782 } 788 783 return rcRet; -
trunk/src/kmk/kmkbuiltin/kSubmit.c
r2884 r2894 574 574 * @param pszCwd The current directory. 575 575 * @param fWatcomBrainDamage The wcc/wcc386 workaround. 576 * @param papszPostCmdArgs The post command and it's arguments. 577 * @param cPostCmdArgs Number of post command argument, including the 578 * command. Zero if no post command scheduled. 576 579 * @param pcbMsg Where to return the message length. 577 580 */ 578 581 static void *kSubmitComposeJobMessage(const char *pszExecutable, char **papszArgs, char **papszEnvVars, 579 const char *pszCwd, int fWatcomBrainDamage, uint32_t *pcbMsg) 582 const char *pszCwd, int fWatcomBrainDamage, 583 char **papszPostCmdArgs, uint32_t cPostCmdArgs, uint32_t *pcbMsg) 580 584 { 581 585 size_t cbTmp; … … 613 617 cbMsg += 1; 614 618 619 cbMsg += sizeof(cPostCmdArgs); 620 for (i = 0; i < cPostCmdArgs; i++) 621 cbMsg += strlen(papszPostCmdArgs[i]) + 1; 622 615 623 /* 616 624 * Compose the message. … … 618 626 pbMsg = pbCursor = xmalloc(cbMsg); 619 627 628 /* header */ 620 629 memcpy(pbCursor, &cbMsg, sizeof(cbMsg)); 621 630 pbCursor += sizeof(cbMsg); … … 623 632 pbCursor += sizeof("JOB"); 624 633 634 /* executable. */ 625 635 cbTmp = strlen(pszExecutable) + 1; 626 636 memcpy(pbCursor, pszExecutable, cbTmp); 627 637 pbCursor += cbTmp; 628 638 639 /* cwd */ 629 640 cbTmp = strlen(pszCwd) + 1; 630 641 memcpy(pbCursor, pszCwd, cbTmp); 631 642 pbCursor += cbTmp; 632 643 644 /* argument */ 633 645 memcpy(pbCursor, &cArgs, sizeof(cArgs)); 634 646 pbCursor += sizeof(cArgs); … … 642 654 assert(i == cArgs); 643 655 656 /* environment */ 644 657 memcpy(pbCursor, &cEnvVars, sizeof(cEnvVars)); 645 658 pbCursor += sizeof(cEnvVars); … … 652 665 assert(i == cEnvVars); 653 666 667 /* flags */ 654 668 *pbCursor++ = fWatcomBrainDamage != 0; 655 669 670 /* post command */ 671 memcpy(pbCursor, &cPostCmdArgs, sizeof(cPostCmdArgs)); 672 pbCursor += sizeof(cPostCmdArgs); 673 for (i = 0; i < cPostCmdArgs; i++) 674 { 675 cbTmp = strlen(papszPostCmdArgs[i]) + 1; 676 memcpy(pbCursor, papszPostCmdArgs[i], cbTmp); 677 pbCursor += cbTmp; 678 } 679 assert(i == cPostCmdArgs); 680 656 681 assert(pbCursor - pbMsg == (size_t)cbMsg); 657 682 658 /* done */ 683 /* 684 * Done. 685 */ 659 686 *pcbMsg = cbMsg; 660 687 return pbMsg; … … 1339 1366 "usage: %s [-Z|--zap-env] [-E|--set <var=val>] [-U|--unset <var=val>]\n" 1340 1367 " [-C|--chdir <dir>] [--wcc-brain-damage]\n" 1341 " [-3|--32-bit] [-6|--64-bit] [-v] -- <program> [args]\n" 1368 " [-3|--32-bit] [-6|--64-bit] [-v]\n" 1369 " [-P|--post-cmd <cmd> [args]] -- <program> [args]\n" 1342 1370 " or: %s --help\n" 1343 1371 " or: %s --version\n" … … 1362 1390 " -v,--verbose\n" 1363 1391 " More verbose execution.\n" 1392 " -P|--post-cmd <cmd> ...\n" 1393 " For running a built-in command on the output, specifying the command\n" 1394 " and all it's parameters. Currently supported commands:\n" 1395 " kDepObj\n" 1364 1396 " -V,--version\n" 1365 1397 " Show the version number.\n" … … 1383 1415 const char *pszExecutable = NULL; 1384 1416 const char *pszCwd = NULL; 1417 int iPostCmd = argc; 1418 int cPostCmdArgs = 0; 1385 1419 unsigned cBitsWorker = g_cArchBits; 1386 1420 int fWatcomBrainDamage = 0; … … 1457 1491 else if (strcmp(pszArg, "chdir") == 0) 1458 1492 chOpt = 'C'; 1493 else if (strcmp(pszArg, "post-cmd") == 0) 1494 chOpt = 'P'; 1459 1495 else if (strcmp(pszArg, "32-bit") == 0) 1460 1496 chOpt = '3'; … … 1489 1525 else 1490 1526 { 1491 errx(1, "Option -%c requires a nvalue!", chOpt);1527 errx(1, "Option -%c requires a value!", chOpt); 1492 1528 return usage(stderr, argv[0]); 1493 1529 } … … 1524 1560 return rcExit; 1525 1561 1562 case 'P': 1563 if (cPostCmdArgs > 0) 1564 return errx(1, "The -P option can only be used once!"); 1565 if (*pszArg != '\0') 1566 return errx(1, "The cmd part of the -P needs to be a separate argument!"); 1567 iPostCmd = ++iArg; 1568 if (iArg >= argc) 1569 return errx(1, "The -P option requires a command following it!"); 1570 while (iArg < argc && strcmp(argv[iArg], "--") != 0) 1571 iArg++; 1572 cPostCmdArgs = iArg - iPostCmd; 1573 iArg--; 1574 break; 1575 1526 1576 case '3': 1527 1577 cBitsWorker = 32; … … 1563 1613 uint32_t cbMsg; 1564 1614 void *pvMsg = kSubmitComposeJobMessage(pszExecutable, &argv[iArg], papszEnv, szCwd, 1565 fWatcomBrainDamage, & cbMsg);1615 fWatcomBrainDamage, &argv[iPostCmd], cPostCmdArgs, &cbMsg); 1566 1616 PWORKERINSTANCE pWorker = kSubmitSelectWorkSpawnNewIfNecessary(cBitsWorker, cVerbosity); 1567 1617 if (pWorker) -
trunk/src/lib/quote_argv.c
r2851 r2894 114 114 || ( !fWatcomBrainDamage 115 115 && (pszProblem = (const char *)memchr(pszOrg, '=', cchOrg)) != NULL) 116 || ( fWatcomBrainDamage 117 && (pszProblem = (const char *)memchr(pszOrg, '\\', cchOrg)) != NULL) 116 118 ) 117 119 {
Note:
See TracChangeset
for help on using the changeset viewer.