summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.Xamlc/Xamlc.cs
blob: ec99b71a63fe9702ac689276dc0ca3b7278eb87d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using Mono.Options;
using Xamarin.Forms.Build.Tasks;

namespace Xamarin.Forms.Xaml
{
	class Xamlc
	{
		static readonly string help_string = "xamlc.exe - a utility for compiling XAML into IL.\n" +
		                                     "xamlc.exe assembly\n\n";

		public static void Main(string[] args)
		{
			bool help = false;
			int verbosity = 1;
			bool keep = false;
			bool optimize = false;
			string paths = null;
			string refs = null;
			List<string> extra = null;

			var p = new OptionSet
			{
				{ "h|?|help", "Print this help message", v => help = true },
				{ "v=|verbosity=", "0 is quiet, 1 is normal, 2 is verbose", v => verbosity = Int32.Parse(v) },
				{ "o|optimize", "Optimize generated IL", v => optimize = true },
				{ "keep", "do not strip compiled embedded xaml", v => keep = true },
				{ "p=|paths=|dependencypaths=", "look for dependencies in (comma separated) list of paths", v => paths = v },
				{ "r=", "referencepath", v => refs = v },
			};

			if (help || args.Length < 1)
			{
				ShowHelp(p);
				Environment.Exit(0);
			}
			try
			{
				extra = p.Parse(args);
			}
			catch (OptionException)
			{
				Console.WriteLine("Type `xamlc --help' for more information.");
				return;
			}

			if (extra.Count == 0)
			{
				if (verbosity > 0)
				{
					Console.WriteLine("assembly missing");
					ShowHelp(p);
				}
				Environment.Exit(0);
			}

			var assembly = extra[0];
			var xamlc = new XamlCTask {
				Assembly = assembly,
				Verbosity = verbosity,
				KeepXamlResources = keep,
				OptimizeIL = optimize,
				DependencyPaths = paths,
				ReferencePath = refs
			};
			xamlc.Execute(null);
		}

		static void ShowHelp(OptionSet ops)
		{
			Console.WriteLine(help_string);
			ops.WriteOptionDescriptions(Console.Out);
		}
	}
}