aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Parborg <darkdefende@gmail.com>2011-07-05 21:10:03 +0200
committerSebastian Parborg <darkdefende@gmail.com>2011-07-05 21:10:03 +0200
commitaafa7105e44bc324e738a2823e617f84a14e03ca (patch)
treed9bc7a718f4b9aa2a06724f347f5e62907f3c592
parentAdded a basic autoconf lex parser (diff)
downloadebuildgen-aafa7105e44bc324e738a2823e617f84a14e03ca.tar.gz
ebuildgen-aafa7105e44bc324e738a2823e617f84a14e03ca.tar.bz2
ebuildgen-aafa7105e44bc324e738a2823e617f84a14e03ca.zip
Added comments to most functions
-rw-r--r--ebuildgen.py22
-rw-r--r--filetypes/autoconf.py49
-rw-r--r--filetypes/automake.py4
-rw-r--r--filetypes/ctypefiles.py23
-rw-r--r--filetypes/makefilecom.py25
-rw-r--r--filetypes/makefiles.py22
-rw-r--r--linkdeps.py5
-rw-r--r--scanfiles.py30
-rw-r--r--scmprojects.py4
9 files changed, 182 insertions, 2 deletions
diff --git a/ebuildgen.py b/ebuildgen.py
index 773efc3..609bedb 100644
--- a/ebuildgen.py
+++ b/ebuildgen.py
@@ -10,6 +10,17 @@ eclass = {
arch = getstatusoutput("portageq envvar ARCH")[1]
def genebuild(iuse,deps,dltype,adress,targets,binaries):
+ """This function starts the ebuild generation.
+
+ You have to provide the following args in order:
+ iuse, a list of useflags
+ deps, a list of dependecies
+ dltype, how to download the source code (wget,GIT,etc)
+ adress, Adress to the source code
+ targets, a list of build targets for the project (used to guess install method)
+ binaries, a list of binaries that is created during compile (used to install them if there is no 'make install')
+ """
+
installmethod = guessinstall(targets,binaries)
outstr = outputebuild(iuse,deps,dltype,adress,installmethod)
f = open("/tmp/workfile.ebuild","w")
@@ -17,6 +28,12 @@ def genebuild(iuse,deps,dltype,adress,targets,binaries):
f.close()
def guessinstall(targets,binaries):
+ """Guess the install method of the project
+
+ Looks at the make targets for a 'make install'
+ if that fails just install the binaries
+ """
+
targetlst = []
returnlst = []
for target in targets:
@@ -31,6 +48,11 @@ def guessinstall(targets,binaries):
return returnlst
def outputebuild(iuse,deps,dltype,adress,installmethod):
+ """Used to generate the text for the ebuild to output
+
+ Generates text with the help of the supplied variables
+ """
+
text = [
'# Copyright 1999-' + strftime("%Y") + ' Gentoo Foundation',
'# Distributed under the terms of the GNU General Public License v2',
diff --git a/filetypes/autoconf.py b/filetypes/autoconf.py
index 2bbd934..1012487 100644
--- a/filetypes/autoconf.py
+++ b/filetypes/autoconf.py
@@ -2,6 +2,10 @@ from ply import lex
from ply import yacc
def scanacfile(acfile):
+ """Scan a autoconfigure (.in/.ac) file.
+
+ Returns ....
+ """
tokens = (
"FUNC",
@@ -11,16 +15,21 @@ def scanacfile(acfile):
"ECHO",
"TEXT",
"IF",
+ "IFCOM",
"ELSE",
"THEN",
"IFEND",
"CASE",
+ "CASEOPT",
+ "COPTEND", #case opt end, doesn't need to be there but SHOULD
"CASEEND",
)
states = (
("func", "exclusive"),
("funcopt", "exclusive"),
+ ("case", "inclusive"),
+ ("if", "inclusive"),
)
def t_ANY_contline(t):
@@ -99,10 +108,16 @@ def scanacfile(acfile):
def t_IF(t):
r"if"
+ t.lexer.push_state("if")
return t
- def t_THEN(t):
+ def t_if_THEN(t):
r"then"
+ t.lexer.pop_state()
+ return t
+
+ def t_if_IFCOM(t):
+ r"[^ \t\n\(\)]+"
return t
def t_ELSE(t):
@@ -115,10 +130,20 @@ def scanacfile(acfile):
def t_CASE(t):
r"case.*in"
+ t.lexer.push_state("case")
return t
def t_CASEEND(t):
r"esac"
+ t.lexer.pop_state()
+ return t
+
+ def t_case_CASEOPT(t):
+ r"[^ \n\t\(\)]+\)"
+ return t
+
+ def t_case_COPTEND(t):
+ r";;"
return t
def t_literal(t):
@@ -127,7 +152,7 @@ def scanacfile(acfile):
t.value = t.value[-1] #return litral char
return t
- def t_TEXT(t):
+ def t_TEXT(t): #most likely commands like "AM_INIT_AUTOMAKE" etc.
r"[^ \t\n\(\)]+"
return t
@@ -141,6 +166,26 @@ def scanacfile(acfile):
for tok in lexer:
print(tok)
+ #YACC stuff begins here
+
+ def p_complst(p):
+ """
+ complst : complst var
+ | complst func
+ | var
+ | func
+ """
+
+ def p_textlst(p):
+ """
+ textlst : textlst TEXT
+ | TEXT
+ """
+ if len(p) == 3:
+ p[0] = p[1] += [p[1]]
+ else:
+ p[0] = [p[1]]
+
file="configure.in"
with open(file, encoding="utf-8", errors="replace") as inputfile:
diff --git a/filetypes/automake.py b/filetypes/automake.py
index fa9f149..e9e31a2 100644
--- a/filetypes/automake.py
+++ b/filetypes/automake.py
@@ -3,6 +3,10 @@ from ply import yacc
import glob
def scanamfile(amfile):
+ """Scan automake (.am) file
+
+ Returns ...
+ """
amfile = "\n" + amfile #Add \n so you can guess vars
tokens = (
"END",
diff --git a/filetypes/ctypefiles.py b/filetypes/ctypefiles.py
index efa4d7e..32cb32d 100644
--- a/filetypes/ctypefiles.py
+++ b/filetypes/ctypefiles.py
@@ -5,6 +5,14 @@ from ply import yacc
#lex stuff begins here
def scanincludes(string,inclst,curdir):
+ """Scan ctype files for #includes
+
+ Adds and returns new includes to the supplied include list
+ input:
+ string with the file contents to scan,
+ a include list
+ string with the current working dir
+ """
tokens = (
"GINCLUDE",
"LINCLUDE",
@@ -151,6 +159,12 @@ def scanincludes(string,inclst,curdir):
return(newinclst)
def islocalinc(inc, curdir):
+ """Checks if this is a local include
+
+ Checks if the file can be found with the path the is supplied.
+ If not this is probably a global include and thus return False
+ """
+
if glob.glob(curdir + "/" + inc) == []:
return False
else:
@@ -158,6 +172,10 @@ def islocalinc(inc, curdir):
def addnewincludes(inclist1,inclist2):
+ """Adds new includes to the first inclist and return it
+
+ Does a deeper scan for ifdef includes
+ """
#come up with better names!!
inclist1[0] = inclist1[0] | inclist2[0]
inclist1[1] = inclist1[1] | inclist2[1]
@@ -165,6 +183,11 @@ def addnewincludes(inclist1,inclist2):
return(inclist1)
def addnewifdefs(dict1,dict2):
+ """Merges the ifdef section of the inclst
+
+ Returns a new list with all of the ifdefs
+ """
+
if dict1 == {} and dict2 == {}:
#we are done here
return(dict())
diff --git a/filetypes/makefilecom.py b/filetypes/makefilecom.py
index a600c79..e76a15c 100644
--- a/filetypes/makefilecom.py
+++ b/filetypes/makefilecom.py
@@ -5,6 +5,14 @@ import os
from subprocess import getstatusoutput
def expand(lst,variables):
+ """Expands makefile variables.
+
+ Expand all items in the supplied list that are list within the list.
+ Returns a list where all the previously unexpanded variables are now
+ expanded.
+ Besides the list this needs a dict with variables found in the makefile.
+ """
+
newlst = []
for item in lst:
if isinstance(item, list):
@@ -16,6 +24,10 @@ def expand(lst,variables):
return newlst
def com_interp(string,variables):
+ """Interpret the supplied command and return a list with the output
+
+ """
+
tokens = (
"COMMAND",
"COMMA",
@@ -323,6 +335,10 @@ def com_interp(string,variables):
return retlst
def foreach(inputlst,variables):
+ """GNU makefile foreach.
+
+ """
+
result = []
var = expand(inputlst[0:1],variables)
lst = expand(inputlst[1:2],variables)
@@ -333,10 +349,16 @@ def foreach(inputlst,variables):
return result
def wildcard(inputlst,variables):
+ """GNU makefile wildcard
+
+ """
command = expand(inputlst,variables)
return glob.glob(command[0])
def shell(inputlst,variables):
+ """GNU makefile shell command
+
+ """
command = ""
retlst = []
for item in expand(inputlst,variables):
@@ -349,6 +371,9 @@ def shell(inputlst,variables):
return retlst
def notdir(inputlst,variables): #strip the dir from the file name
+ """GNU makefile notdir
+
+ """
if isinstance(inputlst[0],list):
files = expand(inputlst,variables)
else:
diff --git a/filetypes/makefiles.py b/filetypes/makefiles.py
index d2057fd..fd9b80f 100644
--- a/filetypes/makefiles.py
+++ b/filetypes/makefiles.py
@@ -4,6 +4,10 @@ import glob
from filetypes.makefilecom import expand
def scanmakefile(makefile):
+ """Scan supplied makefile.
+
+ Returns a list of targets and variables found
+ """
makefile = "\n" + makefile #Add \n so you can guess vars
tokens = (
"END",
@@ -352,6 +356,10 @@ def scanmakefile(makefile):
def convtargets(tarlist,deplist,targets,variables):
+ """Convert makefile targets that are not explicitly stated in the makefile
+
+ """
+
finaltars = []
deps = expand(deplist,variables)
tars = expand(tarlist,variables) #ugh high risk of confusion because of the names...
@@ -375,6 +383,11 @@ def convtargets(tarlist,deplist,targets,variables):
return finaltars
def findfiles(rule,variables): #check if deps exists, if not look for them in VPATH.
+ """Find files for a implicit makefile rule
+
+ This searches the VPATH for files that match the name of the implicitly stated target
+ IE io.o -> src/io.c (if VPATH is src for example)
+ """
newtarget = []
newdeps = []
if "VPATH" in variables: #if vpath isn't defined this it's useless to search
@@ -407,6 +420,12 @@ def findfiles(rule,variables): #check if deps exists, if not look for them in VP
return rule
def find(searchstr,paths):
+ """Returns a list of matches for a search pattern
+
+ This is mostly used in implicit rules so it just returns the first
+ match of the search as this is how it work in makefiles
+ """
+
matches = []
for path in paths:
matches += glob.glob(path + "/" + searchstr)
@@ -416,6 +435,9 @@ def find(searchstr,paths):
return matches
def imprules(rule,targets,variables): #Implicit Rules
+ """Converts implicit rules to explicit rules
+
+ """
if len(rule[0].split(".")) == 1: #this is not a *.* file
deps_type = set() #.o for example
for dep in rule[1]:
diff --git a/linkdeps.py b/linkdeps.py
index c31813e..ec8766a 100644
--- a/linkdeps.py
+++ b/linkdeps.py
@@ -2,6 +2,11 @@ import os
from subprocess import getstatusoutput
def deptopackage(dep,addpaths):
+ """Converts supplied deps with additional include paths to portage packages
+
+ This uses qfile to quess which package certain files belongs to.
+ """
+
print(dep)
incpaths = ["/usr/include", "/usr/local/include"]
incpaths += addpaths
diff --git a/scanfiles.py b/scanfiles.py
index 6b72ce0..af4895e 100644
--- a/scanfiles.py
+++ b/scanfiles.py
@@ -5,6 +5,11 @@ from filetypes.makefiles import scanmakefile
from filetypes.makefilecom import expand
def scandirfor(dir, filetypes):
+ """Scans recursivly the supplied dir for provided filetypes.
+
+ And return a list of files found
+ """
+
files = []
dirs = [f for f in os.listdir(dir)
if os.path.isdir(os.path.join(dir, f))]
@@ -15,6 +20,14 @@ def scandirfor(dir, filetypes):
return files
def scanmakefiledeps(makefile):
+ """Scans makefile for what files it would compile.
+
+ returns a list of files to scan for deps,
+ binaries build with the first makefile option,
+ additional includeflags and what the 'targets : deps'
+ are in the makefile
+ """
+
curdir = os.path.split(makefile)[0] + "/"
olddir = os.getcwd()
makefile = openfile(makefile)
@@ -53,6 +66,14 @@ def scanmakefiledeps(makefile):
return filestoscan,binaries,incflags,targets
def scanfilelist(filelist):
+ """ Scan files in filelist for #includes
+
+ returns a includes list with this structure:
+ [set(),set(),dict()]
+ There the first two sets contains global and local includes
+ and the dict contains variables that can pull in additional includes
+ with the same structure as above
+ """
global_hfiles = set()
local_hfiles = set()
inclst = [global_hfiles,local_hfiles,{}]
@@ -65,6 +86,11 @@ def scanfilelist(filelist):
return(inclst)
def scanproject(dir,projecttype):
+ """Scan a project (source) dir for files that may build it
+
+ This tries to guess which kind of project it is. IE
+ autotools? makefile?
+ """
if projecttype == "guess":
filestolookfor = ["Makefile","makefile"] #add more later
elif projecttype == "makefile":
@@ -76,6 +102,10 @@ def scanproject(dir,projecttype):
return scanfilelist(scanlist),binaries,incflags,targets
def openfile(file):
+ """Open a file and return the content as a string.
+
+ Returns nothing and print an error if the file cannot be read
+ """
try:
with open(file, encoding="utf-8", errors="replace") as inputfile:
return inputfile.read()
diff --git a/scmprojects.py b/scmprojects.py
index 4ecedd0..7310c0b 100644
--- a/scmprojects.py
+++ b/scmprojects.py
@@ -9,6 +9,10 @@ cmdlineget = {
}
def getsourcecode(adress,repotype):
+ """This downloads the sourcecode to /tmp/ebuildgen/curproj
+
+ Supply the adress to the source code and repo type
+ """
callstr = cmdlineget[repotype]
try: