Exemplo n.º 1
0
    def writeRuntime(self, prog):
        p = prog.name
        pc = '%s/%s-runtime.c' % (p,prog.prefix)
        ph = '%s/%s-runtime.h' % (p,prog.prefix)
        with self.buildSystem.fileFor(pc) as f:
            self.writeHeader(prog, pc, f)
            t = templateFor('runtime.c.tmpl')
            d = t.render(program=prog)
            f.write(d.strip())

        with self.buildSystem.fileFor(ph) as f:
            self.writeHeader(prog, ph, f)
            t = templateFor('runtime.h.tmpl')
            d = t.render(program=prog)
            f.write(d.strip())
Exemplo n.º 2
0
    def writeClass(self, prog, klass):
        pc = '%s/%s-%s.c' % (prog.name, prog.prefix, klass.name)
        ph = '%s/%s-%s.h' % (prog.name, prog.prefix, klass.name)

        klass.prepare()

        for prop in klass.properties.itervalues():
            prop.prepare()

            t = None

            if prop.type_name == 'string':
                prop.field_type = 'gchar*'
                t = templateFor('prop-string.c')
            elif prop.type_name == 'string[]':
                prop.field_type = 'gchar**'
                t = templateFor('prop-string-array.c')
            elif prop.type_name in WORD_TYPES:
                if prop.type_name[0].lower() != 'g':
                    prop.field_type = 'g' + prop.type_name
                else:
                    prop.field_type = prop.type_name
                t = templateFor('prop-gwords.c')
            else:
                print 'missing type info for property', prop.name
                prop.field_type = 'gpointer'

            if t:
                state = {}
                d = t.render(program=prog, klass=klass, prop=prop, state=state)
                prop.rendered = d
                prop.prototype = state.get('prototype')
            else:
                prop.rendered = ''
                prop.prototype = ''

        with self.buildSystem.fileFor(pc) as f:
            self.writeHeader(prog, pc, f)
            t = templateFor('class.c')
            d = t.render(program=prog, klass=klass)
            f.write(d)

        with self.buildSystem.fileFor(ph) as f:
            self.writeHeader(prog, ph, f)
            t = templateFor('class.h')
            d = t.render(program=prog, klass=klass)
            f.write(d)
Exemplo n.º 3
0
    def writeStruct(self, prog, klass):
        pc = '%s/%s-%s.c' % (prog.name, prog.prefix, klass.name)
        ph = '%s/%s-%s.h' % (prog.name, prog.prefix, klass.name)

        klass.prepare()

        with self.buildSystem.fileFor(pc) as f:
            self.writeHeader(prog, pc, f)
            t = templateFor('struct.c')
            d = t.render(program=prog, klass=klass)
            f.write(d)

        with self.buildSystem.fileFor(ph) as f:
            self.writeHeader(prog, ph, f)
            t = templateFor('struct.h')
            d = t.render(program=prog, klass=klass)
            f.write(d)
Exemplo n.º 4
0
 def writeMain(self, prog):
     p = '%s/main.c' % (prog.name,)
     with self.buildSystem.fileFor(p) as f:
         def w(*a):
             f.write(' '.join(a) + '\n')
         self.writeHeader(prog, p, f)
         t = templateFor('main.c')
         d = t.render(project=self.project, program=prog)
         w(d)
Exemplo n.º 5
0
    def writeHeader(self, prog, name, stream):
        def w(*a):
            stream.write(' '.join(a) + '\n')
        if prog.license:
            l = prog.license + '.header'
            t = templateFor(l)
            lines = t.render(author='Christian Hergert',
                             year=time.strftime('%Y'),
                             filename=os.path.split(name)[-1]).strip()
            lines = lines.split('\n')
            w('/* ' + '\n * '.join(lines) + '\n */')
	#elif self.project.license:
	#    pass
        else:
            w('/* ', os.path.split(name)[-1], '*/')
        w('')
Exemplo n.º 6
0
    def complete(self):
        with self.fileFor("AUTHORS") as f:
            # I don't particularly need anyone else, but maybe
            # it would be nice to support it someday :-)
            f.write("Christian Hergert <*****@*****.**>\n")

        with self.fileFor("ChangeLog") as f:
            date = time.strftime("%Y-%m-%d")
            f.write("%s\tChristian Hergert\t<*****@*****.**>\n" % date)
            f.write("\n")
            f.write("\t* .: The ChangeLog is obsolete.  Please use `git log'\n")
            f.write("\tfor information on changes.\n")
            f.write("\n")

        with self.fileFor("autogen.sh", mode="rwx") as f:
            t = templateFor("autogen.sh")
            d = t.render(**{"project": self.project})
            f.write(d.strip())

        # project wide license
        if self.project.license:
            d = self.getLicenseData(self.project.license)
            self.fileFor("COPYING").write(d)

        # add special licenses if necessary
        items = [(p.name, p.license) for p in self.project.programs.itervalues()]
        items.extend([(p.name, p.license) for p in self.project.libraries.itervalues()])
        for name, license in items:
            if license != self.project.license:
                with self.fileFor("COPYING." + name) as f:
                    d = self.getLicenseData(license)
                    f.write(d)

        self.fileFor("NEWS").write("")
        self.fileFor("README").write("")

        # copy over some build system files
        self.copyTo("acinclude.m4", "acinclude.m4")
        self.copyTo("shave.in", "build/shave.in")
        self.copyTo("shave-libtool.in", "build/shave-libtool.in")
        self.copyTo("expansions.m4", "build/m4/expansions.m4")

        # build our configure script
        self.addConfigure()

        # setup unit testing
        self.addTests()

        # setup our programs
        for prog in self.project.programs.itervalues():
            self.addMakefile(prog)
            self.addDocs(prog)

        # doc toplevel makefile
        with self.fileFor("doc/Makefile.am") as f:
            subdirs = " ".join([t[2] for t in self.subdirsIn("doc")])
            f.write("SUBDIRS = " + subdirs + "\n")

        if "doc:gtk" in self.features:
            with self.fileFor("doc/reference/Makefile.am") as f:
                subdirs = " ".join([t[3] for t in self.subdirsIn("doc/reference")])
                f.write("SUBDIRS = " + subdirs + "\n")

        with self.fileFor("data/Makefile.am") as f:
            if "dbus" in self.features:
                f.write("SUBDIRS = dbus\n")

        if "dbus" in self.features:
            f = self.fileFor("data/dbus/Makefile.am")
            f.write("EXTRA_DIST = \\\n\t")
            for klass in self.project.classes:
                pn = "com.dronelabs.%s.%s" % (prog.name.split("-")[0].capitalize(), klass.camel_name)
                f.write("%s.xml \\\n\t" % pn)
                with self.fileFor("data/dbus/" + pn + ".xml") as fx:
                    fx.write('<?xml version="1.0" ?>\n')
                    fx.write(
                        """<node>
  <interface name="%(objname)s">
    <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="%(lower_prefix)s"/>\n"""
                        % {"objname": pn, "lower_prefix": prog.lower_name + "_" + klass.lower_name}
                    )
                    if klass.properties:
                        fx.write("\n    <!-- Properties -->\n")
                    for prop in klass.properties.itervalues():
                        if prop.type_name == "string":
                            fx.write('    <property name="%s" type="s" access="readwrite" />\n' % prop.camel_name)
                        elif prop.type_name == "int":
                            fx.write('    <property name="%s" type="u" access="readwrite" />\n' % prop.camel_name)
                        elif prop.type_name == "string[]":
                            fx.write('    <property name="%s" type="as" access="readwrite" />\n' % prop.camel_name)

                    if klass.methods:
                        fx.write("\n    <!-- Methods -->\n")
                        for method in klass.methods:
                            fx.write('    <method name="%s">\n' % method.name.capitalize())
                            fx.write(
                                '      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="%s_%s_%s_dbus"/>\n'
                                % (prog.lower_name, klass.lower_name, method.name.lower())
                            )
                            fx.write("    </method>\n")
                    fx.write("  </interface>\n</node>\n")
            f.write("$(NULL)\n")

        # main makefile
        self.addToplevelMakefile()