Squashed commit of the following:

tools/configure.c: Add missing '\n' in printf statement

    tools/configure.c: Add missed -g option to getopt() string

    tools/configure.c and tools/configure.sh:  Fix Windows native pre-build kconfig-conf incompability.  Looks like prebuilt Windows native kconfig-conf interprets "..\apps" as "..apps" (possibly '\a' as escape-sequence) so expand winnative path to double-backslashed variant "..\\apps".

    tools/mkdeps.c:  Fix '\0' missing in MinGW.  Implicit bug. There are 2 cases.

    1. Under Linux.  The code works as planned: '\n' is always replaced with '\0' due to sprintf fills n-1 bytes and reaches buffer length limit.

    2. Under Windows/MinGW. There is memory corruption.  Seems like it`s a bug inside MinGW/snprintf.  Snprintf fills consecutively "oldbase",' ',"str",'\n', but does not inserts trailing '\0' instead of '\n'.  And when next append() occurs, strlen() returns garbage-appended "oldbase".

    So the fix just removes '\n' and reserves space for '\0'.

    tools/link.bat: Fix .fakelink creation

    configs/Makefile and tools/Config.mk:  Move single file copy to the new function COPYFILE.  This fixes the Windows native build case when there is no cp or cp does not recognize Windows paths.
This commit is contained in:
Anatol Ivanov 2018-11-05 16:35:28 -06:00 committed by Gregory Nutt
parent 65c74f5444
commit 1dad62d3b7
6 changed files with 90 additions and 7 deletions

View File

@ -116,7 +116,7 @@ depend: .depend
$(DUMMY_KCONFIG): $(BOARD_KCONFIG)
$(call DELFILE, $(DUMMY_KCONFIG))
$(Q) cp -f $(BOARD_KCONFIG) $(DUMMY_KCONFIG)
$(call COPYFILE, $(BOARD_KCONFIG), $(DUMMY_KCONFIG))
dirlinks: $(DUMMY_KCONFIG)

View File

@ -268,6 +268,18 @@ define MOVEFILE
endef
endif
# COPYFILE - Copy one file
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
define COPYFILE
$(Q) if exist $1 (copy /y /b $1 $2)
endef
else
define COPYFILE
$(Q) cp -f $1 $2
endef
endif
# CATFILE - Cat and append a list of files
#
# USAGE: $(call CATFILE,dest,src1,src2,src3,...)

View File

@ -202,7 +202,7 @@ static void parse_args(int argc, char **argv)
g_debug = false;
while ((ch = getopt(argc, argv, ":a:bcdfhlmnu")) > 0)
while ((ch = getopt(argc, argv, "a:bcdfghlmnu")) > 0)
{
switch (ch)
{
@ -917,6 +917,59 @@ static void substitute(char *str, int ch1, int ch2)
}
}
static char *double_appdir_backslashes(char *old_appdir)
{
char *new_appdir = NULL;
char *p_old = NULL;
char *p_new = NULL;
int oldlen = 0;
int occurrences = 0;
int alloclen = 0;
p_old = old_appdir;
while ((p_old = strchr(p_old, '\\')) != NULL)
{
occurrences++;
p_old++;
}
if (occurrences != 0)
{
oldlen = strlen(old_appdir);
alloclen = oldlen + occurrences + sizeof((char) '\0');
new_appdir = malloc(alloclen);
if (new_appdir != NULL)
{
p_old = old_appdir;
p_new = new_appdir;
while (oldlen)
{
if (*p_old != '\\')
{
*p_new++ = *p_old;
}
else
{
*p_new++ = '\\';
*p_new++ = '\\';
}
++p_old;
--oldlen;
}
*p_new = '\0';
}
}
else
{
new_appdir = strdup(old_appdir);
}
return new_appdir;
}
static void copy_optional(void)
{
int i;
@ -1155,6 +1208,24 @@ static void configure(void)
}
}
/* Looks like prebuilt winnative kconfig-conf interprets "..\apps" as
* "..apps" (possibly '\a' as escape-sequence) so expand winnative path
* to double-backslashed variant "..\\apps".
*/
if (g_winnative)
{
char *tmp_appdir = double_appdir_backslashes(appdir);
if (NULL == tmp_appdir)
{
fprintf(stderr, "ERROR: Failed to double appdir backslashes\n");
exit(EXIT_FAILURE);
}
free(appdir);
appdir = tmp_appdir;
}
/* Open the file for appending */
stream = fopen(destconfig, "a");
@ -1185,7 +1256,7 @@ static void refresh(void)
exit(EXIT_FAILURE);
}
printf(" Refreshing...");
printf(" Refreshing...\n");
fflush(stdout);
#ifdef WIN32

View File

@ -235,7 +235,7 @@ fi
# For checking the apps dir path, we need a POSIX version of the relative path.
posappdir=`echo "${appdir}" | sed -e 's/\\\\/\\//g'`
winappdir=`echo "${appdir}" | sed -e 's/\\//\\\\/g'`
winappdir=`echo "${appdir}" | sed -e 's/\\//\\\\\\\/g'`
# If appsdir was provided (or discovered) then make sure that the apps/
# directory exists

View File

@ -89,7 +89,7 @@ goto :End
)
xcopy %src% %link% /c /q /s /e /y /i
echo FAKELNK > include\apps\.fakelnk
echo FAKELNK > %link%\.fakelnk
goto :End
:ShowUsage

View File

@ -219,7 +219,7 @@ static void append(char **base, char *str)
}
else
{
alloclen = strlen(oldbase) + strlen(str) + 2;
alloclen = strlen(oldbase) + strlen(str) + sizeof((char) ' ') + sizeof((char) '\0');
newbase = (char *)malloc(alloclen);
if (!newbase)
{
@ -227,7 +227,7 @@ static void append(char **base, char *str)
exit(EXIT_FAILURE);
}
snprintf(newbase, alloclen, "%s %s\n", oldbase, str);
snprintf(newbase, alloclen, "%s %s", oldbase, str);
free(oldbase);
}