diff options
author | 2011-08-04 23:19:52 +0200 | |
---|---|---|
committer | 2011-08-04 23:19:52 +0200 | |
commit | 3c43da8b23e7037e02be445ee17b238b8e86bdfe (patch) | |
tree | d0efdde9d7e5e8789ee46efc967d7a7a21fdb448 | |
parent | Added some basic support for include flags and m4_include (diff) | |
download | ebuildgen-3c43da8b23e7037e02be445ee17b238b8e86bdfe.tar.gz ebuildgen-3c43da8b23e7037e02be445ee17b238b8e86bdfe.tar.bz2 ebuildgen-3c43da8b23e7037e02be445ee17b238b8e86bdfe.zip |
Added basic autotools support
-rwxr-xr-x | cli.py | 25 | ||||
-rw-r--r-- | ebuildgen.py | 21 | ||||
-rw-r--r-- | linkdeps.py | 41 | ||||
-rw-r--r-- | scanfiles.py | 23 |
4 files changed, 74 insertions, 36 deletions
@@ -52,17 +52,30 @@ else: srcdir = args.dir dltype = "www" -(inclst,binaries,incpaths,targets) = scanfiles.scanproject(srcdir,"makefile") -packages = set() -print(binaries) +(iuse,inclst,useargs) = scanfiles.scanproject(srcdir,"autotools") +targets = [["install"]] +binaries = [] +gpackages = set() for dep in inclst[0]: - packages.add(linkdeps.deptopackage(dep,incpaths)[0]) + gpackages.add(linkdeps.deptopackage(dep,[])[0]) +#print(gpackages) -ebuildgen.genebuild([],packages,dltype,args.dir,targets,binaries) +usedeps = {} +for use in useargs: + packages = set() + for dep in useargs[use][0]: + newpack = linkdeps.deptopackage(dep,[])[0] + if not newpack in gpackages: + packages.add(newpack) + usedeps[use] = packages + +#print(usedeps) +#print(iuse) +ebuildgen.genebuild(iuse,gpackages,usedeps,dltype,args.dir,targets,binaries) if args.ginc == args.linc == args.ifdef == args.quiet == False: print(inclst) - print(packages) + print(gpackages) if args.ginc: print(inclst[0]) diff --git a/ebuildgen.py b/ebuildgen.py index 609bedb..10586e6 100644 --- a/ebuildgen.py +++ b/ebuildgen.py @@ -9,7 +9,7 @@ eclass = { arch = getstatusoutput("portageq envvar ARCH")[1] -def genebuild(iuse,deps,dltype,adress,targets,binaries): +def genebuild(iuse,deps,usedeps,dltype,adress,targets,binaries): """This function starts the ebuild generation. You have to provide the following args in order: @@ -22,7 +22,7 @@ def genebuild(iuse,deps,dltype,adress,targets,binaries): """ installmethod = guessinstall(targets,binaries) - outstr = outputebuild(iuse,deps,dltype,adress,installmethod) + outstr = outputebuild(iuse,deps,usedeps,dltype,adress,installmethod) f = open("/tmp/workfile.ebuild","w") f.write(outstr) f.close() @@ -47,7 +47,7 @@ def guessinstall(targets,binaries): return returnlst -def outputebuild(iuse,deps,dltype,adress,installmethod): +def outputebuild(iuse,deps,usedeps,dltype,adress,installmethod): """Used to generate the text for the ebuild to output Generates text with the help of the supplied variables @@ -83,7 +83,7 @@ def outputebuild(iuse,deps,dltype,adress,installmethod): ] iusestr = 'IUSE="' for flag in iuse: - iusestr += (flag + " ") + iusestr += (flag.split("_")[1] + " ") iusestr += '"\n' text.append(iusestr) @@ -92,6 +92,19 @@ def outputebuild(iuse,deps,dltype,adress,installmethod): for dep in deps: depstr += (dep + "\n\t") + for use in usedeps: + #check if packagelist is empty + if usedeps[use]: + if use[0] == "!": + depstr += "!" + use.split("_")[1] + "? ( " + else: + depstr += use.split("_")[1] + "? ( " + + for dep in usedeps[use]: + depstr += dep +"\n\t\t" + depstr = depstr[:-3] + depstr += " )\n\t" + depstr = depstr[:-2] + '"' text.append(depstr) diff --git a/linkdeps.py b/linkdeps.py index 7e81e2e..edf9c7a 100644 --- a/linkdeps.py +++ b/linkdeps.py @@ -3,6 +3,10 @@ from subprocess import getstatusoutput from urllib.request import urlopen def deptopackage(dep,addpaths): + #return pfltopackage(dep,addpaths) + return qfiletopackage(dep,addpaths) + +def qfiletopackage(dep,addpaths): """Converts supplied deps with additional include paths to portage packages This uses qfile to quess which package certain files belongs to. @@ -15,25 +19,25 @@ def deptopackage(dep,addpaths): (statuscode,packagestr) = getstatusoutput("qfile -C " + depname) if not statuscode == 0: - print("something went wrong...") #have it print a more useful error! - return + package = pfltopackage(dep,addpaths) + + else: + packagelst = packagestr.split() + package = [] + n = 0 + for depfile in packagelst[1::2]: + for incpath in incpaths: + if depfile.strip("()") == (incpath + "/" + dep): + package.append(packagelst[n]) + n += 2 - packagelst = packagestr.split() - package = [] - n = 0 - for depfile in packagelst[1::2]: - for incpath in incpaths: - if depfile.strip("()") == (incpath + "/" + dep): - package.append(packagelst[n]) - n += 2 + if len(package) > 1: + print("more than one matching package where found!") - if len(package) > 1: - print("more than one matching package where found!") + if not package: + package = pfltopackage(dep,addpaths) print(package) - if not package: - print("not matching package found within the include paths!") - package = ["dummy"] return package def pfltopackage(dep,addpaths): @@ -41,6 +45,7 @@ def pfltopackage(dep,addpaths): """ + print(dep) incpaths = ["/usr/include", "/usr/local/include"] incpaths += addpaths @@ -61,7 +66,7 @@ def pfltopackage(dep,addpaths): for line in url_lines: #check if path is correct for path in incpaths: - if line[2] + line[3] == path + dep: + if line[2] + "/" + line[3] == path + "/" + dep: matching_packages.add(line[0] + "/" + line[1]) if len(matching_packages) > 1: @@ -71,8 +76,8 @@ def pfltopackage(dep,addpaths): print("no matching package found within the include paths!") print("file not found was: " + dep) print("a dummy dep will be placed in the ebuild, fix it!") - package = ["dummy"] + matching_packages = ["dummy_for_" + dep] - print([matching_packages.pop()]) + return [matching_packages.pop()] #pfltopackage("ncurses.h",[]) diff --git a/scanfiles.py b/scanfiles.py index 584158b..b0cd7aa 100644 --- a/scanfiles.py +++ b/scanfiles.py @@ -111,8 +111,9 @@ def scanautotoolsdeps(acfile,amfile): for usearg in useargs: useargs[usearg] = scanfilelist(useargs[usearg],src_incflag) - print(useargs) - print(includes) + #print(useargs) + #print(includes) + return useflags,includes,useargs def scanfilelist(filelist,src_incflag): """ Scan files in filelist for #includes @@ -143,14 +144,23 @@ def scanproject(dir,projecttype): autotools? makefile? """ if projecttype == "guess": - filestolookfor = ["Makefile","makefile"] #add more later + filestolookfor = ["Makefile","makefile", + "configure.ac","configure.in"] #add more later elif projecttype == "makefile": filestolookfor = ["Makefile","makefile"] + elif projecttype == "autotools": + filestolookfor = ["configure.ac","configure.in"] mfile = scandirfor(dir, filestolookfor)[0] #use first file found print(mfile) - (scanlist,binaries,incflags,targets) = scanmakefiledeps(mfile) - return scanfilelist(scanlist),binaries,incflags,targets + if mfile == "Makefile" or mfile == "makefile": + (scanlist,binaries,incflags,targets) = scanmakefiledeps(mfile) + #this is broken now... rewrite + return scanfilelist(scanlist),binaries,incflags,targets + + else: + amfile = os.path.split(mfile)[0] + "/" + "Makefile.am" + return scanautotoolsdeps(mfile,amfile) def openfile(file): """Open a file and return the content as a string. @@ -162,6 +172,3 @@ def openfile(file): return inputfile.read() 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"])) |