Use the configuration as dictionary, and add stub for auto-debuild system
authorRalf Jung <post@ralfj.de>
Fri, 27 Jul 2012 11:52:30 +0000 (13:52 +0200)
committerRalf Jung <ralfjung-e@gmx.de>
Fri, 27 Jul 2012 11:52:30 +0000 (13:52 +0200)
build_system.py
kdebuildpy.py
vcs.py

index e18d9ffa98545ca16fab9ccfece768b931cea020..073d432663ee5143f3c49831e18f0bca3747690c 100644 (file)
@@ -7,14 +7,13 @@ class CMake:
        def __init__(self, sourceFolder, buildFolder, config):
                self.sourceFolder = os.path.abspath(sourceFolder)
                self.buildFolder = os.path.abspath(buildFolder)
-               self.installDir = config.installDir
-               self.buildType = config.buildType
-               self.jobs = config.jobs
-               self.buildCmdPrefix = config.buildCmdPrefix
-               self.installCmdPrefix = config.installCmdPrefix
+               self.installDir = config['installDir']
+               self.buildType = config['buildType']
+               self.jobs = config['jobs']
+               self.buildCmdPrefix = config['buildCmdPrefix']
+               self.installCmdPrefix = config['installCmdPrefix']
        
        def configure(self, force=False):
-               print "Configuring",self.sourceFolder
                if not os.path.exists(self.buildFolder): os.makedirs(self.buildFolder)
                os.chdir(self.buildFolder)
                # check if we actually need to work
@@ -27,13 +26,27 @@ class CMake:
                os.unsetenv('PKG_CONFIG_PATH')
        
        def build(self):
-               print "Building",self.sourceFolder
                os.chdir(self.buildFolder)
                subprocess.check_call(self.buildCmdPrefix + ['make', '-j'+str(self.jobs)])
        
        def install(self):
-               print "Installing",self.sourceFolder
                os.chdir(self.buildFolder)
                subprocess.check_call(self.installCmdPrefix + ['make', 'install'])
 
-# TODO: class Debian, which creates & install a debian package
+# if auto-debuild is available, provide a wrapper for it
+try:
+       import auto_debuild
+       class AutoDebuild:
+               def __init__(self, sourceFolder, module):
+                       self.autoDebuildConfig = {}
+
+               def configure(self, force=False): # force is ignored
+                       self.files = auto_debuild.createDebianFiles(self.autoDebuildConfig)
+
+               def build(self):
+                       auto_debuild.buildDebianPackage(self.autoDebuildConfig)
+
+               def install(self):
+                       subprocess.check_call(['sudo', 'dpkg', '--install'] + self.files)
+except ImportError:
+       pass
index 3fd5812579751eb08e3ad6e111c791109b30a601..bf2f2a3b8c365b125452257c3b81402daa7a7665 100755 (executable)
@@ -22,14 +22,14 @@ parser.add_argument("modules",  metavar='MODULE', nargs='*',
 args = parser.parse_args()
 
 # load config
-config = imp.load_source('config', args.config)
+config = imp.load_source('config', args.config).__dict__
 os.remove(args.config+'c') # remove compiled python file
 projects = OrderedDict() # all projects
 workProjects = [] # projects we work on
 
 # an entire Project
 class Project:
-       def __init__(self, folder, module):
+       def __init__(self, config, folder, module):
                self.folder = folder
                self.name = module['name']
                # VCS
@@ -41,17 +41,20 @@ class Project:
                else:
                        raise Exception("Unknown VCS type "+vcsName)
                # build system
-               buildSystemName = module.get('build-system', 'cmake')
-               if buildSystemName == 'cmake':
-                       self.buildSystem = build_system.CMake(self.sourceFolder(), self.buildFolder(), config)
+               if config.get('buildDeb', False):
+                       self.buildSystem = build_system.AutoDebuild(self.sourceFolder(), module)
                else:
-                       raise Exception("Unknown build system type "+buildSystemName)
+                       buildSystemName = module.get('build-system', 'cmake')
+                       if buildSystemName == 'cmake':
+                               self.buildSystem = build_system.CMake(self.sourceFolder(), self.buildFolder(), config)
+                       else:
+                               raise Exception("Unknown build system type "+buildSystemName)
        
        def sourceFolder(self):
                return os.path.join(self.folder, self.name)
        
        def buildFolder(self):
-               return os.path.join(config.buildDir, self.sourceFolder())
+               return os.path.join(config['buildDir'], self.sourceFolder())
 
 # return the position of the given item in the list
 def findInList(list, item):
@@ -61,17 +64,17 @@ def findInList(list, item):
        raise Exception("%s not found in list" % str(item))
 
 # populate list of projects
-def loadProjects(modules, folder=''):
+def loadProjects(config, modules, folder=''):
        for module in modules:
                if 'folder' in module: # a subpath
-                       loadProjects(module['modules'], os.path.join(folder, module['folder']))
+                       loadProjects(config, module['modules'], os.path.join(folder, module['folder']))
                else: # a proper project
                        if module['name'] in projects:
                                raise Exception("Duplicate module name "+module['name'])
-                       projects[module['name']] = Project(folder, module)
+                       projects[module['name']] = Project(config, folder, module)
 
 # now check what we have to do
-loadProjects(config.modules)
+loadProjects(config, config['modules'])
 if args.modules:
        if args.resume_from is not None:
                raise Exception("Can not use --resume-from and manually specify modules")
@@ -93,11 +96,15 @@ for project in workProjects:
        try:
                for phase in args.phases:
                        if phase == 'update':
+                               print "Updating",project.sourceFolder()
                                project.vcs.update()
                        elif phase == 'configure':
+                               print "Configuring",project.sourceFolder()
                                project.buildSystem.configure(force=args.reconfigure)
                        elif phase == 'compile':
+                               print "Compiling",project.sourceFolder()
                                project.buildSystem.build()
+                               print "Installing",project.sourceFolder()
                                project.buildSystem.install()
                        else:
                                raise Exception("Invalid phase "+phase)
diff --git a/vcs.py b/vcs.py
index 8acb571aa161a4cb4df82d2a237d2cd77deb0521..a810d35291907ab5464ef1e603640cb2778acf38 100644 (file)
--- a/vcs.py
+++ b/vcs.py
@@ -14,7 +14,6 @@ class Git:
                        print self._cur_line+(" "*30)+"\r",
        
        def update(self):
-               print "Updating",self.folder
                isBranch = (self.commit.startswith('origin/'))
                if isBranch:
                        branchname = self.commit[len('origin/'):]
@@ -58,7 +57,6 @@ class SVN:
                self.svnPath = svnPath
        
        def update(self):
-               print "Updating",self.folder
                if os.path.exists(self.folder):
                        os.chdir(self.folder) # go into repository
                        subprocess.check_call(['svn', 'switch', self.svnPath]) # and update to the URL we got