diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2020-10-26 16:10:37 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2020-10-26 16:10:37 +0100 |
commit | cfc13478b7c1b82dc796553d27a0e003389bbbcd (patch) | |
tree | 05b6cf7b463c860ea0217596763ff359f457e770 /valadoc | |
parent | 1d1a0ccfaba157c306ee21dad51dc191dabddb48 (diff) | |
download | vala-cfc13478b7c1b82dc796553d27a0e003389bbbcd.tar.gz |
valadoc: Refactor setup of main runtime
Diffstat (limited to 'valadoc')
-rw-r--r-- | valadoc/valadoc.vala | 212 |
1 files changed, 103 insertions, 109 deletions
diff --git a/valadoc/valadoc.vala b/valadoc/valadoc.vala index 6ed4a6792..175bbdd9d 100644 --- a/valadoc/valadoc.vala +++ b/valadoc/valadoc.vala @@ -139,18 +139,14 @@ public class ValaDoc : Object { return true; } - private static int quit (ErrorReporter reporter, bool pop_context = false) { + private static int quit (ErrorReporter reporter) { if (reporter.errors == 0 && (!fatal_warnings || reporter.warnings == 0)) { stdout.printf ("Succeeded - %d warning(s)\n", reporter.warnings); - if (pop_context) { - Vala.CodeContext.pop (); - } + Vala.CodeContext.pop (); return 0; } else { stdout.printf ("Failed: %d error(s), %d warning(s)\n", reporter.errors, reporter.warnings); - if (pop_context) { - Vala.CodeContext.pop (); - } + Vala.CodeContext.pop (); return 1; } } @@ -204,7 +200,94 @@ public class ValaDoc : Object { return modules; } - private int run (ErrorReporter reporter) { + private int run () { + var context = new Vala.CodeContext (); + Vala.CodeContext.push (context); + + ErrorReporter reporter = new ErrorReporter(); + + if (disable_diagnostic_colors == false) { + unowned string env_colors = Environment.get_variable ("VALA_COLORS"); + if (env_colors != null) { + reporter.set_colors (env_colors); + } else { + reporter.set_colors (DEFAULT_COLORS); + } + } + + if (directory == null) { + reporter.simple_error (null, "No output directory specified."); + return quit (reporter); + } + + if (!check_pkg_name ()) { + reporter.simple_error (null, "File already exists"); + return quit (reporter); + } + + if (FileUtils.test (directory, FileTest.EXISTS)) { + if (force == true) { + bool tmp = remove_directory (directory); + if (tmp == false) { + reporter.simple_error (null, "Can't remove directory."); + return quit (reporter); + } + } else { + reporter.simple_error (null, "File already exists"); + return quit (reporter); + } + } + + if (wikidirectory != null) { + if (!FileUtils.test(wikidirectory, FileTest.IS_DIR)) { + reporter.simple_error (null, "Wiki-directory does not exist."); + return quit (reporter); + } + } + + foreach (unowned string dir in alternative_resource_dirs) { + if (!FileUtils.test(dir, FileTest.IS_DIR)) { + reporter.simple_error (null, "alternative resource directory '%s' does not exist.".printf (dir)); + return quit (reporter); + } + } + if (reporter.errors > 0) { + return quit (reporter); + } + + if (gir_name != null) { + long gir_len = gir_name.length; + int last_hyphen = gir_name.last_index_of_char ('-'); + + if (last_hyphen == -1 || !gir_name.has_suffix (".gir")) { + reporter.simple_error (null, "GIR file name '%s' is not well-formed, expected NAME-VERSION.gir", gir_name); + return quit (reporter); + } + + gir_namespace = gir_name.substring (0, last_hyphen); + gir_version = gir_name.substring (last_hyphen + 1, gir_len - last_hyphen - 5); + gir_version.canon ("0123456789.", '?'); + + if (gir_namespace == "" || gir_version == "" || !gir_version[0].isdigit () || gir_version.contains ("?")) { + reporter.simple_error (null, "GIR file name '%s' is not well-formed, expected NAME-VERSION.gir", gir_name); + return quit (reporter); + } + + + bool report_warning = true; + foreach (string source in tsources) { + if (source.has_suffix (".vala") || source.has_suffix (".gs")) { + report_warning = false; + break; + } + } + + if (report_warning == true) { + reporter.simple_error (null, "No source file specified to be compiled to gir."); + return quit (reporter); + } + } + // settings: var settings = new Valadoc.Settings (); reporter.settings = settings; @@ -248,14 +331,11 @@ public class ValaDoc : Object { settings.alternative_resource_dirs = alternative_resource_dirs; - var context = new Vala.CodeContext (); - Vala.CodeContext.push (context); - // load plugins: Doclet? doclet = null; ModuleLoader? modules = create_module_loader (reporter, out doclet); if (reporter.errors > 0 || modules == null) { - return quit (reporter, true); + return quit (reporter); } // Create tree: @@ -263,7 +343,7 @@ public class ValaDoc : Object { Valadoc.Api.Tree doctree = builder.build (settings, reporter); if (reporter.errors > 0) { doclet = null; - return quit (reporter, true); + return quit (reporter); } SymbolResolver resolver = new SymbolResolver (builder); doctree.accept (resolver); @@ -275,7 +355,7 @@ public class ValaDoc : Object { // process documentation Valadoc.DocumentationParser docparser = new Valadoc.DocumentationParser (settings, reporter, doctree, modules); if (!doctree.create_tree()) { - return quit (reporter, true); + return quit (reporter); } DocumentationImporter[] importers = { @@ -285,17 +365,17 @@ public class ValaDoc : Object { doctree.parse_comments (docparser); if (reporter.errors > 0) { - return quit (reporter, true); + return quit (reporter); } doctree.import_comments (importers, import_packages, import_directories); if (reporter.errors > 0) { - return quit (reporter, true); + return quit (reporter); } doctree.check_comments (docparser); if (reporter.errors > 0) { - return quit (reporter, true); + return quit (reporter); } if (ValaDoc.gir_name != null) { @@ -307,17 +387,16 @@ public class ValaDoc : Object { settings.gir_version, settings.pkg_name); if (reporter.errors > 0) { - return quit (reporter, true); + return quit (reporter); } } doclet.process (settings, doctree, reporter); - return quit (reporter, true); + return quit (reporter); } static int main (string[] args) { Intl.setlocale (LocaleCategory.ALL, ""); - ErrorReporter reporter = new ErrorReporter(); try { var opt_context = new OptionContext ("- Vala Documentation Tool"); @@ -325,18 +404,9 @@ public class ValaDoc : Object { opt_context.add_main_entries (options, null); opt_context.parse (ref args); } catch (OptionError e) { - reporter.simple_error (null, "%s", e.message); + stdout.printf ("%s\n", e.message); stdout.printf ("Run '%s --help' to see a full list of available command line options.\n", args[0]); - return quit (reporter); - } - - if (disable_diagnostic_colors == false) { - unowned string env_colors = Environment.get_variable ("VALA_COLORS"); - if (env_colors != null) { - reporter.set_colors (env_colors); - } else { - reporter.set_colors (DEFAULT_COLORS); - } + return 1; } if (version) { @@ -344,83 +414,7 @@ public class ValaDoc : Object { return 0; } - if (directory == null) { - reporter.simple_error (null, "No output directory specified."); - return quit (reporter); - } - - if (!check_pkg_name ()) { - reporter.simple_error (null, "File already exists"); - return quit (reporter); - } - - if (FileUtils.test (directory, FileTest.EXISTS)) { - if (force == true) { - bool tmp = remove_directory (directory); - if (tmp == false) { - reporter.simple_error (null, "Can't remove directory."); - return quit (reporter); - } - } else { - reporter.simple_error (null, "File already exists"); - return quit (reporter); - } - } - - if (wikidirectory != null) { - if (!FileUtils.test(wikidirectory, FileTest.IS_DIR)) { - reporter.simple_error (null, "Wiki-directory does not exist."); - return quit (reporter); - } - } - - foreach (unowned string dir in alternative_resource_dirs) { - if (!FileUtils.test(dir, FileTest.IS_DIR)) { - reporter.simple_error (null, "alternative resource directory '%s' does not exist.".printf (dir)); - return quit (reporter); - } - } - if (reporter.errors > 0) { - return quit (reporter); - } - - if (gir_name != null) { - long gir_len = gir_name.length; - int last_hyphen = gir_name.last_index_of_char ('-'); - - if (last_hyphen == -1 || !gir_name.has_suffix (".gir")) { - reporter.simple_error (null, "GIR file name '%s' is not well-formed, expected NAME-VERSION.gir", gir_name); - return quit (reporter); - } - - gir_namespace = gir_name.substring (0, last_hyphen); - gir_version = gir_name.substring (last_hyphen + 1, gir_len - last_hyphen - 5); - gir_version.canon ("0123456789.", '?'); - - if (gir_namespace == "" || gir_version == "" || !gir_version[0].isdigit () || gir_version.contains ("?")) { - reporter.simple_error (null, "GIR file name '%s' is not well-formed, expected NAME-VERSION.gir", gir_name); - return quit (reporter); - } - - - bool report_warning = true; - foreach (string source in tsources) { - if (source.has_suffix (".vala") || source.has_suffix (".gs")) { - report_warning = false; - break; - } - } - - if (report_warning == true) { - reporter.simple_error (null, "No source file specified to be compiled to gir."); - return quit (reporter); - } - } - - - var valadoc = new ValaDoc( ); - return valadoc.run (reporter); + var valadoc = new ValaDoc (); + return valadoc.run (); } } - - |