Re: 3 aap suggestions

Pavol Juhas <[email protected]> Mon, 28 Nov 2005 18:19:56 -0500
Newsgroups gmane.comp.tools.aap.devel
Message-ID <[email protected]>
--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Mon, Nov 28, 2005 at 09:53:45PM +0100, Bram Moolenaar wrote:
> 
> Pavol Juhas wrote:
> 
> > ...
> > > > > > (1) aap is not using correct linker when linking c++ objects.
> > ...
> > > > > > Can this be fixed so that aap uses g++ as a linker when linking
> > > > > > c++ objects?
> 
> [...]
> 
> > A simpler way of telling aap to use g++ to link from hello.o is 
> > to add "LD=$CXXSHLINK" to main.app.
> 
> Yes, but then all programs will use that linker.  It would be nice if
> you can build both C and C++ programs automatically.

For sure it would.  Well, I found another mystery - for main.aap with
    LD=$CXX
    :program hello : hello.cpp
the object-build works (aap; rm hello; aap), but if I add :usetool gcc
to the begining, object-build stops working (clean build works).
That happens with both the original and patched usetool.  

...
> > Well, it's a slight distinction - the original :toolsearch requires
> > that a tool is defined and checks if it is installed, while the 
> > patched one checks if it is defined and installed.  If user made 
> > a typo, he is asking to search for non-existing tool, so it won't be 
> > found - user just gets what he asked for.  Perhaps there could be 
> > a :toolsearch option (allow_undefined_tools=yes or strict=no) for 
> > this behavior?
> 
> Hmm, another choice for the user.  It's not really difficult to copy the
> tool to another system, is it?
> 
> Consider the average use of a recipe: You copy it to another system with
> the files that are used and run it.  The user should be warned if
> something is missing for the recipe to be executed properly.  Note that
> the compiler searched for may be present, but when the Aap tool is
> missing it won't be found.  That may result in an obscure problem in a
> larger application, that the wrong compiler is used might go unnoticed.

Ok, point taken.

> > In any case, I suggest to use the import code from my patch, 
> > otherwise there would be the same problem as with :usetool - the 
> > default tools will not be available as soon as user defines any 
> > custom tool in ~/.aap/tools.
> 
> OK.  Can you make a patch for that?
yep, it is attached.

> > Is there any other place where aap imports from tools?  I guess the 
> > same fixes would apply there as well.
> 
> Ehm, I don't know.  It has been a while since I wrote this...

I only found import from tools in tools/dmd.py, so it probably 
does not work when custom tools are defined.  dmd.py is doing many 
other things like writing to some files - I have no time now to 
figure out how to fix it and I don't use it anyway.

Pavol

--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="usetoolsearch.patch2"

Index: Commands.py
===================================================================
RCS file: /cvsroot/a-a-p/Exec/Commands.py,v
retrieving revision 1.129
diff -u -r1.129 Commands.py
--- Commands.py	12 Aug 2005 10:30:17 -0000	1.129
+++ Commands.py	28 Nov 2005 22:17:14 -0000
@@ -21,6 +21,7 @@
 import string
 import copy
 import glob
+import imp
 
 from Depend import Depend
 from Dictlist import str2dictlist, get_attrdict, list2str, dictlist2str
@@ -2602,21 +2603,19 @@
     if optiondict:
         option_error(rpstack, optiondict, ":toolsearch")
 
-    sys_path_save = sys.path
-    try:
-        # Only import "tools.name" from specific directories.
-        sys.path = get_import_dirs(recdict)
-        didone = 0
-        for a in args:
-            c = a["name"]
-            exec "import tools.%s" % c
-            if eval("tools.%s.exists()" % c):
-                exec "tools.%s.define_actions()" % c
-                if not didone:
-                    didone = 1
-                    exec "tools.%s.use_actions(recdict['_top'])" % c
-    finally:
-        sys.path = sys_path_save
+    # only import "name" from tools directories
+    tools_path = [ os.path.join(d, "tools") 
+                   for d in get_import_dirs(recdict) ]
+    didone = 0
+    for a in args:
+        c = a["name"]
+        fpd = imp.find_module(c, tools_path)
+        exec "tools_%s = imp.load_module(c, *fpd)" % c
+        if eval("tools_%s.exists()" % c):
+            exec "tools_%s.define_actions()" % c
+            if not didone:
+                didone = 1
+                exec "tools_%s.use_actions(recdict['_top'])" % c
 
 
 def maydo_recipe_cmd(rpstack):
@@ -3050,20 +3049,18 @@
         recipe_error(rpstack, _(':usetool requires one argument'))
 
     toolname = args[0]["name"]
-    sys_path_save = sys.path
     try:
-        try:
-            # Only import "tools.name" from specific directories.
-            sys.path = get_import_dirs(recdict)
-            exec "import tools.%s" % toolname
-        finally:
-            sys.path = sys_path_save
+        # Only import "tools_name" module from specific directories.
+        tools_path = [ os.path.join(d, "tools") 
+                       for d in get_import_dirs(recdict) ]
+        fpd = imp.find_module(toolname, tools_path)
+        exec "tools_%s = imp.load_module(toolname, *fpd)" % toolname
     except:
         recipe_error(rpstack, _('Tool "%s" is not supported') % toolname)
 
-    if eval("tools.%s.exists()" % toolname):
-        exec "tools.%s.define_actions()" % toolname
-        exec "tools.%s.use_actions(recdict)" % toolname
+    if eval("tools_%s.exists()" % toolname):
+        exec "tools_%s.define_actions()" % toolname
+        exec "tools_%s.use_actions(recdict)" % toolname
     else:
         recipe_error(rpstack, _('Tool "%s" cannot be found on the system')
                                                                     % toolname)

--jRHKVT23PllUwdXP--


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click