initial stab at :import

Adriaan de Groot <adridg-FlD2LfDziEhmR6Xm/[email protected]>
Newsgroups gmane.comp.tools.aap.devel
Message-ID <[email protected]>
Find attached an initial attempt at implementing :import. I basically copied 
the code from :include and :child. It doesn't _really_ work .. since using 
variables declared in the :imported recipe within the recipe causes scope 
errors later. I need to figure that out - possibly by keeping the pristine 
scope somewhere and looking up variables coming from actions in that scope 
within the scope.

Anyway, does this look vaguely like it's going in the right direction?

-- 
pub  1024D/FEA2A3FE 2002-06-18 Adriaan de Groot <[email protected]>
     Key fingerprint = 934E 31AA 80A7 723F 54F9  50ED 76AC EE01 FEA2 A3FE
aap-import.diff (text/x-diff, 2.8 KB)
Index: Commands.py
===================================================================
RCS file: /cvsroot/a-a-p/Exec/Commands.py,v
retrieving revision 1.100
diff -u -3 -p -b -r1.100 Commands.py
--- Commands.py	8 Sep 2003 19:29:50 -0000	1.100
+++ Commands.py	9 Sep 2003 21:29:03 -0000
@@ -2236,6 +2236,45 @@ def aap_include(line_nr, recdict, arg):
 
     read_recipe(rpstack, recdict, recname, Global.at_toplevel,
                                             optional = optiondict.get("quiet"))
+
+def aap_import(line_nr, recdict, arg):
+    """Handle :import commands. Also used automagically for :produce
+    targets, which specify a new language."""
+
+    from Scope import create_topscope
+
+    work = getwork(recdict)
+    rpstack = getrpstack(recdict, line_nr)
+
+    # Evaluate the options and arguments
+    optiondict, attrdict, args = get_args(line_nr, recdict, arg,
+            { } )
+    if attrdict:
+        option_error(rpstack, attrdict, ":import")
+    if optiondict:
+        option_error(rpstack, optiondict, ":import")
+
+    if len(args) != 1:
+        recipe_error(rpstack, _(":import requires one argument"))
+    args = dictlist_expand(args)
+
+    recname = args[0]["name"]
+    if did_read_recipe(work, recname):
+        msg_extra(recdict, _('Skipping recipe already imported: %s"') % recname)
+        return
+
+    # Calculate absolute path to imported file
+    if Global.aap_rootdir[-1] != "/" and recname[0] != "/":
+        recname = Global.aap_rootdir + "/" + recname
+    else:
+        recname = Global.aap_rootdir + recname
+    if recname[-4:] != ".aap":
+        recname += ".aap"
+
+    tsd = create_topscope(args[0]["name"]).data
+    setwork(tsd,work)
+    read_recipe(rpstack,tsd,recname,2,0,0)
+
 
 
 def maydo_recipe_cmd(rpstack):
Index: Process.py
===================================================================
RCS file: /cvsroot/a-a-p/Exec/Process.py,v
retrieving revision 1.60
diff -u -3 -p -b -r1.60 Process.py
--- Process.py	1 Sep 2003 17:59:12 -0000	1.60
+++ Process.py	9 Sep 2003 21:29:04 -0000
@@ -29,6 +29,7 @@ aap_cmd_toplevel = [
                 "rule",
                 "totype",
                 "variant",
+                "import",
                 ]
 
 # All possible names of ":" commands in a recipe, including toplevel-only ones.
@@ -850,6 +851,10 @@ def Process(fp, recdict, toplevel):
             # command.  The handling of the arguments may depend on the
             # command.
             #
+            # All AAP commands (including :include, :import, etc.) arrive
+            # here for processing and are turned into Python calls
+            # for functions in Commands.py.
+            #
             # recipe:   :cmd arg ...
             # Python:   aap_cmd(123, globals(),
             script.append(indent_string + ('aap_%s(%d, globals(), '
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.