From: Robert Pengelly Date: Sat, 5 Apr 2025 19:38:30 +0000 (+0100) Subject: More bug fixes and added -k to keep going on other targets X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=59dd6b0e6ab5b2d2fb065006fac93fac116cfee5;p=xmake.git More bug fixes and added -k to keep going on other targets --- diff --git a/include/xmake/xmake.h b/include/xmake/xmake.h index 5d2f735..c277782 100644 --- a/include/xmake/xmake.h +++ b/include/xmake/xmake.h @@ -21,7 +21,7 @@ struct xmake_state { char *path; int quiet, no_print; - int dry_run, env_override; + int dry_run, env_override, keep_going; int ignore_errors; }; diff --git a/lib.c b/lib.c index 94b1104..01bf0b3 100644 --- a/lib.c +++ b/lib.c @@ -102,6 +102,15 @@ static int set_env_override (const char *arg) { } +static int set_keep_going (const char *arg) { + + (void) arg; + + state->keep_going = 1; + return 0; + +} + static int add_include_path (const char *path) { const char *in = path; @@ -223,6 +232,9 @@ static struct option opts[] = { { "--environment-overrides", &set_env_override }, { "-e", &set_env_override }, + { "--keep-going", &set_keep_going }, + { "-k", &set_keep_going }, + { 0, &non_option } }; diff --git a/read.c b/read.c index c16069e..5e0eab8 100644 --- a/read.c +++ b/read.c @@ -277,7 +277,7 @@ static int read_lbuf (struct linebuf *lbuf, int set_default) { #define record_waiting_files() \ do { \ if (filenames) { \ - record_files (lbuf->filename, line_no, filenames, cmds, cmds_idx, depstr); \ + record_files (lbuf->filename, line_no - 1, filenames, cmds, cmds_idx, depstr); \ filenames = 0; \ } \ cmds_idx = 0; \ diff --git a/variable.c b/variable.c index df0fe70..e6cd868 100644 --- a/variable.c +++ b/variable.c @@ -117,13 +117,13 @@ static char *func_shell (const char *filename, unsigned long line_no, char *inpu struct linebuf lbuf; input = skip_whitespace (input); - for (p = input; !isspace ((int) *p); p++) { + /*for (p = input; !isspace ((int) *p); p++) { if (*p == '/') { *p = '\\'; } - } + }*/ if ((p = strchr (input, ' '))) { @@ -160,7 +160,7 @@ static char *func_shell (const char *filename, unsigned long line_no, char *inpu } - } else { + }/* else { if (lpApplicationName) { free (lpApplicationName); @@ -168,7 +168,7 @@ static char *func_shell (const char *filename, unsigned long line_no, char *inpu lpApplicationName = 0; - } + }*/ memset (&sa, 0, sizeof (sa)); memset (&si, 0, sizeof (si)); @@ -182,6 +182,10 @@ static char *func_shell (const char *filename, unsigned long line_no, char *inpu fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input); fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ())); + if (state->keep_going) { + return 0; + } + exit (EXIT_FAILURE); } @@ -191,6 +195,10 @@ static char *func_shell (const char *filename, unsigned long line_no, char *inpu fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input); fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ())); + if (state->keep_going) { + return 0; + } + exit (EXIT_FAILURE); } @@ -200,6 +208,10 @@ static char *func_shell (const char *filename, unsigned long line_no, char *inpu fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input); fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ())); + if (state->keep_going) { + return 0; + } + exit (EXIT_FAILURE); } @@ -209,6 +221,10 @@ static char *func_shell (const char *filename, unsigned long line_no, char *inpu fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input); fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ())); + if (state->keep_going) { + return 0; + } + exit (EXIT_FAILURE); } @@ -226,6 +242,10 @@ static char *func_shell (const char *filename, unsigned long line_no, char *inpu fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input); fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ())); + if (state->keep_going) { + return 0; + } + exit (EXIT_FAILURE); } diff --git a/xmake.c b/xmake.c index 47c1378..6753d57 100644 --- a/xmake.c +++ b/xmake.c @@ -52,7 +52,55 @@ static int doing_inference_rule_commands = 0; #if defined (_WIN32) || defined (__WIN32__) # include -static void pipe_command (const char *filename, unsigned long line_no, char *input, int is_ignoring_errors, const char *name) { +static char *internal_commands[] = { + + "assoc", + "break", + "call", + "cd", + "chcp", + "chdir", + "cls", + "color", + "copy", + "ctty", + "date", + "del", + "dir", + "echo", + "echo.", + "endlocal", + "erase", + "exit", + "for", + "ftype", + "goto", + "if", + "md", + "mkdir", + "move", + "path", + "pause", + "prompt", + "rd", + "rem", + "ren", + "rename", + "rmdir", + "set", + "setlocal", + "shift", + "time", + "title", + "type", + "ver", + "verify", + "vol", + 0 + +}; + +static int pipe_command (const char *filename, unsigned long line_no, char *input, int is_ignoring_errors, const char *name) { DWORD dwExitCode; @@ -63,9 +111,10 @@ static void pipe_command (const char *filename, unsigned long line_no, char *inp HANDLE hStdInPipeRead, hStdInPipeWrite; HANDLE hStdOutPipeRead, hStdOutPipeWrite; - char *lpApplicationName = getenv ("COMSPEC"), *lpCommandLine = 0; - struct linebuf lbuf; + char *lpApplicationName = 0, *lpCommandLine = 0; + char *p; + struct linebuf lbuf; input = skip_whitespace (input); /*for (p = input; !isspace ((int) *p); p++) { @@ -76,8 +125,50 @@ static void pipe_command (const char *filename, unsigned long line_no, char *inp }*/ - lpCommandLine = xmalloc (4 + strlen (input) + 1); - sprintf (lpCommandLine, "/C %s", input); + if ((p = strchr (input, ' '))) { + + lpApplicationName = xstrndup (input, p - input); + lpCommandLine = xstrdup (skip_whitespace (p)); + + } else { + lpApplicationName = xstrdup (skip_whitespace (input)); + } + + if (!(p = strchr (lpApplicationName, '\\'))) { + + unsigned long count = sizeof (internal_commands) / sizeof (internal_commands[0]), i; + + for (i = 0; i < count; i++) { + + if (strcasecmp (lpApplicationName, internal_commands[i]) == 0) { + + if (lpApplicationName) { + free (lpApplicationName); + } + + if (lpCommandLine) { + free (lpCommandLine); + } + + lpCommandLine = xmalloc (4 + strlen (input) + 1); + sprintf (lpCommandLine, "/C %s", input); + + lpApplicationName = xstrdup (getenv ("COMSPEC")); + break; + + } + + } + + }/* else { + + if (lpApplicationName) { + free (lpApplicationName); + } + + lpApplicationName = 0; + + }*/ memset (&sa, 0, sizeof (sa)); memset (&si, 0, sizeof (si)); @@ -91,6 +182,10 @@ static void pipe_command (const char *filename, unsigned long line_no, char *inp fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input); fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ())); + if (state->keep_going) { + return 1; + } + exit (EXIT_FAILURE); } @@ -100,6 +195,10 @@ static void pipe_command (const char *filename, unsigned long line_no, char *inp fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input); fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ())); + if (state->keep_going) { + return 1; + } + exit (EXIT_FAILURE); } @@ -109,6 +208,10 @@ static void pipe_command (const char *filename, unsigned long line_no, char *inp fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input); fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ())); + if (state->keep_going) { + return 1; + } + exit (EXIT_FAILURE); } @@ -118,6 +221,10 @@ static void pipe_command (const char *filename, unsigned long line_no, char *inp fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input); fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ())); + if (state->keep_going) { + return 1; + } + exit (EXIT_FAILURE); } @@ -135,6 +242,10 @@ static void pipe_command (const char *filename, unsigned long line_no, char *inp fprintf (stderr, "process_begin: CreateProcess(NULL, %s, ...) failed.\n", input); fprintf (stderr, "%s: %s:%lu: pipe: %s\n", program_name, filename, line_no, strerror (GetLastError ())); + if (state->keep_going) { + return 1; + } + exit (EXIT_FAILURE); } @@ -194,6 +305,10 @@ static void pipe_command (const char *filename, unsigned long line_no, char *inp fprintf (stderr, "%s", lbuf.start); fprintf (stderr, "%s: *** [%s:%lu: %s] Error %ld\n", program_name, filename, line_no, name, dwExitCode); + if (state->keep_going) { + return dwExitCode; + } + exit (EXIT_FAILURE); } @@ -201,13 +316,15 @@ static void pipe_command (const char *filename, unsigned long line_no, char *inp } else { printf ("%s", lbuf.start); } + + return 0; } #elif defined (_WIN32) || defined (__WIN32__) || defined (unix) || defined (__unix) || defined (__unix__) || defined (__APPLE__) # include # include # include -static void pipe_command (const char *filename, unsigned long line_no, char *input, int is_ignoring_errors, const char *name) { +static int pipe_command (const char *filename, unsigned long line_no, char *input, int is_ignoring_errors, const char *name) { int pipefd[2], pid, status; @@ -232,10 +349,10 @@ static void pipe_command (const char *filename, unsigned long line_no, char *inp if (pid == 0) { - char *name = input, *space = 0, *slash; + char *prog = input, *space = 0, *slash; - if ((space = strchr (name, ' '))) { - name = xstrndup (name, space - name); + if ((space = strchr (prog, ' '))) { + prog = xstrndup (prog, space - prog); } dup2 (pipefd[1], STDOUT_FILENO); @@ -243,7 +360,9 @@ static void pipe_command (const char *filename, unsigned long line_no, char *inp close (pipefd[0]); close (pipefd[1]); - execlp (name, (slash = strrchr (name, '/')) ? (slash + 1) : name, space ? skip_whitespace (space) : NULL, NULL); + execlp (prog, (slash = strrchr (prog, '/')) ? (slash + 1) : prog, space ? skip_whitespace (space) : NULL, NULL); + + printf ("%s: %s: %s\n", program_name, prog, strerror (errno)); exit (EXIT_FAILURE); } @@ -292,24 +411,7 @@ static void pipe_command (const char *filename, unsigned long line_no, char *inp } - if (status) { - - if (!is_ignoring_errors) { - - char *space, *p = input; - - if ((space = strchr (p, ' '))) { - p = xstrndup (p, space - p); - } - - fprintf (stderr, "%s: %s: No such file or directory\n", program_name, p); - fprintf (stderr, "%s: *** [%s:%lu: %s] Error %d\n", program_name, filename, line_no, name, status); - - exit (EXIT_FAILURE); - - } - - } else { + { char *p = lbuf.start, ch; @@ -335,10 +437,29 @@ static void pipe_command (const char *filename, unsigned long line_no, char *inp if (isspace ((int) *(p - 1))) { *(p - 1) = '\0'; } + + } + + if (status) { + + if (!is_ignoring_errors) { - printf ("%s\n", lbuf.start); + fprintf (stderr, "%s\n", lbuf.start); + fprintf (stderr, "%s: *** [%s:%lu: %s] Error %d\n", program_name, filename, line_no, name, status); + + if (state->keep_going) { + return status; + } + + exit (EXIT_FAILURE); + + } + } else { + printf ("%s\n", lbuf.start); } + + return 0; } #endif @@ -346,6 +467,7 @@ static void pipe_command (const char *filename, unsigned long line_no, char *inp static int rule_run_command (const char *filename, unsigned long line_no, const char *name, char *p, char *q) { char *new_cmds, *s; + int status = 0; int is_ignoring_errors = state->ignore_errors; int is_quiet = state->quiet; @@ -384,11 +506,9 @@ static int rule_run_command (const char *filename, unsigned long line_no, const if (should_execute) { #if defined (_WIN32) || defined (__WIN32__) || defined (unix) || defined (__unix) || defined (__unix__) || defined (__APPLE__) - pipe_command (filename, line_no, s, is_ignoring_errors, name); + status = pipe_command (filename, line_no, s, is_ignoring_errors, name); #else - int status = system (s); - - if (!is_ignoring_errors && status) { + if ((status = system (s)) && !is_ignoring_errors) { char *space, *p = s; @@ -398,6 +518,10 @@ static int rule_run_command (const char *filename, unsigned long line_no, const fprintf (stderr, "%s: %s: No such file or directory\n", program_name, p); fprintf (stderr, "%s: *** [%s:%lu: %s] Error %d\n", program_name, filename, line_no, name, status); + + if (!keep_going) { + exit (EXIT_FAILURE); + } } #endif @@ -405,7 +529,7 @@ static int rule_run_command (const char *filename, unsigned long line_no, const } free (new_cmds); - return 0; + return status; } @@ -464,7 +588,7 @@ static int run_commands (const char *filename, unsigned long line_no, struct com if (!q) { break; }; - if ((error = rule_run_command (filename, line_no, name, p, q)) < 0) { + if ((error = rule_run_command (filename, line_no, name, p, q))) { return error; } @@ -958,7 +1082,11 @@ int main (int argc, char **argv) { for (i = 0; i < state->nb_goals; i++) { if ((ret = rule_search_and_build (state->goals[i]))) { - goto out; + + if (!state->keep_going) { + goto out; + } + } }