]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Move setting of target profile and standard packages into CodeContext bd73f1ba11c387c919ad06d44badfd7065d1e35f 36/head
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 3 Jan 2019 11:15:21 +0000 (12:15 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 25 Mar 2020 11:28:50 +0000 (12:28 +0100)
compiler/valacompiler.vala
libvaladoc/settings.vala
vala/valacodecontext.vala
valadoc/treebuilder.vala
valadoc/valadoc.vala
vapigen/valavapigen.vala

index e7f7db4ee159ee646cf3a411f94251d9d9bc5fe2..37d43008d7099a773dda0cd2203a4bad7f4c8f73 100644 (file)
@@ -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);
index 823dd5b2059e5f79d2144342f608d6abdca3adc3..67ef42aa02b6dd732f1bf61f657b7d2b1159ad52 100644 (file)
@@ -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.
index 9f21b91393ae62558db4381b20be84aaa9549f4d..da07b6f54f790be403517e7b623453ce52915fee 100644 (file)
@@ -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; }
 
        /**
@@ -582,6 +580,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.
         *
index 433938af2d3b495fc59c4e25cde1b8570e9f10ec..662a8583e2736427a8e230899b543c241c0d070f 100644 (file)
@@ -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) {
index 87695b1e69cb0c9a3ec0a3dc6878317007e4f00e..b9ae48c504419f0295cc9e908e21bda305476178 100644 (file)
@@ -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;
index 11c02b93441a1060c17daf7ccc9e728639f79e36..f39c5250e891d95848de1e5191416d55d4738427 100644 (file)
@@ -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 ();