Commit 2a6032b
Merge remote-tracking branch 'sch/build-refactoring' Conflicts: dodo.py
Changed files (7)
addedbavala.pymodifiedbirdfont-export.shmodifiedbirdfont.shmodifiedbirdfont/GtkWindow.valamodifieddodo.pymodifiedlibbirdfont/ExportTool.valamodifiedlibbirdfont/Svg.vala
Diff
new file mode 100644@@ -0,0 +1,130 @@+"""bavala is a build-tool for Vala based on doit (http://pydoit.org)"""++import glob+from os.path import join++from doit.action import CmdAction+++def cmd(name, *args):+ """create string for command line"""+ parts = [name]+ for item in args:+ if isinstance(item, basestring):+ parts.append(item)+ elif isinstance(item, dict):+ for param, value in item.iteritems():+ if isinstance(value, basestring):+ value = [value]+ parts.extend('--{0} {1}'.format(param, v) for v in value)+ else:+ parts.extend(item)+ return ' '.join(parts)++++class Vala(object):+ """helper to generate tasks to compile vala code"""++ def __init__(self, src, build, pkg_libs, library=None, vala_deps=None):+ self.src = src+ self.build = build+ self.library = library+ self.pkg_libs = pkg_libs+ self.vala_deps = vala_deps or []++ self.vala = list(glob.glob(src + '/*.vala'))+ self.cc = [join(build, f.replace('.vala', '.c')) for f in self.vala]+ self.obj = [join(build, f.replace('.vala', '.o')) for f in self.vala]+ if library:+ self.header = join(build, library) + '.h'+ self.vapi = join(build, library) + '.vapi'+ self.so = join(build, src) + '.so'+++ def gen_c(self, opts):+ """translate code from vala to C and create .vapi"""+ options = ['--ccode', '--save-temps']+ options.extend(opts)+ params = {+ 'basedir': join(self.build, self.src),+ 'vapidir': './',+ 'pkg': self.pkg_libs,+ }+ if self.library:+ params['library'] = self.library+ params['vapi'] = self.vapi+ params['header'] = self.header++ dep_vapi = [d.vapi for d in self.vala_deps]+ action = cmd('valac', options, params, dep_vapi, self.vala)+ targets = self.cc[:]+ if self.library:+ targets += [self.header, self.vapi]+ return {+ 'name': 'compile_c',+ 'actions': [ action ],+ 'file_dep': self.vala + dep_vapi,+ 'targets': targets,+ }+++ def gen_o(self, opts):+ """compile C files to obj `.o` """+ def compile_cmd(conf, opts, libs, pos):+ flags = [conf[l].strip() for l in libs]+ return cmd('gcc', opts, flags, pos)++ for cc, obj in zip(self.cc, self.obj):+ pos = ["-c " + cc, "-o " + obj ]+ cmd_args = {'libs':self.pkg_libs, 'opts':opts, 'pos':pos}+ action = CmdAction((compile_cmd, [], cmd_args))+ yield {+ 'name': obj.rsplit('/')[-1],+ 'file_dep': [ cc ],+ 'actions': [ action ],+ 'getargs': { 'conf': ('pkg_flags', 'out') },+ 'targets': [ obj ],+ }+++ def gen_so(self):+ """generate ".so" lib file"""+ def compile_cmd(conf, libs):+ obj_glob = join(self.build, self.src, '*.o')+ opts = ['-shared ' + obj_glob,+ '-o ' + self.so ]+ flags = [conf[l].strip() for l in libs]+ return cmd('gcc', opts, flags)++ return {+ 'name': self.so.rsplit('/')[-1],+ 'actions': [ CmdAction((compile_cmd, [], {'libs':self.pkg_libs})) ],+ 'getargs': { 'conf': ('pkg_flags', 'out') },+ 'file_dep': self.obj,+ 'targets': [ self.so ],+ }+++ def gen_bin(self, opts):+ """generate binary"""+ def compile_cmd(conf, opts, libs):+ flags = [conf[l].strip() for l in libs]+ return cmd('gcc', opts, flags)++ bin_path = join(self.build, 'bin')+ target = join(bin_path, self.src)+ opts = (self.cc + opts ++ ['-o ' + target, '-I ' + self.build, '-L ' + self.build] ++ ['-l ' + d.library for d in self.vala_deps])+ action = CmdAction((compile_cmd, [], {'opts':opts, 'libs':self.pkg_libs}))+ yield {+ 'name': "bin",+ 'actions': [ 'mkdir -p %s' % bin_path, action ],+ 'getargs': { 'conf': ('pkg_flags', 'out') },+ 'file_dep': self.cc + [ d.so for d in self.vala_deps ],+ 'targets': [ target ],+ }+++@@ -1,4 +1,4 @@ export LD_LIBRARY_PATH="./build/:$LD_LIBRARY_PATH" PKG_PATH=$(dirname "$(readlink -f "$0")") cd "${PKG_PATH}"-./build/birdfont-export $*+./build/bin/birdfont-export $*@@ -1,4 +1,4 @@ export LD_LIBRARY_PATH="./build/:$LD_LIBRARY_PATH" PKG_PATH=$(dirname "$(readlink -f "$0")") cd "${PKG_PATH}"-./build/birdfont $*+./build/bin/birdfont $*@@ -293,7 +293,11 @@ public class GtkWindow : Gtk.Window, NativeWindow { edit_menu.append (paste_item); paste_item.activate.connect (() => { ClipTool.paste (); }); paste_item.add_accelerator ("activate", accel_group, 'V', Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE);- ++ Gtk.MenuItem export_svg_item = new Gtk.MenuItem.with_mnemonic (_("_Export glyph as SVG"));+ edit_menu.append (export_svg_item);+ export_svg_item.activate.connect (() => { SvgFile.export (); }); + // Tab Gtk.MenuItem next_tab_item = new Gtk.MenuItem.with_mnemonic (_("_Next tab")); tab_menu.append (next_tab_item);@@ -1,44 +1,24 @@-import subprocess import os+import glob+import subprocess from doit.tools import run_once from doit.action import CmdAction+from bavala import Vala -############ helpers--def cmd(name, *args):- """create string for command line"""- parts = [name]- for item in args:- if isinstance(item, basestring):- parts.append(item)- elif isinstance(item, dict):- for param, value in item.iteritems():- if isinstance(value, basestring):- value = [value]- parts.extend('--{0} {1}'.format(param, v) for v in value)- else:- parts.extend(item)- return ' '.join(parts)---###############################################- DOIT_CONFIG = {- 'verbosity': 2, 'default_tasks': [ 'build',+ 'libbirdfont', 'birdfont', 'birdfont_export',- 'libbirdfont_c',- 'libbirdfont_o',- 'libbirdfont_so', 'compile_translations', 'man' ], } +# external Vala libs LIBS = [ 'glib-2.0', 'libxml-2.0',@@ -50,17 +30,6 @@ LIBS = [ ] -def task_pkg_flags():- """get compiler flags for libs/pkgs """- for pkg in LIBS:- cmd = 'pkg-config --cflags --libs {pkg}'- yield {- 'name': pkg,- 'actions': [CmdAction(cmd.format(pkg=pkg), save_out='out')],- 'uptodate': [run_once],- }-- def task_build (): if not os.path.exists ("build/configured"): print ("Project is not configured")@@ -73,188 +42,65 @@ def task_build (): 'actions': ['echo "Build"'], } -def task_libbirdfont_c ():- """translate code from vala to C and create .vapi"""- options = [- '--ccode', # output C code- '--enable-experimental-non-null',- '--thread',- '--save-temps',- ]-- # include binding for pakages- params = {- 'basedir': './build/libbirdfont',- 'vapidir': './',- 'library': 'birdfont',- 'vapi': './build/birdfont.vapi',- 'header': './build/birdfont.h',- 'pkg': ['gtk+-2.0', 'libxml-2.0', 'webkit-1.0'],- }-- actions = [ cmd('valac', options, params, 'libbirdfont/*.vala') ]-- libbirdfont_sources = os.listdir('libbirdfont/')- file_dep = ["libbirdfont/" + f for f in libbirdfont_sources]- targets = ["build/" + f.replace('.vala', '.c') for f in file_dep]- targets.extend([ 'build/birdfont.h', 'build/birdfont.vapi'])- return {- 'actions': actions,- 'file_dep': file_dep,- 'targets': targets,- }----def compile_cmd(conf, pos, libs):- opts = ['-fPIC', """-D 'GETTEXT_PACKAGE="birdfont"'"""]- flags = [conf[l].strip() for l in LIBS]- return cmd('gcc', opts, flags, pos)-def task_libbirdfont_o ():- """compile C files to obj `.o` """- for vala in os.listdir('libbirdfont/'):- cee = vala.replace ('.vala', '.c')- obj = vala.replace ('.vala', '.o')- pos = ["-c build/libbirdfont/" + cee,- "-o build/libbirdfont/" + obj,- ]+def task_pkg_flags():+ """get compiler flags for libs/pkgs """+ for pkg in LIBS:+ cmd = 'pkg-config --cflags --libs {pkg}' yield {- 'name': obj,- 'file_dep': [ 'build/libbirdfont/' + cee ],- 'actions': [ CmdAction((compile_cmd, [], {'pos':pos, 'libs':LIBS}))],- 'getargs': { 'conf': ('pkg_flags', 'out') },- 'targets': [ 'build/libbirdfont/' + obj ],+ 'name': pkg,+ 'actions': [CmdAction(cmd.format(pkg=pkg), save_out='out')],+ 'uptodate': [run_once], } -def task_libbirdfont_so ():- action = """gcc -shared build/libbirdfont/*.o \- $(pkg-config --cflags --libs glib-2.0) \- $(pkg-config --cflags --libs libxml-2.0) \- $(pkg-config --cflags --libs gio-2.0) \- $(pkg-config --cflags --libs libsoup-2.4) \- $(pkg-config --cflags --libs cairo) \- $(pkg-config --cflags --libs gdk-pixbuf-2.0) \- $(pkg-config --cflags --libs webkit-1.0) \- -o build/libbirdfont.so""" - return {- 'actions': [ action ],- 'file_dep': [ 'build/libbirdfont/Config.c' ],- 'targets': [ 'build/libbirdfont.so' ],- 'task_dep': ['libbirdfont_o'],- }+libbird = Vala(src='libbirdfont', build='build', library='birdfont', pkg_libs=LIBS)+def task_libbirdfont():+ yield libbird.gen_c(['--enable-experimental-non-null', '--thread'])+ yield libbird.gen_o(['-fPIC', """-D 'GETTEXT_PACKAGE="birdfont"'"""])+ yield libbird.gen_so() -def task_birdfont ():- birdfont_sources = os.listdir('birdfont/')-- files = []- for f in birdfont_sources:- files += ["birdfont/" + f]- files.append('build/birdfont.vapi')-- options = ['--ccode']- params = {- 'basedir': './build/main',- 'pkg': ['gtk+-2.0', 'libxml-2.0', 'gdk-2.0', 'webkit-1.0'],- }-- yield {- 'name': 'compile_birdfont_executable',- 'actions': [ cmd('valac', options, params,- './build/birdfont.vapi', './birdfont/*.vala') ],- 'file_dep': files,- 'targets': [ 'build/main/Main.c', 'build/main/GtkWindow.c' ],- } - build_action = """gcc ./build/main/*.c \- -D 'GETTEXT_PACKAGE="birdfont"' \- -I ./build/ -L ./build -l birdfont \- -o ./build/birdfont \- $(pkg-config --cflags --libs glib-2.0) \- $(pkg-config --cflags --libs libxml-2.0) \- $(pkg-config --cflags --libs gio-2.0) \- $(pkg-config --cflags --libs libsoup-2.4) \- $(pkg-config --cflags --libs gtk+-2.0) \- $(pkg-config --cflags --libs webkit-1.0)"""-- yield {- 'name': "build_birdfont_executable",- 'actions': [ build_action ],- 'file_dep': [ 'build/main/Main.c', 'build/libbirdfont.so'],- 'targets': [ 'build/birdfont' ],- }+def task_birdfont ():+ bird = Vala(src='birdfont', build='build', pkg_libs=LIBS, vala_deps=[libbird])+ yield bird.gen_c([])+ yield bird.gen_bin(["""-D 'GETTEXT_PACKAGE="birdfont"' """]) def task_birdfont_export ():- birdfont_sources = os.listdir('birdfont-export/')+ exp = Vala(src='birdfont-export', build='build', pkg_libs=LIBS,+ vala_deps=[libbird])+ yield exp.gen_c([])+ yield exp.gen_bin(["""-D 'GETTEXT_PACKAGE="birdfont"' """]) - files = []- for f in birdfont_sources:- files += ["birdfont-export/" + f]-- action = """valac \- --basedir ./build/export \- -C ./build/birdfont.vapi \- ./birdfont-export/*.vala \- -X ../build/libbirdfont/libbirdfont.so -X ./build/birdfont.h \- --pkg gtk+-2.0 --pkg libxml-2.0 --pkg gdk-2.0 --pkg webkit-1.0"""-- yield {- 'name': 'compile_birdfont_export_executable',- 'actions': [ action ],- 'file_dep': files,- 'targets': [ 'build/export/BirdfontExport.c' ],- 'task_dep': ['libbirdfont_o'],- } - build_action = """gcc ./build/main/*.c \- -D 'GETTEXT_PACKAGE="birdfont"' \- -I ./build -L ./build -l birdfont \- -o ./build/birdfont-export \- $(pkg-config --cflags --libs glib-2.0) \- $(pkg-config --cflags --libs libxml-2.0) \- $(pkg-config --cflags --libs gio-2.0) \- $(pkg-config --cflags --libs libsoup-2.4) \- $(pkg-config --cflags --libs gtk+-2.0) \- $(pkg-config --cflags --libs webkit-1.0)""" - yield {- 'name': "build_birdfont_export_executable",- 'actions': [ build_action ],- 'file_dep': [ 'build/export/BirdfontExport.c' ],- 'targets': [ 'build/birdfont-export' ],- } def task_compile_translations ():- for file in os.listdir('./po'):- if file == "birdfont.pot": continue-- loc = file.replace (".po", "")-+ """translate po files"""+ for f_name in glob.glob('po/*.po'):+ lang = os.path.relpath(f_name)[:-3] # remove ".po"+ build_path = "build/locale/" + lang + "/LC_MESSAGES/"+ target = build_path + "birdfont.mo"+ cmd = "msgfmt --output=%s %s" % (target, f_name) yield {- 'name': loc + "_dir",- 'actions': ["mkdir -p build/locale/" + loc + "/LC_MESSAGES/"],- 'targets': [ "build/locale/" + loc + "/LC_MESSAGES/" ]+ 'name': lang,+ 'actions': ["mkdir -p " + build_path, cmd],+ 'file_dep': [f_name],+ 'targets': [ target ], } +def task_man():+ """gzip linux man pages"""+ for name in ("birdfont.1", "birdfont-export.1"): yield {- 'name': loc + "_msgfmt",- 'actions': ["msgfmt --output=build/locale/" + loc + "/LC_MESSAGES/birdfont.mo ./po/" + loc + ".po"],- 'targets': [ "build/locale/" + loc + "/LC_MESSAGES/birdfont.mo" ]+ 'name': name,+ 'file_dep': ['linux/%s' % name],+ 'targets': ['build/%s.gz' % name],+ 'actions': ["gzip -9 -c %(dependencies)s > %(targets)s"], } -def task_man ():- yield {- 'name': "birdfont.1",- 'actions': ["gzip -9 -c ./linux/birdfont.1 > build/birdfont.1.gz"],- }-- yield {- 'name': "birdfont-export.1",- 'actions': ["gzip -9 -c ./linux/birdfont-export.1 > build/birdfont-export.1.gz"],- } def task_distclean (): return {@@ -68,69 +68,6 @@ public class ExportTool : Tool { return true; } - public void export_glyph_to_svg () {- Glyph glyph = MainWindow.get_current_glyph ();- Font font = Supplement.get_current_font ();- FontDisplay fd = MainWindow.get_current_display ();- string glyph_svg;- string svg_file = @"$(glyph.get_name ()).svg";- File file = font.get_folder ().get_child (svg_file);- DataOutputStream os;- string name = glyph.get_name ();- int pid = 0;- - if (!(fd is Glyph)) {- return;- }- - try {- - if (file.query_exists ()) {- file.delete ();- }- - os = new DataOutputStream (file.create(FileCreateFlags.REPLACE_DESTINATION)); - - _("Alphabet");- - os.put_string (-"""<?xml version="1.0" standalone="no"?>-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >-<svg """);-- os.put_string (@"xmlns=\"http://www.w3.org/2000/svg\"\n");- os.put_string (@"\twidth=\"$(glyph.get_width () / Glyph.SCALE)\"\n");- os.put_string (@"\theight=\"$(glyph.get_height () / Glyph.SCALE)\"\n");- os.put_string (@"\tid=\"glyph_$(name)\"\n");- os.put_string (@"\tversion=\"1.1\">\n");- - os.put_string (@"\n");- - os.put_string (@"<g id=\"$(name)\">\n");- - foreach (Path p in glyph.path_list) {- - glyph_svg = Svg.to_svg_path (p, glyph);- - os.put_string (@"<path ");- os.put_string (@"style=\"fill:#000000;stroke-width:0px\" ");- os.put_string (@"d=\"$(glyph_svg)\" id=\"path_$(name)$(pid++)\" />\n");- - }- - os.put_string ("""</g>- -</svg>""");- - } catch (Error e) {- stderr.printf (@"Export \"$svg_file\" \n");- critical (@"$(e.message)");- status (_("Can't export") + @" $svg_file.");- }- - status (_("Wrote") + @" $svg_file.");- }- public static void generate_html_document (string html_file, Font font) { File file = File.new_for_path (html_file); DataOutputStream os;@@ -32,7 +32,7 @@ class Svg { return svg.str; } - /** Export to regular svg path data. */+ /** Export to svg-font data. */ public static string to_svg_path (Path pl, Glyph g, double scale = 1) { StringBuilder svg = new StringBuilder (); pl.create_list ();@@ -91,11 +91,15 @@ class Svg { private static void add_abs_start (EditPoint ep, StringBuilder svg, Glyph g, bool do_glyph, double scale = 1) { double left = g.left_limit; double baseline = Supplement.get_current_font ().base_line;+ double height = Supplement.get_current_font ().get_height (); // no probably not svg.append_printf ("M"); - svg.append_printf ("%s ", round ((ep.x - left) * scale));- svg.append_printf ("%s ", round ((ep.y + baseline) * scale));+ //svg.append_printf ("%s ", round ((ep.x - left) * scale));+ //svg.append_printf ("%s ", round ((ep.y + baseline) * scale));+ + svg.append_printf ("%s ", round ((ep.x - Glyph.xc () - left) * scale));+ svg.append_printf ("%s ", round ((ep.y - Glyph.yc () - baseline + height) * scale)); } private static void close_path (StringBuilder svg) {