From: Florian Brosch Date: Tue, 15 Feb 2011 02:13:00 +0000 (+0100) Subject: doclets/gtkdoc: Use ErrorReporter instead of GLib.warning X-Git-Tag: 0.37.1~3^2~392 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0aa1118caae88f7154dfd54641630e7bc5e60de;p=thirdparty%2Fvala.git doclets/gtkdoc: Use ErrorReporter instead of GLib.warning --- diff --git a/src/doclets/gtkdoc/commentconverter.vala b/src/doclets/gtkdoc/commentconverter.vala index 73798780e..881db2c2e 100644 --- a/src/doclets/gtkdoc/commentconverter.vala +++ b/src/doclets/gtkdoc/commentconverter.vala @@ -37,9 +37,11 @@ public class Gtkdoc.CommentConverter : ContentVisitor { private StringBuilder current_builder = new StringBuilder (); private bool in_brief_comment = true; + private ErrorReporter reporter; - public CommentConverter (Api.Node? node_reference = null) { + public CommentConverter (ErrorReporter reporter, Api.Node? node_reference = null) { this.node_reference = node_reference; + this.reporter = reporter; } public void convert (Comment comment, bool is_dbus = false) { @@ -75,7 +77,7 @@ public class Gtkdoc.CommentConverter : ContentVisitor { public override void visit_headline (Headline hl) { // what to do here? - warning ("GtkDoc: Headline elements not supported"); + reporter.simple_warning ("GtkDoc: Headline elements not supported"); current_builder.append ("\n"); hl.accept_children (this); current_builder.append ("\n"); @@ -133,7 +135,7 @@ public class Gtkdoc.CommentConverter : ContentVisitor { break; default: - warning ("GtkDoc: unsupported list type: %s", list.bullet.to_string ()); + reporter.simple_warning ("GtkDoc: unsupported list type: %s".printf (list.bullet.to_string ())); break; } @@ -255,7 +257,7 @@ public class Gtkdoc.CommentConverter : ContentVisitor { } else if (t is Taglets.Link) { ((Taglets.Link)t).produce_content().accept (this); } else { - warning ("GtkDoc: Taglet not supported"); // TODO + reporter.simple_warning ("GtkDoc: Taglet not supported"); // TODO } current_builder = (owned)old_builder; } diff --git a/src/doclets/gtkdoc/dbus.vala b/src/doclets/gtkdoc/dbus.vala index 992dc4ae9..45c8198f8 100644 --- a/src/doclets/gtkdoc/dbus.vala +++ b/src/doclets/gtkdoc/dbus.vala @@ -135,22 +135,22 @@ namespace Gtkdoc.DBus { return to_docbook_id (name); } - public bool write (Settings settings) { + public bool write (Settings settings, ErrorReporter reporter) { var xml_dir = Path.build_filename (settings.path, "xml"); DirUtils.create_with_parents (xml_dir, 0777); var xml_file = Path.build_filename (xml_dir, "%s.xml".printf (to_docbook_id (name))); var writer = new TextWriter (xml_file, "w"); if (!writer.open ()) { - warning ("GtkDoc: unable to open %s for writing", writer.filename); + reporter.simple_error ("GtkDoc: unable to open %s for writing".printf (writer.filename)); return false; } - writer.write_line (to_string ()); + writer.write_line (to_string (reporter)); writer.close (); return true; } - public string to_string () { + public string to_string (ErrorReporter reporter) { /* compute minimum indent for methods */ var method_indent = 0; foreach (var method in methods) { @@ -236,7 +236,7 @@ namespace Gtkdoc.DBus { %s %s -""", docbook_id, method.get_docbook_id (), method.name, method.to_string (method_indent, false), method.comment != null ? method.comment.to_docbook () : ""); +""", docbook_id, method.get_docbook_id (), method.name, method.to_string (method_indent, false), method.comment != null ? method.comment.to_docbook (reporter) : ""); } builder.append (""); @@ -257,7 +257,7 @@ namespace Gtkdoc.DBus { %s %s -""", docbook_id, sig.get_docbook_id (), sig.name, sig.to_string (signal_indent, false), sig.comment != null ? sig.comment.to_docbook () : ""); +""", docbook_id, sig.get_docbook_id (), sig.name, sig.to_string (signal_indent, false), sig.comment != null ? sig.comment.to_docbook (reporter) : ""); } builder.append (""); @@ -267,4 +267,4 @@ namespace Gtkdoc.DBus { return builder.str; } } -} \ No newline at end of file +} diff --git a/src/doclets/gtkdoc/doclet.vala b/src/doclets/gtkdoc/doclet.vala index f56b1bea4..8891aa20c 100644 --- a/src/doclets/gtkdoc/doclet.vala +++ b/src/doclets/gtkdoc/doclet.vala @@ -41,7 +41,7 @@ namespace Gtkdoc.Config { { null } }; - public static bool parse (string[] rargs) { + public static bool parse (string[] rargs, ErrorReporter reporter) { string[] args = { "gtkdoc" }; foreach (var arg in rargs) { args += arg; @@ -54,8 +54,7 @@ namespace Gtkdoc.Config { unowned string[] gtkdoc_args = args; opt_context.parse (ref gtkdoc_args); } catch (OptionError e) { - warning ("GtkDoc: Error: %s", e.message); - warning ("GtkDoc: Run '-X --help' to see a full list of available command line options.\n"); + reporter.simple_error ("GtkDoc: Error: %s\nRun '-X --help' to see a full list of available command line options.".printf (e.message)); return false; } @@ -91,7 +90,7 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { */ public void process (Settings settings, Api.Tree tree, ErrorReporter reporter) { this.settings = settings; - if (!Config.parse (settings.pluginargs)) { + if (!Config.parse (settings.pluginargs, reporter)) { return; } this.reporter = reporter; @@ -107,7 +106,7 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { find_files (ccomments_dir); if (vala_headers.length <= 0) { - warning ("GtkDoc: No vala header found"); + reporter.simple_error ("GtkDoc: No vala header found"); return; } @@ -127,7 +126,7 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { Path.build_filename (settings.path, "%s-sections.txt".printf (settings.pkg_name))); generator = new Gtkdoc.Generator (); - if (!generator.execute (settings, tree)) { + if (!generator.execute (settings, tree, reporter)) { return; } @@ -147,7 +146,7 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { private void prepare_external_c_files (Api.Tree tree, string comments_dir) { foreach (string filename in tree.get_external_c_files ()) { if (!copy_file (filename, Path.build_filename (comments_dir, Path.get_basename (filename)))) { - warning ("GtkDoc: Can't copy %s", filename); + reporter.simple_error ("GtkDoc: Can't copy %s".printf (filename)); return ; } } @@ -161,7 +160,7 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { try { dir = Dir.open (dirname); } catch (Error e) { - warning ("GtkDoc: Can't open %s: %s", settings.basedir, e.message); + reporter.simple_error ("GtkDoc: Can't open %s: %s".printf (settings.basedir, e.message)); return; } @@ -194,9 +193,10 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { } string[] args = { "gtkdoc-scan", - "--module", settings.pkg_name, - "--output-dir", output_dir, - "--rebuild-sections", "--rebuild-types" }; + "--module", settings.pkg_name, + "--output-dir", output_dir, + "--rebuild-sections", + "--rebuild-types" }; foreach (var header in headers) { args += header; @@ -215,7 +215,7 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { try { Process.spawn_sync (settings.path, args, null, SpawnFlags.SEARCH_PATH, null, null, null); } catch (Error e) { - warning ("gtkdoc-scan: %s", e.message); + reporter.simple_error ("gtkdoc-scan: %s".printf (e.message)); return false; } @@ -231,7 +231,7 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { string[] pc = { "pkg-config" }; foreach (var package in tree.get_package_list()) { - if (package.is_package && package_exists (package.name)) { + if (package.is_package && package_exists (package.name, reporter)) { pc += package.name; } } @@ -248,7 +248,7 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { string cflags; Process.spawn_sync (null, pc_cflags, null, SpawnFlags.SEARCH_PATH, null, out cflags, out stderr, out status); if (status != 0) { - warning ("GtkDoc: pkg-config cflags error: %s\n", stderr); + reporter.simple_error ("GtkDoc: pkg-config cflags error: %s".printf (stderr)); return false; } cflags = cflags.strip (); @@ -256,7 +256,7 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { string libs; Process.spawn_sync (null, pc_libs, null, SpawnFlags.SEARCH_PATH, null, out libs, out stderr, out status); if (status != 0) { - warning ("GtkDoc: pkg-config libs error: %s\n", stderr); + reporter.simple_error ("GtkDoc: pkg-config libs error: %s".printf (stderr)); return false; } @@ -268,11 +268,11 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { "--output-dir", settings.path }; string[] env = { "CFLAGS=%s %s".printf (cflags, - Environment.get_variable ("CFLAGS") ?? ""), - "LDFLAGS=%s %s %s".printf (libs, library, - Environment.get_variable ("LDFLAGS") ?? ""), - "LD_LIBRARY_PATH=%s:%s".printf (Path.get_dirname (library), - Environment.get_variable ("LD_LIBRARY_PATH") ?? "")}; + Environment.get_variable ("CFLAGS") ?? ""), + "LDFLAGS=%s %s %s".printf (libs, library, + Environment.get_variable ("LDFLAGS") ?? ""), + "LD_LIBRARY_PATH=%s:%s".printf (Path.get_dirname (library), + Environment.get_variable ("LD_LIBRARY_PATH") ?? "")}; foreach (var evar in Environment.list_variables()) { if (evar != "CFLAGS" && evar != "LDFLAGS" && evar != "LD_LIBRARY_PATH") env += "%s=%s".printf (evar, Environment.get_variable(evar)); @@ -280,7 +280,7 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { Process.spawn_sync (settings.path, args, env, SpawnFlags.SEARCH_PATH, null, null, null); } catch (Error e) { - warning ("gtkdoc-scangobj: %s", e.message); + reporter.simple_error ("gtkdoc-scangobj: %s".printf (e.message)); return false; } @@ -293,18 +293,17 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { var must_update_main_file = !FileUtils.test (main_file, FileTest.EXISTS); var args = new string[] { "gtkdoc-mkdb", - "--module", settings.pkg_name, - "--source-dir", code_dir, - "--output-format", "xml", - "--sgml-mode", - "--main-sgml-file", "%s-docs.xml".printf (settings.pkg_name), - "--name-space", settings.pkg_name }; + "--module", settings.pkg_name, + "--source-dir", code_dir, + "--output-format", "xml", + "--sgml-mode", + "--main-sgml-file", "%s-docs.xml".printf (settings.pkg_name), + "--name-space", settings.pkg_name }; try { - Process.spawn_sync (settings.path, args, - null, SpawnFlags.SEARCH_PATH, null, null, null); + Process.spawn_sync (settings.path, args, null, SpawnFlags.SEARCH_PATH, null, null, null); } catch (Error e) { - warning ("gtkdoc-mkdb: %s", e.message); + reporter.simple_error ("gtkdoc-mkdb: %s".printf (e.message)); return false; } @@ -314,7 +313,7 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { try { FileUtils.get_contents (main_file, out contents); } catch (Error e) { - warning ("GtkDoc: Error while reading main file '%s' contents: %s", main_file, e.message); + reporter.simple_error ("GtkDoc: Error while reading main file '%s' contents: %s".printf (main_file, e.message)); return false; } @@ -346,7 +345,7 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { try { FileUtils.set_contents (main_file, contents); } catch (Error e) { - warning ("GtkDoc: Error while writing main file '%s' contents: %s", main_file, e.message); + reporter.simple_error ("GtkDoc: Error while writing main file '%s' contents: %s".printf (main_file, e.message)); return false; } } @@ -364,24 +363,24 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { try { Process.spawn_sync (html_dir, - {"gtkdoc-mkhtml", - settings.pkg_name, "../%s-docs.xml".printf (settings.pkg_name)}, - null, SpawnFlags.SEARCH_PATH, null, null, null); + {"gtkdoc-mkhtml", + settings.pkg_name, "../%s-docs.xml".printf (settings.pkg_name)}, + null, SpawnFlags.SEARCH_PATH, null, null, null); } catch (Error e) { - warning ("gtkdoc-mkhtml: %s", e.message); + reporter.simple_error ("gtkdoc-mkhtml: %s".printf (e.message)); return false; } /* fix xrefs for regenerated html */ try { Process.spawn_sync (settings.path, - { "gtkdoc-fixxref", - "--module", settings.pkg_name, - "--module-dir", html_dir, - "--html-dir", html_dir }, - null, SpawnFlags.SEARCH_PATH, null, null, null); + { "gtkdoc-fixxref", + "--module", settings.pkg_name, + "--module-dir", html_dir, + "--html-dir", html_dir }, + null, SpawnFlags.SEARCH_PATH, null, null, null); } catch (Error e) { - warning ("gtkdoc-fixxref: %s", e.message); + reporter.simple_error ("gtkdoc-fixxref: %s".printf (e.message)); return false; } @@ -391,7 +390,7 @@ public class Gtkdoc.Director : Valadoc.Doclet, Object { [ModuleInit] public Type register_plugin (GLib.TypeModule module) { - return typeof ( Gtkdoc.Director ); + return typeof (Gtkdoc.Director); } diff --git a/src/doclets/gtkdoc/gcomment.vala b/src/doclets/gtkdoc/gcomment.vala index 35bc2319b..6e686fa8a 100644 --- a/src/doclets/gtkdoc/gcomment.vala +++ b/src/doclets/gtkdoc/gcomment.vala @@ -128,7 +128,7 @@ public class Gtkdoc.GComment { return builder.str; } - public string to_docbook () { + public string to_docbook (Valadoc.ErrorReporter reporter) { /* * FIXME: this is not how it should be. * The real solution is to create a comment like gtkdoc-mkdb does. @@ -149,7 +149,7 @@ public class Gtkdoc.GComment { } else if (header.name == "Since") { since = header.value; } else { - warning ("GtkDoc: Unknown versioning tag '%s'", header.name); + reporter.simple_warning ("GtkDoc: Unknown versioning tag '%s'".printf (header.name)); } } diff --git a/src/doclets/gtkdoc/generator.vala b/src/doclets/gtkdoc/generator.vala index af91212a8..97e0c3089 100644 --- a/src/doclets/gtkdoc/generator.vala +++ b/src/doclets/gtkdoc/generator.vala @@ -35,6 +35,7 @@ public class Gtkdoc.Generator : Api.Visitor { public Gee.List dbus_interfaces = new Gee.LinkedList(); + private ErrorReporter reporter; private Settings settings; private Gee.Map files_data = new Gee.HashMap(); private string current_cname; @@ -57,8 +58,9 @@ public class Gtkdoc.Generator : Api.Visitor { } } - public bool execute (Settings settings, Api.Tree tree) { + public bool execute (Settings settings, Api.Tree tree, ErrorReporter reporter) { this.settings = settings; + this.reporter = reporter; tree.accept (this); var code_dir = Path.build_filename (settings.path, "ccomments"); var sections = Path.build_filename (settings.path, "%s-sections.txt".printf (settings.pkg_name)); @@ -66,7 +68,7 @@ public class Gtkdoc.Generator : Api.Visitor { var sections_writer = new TextWriter (sections, "a"); if (!sections_writer.open ()) { - warning ("GtkDoc: unable to open %s for writing", sections_writer.filename); + reporter.simple_error ("GtkDoc: unable to open %s for writing".printf (sections_writer.filename)); return false; } @@ -76,7 +78,7 @@ public class Gtkdoc.Generator : Api.Visitor { var cwriter = new TextWriter (Path.build_filename (code_dir, "%s.c".printf (basename)), "w"); if (!cwriter.open ()) { - warning ("GtkDoc: unable to open %s for writing", cwriter.filename); + reporter.simple_error ("GtkDoc: unable to open %s for writing".printf (cwriter.filename)); return false; } @@ -182,7 +184,7 @@ public class Gtkdoc.Generator : Api.Visitor { } private GComment create_gcomment (string symbol, Comment? comment, string[]? returns_annotations = null, bool is_dbus = false) { - var converter = new Gtkdoc.CommentConverter (current_method_or_delegate); + var converter = new Gtkdoc.CommentConverter (reporter, current_method_or_delegate); if (comment != null) { converter.convert (comment, is_dbus); @@ -247,7 +249,7 @@ public class Gtkdoc.Generator : Api.Visitor { return null; } - var converter = new Gtkdoc.CommentConverter (current_method_or_delegate); + var converter = new Gtkdoc.CommentConverter (reporter, current_method_or_delegate); var header = new Header (name); header.pos = pos; @@ -305,7 +307,7 @@ public class Gtkdoc.Generator : Api.Visitor { set_section_comment (iface.get_filename(), iface.get_cname(), iface.documentation); if (current_dbus_interface != null) { - current_dbus_interface.write (settings); + current_dbus_interface.write (settings, reporter); dbus_interfaces.add (current_dbus_interface); } @@ -337,7 +339,7 @@ public class Gtkdoc.Generator : Api.Visitor { set_section_comment (cl.get_filename(), cl.get_cname(), cl.documentation); if (current_dbus_interface != null) { - current_dbus_interface.write (settings); + current_dbus_interface.write (settings, reporter); dbus_interfaces.add (current_dbus_interface); } diff --git a/src/doclets/gtkdoc/utils.vala b/src/doclets/gtkdoc/utils.vala index d95e6cc3d..250331e75 100644 --- a/src/doclets/gtkdoc/utils.vala +++ b/src/doclets/gtkdoc/utils.vala @@ -163,7 +163,7 @@ namespace Gtkdoc { return name.replace(".", "-").replace("_", "-"); } - public bool package_exists (string package_name) { + public bool package_exists (string package_name, ErrorReporter reporter) { // copied from vala/codegen/valaccodecompiler.vala string pc = "pkg-config --exists " + package_name; int exit_status; @@ -172,7 +172,7 @@ namespace Gtkdoc { Process.spawn_command_line_sync (pc, null, null, out exit_status); return (0 == exit_status); } catch (SpawnError e) { - warning ("GtkDoc: Error pkg-config --exists %s: %s", package_name, e.message); + reporter.simple_warning ("GtkDoc: Error pkg-config --exists %s: %s".printf (package_name, e.message)); return false; } }