Skip to content

Instantly share code, notes, and snippets.

@AlexsJones
Created March 25, 2014 14:55
Show Gist options
  • Save AlexsJones/9763480 to your computer and use it in GitHub Desktop.
Save AlexsJones/9763480 to your computer and use it in GitHub Desktop.
import os,sys,getopt,argparse,shutil,configparser
#[GlobalOptions]
#COMPILER=gcc
#OUTPUT=pickle
#[CompilerOptions]
#OPTS=-o
#LIBS=-ljnxc
#SRC=*.c
class builder:
def __init__(self):
print("Starting builder...")
self.cfiles = dict()
self.hfiles = dict()
self.buildcommands = None
def builddir(self):
if os.path.exists("build"):
shutil.rmtree("build")
os.makedirs("build")
def walk(self,path):
for dirpath, dnames, fnames in os.walk(path):
for f in fnames:
ext = os.path.splitext(f)[1]
fullpath = dirpath + '/' + f
if ext == ".c":
self.cfiles[f] = fullpath
elif ext == ".h":
self.hfiles[f] = fullpath
def process(self):
self.builddir()
for l in self.cfiles:
shutil.copy(self.cfiles[l],"build")
for l in self.hfiles:
shutil.copy(self.hfiles[l],"build")
def readconf(self,path):
c = configparser.ConfigParser()
c.read(path)
self.buildsequence(c)
def buildsequence(self,c):
s_compiler = c['GlobalOptions']['COMPILER']
s_src = c['CompilerOptions']['SRC']
s_libs = c['CompilerOptions']['LIBS']
s_output = c['GlobalOptions']['OUTPUT']
s_opts = c['CompilerOptions']['OPTS']
out = "%s %s %s %s %s" % (s_compiler,s_src,s_opts,s_output,s_libs)
print("Outputting: %s" % out)
self.buildcommands = out
def build(self):
pwd = os.getcwd()
os.chdir("build")
ret = os.system(self.buildcommands)
print("Built with %d" % ret)
os.chdir(pwd)
if ret == 0:
shutil.move(s_output,"../")
if __name__ == "__main__" :
print("Booting")
parser = argparse.ArgumentParser()
parser.add_argument('-p','--path')
parser.add_argument('-b','--build')
args = parser.parse_args()
assert args.build, "build argument not found"
b = builder()
b.readconf(args.build)
b.walk(args.path)
b.process()
b.build()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment