Kaydet (Commit) c2b467b8 authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen

fix concat-deps

* make concat-deps use absolute paths whereever possible
* collapse /../ _after_ making the path absolute otherwise it will break for
  relative paths starting with ../
* substitude SRCDIR variable, so trees can be moved
* this fixes subsequentcheck as it does run gbuild from a different work
  directory in a few non-tail_build modules, which are then complaining about
  missing/unresolvable deps
* this should fix troubles from module rebuild as relative paths were different
  between tail_build and the module dir

Change-Id: I5a25e1f55bdc2b475df2af04b711fd808d95cdaf
üst e1544be5
......@@ -109,6 +109,12 @@
#define FALSE 0
#endif
static char* base_dir_var = "$(SRCDIR)";
#define kBASE_DIR_VAR_LENGTH 9
static char* current_dir;
static size_t current_dir_length;
static char* base_dir;
static size_t base_dir_length;
#ifdef __GNUC__
#define clz __builtin_clz
......@@ -684,21 +690,65 @@ int fd;
return buffer;
}
static void _cancel_relative(char* base, char** ref_cursor, char** ref_cursor_out, char* end)
static inline void print_nodotdot(char* path)
{
char* cursor = *ref_cursor;
char* cursor_out = *ref_cursor_out;
char* pathpart;
char* lastnondotdot;
pathpart = path;
lastnondotdot = NULL;
while(pathpart != NULL)
{
if(strncmp(pathpart, "/../", 4) == 0)
{
if(!lastnondotdot)
break; /* this should never happen with abs. paths */
memmove(lastnondotdot, pathpart+4, strlen(pathpart)-3);
lastnondotdot = NULL;
pathpart = path;
}
else
{
lastnondotdot = pathpart+1;
pathpart = strchr(pathpart+1,'/');
}
}
fputs(path, stdout);
}
do
static char* print_fullpaths_buffer = NULL;
static size_t print_fullpaths_buffersize = 0;
/* prefix paths to absolute */
static inline void print_fullpaths(char* line)
{
char* token;
size_t token_length;;
token = strtok(line," ");
while(token != NULL)
{
cursor += 3;
while(cursor_out > base && cursor_out[-1] == '/')
cursor_out--;
while(cursor_out > base && *--cursor_out != '/');
if(*token == ':' || *token == '\\' || *token == '/' || *token == '$')
{
fputs(token, stdout);
}
else
{
token_length=strlen(token);
if(print_fullpaths_buffersize < current_dir_length+token_length+2)
{
/* we really should avoid to get there more than once, so print a message to alert of the condition */
if(print_fullpaths_buffersize)
fprintf(stderr, "resize fullpaths buffer %d -> %d\n", ((int)print_fullpaths_buffersize), ((int)(current_dir_length+token_length))+1024);
print_fullpaths_buffersize = current_dir_length+token_length+1024;
print_fullpaths_buffer = realloc(print_fullpaths_buffer, print_fullpaths_buffersize);
}
memcpy(print_fullpaths_buffer, current_dir, current_dir_length);
*(print_fullpaths_buffer+current_dir_length) = '/';
memcpy(print_fullpaths_buffer+current_dir_length+1, token, token_length+1);
print_nodotdot(print_fullpaths_buffer);
}
fputc(' ', stdout);
token = strtok(NULL," ");
}
while(cursor + 3 < end && !memcmp(cursor, "/../", 4));
*ref_cursor = cursor;
*ref_cursor_out = cursor_out;
}
static int _process(struct hash* dep_hash, char* fn)
......@@ -732,13 +782,6 @@ off_t size;
}
else if(*cursor == '/')
{
if(cursor + 3 < end)
{
if(!memcmp(cursor, "/../", 4))
{
_cancel_relative(base, &cursor, &cursor_out, end);
}
}
*cursor_out++ = *cursor++;
}
else if(*cursor == '\n')
......@@ -757,14 +800,14 @@ off_t size;
*/
if(hash_store(dep_hash, base, (int)(cursor_out - base)))
{
puts(base);
print_fullpaths(base);
putc('\n', stdout);
}
}
else
{
/* rule with dep, just write it */
puts(base);
print_fullpaths(base);
putc('\n', stdout);
}
}
......@@ -825,8 +868,8 @@ off_t in_list_size = 0;
char* in_list;
char* in_list_cursor;
char* in_list_base;
char* buffer;
struct hash* dep_hash;
char* base_dir;
if(argc < 2)
{
......@@ -836,9 +879,29 @@ char* base_dir;
base_dir = getenv("SRCDIR");
if(!base_dir)
{
fputs("Error: SRCDIR si missing in the environement\n", stderr);
fputs("Error: SRCDIR is missing in the environement\n", stderr);
return 1;
}
current_dir = getcwd(NULL, 0);
base_dir_length = strlen(base_dir);
current_dir_length = strlen(current_dir);
if(strncmp(base_dir, current_dir, base_dir_length) == 0)
{
if(current_dir_length == base_dir_length)
{
current_dir = base_dir_var;
}
else
{
buffer = malloc(kBASE_DIR_VAR_LENGTH+current_dir_length-base_dir_length+1);
memcpy(buffer, base_dir_var, kBASE_DIR_VAR_LENGTH);
memcpy(buffer+kBASE_DIR_VAR_LENGTH, current_dir+base_dir_length, current_dir_length-base_dir_length+1);
free(current_dir);
current_dir=buffer;
current_dir_length=kBASE_DIR_VAR_LENGTH+current_dir_length-base_dir_length;
}
}
in_list = file_load(argv[1], &in_list_size, &rc);
if(!rc)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment