aboutsummaryrefslogtreecommitdiff
blob: 3c456a5ae960906ddf5f61d0e42f083bfcaee111 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/python3

import argparse
import ebuildgen.scanfiles as scanfiles
import ebuildgen.linkdeps  as linkdeps
import ebuildgen.ebuildoutput as ebuildoutput
from ebuildgen.scmprojects import getsourcecode

def cli():
    parser = argparse.ArgumentParser(
            description="Generate ebuilds for autotools projects",
            epilog="Example: genebuild --svn <url>")

    parser.add_argument("url")
    parser.add_argument("-t", "--types", metavar="filetype", nargs="+",
                        default=[".c",".cpp",".h"],
                        help="what filetypes it should scan")
    parser.add_argument("-g", "--ginc", action="store_true",
                        help="print global includes")
    parser.add_argument("-l", "--linc", action="store_true",
                        help="print local includes")
    parser.add_argument("-d", "--ifdef", action="store_true",
                        help="print includes the depends on ifdefs")
    parser.add_argument("-q", "--quiet", action="store_true",
                        help="don't print anything (doesn't work ATM)")  #this needs work...

    parser.add_argument("--svn", action="store_true",
                        help="this is a SVN project")
    parser.add_argument("--git", action="store_true",
                        help="this is a GIT project")
    parser.add_argument("--hg", action="store_true",
                        help="this is a HG project")

    args = parser.parse_args()

    #print(args.url)
    #print(args.types)

    #inclst is a list of includes. First in it is global then local.
    if args.svn:
        getsourcecode(args.url,"svn")
        srcdir = "/tmp/ebuildgen/curproj"
        dltype = "svn"
    elif args.git:
        getsourcecode(args.url,"git")
        srcdir = "/tmp/ebuildgen/curproj"
        dltype = "git"
    elif args.hg:
        getsourcecode(args.url,"hg")
        srcdir = "/tmp/ebuildgen/curproj"
        dltype = "hg"
    else:
        srcdir = args.url
        dltype = "www"

    (iuse,inclst,useargs) = scanfiles.scanproject(srcdir,"autotools")
    targets = [["install"]]
    binaries = []
    gpackages = set()
    for dep in inclst[0]:
        newpack = linkdeps.deptopackage(dep,[])
        if newpack:
            gpackages.add(newpack)
    #print(gpackages)
    if "__cplusplus" in inclst[2]:
        for dep in inclst[2]["__cplusplus"][0]:
            newpack = linkdeps.deptopackage(dep,[])
            if newpack:
                gpackages.add(newpack)

    usedeps = {}
    for use in useargs:
        packages = set()
        for dep in useargs[use][0]:
            newpack = linkdeps.deptopackage(dep,[])
            if newpack and not newpack in gpackages:
                packages.add(newpack)
        if "__cplusplus" in useargs[use][2]:
            for dep in useargs[use][2]["__cplusplus"][0]:
                newpack = linkdeps.deptopackage(dep,[])
                if newpack and not newpack in gpackages:
                    packages.add(newpack)
        usedeps[use] = packages

    #print(usedeps)
    #print(iuse)
    ebuildoutput.genebuild(iuse,gpackages,usedeps,dltype,args.url,targets,binaries)

    if args.ginc == args.linc == args.ifdef == args.quiet == False:
        print(inclst)
        print(gpackages)

    if args.ginc:
        print(inclst[0])
    if args.linc:
        print(inclst[1])

    if args.ifdef:
        for name in inclst[2]:
            print(name)
            print(inclst[2][name][0])
            print(inclst[2][name][1])