Manifest updates.. preparing to actually make use of it.
authorChris Larson <clarson@kergoth.com>
Wed, 31 Mar 2004 18:14:19 +0000 (18:14 +0000)
committerChris Larson <clarson@kergoth.com>
Wed, 31 Mar 2004 18:14:19 +0000 (18:14 +0000)
bin/file_manifest
bin/oe/__init__.py
bin/oe/manifest.py [new file with mode: 0644]
bin/parse_manifest [new file with mode: 0644]
bin/parse_manifest.py [deleted file]

index fe77adb..6b6ee9a 100644 (file)
@@ -34,6 +34,7 @@
 #
 
 #<pkgname>     <from>  <name>          <type>  <mode>  <uid>   <gid>   <major> <minor> <start> <inc>   <count>
+blah   -       ${libdir}       d
 blah   blah-1.2.3/src/.libs/libblah.so.1.2.3   ${libdir}/libblah.so.1.2.3      f       0755    0       0
 blah   libblah.so.1.2.3        ${libdir}/libblah.so.1  s
 blah-dev       libblah.so.1.2.3        ${libdir}/libblah.so    s
index b2263e2..4003f33 100644 (file)
@@ -49,6 +49,7 @@ __all__ = [
        "event",
        "build",
        "fetch",
+       "manifest"
  ]
 
 import sys,os,string,types,re
diff --git a/bin/oe/manifest.py b/bin/oe/manifest.py
new file mode 100644 (file)
index 0000000..00282a9
--- /dev/null
@@ -0,0 +1,119 @@
+#!/usr/bin/env python
+
+import os, sys, string
+import oe, oe.data
+
+def getfields(line):
+       fields = {}
+       fieldmap = ( "pkg", "src", "dest", "type", "mode", "uid", "gid", "major", "minor", "start", "inc", "count" )
+       for f in xrange(len(fieldmap)):
+               fields[fieldmap[f]] = None
+
+       if not line:
+               return None
+
+       splitline = line.split()
+       if not len(splitline):
+               return None
+
+       try:
+               for f in xrange(len(fieldmap)):
+                       if splitline[f] == '-':
+                               continue
+                       fields[fieldmap[f]] = splitline[f]
+       except IndexError:
+               pass
+       return fields
+
+def parse (mfile, d):
+       manifest = []
+       while 1:
+               line = mfile.readline()
+               if not line:
+                       break
+               if line.startswith("#"):
+                       continue
+               fields = getfields(oe.data.expand(line, d))
+               if not fields:
+                       continue
+               manifest.append(fields)
+       return manifest
+
+def emit (func, manifest, d):
+#str = "%s () {\n" % func
+       str = ""
+       for line in manifest:
+               emittedline = emit_line(func, line, d)
+               if not emittedline:
+                       continue
+               str += emittedline + "\n"
+#      str += "}\n"
+       return str
+
+def mangle (func, line):
+       src = line["src"]
+
+       if src:
+               if not os.path.isabs(src):
+                       src = "${WORKDIR}/" + src
+
+       dest = line["dest"]
+       if not dest:
+               return
+
+       if dest.startswith("/"):
+               dest = dest[1:]
+
+       if func is "do_install":
+               dest = "${D}/" + dest
+
+       elif func is "do_populate":
+               dest = "${WORKDIR}/install/" + line["pkg"] + "/" + dest
+
+       elif func is "do_stage":
+               varmap = {}
+               varmap["${bindir}"] = "${STAGING_BINDIR}"
+               varmap["${libdir}"] = "${STAGING_LIBDIR}"
+               varmap["${includedir}"] = "${STAGING_INCDIR}"
+               varmap["${datadir}"] = "${STAGING_DIR}/share"
+
+               matched = 0
+               for key in varmap.keys():
+                       if dest.startswith(key):
+                               dest = varmap[key] + "/" + dest[len(key):]
+                               matched = 1
+               if not matched:
+                       line = None
+                       return
+       else:
+               line = None
+               return
+
+       line["src"] = src
+       line["dest"] = dest
+
+def emit_line (func, line, d):
+       import copy
+       newline = copy.deepcopy(line)
+       mangle(func, newline)
+       if not newline:
+               return None
+
+       str = ""
+       type = newline["type"]
+       mode = newline["mode"]
+       src = newline["src"]
+       dest = newline["dest"]
+       if type is "d":
+               str = "install -d " + dest
+               if mode:
+                       str += "-m %s " % mode
+       elif type is "f":
+               if not src:
+                       return None
+               str = "install -D "
+               if mode:
+                       str += "-m %s " % mode
+               str += src + " " + dest
+       del newline
+       return str
diff --git a/bin/parse_manifest b/bin/parse_manifest
new file mode 100644 (file)
index 0000000..29fcac3
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+
+import sys, oe, oe.manifest
+
+mfile = sys.__stdin__
+if len(sys.argv) == 2:
+       mfile = file(sys.argv[1], "r")
+
+d = oe.data.init()
+
+manifest = oe.manifest.parse(mfile, d)
+
+for func in ("do_stage", "do_install", "do_populate"):
+       value = oe.manifest.emit(func, manifest, d)
+       if value:
+               oe.data.setVar(func, value, d)
+       oe.data.setVarFlag(func, "func", 1, d)
+       oe.data.emit_var(func, sys.__stdout__, d)
+       sys.__stdout__.write("\n")
diff --git a/bin/parse_manifest.py b/bin/parse_manifest.py
deleted file mode 100644 (file)
index 737a017..0000000
+++ /dev/null
@@ -1,213 +0,0 @@
-#!/usr/bin/env python
-
-import os, sys, string
-
-srcdir = "${WORKDIR}"
-destdir = "${D}"
-pkgdestdir = "${WORKDIR}/install"
-
-manifest = sys.__stdin__
-if len(sys.argv) == 2:
-       manifest = file(sys.argv[1], "r")
-
-def mangle_path_stage(field, fields):
-       path = fields[field]
-       if not path:
-               return None
-       if field == "src":
-               if os.path.isabs(path):
-                       return path
-               if path.startswith('/'):
-                       path = path[1:]
-               path = os.path.join(srcdir, path)
-       elif field == "dest":   
-               if os.path.isabs(path):
-                       return path
-               if path.startswith('/'):
-                       path = path[1:]
-               path = os.path.join(destdir, path)
-               libpath = os.path.join(destdir, '${libdir}')
-               incpath = os.path.join(destdir, '${includedir}')
-               if path.startswith(libpath):
-                       path = "${STAGING_LIBDIR}" + path[len(libpath):]
-               elif path.startswith(incpath):
-                       path = "${STAGING_INCDIR}" + path[len(incpath):]
-               else:
-                       return None     
-       return path     
-
-def mangle_path_install(field, fields):
-       path = fields[field]
-       if not path:
-               return None
-       if field == "src":
-               if os.path.isabs(path):
-                       return path
-               if path.startswith('/'):
-                       path = path[1:]
-               path = os.path.join(srcdir, path)
-       elif field == "dest":
-               if os.path.isabs(path):
-                       return path
-               if path.startswith('/'):
-                       path = path[1:]
-               path = os.path.join(destdir, path)
-       return path
-
-def mangle_path_populate(field, fields):
-       path = fields[field]
-       pkg = fields["pkg"]
-       if None in (pkg, path):
-               return None
-       if field == "src":
-               if os.path.isabs(path):
-                       return path
-               if path.startswith('/'):
-                       path = path[1:]
-               path = os.path.join(srcdir, path)
-       elif field == "dest":
-               if os.path.isabs(path):
-                       return path
-               if path.startswith('/'):
-                       path = path[1:]
-               path = os.path.join(pkgdestdir, pkg, path)
-       return path
-
-def getfields(line):
-       fields = {}
-       fieldmap = ( "pkg", "src", "dest", "type", "mode", "uid", "gid", "major", "minor", "start", "inc", "count" )
-       for f in xrange(len(fieldmap)):
-               fields[fieldmap[f]] = None
-       
-       if not line:
-               return None
-
-       splitline = line.split()
-       if not len(splitline):
-               return None
-
-       try:
-               for f in xrange(len(fieldmap)):
-                       if splitline[f] == '-':
-                               continue
-                       fields[fieldmap[f]] = splitline[f]
-       except IndexError:
-               pass
-       return fields
-
-def handle_directory(fields, commands, mangle_path):
-       dest = fields["dest"]
-       if not dest:
-               return
-       if os.path.isabs(dest):
-               return
-       if dest.startswith('/'):
-               dest = dest[1:]
-       cmd = "install -d "
-       dest = mangle_path("dest", fields)
-       if not dest:
-               return
-       cmd += os.path.dirname(dest)
-       if not cmd in commands:
-               commands.append(cmd)
-
-def handle_file(fields, commands, mangle_path):
-       if None in (fields["src"], fields["dest"]):
-               return
-
-       handle_directory(fields, commands, mangle_path)
-       src = mangle_path("src", fields)
-       if not src:
-               return
-       dest = mangle_path("dest", fields)
-       if not dest:
-               return
-       mode = fields["mode"]
-
-       cmd = "install "
-       if mode:
-               cmd += "-m " + mode + " "
-       cmd += src + " " + dest
-       if not cmd in commands:
-               commands.append(cmd)
-
-def handle_symbolic_link(fields, commands, mangle_path):
-       if None in (fields["src"], fields["dest"]):
-               return
-
-       handle_directory(fields, commands, mangle_path)
-       dest = mangle_path("dest", fields)
-       src = fields["src"]
-       if None in (src, dest):
-               return
-
-       cmd = "ln -sf " + src + " " + dest
-       if not cmd in commands:
-               commands.append(cmd)
-
-def handle_hard_link(fields, commands, mangle_path):
-       if None in (fields["src"], fields["dest"]):
-               return
-
-       handle_directory(fields, commands, mangle_path)
-       src = mangle_path("src", fields)
-       dest = mangle_path("dest", fields)
-       if None in (src, dest):
-               return
-
-       cmd = "ln -f " + src + " " + dest
-       if not cmd in commands:
-               commands.append(cmd)
-
-commands = list()
-commands_populate = list()
-commands_stage = list()
-entries = list()       
-while 1:
-       line = manifest.readline()
-       if not line:
-               break
-       if line.startswith("#"):
-               # skip comments
-               continue
-       fields = getfields(line)
-       if not fields:
-               continue
-
-       if not fields in entries:
-               entries.append(fields)
-                       
-       if fields["type"] == "d":
-               handle_directory(fields, commands, mangle_path_install)
-       if fields["type"] == "f":
-               handle_file(fields, commands, mangle_path_install)
-       if fields["type"] == "s":
-               handle_symbolic_link(fields, commands, mangle_path_install)
-       if fields["type"] == "h":
-               handle_hard_link(fields, commands, mangle_path_install)
-
-       if fields["type"] == "d":
-               handle_directory(fields, commands_populate, mangle_path_populate)
-       if fields["type"] == "f":
-               handle_file(fields, commands_populate, mangle_path_populate)
-       if fields["type"] == "s":
-               handle_symbolic_link(fields, commands_populate, mangle_path_populate)
-       if fields["type"] == "h":
-               handle_hard_link(fields, commands_populate, mangle_path_populate)
-
-       if fields["type"] == "d":
-               handle_directory(fields, commands_stage, mangle_path_stage)
-       if fields["type"] == "f":
-               handle_file(fields, commands_stage, mangle_path_stage)
-       if fields["type"] == "s":
-               handle_symbolic_link(fields, commands_stage, mangle_path_stage)
-       
-print "do_stage () {"
-print '\t' + string.join(commands_stage, '\n\t')
-print "}"
-print "do_install () {"
-print '\t' + string.join(commands, '\n\t')
-print "}"
-print "do_populate () {"
-print '\t' + string.join(commands_populate, '\n\t')
-print "}"