diff options
author | 2011-08-02 02:02:39 +0200 | |
---|---|---|
committer | 2011-08-02 02:02:39 +0200 | |
commit | 6cccf68576fde668220b8e1149c797d38e4b8982 (patch) | |
tree | 9b41da553540ee926639e8c86bdbe94ef37d7106 | |
parent | Need to rework how the automakefile scan works. (diff) | |
download | ebuildgen-6cccf68576fde668220b8e1149c797d38e4b8982.tar.gz ebuildgen-6cccf68576fde668220b8e1149c797d38e4b8982.tar.bz2 ebuildgen-6cccf68576fde668220b8e1149c797d38e4b8982.zip |
Added some basic support for include flags and m4_include
-rw-r--r-- | filetypes/autoconf.py | 15 | ||||
-rw-r--r-- | filetypes/automake.py | 25 | ||||
-rw-r--r-- | filetypes/ctypefiles.py | 17 | ||||
-rw-r--r-- | scanfiles.py | 22 |
4 files changed, 54 insertions, 25 deletions
diff --git a/filetypes/autoconf.py b/filetypes/autoconf.py index 9b9dba0..71ec0b2 100644 --- a/filetypes/autoconf.py +++ b/filetypes/autoconf.py @@ -357,7 +357,7 @@ def scanacfile(acfile): from filetypes.acif import parseif -def output(inputlst): +def output(inputlst,topdir): variables = dict() iflst = [] for item in inputlst: @@ -397,6 +397,11 @@ def output(inputlst): #"!" == not zero/defined, "" zero/not defined if_state[1][var] = "true" + elif item[0] == "m4_include": + newvar,newiflst = output(scanacfile(openfile(topdir + item[1])),topdir) + variables.update(newvar) + iflst += newiflst + #for variable in variables: #print(variable) #print(variables[variable]) @@ -466,5 +471,9 @@ def convnames(string): #strip none alfanumeric chars and replace them with "_" return newstr #this is no a good name, come up with a better one! -def scanac(acfile): - return output(scanacfile(acfile)) +def scanac(acfile,topdir): + return output(scanacfile(acfile),topdir) + +def openfile(ofile): + with open(ofile, encoding="utf-8", errors="replace") as inputfile: + return inputfile.read() diff --git a/filetypes/automake.py b/filetypes/automake.py index d338b71..3bd061e 100644 --- a/filetypes/automake.py +++ b/filetypes/automake.py @@ -253,6 +253,8 @@ def scanamfile(amfile): def initscan(amfile,iflst): useflag_sources = {} #{source: [useflag, value]} + incflag_sources = {} #{source: [include flags]} + top_dir = os.path.split(amfile)[0] + "/" def scan(amfile): curdir = os.path.split(amfile)[0] + "/" @@ -260,6 +262,7 @@ def initscan(amfile,iflst): #print(amfile) def sources_to_scan(amlist,curdir): + incflags = [] sources = [] extra_sources = [] #perhaps use set() here to eliminate the possibilty of duplicates? @@ -278,12 +281,23 @@ def initscan(amfile,iflst): for file in ifstate[1][item.strip("@")]: for src in extra_sources: if file.split(".")[0] == src.split(".")[0]: - useflag_sources.update({curdir + src : ifstate[0]}) + useflag_sources[curdir + src] = ifstate[0] + incflag_sources[curdir + src] = incflags for src in extra_sources: if item.split(".")[0] == src.split(".")[0]: sources += [src] + if variable.split("_")[-1] == "CFLAGS": + for item in amlist[0][variable]: + if item[:2] == "-I": + if item[2:] == "$(top_srcdir)" or item[2:] == "$(srcdir)": + incflags += [top_dir] + elif item[2] == "/": + incflags += [item[2:]] + else: + incflags += [curdir + item[2:]] + if "SUBDIRS" in amlist[0]: for dir in amlist[0]["SUBDIRS"]: sources += scan(curdir + dir + "/Makefile.am") @@ -291,7 +305,7 @@ def initscan(amfile,iflst): for lst in amlist[1]: if lst[0] == "SUBDIRS": for dir in lst[1]: - sources += scan(curdir + dir + "/Makefile.am") + sources += scan(curdir + dir + "/Makefile.am") for ifstatement in amlist[2]: #print(ifstatement) @@ -300,24 +314,25 @@ def initscan(amfile,iflst): if ifstatement[0] == "!": if item[1][ifstatement.lstrip("!")] == "false": for src in sources_to_scan(amlist[2][ifstatement],curdir): - useflag_sources.update({src : item[0]}) + useflag_sources[src] = item[0] elif item[1][ifstatement] == "true": for src in sources_to_scan(amlist[2][ifstatement],curdir): - useflag_sources.update({src : item[0]}) + useflag_sources[src] = item[0] #add filepath dirsources = [] for source in sources: if os.path.split(source)[0] == "": dirsources += [curdir + source] + incflag_sources[curdir + source] = incflags else: dirsources += [source] return dirsources return sources_to_scan(amlist,curdir) - return scan(amfile),useflag_sources + return scan(amfile),useflag_sources,incflag_sources def openfile(ofile): with open(ofile, encoding="utf-8", errors="replace") as inputfile: diff --git a/filetypes/ctypefiles.py b/filetypes/ctypefiles.py index ef6cbc5..e6b9624 100644 --- a/filetypes/ctypefiles.py +++ b/filetypes/ctypefiles.py @@ -4,7 +4,7 @@ from ply import yacc #lex stuff begins here -def scanincludes(string,inclst,curdir): +def scanincludes(string,inclst,curdir,incpaths): """Scan ctype files for #includes Adds and returns new includes to the supplied include list @@ -103,7 +103,7 @@ def scanincludes(string,inclst,curdir): """ includes : includes linc """ - if islocalinc(p[2],curdir): + if islocalinc(p[2],curdir,incpaths): p[1][1].add(p[2]) else: p[1][0].add(p[2]) @@ -142,7 +142,7 @@ def scanincludes(string,inclst,curdir): "includes : linc" locinc = set() locinc.add(p[1]) - if islocalinc(p[1], curdir): + if islocalinc(p[1], curdir, incpaths): p[0] = [set(),locinc,{}] else: p[0] = [locinc,set(),{}] @@ -168,18 +168,19 @@ def scanincludes(string,inclst,curdir): newinclst = addnewincludes(newinclst,inclst) return(newinclst) -def islocalinc(inc, curdir): +def islocalinc(inc, curdir, incpaths): """Checks if this is a local include Checks if the file can be found with the path that is supplied. If not this is probably a global include and thus return False """ + incpaths += [curdir + "/"] - if glob.glob(curdir + "/" + inc) == []: - return False - else: - return True + for incpath in incpaths: + if not glob.glob(incpath + inc) == []: + return True + return False def addnewincludes(inclist1,inclist2): """Adds new includes to the first inclist and return it diff --git a/scanfiles.py b/scanfiles.py index a14200f..584158b 100644 --- a/scanfiles.py +++ b/scanfiles.py @@ -80,11 +80,14 @@ def scanautotoolsdeps(acfile,amfile): returns. """ #these are not really useflags yet. So perhaps change name? - useflags, iflst = scanac(openfile(acfile)) - srcfiles, src_useflag = initscan(amfile, iflst) + topdir = os.path.split(amfile)[0] + "/" + useflags, iflst = scanac(openfile(acfile),topdir) + srcfiles, src_useflag, src_incflag = initscan(amfile, iflst) + #print(iflst) + #print(srcfiles) #standard includes - includes = scanfilelist(srcfiles) + includes = scanfilelist(srcfiles,src_incflag) def inter_useflag(uselst): if uselst[1] == "yes" or uselst[1] == "!no": @@ -106,12 +109,12 @@ def scanautotoolsdeps(acfile,amfile): useargs[usearg] = [src] for usearg in useargs: - useargs[usearg] = scanfilelist(useargs[usearg]) + useargs[usearg] = scanfilelist(useargs[usearg],src_incflag) print(useargs) - #print(includes) + print(includes) -def scanfilelist(filelist): +def scanfilelist(filelist,src_incflag): """ Scan files in filelist for #includes returns a includes list with this structure: @@ -126,9 +129,10 @@ def scanfilelist(filelist): for file in filelist: #print(file) + incpaths = src_incflag[file] filestring = openfile(file) if not filestring == None: - inclst = scanincludes(filestring,inclst,os.path.split(file)[0]) + inclst = scanincludes(filestring,inclst,os.path.split(file)[0],incpaths) return(inclst) @@ -159,5 +163,5 @@ def openfile(file): except IOError: print('cannot open', file) -#scanautotoolsdeps("/usr/portage/distfiles/svn-src/moc/trunk/configure.in","/usr/portage/distfiles/svn-src/moc/trunk/Makefile.am") -print(scanfilelist(["/usr/portage/distfiles/svn-src/moc/trunk/decoder_plugins/sidplay2/sidplay2.h"])) +scanautotoolsdeps("/usr/portage/distfiles/svn-src/moc/trunk/configure.in","/usr/portage/distfiles/svn-src/moc/trunk/Makefile.am") +#print(scanfilelist(["/usr/portage/distfiles/svn-src/moc/trunk/decoder_plugins/sidplay2/sidplay2.h"])) |