[ccache] [PATCH] Hash also Clang plugins

2012-07-30 Thread Lubos Lunak

 Hello,

 please review and push the attached patch, which adds Clang plugins to the 
hash, similarly as is already done with GCC plugins.

-- 
 Lubos Lunak
 l.lu...@suse.cz
From 11b35610cf97b1540dc883b03e7ce059735bd04c Mon Sep 17 00:00:00 2001
From: Lubos Lunak l.lu...@suse.cz
Date: Thu, 26 Jul 2012 14:45:16 +0200
Subject: [PATCH] hash also Clang plugins

---
 ccache.c |   10 ++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/ccache.c b/ccache.c
index 8e36bdd..e5c2481 100644
--- a/ccache.c
+++ b/ccache.c
@@ -1061,6 +1061,16 @@ calculate_object_hash(struct args *args, struct mdfour *hash, int direct_mode)
 			continue;
 		}
 
+		if (str_eq(args-argv[i], -Xclang)
+		 i + 3  args-argc
+		 str_eq(args-argv[i+1], -load)
+		 str_eq(args-argv[i+2], -Xclang)
+		 stat(args-argv[i+3], st) == 0) {
+			hash_delimiter(hash, plugin);
+			hash_compiler(hash, st, args-argv[i+3], false);
+			continue;
+		}
+
 		/* All other arguments are included in the hash. */
 		hash_delimiter(hash, arg);
 		hash_string(hash, args-argv[i]);
-- 
1.7.7

___
ccache mailing list
ccache@lists.samba.org
https://lists.samba.org/mailman/listinfo/ccache


Re: [ccache] [PATCH] Hash also Clang plugins

2012-07-30 Thread Joel Rosdahl
On 30 July 2012 19:03, Lubos Lunak l.lu...@suse.cz wrote:
 please review and push the attached patch, which adds Clang plugins to the
 hash, similarly as is already done with GCC plugins.

Thanks, applied.

-- Joel
___
ccache mailing list
ccache@lists.samba.org
https://lists.samba.org/mailman/listinfo/ccache


Re: [ccache] [PATCH] add support for '@' parameters

2012-07-30 Thread Boie, Andrew P
 -Original Message-
 From: joel.rosd...@gmail.com [mailto:joel.rosd...@gmail.com] On Behalf Of
 Joel Rosdahl
  +   file_args = args_init_from_string(argdata);
 
 Isn't args_init_from_string too simplistic for parsing the contents?

Oof, yeah you're right. It seems that args_init_from_string needs to be 
significantly beefed-up. I don't suppose you know of some library code 
somewhere that does this? I should dig into the bash sources, IIRC it's the 
shell that turns the string into argv array...

 It would be nice if this code could be extracted to a new
 args_insert(struct args *args, struct args *to_insert, int pos)
 function or so. (There's a test suite for args_* in test/test_args.c.)

Done. I'll add a test case as well.

-Andrew
___
ccache mailing list
ccache@lists.samba.org
https://lists.samba.org/mailman/listinfo/ccache


[ccache] [PATCH v2] add support for '@' parameters

2012-07-30 Thread Andrew Boie
From: Boie, Andrew P andrew.p.b...@intel.com

These indicate to the compiler that additional command line options
should be read from a text file. If encountered, read the file,
tokenize any arguments, and if any are found, do an in-place replacement
of the '@' parameter with the arguments within the file.

args_insert() added to insert a set of arguments into a position within
another set of arguments.

args_init_from_string() has been improved so that any character may be
included by prefixing that character with a backslash, and support for
quoted arguments which pass special characters within the quotation marks
unmodified.

Signed-off-by: Andrew Boie andrew.p.b...@intel.com
---
 args.c   |  108 +-
 ccache.c |   25 -
 ccache.h |1 +
 test/test_args.c |   47 +---
 4 files changed, 166 insertions(+), 15 deletions(-)

diff --git a/args.c b/args.c
index 13a3d37..ee84951 100644
--- a/args.c
+++ b/args.c
@@ -37,17 +37,57 @@ struct args *
 args_init_from_string(const char *command)
 {
struct args *args;
-   char *p = x_strdup(command);
-   char *q = p;
-   char *word, *saveptr = NULL;
-
+   const char *pos = command;
+   char *argbuf = x_malloc(strlen(command) + 1);
+   char *argpos = argbuf;
args = args_init(0, NULL);
-   while ((word = strtok_r(q,  \t\r\n, saveptr))) {
-   args_add(args, word);
-   q = NULL;
-   }
+   argpos = argbuf;
+   char quoting = '\0';
+
+   while (1) {
+   switch (*pos) {
+   case '\\':
+   pos++;
+   if (*pos == '\0')
+   continue;
+   break;
 
-   free(p);
+   case '\': case '\'':
+   if (quoting != '\0') {
+   if (quoting == *pos) {
+   quoting = '\0';
+   pos++;
+   continue;
+   } else
+   break;
+   } else {
+   quoting = *pos;
+   pos++;
+   continue;
+   }
+   case '\n': case '\t': case ' ':
+   if (quoting)
+   break;
+   /* Fall through */
+   case '\0':
+   /* end of token */
+   *argpos = '\0';
+   if (argbuf[0] != '\0')
+   args_add(args, argbuf);
+   argpos = argbuf;
+   if (*pos == '\0')
+   goto out;
+   else {
+   pos++;
+   continue;
+   }
+   }
+   *argpos = *pos;
+   pos++;
+   argpos++;
+   }
+out:
+   free(argbuf);
return args;
 }
 
@@ -57,6 +97,56 @@ args_copy(struct args *args)
return args_init(args-argc, args-argv);
 }
 
+/* Insert all arguments in src into dest at position index.
+ * If replace is true, the element at dest-argv[index] is replaced
+ * with the contents of src and everything past it is shifted.
+ * Otherwise, dest-argv[index] is also shifted.
+ *
+ * This operation modifies dest but leaves src untouched. */
+void
+args_insert(struct args *dest, int index, struct args *src, bool replace)
+{
+   int offset;
+   int j;
+
+   /* Adjustments made if we are replacing or shifting the element
+* currently at dest-argv[index] */
+   offset = replace ? 1 : 0;
+
+   if (replace)
+   free(dest-argv[index]);
+
+   if (src-argc == 0) {
+   if (replace) {
+   /* Have to shift everything down by 1 since
+* we replaced with an empty list */
+   for (j = index; j  dest-argc; j++)
+   dest-argv[j] = dest-argv[j + 1];
+   }
+   return;
+   }
+
+   if (src-argc == 1  replace) {
+   /* Trivial case; replace with 1 element */
+   dest-argv[index] = x_strdup(src-argv[0]);
+   return;
+   }
+
+   dest-argv = (char**)x_realloc(dest-argv,
+   (src-argc + dest-argc + 1 - offset) *
+   sizeof(char *));
+
+   /* Shift arguments over */
+   for (j = dest-argc; j = index + offset; j--)
+   dest-argv[j + src-argc - offset] = dest-argv[j];
+
+   /* Copy the new arguments into place */
+   for (j = 0; j  src-argc; j++)
+   dest-argv[j + index] = x_strdup(src-argv[j]);
+
+   dest-argc += src-argc - offset;
+}
+
 

Re: [ccache] [PATCH v3] add support for '@' parameters

2012-07-30 Thread Boie, Andrew P


 -Original Message-
 From: Jürgen Buchmüller [mailto:pullm...@t-online.de]
 Sent: Monday, July 30, 2012 4:46 PM
 To: Boie, Andrew P
 Cc: ccache@lists.samba.org
 Subject: Re: [ccache] [PATCH v3] add support for '@' parameters
 
 Am Montag, den 30.07.2012, 16:05 -0700 schrieb Andrew Boie:
 [..snip..]
  +   /* Trivial case; replace with 1 element */
  +   dest-argv[index] = x_strdup(src-argv[0]);
 [..snap..]
 
 Shouldn't dest-argv[index] be free()d before overwriting it?

This was already freed, look 7 lines up.

  +   /* Copy the new arguments into place */
  +   for (j = 0; j  src-argc; j++)
  +   dest-argv[j + index] = x_strdup(src-argv[j]);
 
 Shouldn't src-argv[j] be free()d after it is strdup()ed?
 Or alternatively: why not copy src-argv[j] an re-use it?

src array isn't touched by this function the way it is currently implemented; 
this is stated in the function comments.  I could change this to have the 
function consume src if desired; I'm not sure what other cases Joel had in mind 
for this function when he asked me to move it to common code.

Andrew

___
ccache mailing list
ccache@lists.samba.org
https://lists.samba.org/mailman/listinfo/ccache


Re: [ccache] [PATCH v3] add support for '@' parameters

2012-07-30 Thread Jürgen Buchmüller
Am Montag, den 30.07.2012, 16:05 -0700 schrieb Andrew Boie:
[..snip..]
 + /* Trivial case; replace with 1 element */
 + dest-argv[index] = x_strdup(src-argv[0]);
[..snap..]

Shouldn't dest-argv[index] be free()d before overwriting it?

 + /* Copy the new arguments into place */
 + for (j = 0; j  src-argc; j++)
 + dest-argv[j + index] = x_strdup(src-argv[j]);

Shouldn't src-argv[j] be free()d after it is strdup()ed?
Or alternatively: why not copy src-argv[j] an re-use it?

The code patch doesn't seem to be too clean.. just my 'feeling' :-P
Excuse me, if I overlooked something essential.

Juergen




___
ccache mailing list
ccache@lists.samba.org
https://lists.samba.org/mailman/listinfo/ccache


[ccache] [PATCH v4] add support for '@' parameters

2012-07-30 Thread Andrew Boie
From: Boie, Andrew P andrew.p.b...@intel.com

These indicate to the compiler that additional command line options
should be read from a text file. If encountered, read the file,
tokenize any arguments, and if any are found, do an in-place replacement
of the '@' parameter with the arguments within the file.

args_insert() added to insert a set of arguments into a position within
another set of arguments.

args_init_from_string() has been improved so that any character may be
included by prefixing that character with a backslash, and support for
quoted arguments which pass special characters within the quotation marks
unmodified.

Signed-off-by: Andrew Boie andrew.p.b...@intel.com
---
 args.c   |  115 +-
 ccache.c |   24 +++-
 ccache.h |1 +
 test/test_args.c |   53 ++---
 4 files changed, 178 insertions(+), 15 deletions(-)

diff --git a/args.c b/args.c
index 13a3d37..aa0e5ac 100644
--- a/args.c
+++ b/args.c
@@ -37,17 +37,57 @@ struct args *
 args_init_from_string(const char *command)
 {
struct args *args;
-   char *p = x_strdup(command);
-   char *q = p;
-   char *word, *saveptr = NULL;
-
+   const char *pos = command;
+   char *argbuf = x_malloc(strlen(command) + 1);
+   char *argpos = argbuf;
args = args_init(0, NULL);
-   while ((word = strtok_r(q,  \t\r\n, saveptr))) {
-   args_add(args, word);
-   q = NULL;
-   }
+   argpos = argbuf;
+   char quoting = '\0';
+
+   while (1) {
+   switch (*pos) {
+   case '\\':
+   pos++;
+   if (*pos == '\0')
+   continue;
+   break;
 
-   free(p);
+   case '\': case '\'':
+   if (quoting != '\0') {
+   if (quoting == *pos) {
+   quoting = '\0';
+   pos++;
+   continue;
+   } else
+   break;
+   } else {
+   quoting = *pos;
+   pos++;
+   continue;
+   }
+   case '\n': case '\t': case ' ':
+   if (quoting)
+   break;
+   /* Fall through */
+   case '\0':
+   /* end of token */
+   *argpos = '\0';
+   if (argbuf[0] != '\0')
+   args_add(args, argbuf);
+   argpos = argbuf;
+   if (*pos == '\0')
+   goto out;
+   else {
+   pos++;
+   continue;
+   }
+   }
+   *argpos = *pos;
+   pos++;
+   argpos++;
+   }
+out:
+   free(argbuf);
return args;
 }
 
@@ -57,6 +97,63 @@ args_copy(struct args *args)
return args_init(args-argc, args-argv);
 }
 
+/* Insert all arguments in src into dest at position index.
+ * If replace is true, the element at dest-argv[index] is replaced
+ * with the contents of src and everything past it is shifted.
+ * Otherwise, dest-argv[index] is also shifted.
+ *
+ * src is consumed by this operation and should not be freed or used
+ * again by the caller */
+void
+args_insert(struct args *dest, int index, struct args *src, bool replace)
+{
+   int offset;
+   int j;
+
+   /* Adjustments made if we are replacing or shifting the element
+* currently at dest-argv[index] */
+   offset = replace ? 1 : 0;
+
+   if (replace)
+   free(dest-argv[index]);
+
+   if (src-argc == 0) {
+   if (replace) {
+   /* Have to shift everything down by 1 since
+* we replaced with an empty list */
+   for (j = index; j  dest-argc; j++)
+   dest-argv[j] = dest-argv[j + 1];
+   dest-argc--;
+   }
+   args_free(src);
+   return;
+   }
+
+   if (src-argc == 1  replace) {
+   /* Trivial case; replace with 1 element */
+   dest-argv[index] = src-argv[0];
+   src-argc = 0;
+   args_free(src);
+   return;
+   }
+
+   dest-argv = (char**)x_realloc(dest-argv,
+   (src-argc + dest-argc + 1 - offset) *
+   sizeof(char *));
+
+   /* Shift arguments over */
+   for (j = dest-argc; j = index + offset; j--)
+   dest-argv[j + src-argc - offset] = dest-argv[j];
+
+   /* Copy the new arguments into 

Re: [ccache] [PATCH v4] add support for '@' parameters

2012-07-30 Thread Boie, Andrew P
Changes from patch set 3:

- args_insert() now consumes the arguments to be inserted, the caller doesn't 
need to subsequently free it. Avoids some strdups
- test cases and args_insert use in ccache.c updated to reflect new semantics

Andrew

 -Original Message-
 From: Boie, Andrew P
 Sent: Monday, July 30, 2012 5:51 PM
 To: ccache@lists.samba.org
 Cc: Boie, Andrew P
 Subject: [PATCH v4] add support for '@' parameters
 
 From: Boie, Andrew P andrew.p.b...@intel.com
 
 These indicate to the compiler that additional command line options
 should be read from a text file. If encountered, read the file,
 tokenize any arguments, and if any are found, do an in-place replacement
 of the '@' parameter with the arguments within the file.
 
 args_insert() added to insert a set of arguments into a position within
 another set of arguments.
 
 args_init_from_string() has been improved so that any character may be
 included by prefixing that character with a backslash, and support for
 quoted arguments which pass special characters within the quotation marks
 unmodified.
 
 Signed-off-by: Andrew Boie andrew.p.b...@intel.com
 ---
  args.c   |  115
 +-
  ccache.c |   24 +++-
  ccache.h |1 +
  test/test_args.c |   53 ++---
  4 files changed, 178 insertions(+), 15 deletions(-)
 
 diff --git a/args.c b/args.c
 index 13a3d37..aa0e5ac 100644
 --- a/args.c
 +++ b/args.c
 @@ -37,17 +37,57 @@ struct args *
  args_init_from_string(const char *command)
  {
   struct args *args;
 - char *p = x_strdup(command);
 - char *q = p;
 - char *word, *saveptr = NULL;
 -
 + const char *pos = command;
 + char *argbuf = x_malloc(strlen(command) + 1);
 + char *argpos = argbuf;
   args = args_init(0, NULL);
 - while ((word = strtok_r(q,  \t\r\n, saveptr))) {
 - args_add(args, word);
 - q = NULL;
 - }
 + argpos = argbuf;
 + char quoting = '\0';
 +
 + while (1) {
 + switch (*pos) {
 + case '\\':
 + pos++;
 + if (*pos == '\0')
 + continue;
 + break;
 
 - free(p);
 + case '\': case '\'':
 + if (quoting != '\0') {
 + if (quoting == *pos) {
 + quoting = '\0';
 + pos++;
 + continue;
 + } else
 + break;
 + } else {
 + quoting = *pos;
 + pos++;
 + continue;
 + }
 + case '\n': case '\t': case ' ':
 + if (quoting)
 + break;
 + /* Fall through */
 + case '\0':
 + /* end of token */
 + *argpos = '\0';
 + if (argbuf[0] != '\0')
 + args_add(args, argbuf);
 + argpos = argbuf;
 + if (*pos == '\0')
 + goto out;
 + else {
 + pos++;
 + continue;
 + }
 + }
 + *argpos = *pos;
 + pos++;
 + argpos++;
 + }
 +out:
 + free(argbuf);
   return args;
  }
 
 @@ -57,6 +97,63 @@ args_copy(struct args *args)
   return args_init(args-argc, args-argv);
  }
 
 +/* Insert all arguments in src into dest at position index.
 + * If replace is true, the element at dest-argv[index] is replaced
 + * with the contents of src and everything past it is shifted.
 + * Otherwise, dest-argv[index] is also shifted.
 + *
 + * src is consumed by this operation and should not be freed or used
 + * again by the caller */
 +void
 +args_insert(struct args *dest, int index, struct args *src, bool replace)
 +{
 + int offset;
 + int j;
 +
 + /* Adjustments made if we are replacing or shifting the element
 +  * currently at dest-argv[index] */
 + offset = replace ? 1 : 0;
 +
 + if (replace)
 + free(dest-argv[index]);
 +
 + if (src-argc == 0) {
 + if (replace) {
 + /* Have to shift everything down by 1 since
 +  * we replaced with an empty list */
 + for (j = index; j  dest-argc; j++)
 + dest-argv[j] = dest-argv[j + 1];
 + dest-argc--;
 + }
 + args_free(src);
 + return;
 + }
 +
 + if (src-argc == 1  replace) {
 + /* Trivial case; replace with 1 element */
 + dest-argv[index] = src-argv[0];
 + src-argc = 0;
 +