[vala/wip/valadoc-code-context: 586/587] vala: Move setting of target profile into CodeContext
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/valadoc-code-context: 586/587] vala: Move setting of target profile into CodeContext
- Date: Fri, 6 Dec 2019 17:43:24 +0000 (UTC)
commit d8a9b4311e1d488780e7bf068d92311cd6b8622b
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Thu Jan 3 12:15:21 2019 +0100
vala: Move setting of target profile into CodeContext
compiler/valacompiler.vala | 34 ++++++----------------------------
vala/valacodecontext.vala | 36 +++++++++++++++++++++++++++++++++---
valadoc/treebuilder.vala | 23 +++--------------------
vapigen/valavapigen.vala | 9 +--------
4 files changed, 43 insertions(+), 59 deletions(-)
---
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index 54c3535a5..8e337d8c6 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -281,18 +281,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;
@@ -303,29 +292,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/vala/valacodecontext.vala b/vala/valacodecontext.vala
index 47c1cede4..adbf04c15 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; }
/**
@@ -572,6 +570,38 @@ public class Vala.CodeContext {
}
}
+ /**
+ * Set the target profile for code generation.
+ *
+ * This must be called once.
+ *
+ * @param profile a string
+ * @param include_stdpkg whether to include profile-specific default packages
+ */
+ public void set_target_profile (string? profile, bool include_stdpkg) {
+ if (profile == "gobject-2.0" || profile == "gobject" || profile == null) {
+ // default profile
+ this.profile = Profile.GOBJECT;
+ add_define ("GOBJECT");
+
+ if (include_stdpkg) {
+ /* default packages */
+ add_external_package ("glib-2.0");
+ add_external_package ("gobject-2.0");
+ }
+ } else if (profile == "posix") {
+ this.profile = Profile.POSIX;
+ add_define ("POSIX");
+
+ if (include_stdpkg) {
+ /* default package */
+ add_external_package ("posix");
+ }
+ } else {
+ Report.error (null, "Unknown profile %s".printf (profile));
+ }
+ }
+
/**
* Set the target version of glib for code generation.
*
diff --git a/valadoc/treebuilder.vala b/valadoc/treebuilder.vala
index ed6dced10..d6e7534a8 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/vapigen/valavapigen.vala b/vapigen/valavapigen.vala
index ef0b37200..2a994c8dc 100644
--- a/vapigen/valavapigen.vala
+++ b/vapigen/valavapigen.vala
@@ -73,20 +73,13 @@ class Vala.VAPIGen {
private int run () {
context = new CodeContext ();
- context.profile = Profile.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 ("gobject", !nostdpkg);
if (context.report.get_errors () > 0) {
return quit ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]