diff options
author | Marc-André Lureau <marcandre.lureau@gmail.com> | 2013-01-08 17:46:15 +0100 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@gmail.com> | 2013-01-08 18:21:13 +0100 |
commit | c6e867fbf33342a047ae4f255c1b8ad3e03c5f69 (patch) | |
tree | 81a9495a67d2b3a4f5c290b935a2d1000e374e2b | |
parent | 9cc9b8d81023f39900115bc38eb48c038c5d182f (diff) | |
download | msitools-c6e867fbf33342a047ae4f255c1b8ad3e03c5f69.tar.gz msitools-c6e867fbf33342a047ae4f255c1b8ad3e03c5f69.tar.xz msitools-c6e867fbf33342a047ae4f255c1b8ad3e03c5f69.zip |
Add preprocessor variables test
-rw-r--r-- | src/builder.vala | 7 | ||||
-rw-r--r-- | src/preprocessor.vala | 1 | ||||
-rw-r--r-- | src/wixl.vala | 30 | ||||
-rw-r--r-- | tests/testsuite.at | 41 |
4 files changed, 67 insertions, 12 deletions
diff --git a/src/builder.vala b/src/builder.vala index 5a441dd..d2f5035 100644 --- a/src/builder.vala +++ b/src/builder.vala @@ -30,12 +30,17 @@ namespace Wixl { } } - public void load_file (File file) throws GLib.Error { + public void load_file (File file, bool preproc_only = false) throws GLib.Error { string data; FileUtils.get_contents (file.get_path (), out data); var p = new Preprocessor (); var doc = p.preprocess (data, file); + if (preproc_only) { + doc.dump_format (FileStream.fdopen (1, "w")); + return; + } + load_doc (doc); } diff --git a/src/preprocessor.vala b/src/preprocessor.vala index e5bfd1b..6953aa5 100644 --- a/src/preprocessor.vala +++ b/src/preprocessor.vala @@ -107,7 +107,6 @@ namespace Wixl { } writer.end_document (); - doc.dump_format (FileStream.fdopen (1, "w")); return doc; } } diff --git a/src/wixl.vala b/src/wixl.vala index 904daf7..24d0ad4 100644 --- a/src/wixl.vala +++ b/src/wixl.vala @@ -3,11 +3,17 @@ using Posix; namespace Wixl { static bool version; + static bool verbose; + static bool preproc; + static string output; [CCode (array_length = false, array_null_terminated = true)] static string[] files; private const OptionEntry[] options = { { "version", 0, 0, OptionArg.NONE, ref version, N_("Display version number"), null }, + { "verbose", 'v', 0, OptionArg.NONE, ref verbose, N_("Verbose output"), null }, + { "output", 'o', 0, OptionArg.FILENAME, ref output, N_("Output file"), null }, + { "only-preproc", 'E', 0, OptionArg.NONE, ref preproc, N_("Stop after the preprocessing stage"), null }, { "", 0, 0, OptionArg.FILENAME_ARRAY, ref files, null, N_("OUTPUT_FILE INPUT_FILE...") }, { null } }; @@ -37,23 +43,33 @@ namespace Wixl { exit (0); } - if (files.length < 2) { - GLib.stderr.printf (_("Please specify output and input files.\n")); + if (files.length < 1) { + GLib.stderr.printf (_("Please specify input files.\n")); + exit (1); + } + + if (output == null && !preproc) { + GLib.stderr.printf (_("Please specify the output file.\n")); exit (1); } try { var builder = new WixBuilder (); - foreach (var arg in files[1:files.length]) { - print ("Loading %s...\n", arg); + foreach (var arg in files) { + if (verbose) + print ("Loading %s...\n", arg); var file = File.new_for_commandline_arg (arg); - builder.load_file (file); + builder.load_file (file, preproc); builder.add_path (file.get_parent ().get_path ()); } - print ("Building %s...\n", files[0]); + if (preproc) + return 0; + + if (verbose) + print ("Building %s...\n", files[0]); var msi = builder.build (); - msi.build (files[0]); + msi.build (output); } catch (GLib.Error error) { printerr (error.message + "\n"); return 1; diff --git a/tests/testsuite.at b/tests/testsuite.at index 104a2e9..194b4ab 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -16,7 +16,10 @@ AT_CHECK([cp $abs_srcdir/tests/data/$1 $1])]) AT_SETUP([Invalid command line]) AT_CHECK_WIXL([], [1], [ignore], [ignore]) -AT_CHECK_WIXL([out.msi], [1], [ignore], [ignore]) +AT_CHECK_WIXL([out.msi foo.wxs], [1], [ignore], [ignore]) +AT_CHECK_WIXL([-o out.msi], [1], [ignore], [ignore]) +AT_CHECK_WIXL([-E], [1], [ignore], [ignore]) +AT_CHECK_WIXL([-E -o out.msi], [1], [ignore], [ignore]) AT_CHECK([test -f out.msi], [1]) AT_CLEANUP @@ -25,7 +28,7 @@ AT_WIXLDATA([SampleFirst.wxs]) AT_WIXLDATA([FoobarAppl10.exe]) AT_WIXLDATA([Helper.dll]) AT_WIXLDATA([Manual.pdf]) -AT_CHECK_WIXL([out.msi SampleFirst.wxs], [0], [ignore], [ignore]) +AT_CHECK_WIXL([-o out.msi SampleFirst.wxs], [0], [ignore], [ignore]) # FIXME: add tons of tests on out.msi AT_CHECK([test -f out.msi], [0]) AT_CLEANUP @@ -36,7 +39,39 @@ AT_WIXLDATA([Manual.wxs]) AT_WIXLDATA([FoobarAppl10.exe]) AT_WIXLDATA([Helper.dll]) AT_WIXLDATA([Manual.pdf]) -AT_CHECK_WIXL([out.msi SampleFragment.wxs Manual.wxs], [0], [ignore], [ignore]) +AT_CHECK_WIXL([-o out.msi SampleFragment.wxs Manual.wxs], [0], [ignore], [ignore]) # FIXME: add tons of tests on out.msi AT_CHECK([test -f out.msi], [0]) AT_CLEANUP + +AT_SETUP([Preprocessor variables]) +export MY_VAR="Hello!" +AT_DATA([variables.wxs], [<?xml version="1.0"?> +<?define Version = "0.2.0"?> +<?define UpgradeCode = "ABCDDCBA-8392-0202-1993-199374829923"?> +<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'> + <Property Id="Id0" Value="$(var.UpgradeCode)"/> + <Property Id="Id0.1" Value="$$(var.UpgradeCode)"/> + <Property Id="Id0.2" Value="$$$(var.UpgradeCode)"/> + <?define UpgradeCode = "ABCDDCBA-8392-0202-1993-199374829924"?> + <Property Id="Id2" Value="$(var.UpgradeCode)"/> + <Property Id="Id3" Value="$(var.Version)"/> + <?define A = "A"?><?define B = "B"?> + <Property Id="IdAB" Value="$(var.A)$(var.B)"/> + <Property Id="IdHello" Value="$(env.MY_VAR)"/> + <Property Id="IdSys" Value="($(sys.SOURCEFILEDIR))foo"/> +</Wix> +]) +AT_CHECK_WIXL([-E variables.wxs], [0], [<?xml version="1.0"?> +<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> + <Property Id="Id0" Value="ABCDDCBA-8392-0202-1993-199374829923"/> + <Property Id="Id0.1" Value="$ABCDDCBA-8392-0202-1993-199374829923"/> + <Property Id="Id0.2" Value="$$ABCDDCBA-8392-0202-1993-199374829923"/> + <Property Id="Id2" Value="ABCDDCBA-8392-0202-1993-199374829924"/> + <Property Id="Id3" Value="0.2.0"/> + <Property Id="IdAB" Value="AB"/> + <Property Id="IdHello" Value="Hello!"/> + <Property Id="IdSys" Value="(variables.wxs)foo"/> +</Wix> +], [ignore]) +AT_CLEANUP |