tools/mkdeps: Fix the nxstyle problem

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2020-05-21 21:53:49 +08:00 committed by patacongo
parent d2bb9bf2b4
commit 02e028a595

View File

@ -47,6 +47,7 @@
#include <ctype.h>
#include <libgen.h>
#include <errno.h>
#include <dirent.h>
#ifdef HOST_CYGWIN
# include <sys/cygwin.h>
@ -77,7 +78,6 @@
/* MAXNAMELEN might be defined in dirent.h */
# include <dirent.h>
# if defined(MAXNAMLEN)
# define NAME_MAX MAXNAMLEN
# else
@ -131,7 +131,7 @@ static char g_posixpath[MAX_PATH];
/* MinGW does not seem to provide strtok_r */
#ifndef HAVE_STRTOK_R
static char *MY_strtok_r(char *str, const char *delim, char **saveptr)
static char *my_strtok_r(char *str, const char *delim, char **saveptr)
{
char *pbegin;
char *pend = NULL;
@ -198,7 +198,7 @@ static char *MY_strtok_r(char *str, const char *delim, char **saveptr)
}
#undef strtok_r
#define strtok_r MY_strtok_r
#define strtok_r my_strtok_r
#endif
static void append(char **base, char *str)
@ -219,7 +219,8 @@ static void append(char **base, char *str)
}
else
{
alloclen = strlen(oldbase) + strlen(str) + sizeof((char) ' ') + sizeof((char) '\0');
alloclen = strlen(oldbase) + strlen(str) +
sizeof((char) ' ') + sizeof((char) '\0');
newbase = (char *)malloc(alloclen);
if (!newbase)
{
@ -229,7 +230,7 @@ static void append(char **base, char *str)
snprintf(newbase, alloclen, "%s %s", oldbase, str);
free(oldbase);
}
}
*base = newbase;
}
@ -248,33 +249,46 @@ static void show_usage(const char *progname, const char *msg, int exitcode)
fprintf(stderr, "\n");
fprintf(stderr, "Where:\n");
fprintf(stderr, " CC\n");
fprintf(stderr, " A variable number of arguments that define how to execute the compiler\n");
fprintf(stderr, " A variable number of arguments that define how to\n");
fprintf(stderr, " execute the compiler\n");
fprintf(stderr, " CFLAGS\n");
fprintf(stderr, " The compiler compilation flags\n");
fprintf(stderr, " file\n");
fprintf(stderr, " One or more C files whose dependencies will be checked. Each file is expected\n");
fprintf(stderr, " to reside in the current directory unless --dep-path is provided on the command line\n");
fprintf(stderr, " One or more C files whose dependencies will be\n");
fprintf(stderr, " checked. Each file is expected\n");
fprintf(stderr, " to reside in the current directory unless\n");
fprintf(stderr, " --dep-path is provided on the command line\n");
fprintf(stderr, "\n");
fprintf(stderr, "And [OPTIONS] include:\n");
fprintf(stderr, " --dep-debug\n");
fprintf(stderr, " Enable script debug\n");
fprintf(stderr, " --dep-path <path>\n");
fprintf(stderr, " Do not look in the current directory for the file. Instead, look in <path> to see\n");
fprintf(stderr, " if the file resides there. --dep-path may be used multiple times to specify\n");
fprintf(stderr, " Do not look in the current directory for the\n");
fprintf(stderr, " file. Instead, look in <path> to see\n");
fprintf(stderr, " if the file resides there. --dep-path may be\n");
fprintf(stderr, " used multiple times to specify\n");
fprintf(stderr, " multiple alternative location\n");
fprintf(stderr, " --obj-path <path>\n");
fprintf(stderr, " The final objects will not reside in this path but, rather, at the path provided by\n");
fprintf(stderr, " <path>. if provided multiple time, only the last --obj-path will be used.\n");
fprintf(stderr, " The final objects will not reside in this path\n");
fprintf(stderr, " but, rather, at the path provided by\n");
fprintf(stderr, " <path>. if provided multiple time, only the last\n");
fprintf(stderr, " --obj-path will be used.\n");
fprintf(stderr, " --obj-suffix <suffix>\n");
fprintf(stderr, " If and object path is provided, then the extension will be assumed to be .o. This\n");
fprintf(stderr, " default suffix can be overriden with this command line option.\n");
fprintf(stderr, " If an object path is provided, then the extension\n");
fprintf(stderr, " will be assumed to be .o. This\n");
fprintf(stderr, " default suffix can be overriden with this command\n");
fprintf(stderr, " line option.\n");
fprintf(stderr, " --winnative\n");
fprintf(stderr, " By default, a POSIX-style environment is assumed (e.g., Linux, Cygwin, etc.) This option is\n");
fprintf(stderr, " inform the tool that is working in a pure Windows native environment.\n");
fprintf(stderr, " By default, a POSIX-style environment is assumed\n");
fprintf(stderr, " (e.g., Linux, Cygwin, etc.) This option is\n");
fprintf(stderr, " inform the tool that is working in a pure Windows\n");
fprintf(stderr, " native environment.\n");
#ifdef HOST_CYGWIN
fprintf(stderr, " --winpaths\n");
fprintf(stderr, " This option is useful when using a Windows native toolchain in a POSIX environment (such\n");
fprintf(stderr, " such as Cygwin). In this case, will CC generates dependency lists using Windows paths\n");
fprintf(stderr, " This option is useful when using a Windows native\n");
fprintf(stderr, " toolchain in a POSIX environment (such such as\n");
fprintf(stderr, " Cygwin). In this case, will CC\n");
fprintf(stderr, " generates dependency lists using Windows paths\n");
fprintf(stderr, " (e.g., C:\\blablah\\blabla).\n");
#endif
fprintf(stderr, " --help\n");
@ -310,7 +324,8 @@ static void parse_args(int argc, char **argv)
argidx++;
if (argidx >= argc)
{
show_usage(argv[0], "ERROR: Missing argument to --dep-path", EXIT_FAILURE);
show_usage(argv[0], "ERROR: Missing argument to --dep-path",
EXIT_FAILURE);
}
if (args)
@ -327,7 +342,8 @@ static void parse_args(int argc, char **argv)
argidx++;
if (argidx >= argc)
{
show_usage(argv[0], "ERROR: Missing argument to --obj-path", EXIT_FAILURE);
show_usage(argv[0], "ERROR: Missing argument to --obj-path",
EXIT_FAILURE);
}
g_objpath = argv[argidx];
@ -337,7 +353,8 @@ static void parse_args(int argc, char **argv)
argidx++;
if (argidx >= argc)
{
show_usage(argv[0], "ERROR: Missing argument to --obj-suffix", EXIT_FAILURE);
show_usage(argv[0], "ERROR: Missing argument to --obj-suffix",
EXIT_FAILURE);
}
g_suffix = argv[argidx];
@ -369,10 +386,14 @@ static void parse_args(int argc, char **argv)
if (g_debug)
{
fprintf(stderr, "SELECTIONS\n");
fprintf(stderr, " CC : [%s]\n", g_cc ? g_cc : "(None)");
fprintf(stderr, " CFLAGS : [%s]\n", g_cflags ? g_cflags : "(None)");
fprintf(stderr, " FILES : [%s]\n", g_files ? g_files : "(None)");
fprintf(stderr, " PATHS : [%s]\n", g_altpath ? g_altpath : "(None)");
fprintf(stderr, " CC : [%s]\n",
g_cc ? g_cc : "(None)");
fprintf(stderr, " CFLAGS : [%s]\n",
g_cflags ? g_cflags : "(None)");
fprintf(stderr, " FILES : [%s]\n",
g_files ? g_files : "(None)");
fprintf(stderr, " PATHS : [%s]\n",
g_altpath ? g_altpath : "(None)");
if (g_objpath)
{
fprintf(stderr, " OBJDIR : [%s]\n", g_objpath);
@ -384,9 +405,11 @@ static void parse_args(int argc, char **argv)
}
#ifdef HOST_CYGWIN
fprintf(stderr, " Windows Paths : [%s]\n", g_winpath ? "TRUE" : "FALSE");
fprintf(stderr, " Windows Paths : [%s]\n",
g_winpath ? "TRUE" : "FALSE");
#endif
fprintf(stderr, " Windows Native : [%s]\n", g_winnative ? "TRUE" : "FALSE");
fprintf(stderr, " Windows Native : [%s]\n",
g_winnative ? "TRUE" : "FALSE");
}
/* Check for required parameters */
@ -398,7 +421,9 @@ static void parse_args(int argc, char **argv)
if (!g_files)
{
/* Don't report an error -- this happens normally in some configurations */
/* Don't report an error --
* this happens normally in some configurations
*/
printf("# No files specified for dependency generataion\n");
exit(EXIT_SUCCESS);
@ -407,7 +432,9 @@ static void parse_args(int argc, char **argv)
#ifdef HOST_CYGWIN
if (g_winnative && g_winpath)
{
show_usage(argv[0], "ERROR: Both --winnative and --winpath makes no sense", EXIT_FAILURE);
show_usage(argv[0],
"ERROR: Both --winnative and --winpath makes no sense",
EXIT_FAILURE);
}
#endif
}
@ -465,16 +492,17 @@ static const char *do_expand(const char *argument)
}
}
else
{
*dest++ = *src++;
len++;
}
{
*dest++ = *src++;
len++;
}
}
if (*src)
{
fprintf(stderr, "ERROR: Truncated during expansion string is too long [%lu/%u]\n",
(unsigned long)strlen(argument), MAX_EXPAND);
fprintf(stderr,
"ERROR: Truncated during expansion string is too long"
"[%lu/%u]\n", (unsigned long)strlen(argument), MAX_EXPAND);
exit(EXIT_FAILURE);
}
@ -498,7 +526,7 @@ static bool dequote_path(const char *winpath)
while (*src && len < MAX_PATH)
{
if (src[0] != '\\' || (src[1] != ' ' && src[1] != '(' && src[1] != ')'))
if (*src != '\\' || (src[1] != ' ' && src[1] != '(' && src[1] != ')'))
{
*dest++ = *src;
len++;
@ -544,7 +572,7 @@ static const char *convert_path(const char *path)
size = cygwin_conv_path(CCP_POSIX_TO_WIN_A | CCP_RELATIVE, g_dequoted,
NULL, 0);
if (size > (MAX_PATH-3))
if (size > (MAX_PATH - 3))
{
fprintf(stderr, "# ERROR: POSIX path too long: %lu\n",
(unsigned long)size);
@ -552,7 +580,7 @@ static const char *convert_path(const char *path)
}
ret = cygwin_conv_path(CCP_POSIX_TO_WIN_A | CCP_RELATIVE, g_dequoted,
&g_posixpath[1], MAX_PATH-3);
&g_posixpath[1], MAX_PATH - 3);
if (ret < 0)
{
fprintf(stderr, "# ERROR: cygwin_conv_path '%s' failed: %s\n",
@ -567,7 +595,7 @@ static const char *convert_path(const char *path)
g_posixpath[size] = '"';
}
g_posixpath[size+1] = '\0';
g_posixpath[size + 1] = '\0';
return retptr;
}
else
@ -616,7 +644,7 @@ static void do_dependency(const char *file)
if (g_objpath)
{
char tmp[NAME_MAX+6];
char tmp[NAME_MAX + 6];
char *dupname;
char *objname;
char *dotptr;
@ -636,7 +664,7 @@ static void do_dependency(const char *file)
*dotptr = '\0';
}
snprintf(tmp, NAME_MAX+6, " -MT %s%c%s%s ",
snprintf(tmp, NAME_MAX + 6, " -MT %s%c%s%s ",
g_objpath, separator, objname, g_suffix);
expanded = do_expand(tmp);
@ -689,8 +717,8 @@ static void do_dependency(const char *file)
cmdlen++;
g_command[cmdlen] = '\0';
/* Make a copy of g_altpath. We need to do this because at least the version
* of strtok_r above does modify it.
/* Make a copy of g_altpath. We need to do this because at least the
* version of strtok_r above does modify it.
*/
alloc = strdup(g_altpath);
@ -729,10 +757,10 @@ static void do_dependency(const char *file)
exit(EXIT_FAILURE);
}
if (g_path[pathlen-1] != separator)
if (g_path[pathlen - 1] != separator)
{
g_path[pathlen] = separator;
g_path[pathlen+1] = '\0';
g_path[pathlen + 1] = '\0';
pathlen++;
}
@ -765,7 +793,8 @@ static void do_dependency(const char *file)
if (!S_ISREG(buf.st_mode))
{
fprintf(stderr, "ERROR: File %s exists but is not a regular file\n",
fprintf(stderr,
"ERROR: File %s exists but is not a regular file\n",
g_path);
exit(EXIT_FAILURE);
}
@ -805,7 +834,8 @@ static void do_dependency(const char *file)
}
else
{
fprintf(stderr, "ERROR: %s failed: %d\n", g_cc, WEXITSTATUS(ret));
fprintf(stderr,
"ERROR: %s failed: %d\n", g_cc, WEXITSTATUS(ret));
}
fprintf(stderr, " command: %s\n", g_command);
@ -820,14 +850,16 @@ static void do_dependency(const char *file)
}
#endif
/* We don't really know that the command succeeded... Let's assume that it did */
/* We don't really know that the command succeeded...
* Let's assume that it did
*/
free(alloc);
return;
}
printf("# ERROR: File \"%s\" not found at any location\n", file);
exit(EXIT_FAILURE);
printf("# ERROR: File \"%s\" not found at any location\n", file);
exit(EXIT_FAILURE);
}
/****************************************************************************