[vala/wip/valadoc-code-context: 18/19] 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: 18/19] vala: Move setting of target profile into CodeContext
- Date: Sun, 6 Jan 2019 10:31:27 +0000 (UTC)
commit 909c8d3c44212200095fe82d8d552718500a5036
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 | 18 +++---------------
vapigen/valavapigen.vala | 9 +--------
4 files changed, 43 insertions(+), 54 deletions(-)
---
diff --git a/compiler/valacompiler.vala b/compiler/valacompiler.vala
index e0b02060e..90eb645ca 100644
--- a/compiler/valacompiler.vala
+++ b/compiler/valacompiler.vala
@@ -272,18 +272,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;
@@ -294,29 +283,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 34543a8d9..b388add56 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; }
/**
@@ -544,6 +542,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 183c07aa3..8fee38851 100644
--- a/valadoc/treebuilder.vala
+++ b/valadoc/treebuilder.vala
@@ -368,30 +368,18 @@ public class Valadoc.Drivers.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
- context.add_external_package ("glib-2.0");
- context.add_external_package ("gobject-2.0");
- }
-
// add user defined files:
foreach (string package in settings.packages) {
context.add_external_package (package);
diff --git a/vapigen/valavapigen.vala b/vapigen/valavapigen.vala
index 63205499d..ebaee9b35 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]