diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-01-03 12:15:21 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2020-03-25 12:28:50 +0100 |
commit | bd73f1ba11c387c919ad06d44badfd7065d1e35f (patch) | |
tree | 0f80303ac04d57a60988e07c8de50ddb34484215 | |
parent | 66c23e839b63c81ce5da1c0212b22e2c4c6b8c81 (diff) | |
download | vala-bd73f1ba11c387c919ad06d44badfd7065d1e35f.tar.gz |
vala: Move setting of target profile and standard packages into CodeContext
-rw-r--r-- | compiler/valacompiler.vala | 49 | ||||
-rw-r--r-- | libvaladoc/settings.vala | 4 | ||||
-rw-r--r-- | vala/valacodecontext.vala | 38 | ||||
-rw-r--r-- | valadoc/treebuilder.vala | 23 | ||||
-rw-r--r-- | valadoc/valadoc.vala | 15 | ||||
-rw-r--r-- | vapigen/valavapigen.vala | 10 |
6 files changed, 73 insertions, 66 deletions
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala index e7f7db4ee..37d43008d 100644 --- a/compiler/valacompiler.vala +++ b/compiler/valacompiler.vala @@ -87,7 +87,7 @@ class Vala.Compiler { static string[] defines; static bool quiet_mode; static bool verbose_mode; - static string profile; + static Profile profile; static bool nostdpkg; static bool enable_version_header; static bool disable_version_header; @@ -154,7 +154,7 @@ class Vala.Compiler { { "pkg-config", 0, 0, OptionArg.STRING, ref pkg_config_command, "Use COMMAND as pkg-config command", "COMMAND" }, { "dump-tree", 0, 0, OptionArg.FILENAME, ref dump_tree, "Write code tree to FILE", "FILE" }, { "save-temps", 0, 0, OptionArg.NONE, ref save_temps, "Keep temporary files", null }, - { "profile", 0, 0, OptionArg.STRING, ref profile, "Use the given profile instead of the default", "PROFILE" }, + { "profile", 0, OptionFlags.OPTIONAL_ARG, OptionArg.CALLBACK, (void*) option_parse_profile, "Use the given profile instead of the default, options are 'gobject' or 'posix'", "PROFILE" }, { "quiet", 'q', 0, OptionArg.NONE, ref quiet_mode, "Do not print messages to the console", null }, { "verbose", 'v', 0, OptionArg.NONE, ref verbose_mode, "Print additional messages to the console", null }, { "no-color", 0, 0, OptionArg.NONE, ref disable_colored_output, "Disable colored output, alias for --color=never", null }, @@ -181,6 +181,17 @@ class Vala.Compiler { return true; } + static bool option_parse_profile (string option_name, string? val, void* data) throws OptionError { + switch (val) { + case null: + case "gobject-2.0": + case "gobject": profile = Profile.GOBJECT; break; + case "posix": profile = Profile.POSIX; break; + default: throw new OptionError.FAILED ("Invalid --profile argument '%s'", val); + } + return true; + } + static bool option_deprecated (string option_name, string? val, void* data) throws OptionError { stdout.printf ("Command-line option `%s` is deprecated and will be ignored\n", option_name); return true; @@ -286,18 +297,7 @@ class Vala.Compiler { if (ccode_only && save_temps) { Report.warning (null, "--save-temps has no effect when -C or --ccode is set"); } - if (profile == "posix") { - context.profile = Profile.POSIX; - context.add_define ("POSIX"); - } else if (profile == "gobject-2.0" || profile == "gobject" || profile == null) { - // default profile - context.profile = Profile.GOBJECT; - context.add_define ("GOBJECT"); - } else { - Report.error (null, "Unknown profile %s".printf (profile)); - } nostdpkg |= fast_vapi_filename != null; - context.nostdpkg = nostdpkg; context.entry_point_name = entry_point; @@ -308,29 +308,18 @@ class Vala.Compiler { } context.pkg_config_command = pkg_config_command; + context.set_target_profile (profile, !nostdpkg); + + if (target_glib != null) { + context.set_target_glib_version (target_glib); + } + if (defines != null) { foreach (string define in defines) { context.add_define (define); } } - if (context.profile == Profile.POSIX) { - if (!nostdpkg) { - /* default package */ - context.add_external_package ("posix"); - } - } else if (context.profile == Profile.GOBJECT) { - if (target_glib != null) { - context.set_target_glib_version (target_glib); - } - - if (!nostdpkg) { - /* default packages */ - context.add_external_package ("glib-2.0"); - context.add_external_package ("gobject-2.0"); - } - } - if (packages != null) { foreach (string package in packages) { context.add_external_package (package); diff --git a/libvaladoc/settings.vala b/libvaladoc/settings.vala index 823dd5b20..67ef42aa0 100644 --- a/libvaladoc/settings.vala +++ b/libvaladoc/settings.vala @@ -91,9 +91,9 @@ public class Valadoc.Settings : Object { public bool experimental_non_null; /** - * Use the given profile (dova, gobject, posix, ...) instead of the defaul + * Use the given profile (gobject, posix, ...) instead of the default */ - public string? profile; + public Vala.Profile profile; /** * Base source directory. diff --git a/vala/valacodecontext.vala b/vala/valacodecontext.vala index 9f21b9139..da07b6f54 100644 --- a/vala/valacodecontext.vala +++ b/vala/valacodecontext.vala @@ -163,14 +163,12 @@ public class Vala.CodeContext { */ public bool save_temps { get; set; } - public Profile profile { get; set; } + public Profile profile { get; private set; } public bool verbose_mode { get; set; } public bool version_header { get; set; } - public bool nostdpkg { get; set; } - public bool use_fast_vapi { get; set; } /** @@ -583,6 +581,40 @@ public class Vala.CodeContext { } /** + * Set the target profile for code generation. + * + * This must be called once. + * + * @param profile the profile to use + * @param include_stdpkg whether to include profile-specific default packages + */ + public void set_target_profile (Profile profile, bool include_stdpkg = true) { + switch (profile) { + default: + case Profile.GOBJECT: + // default profile + this.profile = profile; + add_define ("GOBJECT"); + + if (include_stdpkg) { + /* default packages */ + add_external_package ("glib-2.0"); + add_external_package ("gobject-2.0"); + } + break; + case Profile.POSIX: + this.profile = profile; + add_define ("POSIX"); + + if (include_stdpkg) { + /* default package */ + add_external_package ("posix"); + } + break; + } + } + + /** * Set the target version of glib for code generation. * * This may be called once or not at all. diff --git a/valadoc/treebuilder.vala b/valadoc/treebuilder.vala index 433938af2..662a8583e 100644 --- a/valadoc/treebuilder.vala +++ b/valadoc/treebuilder.vala @@ -489,35 +489,18 @@ public class Valadoc.TreeBuilder : Vala.CodeVisitor { context.directory = context.basedir; } + context.set_target_profile (settings.profile, true); - // add default packages: - if (settings.profile == "gobject-2.0" || settings.profile == "gobject" || settings.profile == null) { - context.profile = Vala.Profile.GOBJECT; - context.add_define ("GOBJECT"); + if (settings.target_glib != null) { + context.set_target_glib_version (settings.target_glib); } - if (settings.defines != null) { foreach (string define in settings.defines) { context.add_define (define); } } - if (context.profile == Vala.Profile.GOBJECT) { - if (settings.target_glib != null) { - context.set_target_glib_version (settings.target_glib); - } - - // default packages - if (!this.add_package (context, "glib-2.0")) { // - Vala.Report.error (null, "glib-2.0 not found in specified Vala API directories"); - } - - if (!this.add_package (context, "gobject-2.0")) { // - Vala.Report.error (null, "gobject-2.0 not found in specified Vala API directories"); - } - } - // add user defined files: add_depencies (context, settings.packages); if (reporter.errors > 0) { diff --git a/valadoc/valadoc.vala b/valadoc/valadoc.vala index 87695b1e6..b9ae48c50 100644 --- a/valadoc/valadoc.vala +++ b/valadoc/valadoc.vala @@ -55,7 +55,7 @@ public class ValaDoc : Object { private static string[] defines; private static bool experimental; private static bool experimental_non_null = false; - private static string profile; + private static Vala.Profile profile; [CCode (array_length = false, array_null_terminated = true)] private static string[] import_packages; [CCode (array_length = false, array_null_terminated = true)] @@ -79,7 +79,7 @@ public class ValaDoc : Object { { "basedir", 'b', 0, OptionArg.FILENAME, ref basedir, "Base source directory", "DIRECTORY" }, { "define", 'D', 0, OptionArg.STRING_ARRAY, ref defines, "Define SYMBOL", "SYMBOL..." }, - { "profile", 0, 0, OptionArg.STRING, ref profile, "Use the given profile instead of the default", "PROFILE" }, + { "profile", 0, OptionFlags.OPTIONAL_ARG, OptionArg.CALLBACK, (void*) option_parse_profile, "Use the given profile instead of the default, options are 'gobject' or 'posix'", "PROFILE" }, { "enable-experimental", 0, 0, OptionArg.NONE, ref experimental, "Enable experimental features", null }, { "enable-experimental-non-null", 0, 0, OptionArg.NONE, ref experimental_non_null, "Enable experimental enhancements for non-null types", null }, @@ -123,6 +123,17 @@ public class ValaDoc : Object { { null } }; + static bool option_parse_profile (string option_name, string? val, void* data) throws OptionError { + switch (val) { + case null: + case "gobject-2.0": + case "gobject": profile = Vala.Profile.GOBJECT; break; + case "posix": profile = Vala.Profile.POSIX; break; + default: throw new OptionError.FAILED ("Invalid --profile argument '%s'", val); + } + return true; + } + static bool option_deprecated (string option_name, string? val, void* data) throws OptionError { stdout.printf ("Command-line option `%s` is deprecated and will be ignored\n", option_name); return true; diff --git a/vapigen/valavapigen.vala b/vapigen/valavapigen.vala index 11c02b934..f39c5250e 100644 --- a/vapigen/valavapigen.vala +++ b/vapigen/valavapigen.vala @@ -75,21 +75,13 @@ class Vala.VAPIGen { private int run () { context = new CodeContext (); - context.profile = Profile.GOBJECT; - context.add_define ("GOBJECT"); context.vapi_directories = vapi_directories; context.gir_directories = gir_directories; context.metadata_directories = metadata_directories; context.report.enable_warnings = !disable_warnings; context.report.set_verbose_errors (!quiet_mode); CodeContext.push (context); - context.nostdpkg = nostdpkg; - - if (!nostdpkg) { - /* default package */ - context.add_external_package ("glib-2.0"); - context.add_external_package ("gobject-2.0"); - } + context.set_target_profile (Profile.GOBJECT, !nostdpkg); if (context.report.get_errors () > 0) { return quit (); |