diff mbox

[MELT] Fix loading of .c files

Message ID 1314613272-5900-1-git-send-email-alissy@mandriva.com
State New
Headers show

Commit Message

Alexandre Lissy Aug. 29, 2011, 10:21 a.m. UTC
Files containing the MELT translated to C code were not loaded correctly
due to bad search path when working with an installed plugin. Present
commit fixes this by:
 - using a melt find to search in current dir
 - ensuring the melt_modulename in melt descriptor only contains the
   module name, and no path component
---
 gcc/ChangeLog.MELT           |    6 ++++++
 gcc/melt-runtime.c           |   24 ++++++++++++++++++++++--
 gcc/melt/warmelt-outobj.melt |    7 ++++++-
 3 files changed, 34 insertions(+), 3 deletions(-)

Comments

Basile Starynkevitch Aug. 29, 2011, 1:15 p.m. UTC | #1
On Mon, Aug 29, 2011 at 12:21:12PM +0200, Alexandre Lissy wrote:
> Files containing the MELT translated to C code were not loaded correctly
> due to bad search path when working with an installed plugin. Present
> commit fixes this by:
>  - using a melt find to search in current dir
>  - ensuring the melt_modulename in melt descriptor only contains the
>    module name, and no path component

Are you sure of that patch?  It seems that it loops on the hello world tiny test I added in the MELT branch rev 178154

Does it work for you when merging with latest MELT updates (ie when applying that patch to rev  178154 of the MELT branch?

(I am investigating)

Cheers.
Alexandre Lissy Aug. 29, 2011, 1:19 p.m. UTC | #2
Le 29/08/2011 15:15, Basile Starynkevitch a écrit :
> On Mon, Aug 29, 2011 at 12:21:12PM +0200, Alexandre Lissy wrote:
>> Files containing the MELT translated to C code were not loaded correctly
>> due to bad search path when working with an installed plugin. Present
>> commit fixes this by:
>>  - using a melt find to search in current dir
>>  - ensuring the melt_modulename in melt descriptor only contains the
>>    module name, and no path component
> 
> Are you sure of that patch?  It seems that it loops on the hello world tiny test I added in the MELT branch rev 178154
At least it works here with MELT as a plugin.

> 
> Does it work for you when merging with latest MELT updates (ie when applying that patch to rev  178154 of the MELT branch?
> 
> (I am investigating)
> 
> Cheers.
>
Alexandre Lissy Aug. 29, 2011, 1:41 p.m. UTC | #3
Le 29/08/2011 15:15, Basile Starynkevitch a écrit :
> On Mon, Aug 29, 2011 at 12:21:12PM +0200, Alexandre Lissy wrote:
>> Files containing the MELT translated to C code were not loaded correctly
>> due to bad search path when working with an installed plugin. Present
>> commit fixes this by:
>>  - using a melt find to search in current dir
>>  - ensuring the melt_modulename in melt descriptor only contains the
>>    module name, and no path component
> 
> Are you sure of that patch?  It seems that it loops on the hello world tiny test I added in the MELT branch rev 178154
> 
> Does it work for you when merging with latest MELT updates (ie when applying that patch to rev  178154 of the MELT branch?
> 
> (I am investigating)
> 
> Cheers.
> 

I did a contrib/gcc_update, cherry-pick'd my patch and for now it builds
well, however I ran into:

***** doing  melt-sayhello
gcc -c @melt-sayhello.args
gcc: erreur: missing argument to ‘-frandom-seed=’
make: *** [melt-tiny-tests] Erreur 1
rm gfmeltgcc_revision gfmeltgcc_version_number
Alexandre Lissy Aug. 29, 2011, 1:52 p.m. UTC | #4
Le 29/08/2011 15:15, Basile Starynkevitch a écrit :
> On Mon, Aug 29, 2011 at 12:21:12PM +0200, Alexandre Lissy wrote:
>> Files containing the MELT translated to C code were not loaded correctly
>> due to bad search path when working with an installed plugin. Present
>> commit fixes this by:
>>  - using a melt find to search in current dir
>>  - ensuring the melt_modulename in melt descriptor only contains the
>>    module name, and no path component
> 
> Are you sure of that patch?  It seems that it loops on the hello world tiny test I added in the MELT branch rev 178154
> 
> Does it work for you when merging with latest MELT updates (ie when applying that patch to rev  178154 of the MELT branch?
> 
> (I am investigating)
> 
> Cheers.
> 

And on a second run, I get:

$ LC_ALL=C gcc -c @melt-sayhello.args
cc1: warning: MELT cannot access module makefile
/usr/lib64/gcc/x86_64-mandriva-linux-gnu/4.6.1/plugin/melt-module.mk :
No such file or directory [enabled by default]
cc1: error: cannot load MELT module list melt-default-modules
cc1: note: MELT source path
/home/alex/BuildSystem/gcc-plugin-melt/BUILD/melt-0.8.99-plugin-for-gcc-4.6/melt-sources
cc1: note: builtin MELT source directory
/usr/lib64/gcc/x86_64-mandriva-linux-gnu/4.6.1/plugin/melt-sources
cc1: error: MELT fatal failure from melt-runtime.c:9050 [MELT built Aug
29 2011]
cc1: error: MELT failed at melt-runtime.c:9050 in directory
/home/alex/BuildSystem/gcc-plugin-melt/BUILD/melt-0.8.99-plugin-for-gcc-4.6

SHORT BACKTRACE[#0] MELT fatal failure;
#1:_ {melt-runtime.c:9020:: meltgc_load_module_list start depth 0
modlistbase melt-default-modules}
#2:_ {melt-runtime.c:9347:: meltgc_load_modules_and_do_mode before
loading curmod @@} .

cc1: error: MELT got fatal failure from melt-runtime.c:9050
cc1: fatal error: MELT failed to load module list
melt-default-modules.modlis
compilation terminated.
Alexandre Lissy Aug. 29, 2011, 2:44 p.m. UTC | #5
Le 29/08/2011 15:15, Basile Starynkevitch a écrit :
> On Mon, Aug 29, 2011 at 12:21:12PM +0200, Alexandre Lissy wrote:
>> Files containing the MELT translated to C code were not loaded correctly
>> due to bad search path when working with an installed plugin. Present
>> commit fixes this by:
>>  - using a melt find to search in current dir
>>  - ensuring the melt_modulename in melt descriptor only contains the
>>    module name, and no path component
> 
> Are you sure of that patch?  It seems that it loops on the hello world tiny test I added in the MELT branch rev 178154
> 
> Does it work for you when merging with latest MELT updates (ie when applying that patch to rev  178154 of the MELT branch?
> 
> (I am investigating)
> 
> Cheers.
> 

Okay, once fixing your Makefile it's okay:

$ LC_ALL=C time -p gcc -c @melt-sayhello.args
cc1: note: MELT is bootstrapping so ignore builtin source directory
/usr/lib64/gcc/x86_64-mandriva-linux-gnu/4.6.1/plugin/melt-sources
cc1: note: MELT is bootstrapping so ignore builtin module directory
/usr/lib64/gcc/x86_64-mandriva-linux-gnu/4.6.1/plugin/melt-modules
cc1: note: MELT generating C code of module melt-sayhello
cc1: note: MELT generated same file melt-sayhello.c in
/home/alex/BuildSystem/gcc-plugin-melt/BUILD/melt-0.8.99-plugin-for-gcc-4.6
cc1: note: MELT generated descriptor file melt-sayhello+meltdesc.c
cc1: note: MELT generated C code of module melt-sayhello with 0
secondary files in 10 CPU millisec.
real 0.06
user 0.02
sys 0.02

The bug was: -fplugin-arg-melt-arg=melt-modules. I suspect it's this
line in melt-build.tpl:
$(meltarg_arg)=$<  -frandom-seed=$(shell md5sum melt-sayhello.melt | cut
-b-24) \

The '$<' part ... But I have no idea of your intentions.
Alexandre Lissy Aug. 29, 2011, 2:57 p.m. UTC | #6
Le 29/08/2011 16:44, Alexandre Lissy a écrit :
> Le 29/08/2011 15:15, Basile Starynkevitch a écrit :
>> On Mon, Aug 29, 2011 at 12:21:12PM +0200, Alexandre Lissy wrote:
>>> Files containing the MELT translated to C code were not loaded correctly
>>> due to bad search path when working with an installed plugin. Present
>>> commit fixes this by:
>>>  - using a melt find to search in current dir
>>>  - ensuring the melt_modulename in melt descriptor only contains the
>>>    module name, and no path component
>>
>> Are you sure of that patch?  It seems that it loops on the hello world tiny test I added in the MELT branch rev 178154
>>
>> Does it work for you when merging with latest MELT updates (ie when applying that patch to rev  178154 of the MELT branch?
>>
>> (I am investigating)
>>
>> Cheers.
>>
> 
> Okay, once fixing your Makefile it's okay:
> 
> $ LC_ALL=C time -p gcc -c @melt-sayhello.args
> cc1: note: MELT is bootstrapping so ignore builtin source directory
> /usr/lib64/gcc/x86_64-mandriva-linux-gnu/4.6.1/plugin/melt-sources
> cc1: note: MELT is bootstrapping so ignore builtin module directory
> /usr/lib64/gcc/x86_64-mandriva-linux-gnu/4.6.1/plugin/melt-modules
> cc1: note: MELT generating C code of module melt-sayhello
> cc1: note: MELT generated same file melt-sayhello.c in
> /home/alex/BuildSystem/gcc-plugin-melt/BUILD/melt-0.8.99-plugin-for-gcc-4.6
> cc1: note: MELT generated descriptor file melt-sayhello+meltdesc.c
> cc1: note: MELT generated C code of module melt-sayhello with 0
> secondary files in 10 CPU millisec.
> real 0.06
> user 0.02
> sys 0.02
> 
> The bug was: -fplugin-arg-melt-arg=melt-modules. I suspect it's this
> line in melt-build.tpl:
> $(meltarg_arg)=$<  -frandom-seed=$(shell md5sum melt-sayhello.melt | cut
> -b-24) \
> 
> The '$<' part ... But I have no idea of your intentions.
> 

I suspect '$<' should be replaced by 'melt-sayhello.melt' to get
-fplugin-arg-melt-arg=melt-sayhello.melt

At least, it goes well doing this ...
diff mbox

Patch

diff --git a/gcc/ChangeLog.MELT b/gcc/ChangeLog.MELT
index cfdac12..241c862 100644
--- a/gcc/ChangeLog.MELT
+++ b/gcc/ChangeLog.MELT
@@ -1,3 +1,9 @@ 
+2011-08-29  Alexandre Lissy  <alissy@mandriva.com>
+	* melt-runtime.c (melt_load_module_index): Fix loading path of .c
+	files.
+	* melt/warmelt-outobj.melt (output_melt_descriptor): Fix generation
+	of melt_modulename (taking basename).
+
 2011-08-27  Pierre Vittet  <piervit@pvittet.com>
 
 	* melt-build.tpl (warmelt-upgrade-translator): replace move-if-change
diff --git a/gcc/melt-runtime.c b/gcc/melt-runtime.c
index dd11a6e..cf8e0cc 100644
--- a/gcc/melt-runtime.c
+++ b/gcc/melt-runtime.c
@@ -8683,6 +8683,8 @@  melt_load_module_index (const char*srcbase, const char*flavor)
     {
       FILE *sfil = 0;
       char *curpath = 0;
+      char *srcpath = 0;
+      const char* srcpathstr = melt_argument ("source-path");
       int nbsecfile = 0;
       int cursecix = 0;
       time_t gentim = 0;
@@ -8701,7 +8703,15 @@  melt_load_module_index (const char*srcbase, const char*flavor)
 		 melt_run_preprocessed_md5);
       nbsecfile = *(MELTDESCR_REQUIRED(melt_lastsecfileindex));
       debugeprintf ("melt_load_module_index descmodulename %s nbsecfile %d", descmodulename, nbsecfile);
-      curpath = concat (descmodulename, ".c", NULL);
+      srcpath = concat (descmodulename, ".c", NULL);
+      curpath = 
+          MELT_FIND_FILE (srcpath,
+		    MELT_FILE_IN_DIRECTORY, ".",
+		    MELT_FILE_IN_PATH, srcpathstr,
+		    MELT_FILE_IN_PATH, getenv ("GCCMELT_SOURCE_PATH"),
+		    MELT_FILE_IN_DIRECTORY, melt_source_dir,
+		    NULL);
+      debugeprintf ("melt_load_module_index srcpath %s ", srcpath);
       sfil = fopen (curpath, "r");
       if (!sfil) 
 	warning (0,
@@ -8714,6 +8724,7 @@  melt_load_module_index (const char*srcbase, const char*flavor)
 		     curpath, MELTDESCR_REQUIRED (melt_primaryhexmd5));
 	  fclose (sfil), sfil = NULL;
 	};
+      free (srcpath), srcpath = NULL;
       free (curpath), curpath = NULL;
       for (cursecix = 1; cursecix < nbsecfile; cursecix++) 
 	{
@@ -8722,7 +8733,15 @@  melt_load_module_index (const char*srcbase, const char*flavor)
 	    continue;
 	  memset (suffixbuf, 0, sizeof(suffixbuf));
 	  snprintf (suffixbuf, sizeof(suffixbuf)-1, "+%02d.c", cursecix);
-	  curpath = concat (descmodulename, suffixbuf, NULL);
+	  srcpath = concat (descmodulename, suffixbuf, NULL);
+          curpath = 
+              MELT_FIND_FILE (srcpath,
+		    MELT_FILE_IN_DIRECTORY, ".",
+		    MELT_FILE_IN_PATH, srcpathstr,
+		    MELT_FILE_IN_PATH, getenv ("GCCMELT_SOURCE_PATH"),
+		    MELT_FILE_IN_DIRECTORY, melt_source_dir,
+		    NULL);
+          debugeprintf ("melt_load_module_index srcpath %s ", srcpath);
 	  sfil = fopen (curpath, "r");
 	  if (!sfil) 
 	    warning (0,
@@ -8737,6 +8756,7 @@  melt_load_module_index (const char*srcbase, const char*flavor)
 			 curpath, MELTDESCR_REQUIRED(melt_secondaryhexmd5tab)[cursecix]);
 	      fclose (sfil), sfil = NULL;
 	    };
+          free (srcpath), srcpath = NULL;
 	  free (curpath), curpath = NULL;
 	};
       if (MELTDESCR_OPTIONAL(melt_genversionstr)
diff --git a/gcc/melt/warmelt-outobj.melt b/gcc/melt/warmelt-outobj.melt
index 0a63efb..a8b9650 100644
--- a/gcc/melt/warmelt-outobj.melt
+++ b/gcc/melt/warmelt-outobj.melt
@@ -3791,7 +3791,12 @@ 
     (add2sbuf_strconst debuf " */")
     (add2sbuf_indentnl debuf 0)
     (add2sbuf_strconst debuf "const char melt_modulename[]=\"")
-    (add2sbuf_cencstring  debuf modnamstr)
+    (code_chunk
+     genmodnamstr
+     #{ /* output_melt_descriptor $GENMODNAMSTR + */
+     meltgc_add_strbuf_cstr ($DEBUF, lbasename (melt_string_str($MODNAMSTR)));
+     }#
+    )
     (add2sbuf_strconst debuf "\";")
     (add2sbuf_indentnl debuf 0)
     (add2sbuf_strconst debuf "const char melt_modulerealpath[]=\"")