Use the new rootfs configuration style. Remove the sb1-isms from root
authorKalle Vahlman <zuh@iki.fi>
Tue, 24 Jun 2008 19:49:45 +0000 (22:49 +0300)
committerKalle Vahlman <zuh@iki.fi>
Tue, 24 Jun 2008 19:49:45 +0000 (22:49 +0300)
path and target name, the configuration allows specifying them now.

matrix/rootfs.py

index e29cb97..7b6dcb7 100644 (file)
@@ -11,6 +11,7 @@ import shutil
 import sys
 
 from config import config
+from config import rootfs
 from config import parse as config_parse
 
 image_type_list = (
@@ -57,19 +58,15 @@ def main():
        config_parse('main')
        config_parse('rootfs')
 
-       f = os.popen('sb-conf cu')
-       target = f.read()
-       f.close()
-
-       build = Builder(target.strip())
-       build.include_paths(config.include_paths)
-       build.include_files(config.include_files)
-       build.filter_paths(config.exclude_paths)
-       build.filter_files(config.exclude_files)
-       build.filter_expressions(config.exclude_expressions)
-       build.add_paths(config.created_paths)
-       build.set_devices(config.devices)
-       build.set_change_owner(config.change_owner)
+       build = Builder(rootfs.path, rootfs.target)
+       build.include_paths(rootfs.include_paths)
+       build.include_files(rootfs.include_files)
+       build.filter_paths(rootfs.exclude_paths)
+       build.filter_files(rootfs.exclude_files)
+       build.filter_expressions(rootfs.exclude_expressions)
+       build.add_paths(rootfs.created_paths)
+       build.set_devices(rootfs.devices)
+       build.set_change_owner(rootfs.directory_owners)
        build.set_flash_erase_size(config.boards[config.board].flash_erase_size)
        build.set_flash_pad_size(config.boards[config.board].flash_pad_size)
 
@@ -90,6 +87,7 @@ def main():
 
 class Builder(object):
        builddir = "/tmp"
+       path = None
        target = None
 
        # Tools
@@ -132,16 +130,17 @@ class Builder(object):
        devices = {}
        chown_owner = {}
 
-       def __init__(self, mytarget):
-               self.target = mytarget
+       def __init__(self, rootpath, targetname = None):
+               self.path = rootpath
+               self.target = targetname or os.path.split(rootpath)[-1]
 
        def include_paths(self, paths):
                old_dir = os.getcwd()
-               os.chdir("/targets")
+               os.chdir(self.path)
 
                # Traverse include_paths hierarchies and grab all files there
                for path in paths:
-                       for root, dirs, files in os.walk(self.target + path):
+                       for root, dirs, files in os.walk(self.path + path):
                                for f in files:
                                        self.file_list.append("%s/%s" % (root, f))
                                if len(files) == 0:
@@ -151,11 +150,11 @@ class Builder(object):
 
        def include_files(self, files):
                old_dir = os.getcwd()
-               os.chdir("/targets")
+               os.chdir(self.path)
 
                # Append included individual files
                for f in files:
-                       self.file_list.append(self.target + f)
+                       self.file_list.append(f)
 
                os.chdir(old_dir)
 
@@ -237,7 +236,7 @@ class Builder(object):
                current_file = 0.0
 
                old_dir = os.getcwd()
-               os.chdir("/targets")
+               os.chdir(self.path)
 
                if os.path.exists(os.path.join(self.builddir, self.target)):
                        print "%s exists, please remove it and try again" % os.path.join(self.builddir, self.target)
@@ -246,9 +245,10 @@ class Builder(object):
                # Copy the wanted files, strip binaries
                print "Copying files..."
                for f in copy_list:
+                       f = f.replace(self.path, "")
                        if f[0] == '/':
                                f = f[1:]
-                       path = os.path.join(self.builddir, os.path.dirname(f))
+                       path = os.path.join(self.builddir, self.target, os.path.dirname(f))
                        try:
                                os.makedirs(path)
                        except OSError, e:
@@ -257,18 +257,23 @@ class Builder(object):
 
                        if os.path.islink(f):
                                link_dest = os.readlink(f)
-                               os.symlink(link_dest, os.path.join(self.builddir, f))
+                               os.symlink(link_dest, os.path.join(self.builddir, self.target, f))
                        elif os.path.isdir(f):
                                try:
-                                       os.makedirs(os.path.join(self.builddir, f))
+                                       os.makedirs(os.path.join(self.builddir, self.target, f))
                                except OSError, e:
                                        if e.errno == errno.EEXIST:
                                                pass
                        else:
-                               shutil.copy(f, path)
-                               if not f.endswith(".ko"):
-                                       os.system(self.strip + " " + os.path.join(path,os.path.basename(f)) + " &> /dev/null")
-
+                               try:
+                                       shutil.copy(f, path)
+                                       if not f.endswith(".ko"):
+                                               os.system(self.strip + " " + os.path.join(path,os.path.basename(f)) + " &> /dev/null")
+                               except IOError, e:
+                                       # We allow nonexistent files since only place where we'll get those
+                                       # is from the include files directive
+                                       if e.errno == errno.EEXIST:
+                                               pass
                        if (current_file/n_files)*100 > current_percent:
                                current_percent += 10.0
                                print "%0.1f%%" % current_percent,
@@ -360,7 +365,7 @@ class Builder(object):
                # Build development rootfs
                if build_target == "all" or build_target == "devrootfs":
                        print "Creating a rootstrap..."
-                       os.system("%s -c --one-file-system -C /targets/%s -z -f %s/%s-rootstrap.tgz ." % ("tar", self.target, self.builddir, self.target))
+                       os.system("%s -c --one-file-system -C /targets/%s -z -f %s/%s-rootstrap.tgz ." % ("tar", self.path, self.builddir, self.target))
 
                os.chdir(old_dir)
 
@@ -382,3 +387,4 @@ class Builder(object):
                        print "Cleaning up"
                        os.remove("/tmp/env.faked")
                        os.system("rm -rf %s/%s" % (self.builddir, self.target))
+