summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@gmail.com>2013-01-14 01:02:12 +0100
committerMarc-André Lureau <marcandre.lureau@gmail.com>2013-01-15 16:24:44 +0100
commitda61a02677846ab12766631f3ead1bb4fb644ab6 (patch)
treea37760a893f6fc3b9dd964c18d1d104c59d1306f /tools
parent024901670ee2bd32910d398c4a80258307f5ecb4 (diff)
downloadmsitools-da61a02677846ab12766631f3ead1bb4fb644ab6.tar.gz
msitools-da61a02677846ab12766631f3ead1bb4fb644ab6.tar.xz
msitools-da61a02677846ab12766631f3ead1bb4fb644ab6.zip
wixl: add "require" preprocessor support (not available in WiX)
The idea is to avoid including the same file multiple time and having the same element multiple time defined.
Diffstat (limited to 'tools')
-rw-r--r--tools/wixl/builder.vala2
-rw-r--r--tools/wixl/preprocessor.vala54
2 files changed, 38 insertions, 18 deletions
diff --git a/tools/wixl/builder.vala b/tools/wixl/builder.vala
index 65f4540..11e6309 100644
--- a/tools/wixl/builder.vala
+++ b/tools/wixl/builder.vala
@@ -395,6 +395,8 @@ namespace Wixl {
}
void feature_add_component (WixFeature feature, WixComponent component) throws GLib.Error {
+ if (component.in_feature.find (feature) != null)
+ return;
component.in_feature.append (feature);
db.table_feature_components.add (feature.Id, component.Id);
}
diff --git a/tools/wixl/preprocessor.vala b/tools/wixl/preprocessor.vala
index fe75244..73fe114 100644
--- a/tools/wixl/preprocessor.vala
+++ b/tools/wixl/preprocessor.vala
@@ -85,8 +85,8 @@ namespace Wixl {
}
class Location: Object {
- File file;
- int line;
+ public File file;
+ public int line;
public Location (Xml.TextReader reader, File file) {
this.file = file;
@@ -199,23 +199,13 @@ namespace Wixl {
var value = reader.const_value ().strip ();
undefine_variable (value);
break;
+ case "require":
+ var value = eval (reader.const_value (), file).strip ();
+ include (value, loc, writer, true);
+ break;
case "include":
var value = eval (reader.const_value (), file).strip ();
- var success = false;
- string[] dirs = {};
- dirs += value;
- dirs += file.get_parent ().get_child (value).get_path ();
- foreach (var dir in includedirs)
- dirs += dir.get_child (value).get_path ();
- foreach (var inc in dirs) {
- success = include (inc, writer);
- if (success)
- break;
- }
- if (!success) {
- print ("error", loc, "Failed to include %s".printf (value));
- Posix.exit (1);
- }
+ include (value, loc, writer);
break;
case "warning":
print ("warning", loc, eval (reader.const_value (), file));
@@ -264,7 +254,7 @@ namespace Wixl {
throw new Wixl.Error.FAILED ("Missing endif");
}
- bool include (string filename, Xml.TextWriter writer) throws GLib.Error {
+ bool include_try (string filename, Xml.TextWriter writer) throws GLib.Error {
string data;
var file = File.new_for_path (filename);
@@ -279,6 +269,34 @@ namespace Wixl {
return true;
}
+ // Use it as a set
+ HashTable<string,string*> requires = new HashTable<string, string*> (str_hash, str_equal);
+ void include (string name, Location loc, Xml.TextWriter writer, bool is_req = false) throws GLib.Error {
+ var success = false;
+
+ if (is_req) {
+ if (requires.lookup_extended (name, null, null))
+ return;
+ requires.add (name);
+ }
+
+ string[] dirs = {};
+ dirs += name;
+ dirs += loc.file.get_parent ().get_child (name).get_path ();
+ foreach (var dir in includedirs)
+ dirs += dir.get_child (name).get_path ();
+
+ foreach (var inc in dirs) {
+ success = include_try (inc, writer);
+ if (success)
+ break;
+ }
+ if (!success) {
+ print ("error", loc, "Failed to include %s".printf (name));
+ Posix.exit (1);
+ }
+ }
+
public Xml.Doc preprocess (string data, File? file) throws GLib.Error {
Xml.Doc doc;
Xml.TextWriter writer = new Xml.TextWriter.doc (out doc);