Esempio n. 1
0
        public static CommandLineOptions From(string[] args)
        {
            var help    = false;
            var verbose = false;
            var quiet   = false;

            var commandOptions = new CommandLineOptions();

            string targetName = null;
            var    p          = new OptionSet
            {
                { "h|?|help", "Show help", v => help = v != null },
                { "r|reporter=", "Reporter type (not used)", v => Console.Error.WriteLine("WARNING: --reporter is deprecated and has no effect.") },
                { "l|logfile=", "Write output to this file instead of stdout", v => commandOptions.LogFileName = v },
                { "t|target=", "Build target. Supported: android, dotnet and native", v => targetName = v },
                { "v|verbose", "Verbose, always prints output from compiler and debug_log", v => verbose = v != null },
                { "q|quiet", "Quiet, only prints output from compiler and debug_log in case of errors.", v => quiet = v != null },
                { "f|filter=", "Only run tests matching this string", v => commandOptions.Filter = Regex.Escape(v) },
                { "e|regex-filter=", "Only run tests matching this regular expression", v => commandOptions.Filter = v },
                { "o|timeout=", "Timeout for individual tests (in seconds)", (int v) => Console.Error.WriteLine("WARNING: --timeout is deprecated and has no effect.") },
                { "startup-timeout=", "Timeout for connection from uno process (in seconds)", (int v) => Console.Error.WriteLine("WARNING: --startup-timeout is deprecated and has no effect.") },
                { "trace", "Print trace information from unotest", v => { commandOptions.Trace = v != null; } },
                { "only-build", "Don't run compiled program.", v => commandOptions.OnlyBuild = v != null },
                { "allow-debugger", "Don't run compiled program, allow user to start it from a debugger.", v => Console.Error.WriteLine("WARNING: --allow-debugger is deprecated and has no effect.") },
                { "d|debug", "Open IDE for debugging tests.", v => Console.Error.WriteLine("WARNING: --debug is deprecated and has no effect.") },
                { "run-local", "Run the test directly (not used)", v => Console.Error.WriteLine("WARNING: --run-local is deprecated and has no effect.") },
                { "no-uninstall", "Don't uninstall tests after running on device", v => commandOptions.NoUninstall = v != null },
                { "D=|define=", "Add define, to enable a feature", commandOptions.Defines.Add },
                { "U=|undefine=", "Remove define, to disable a feature", commandOptions.Undefines.Add },
                { "output-dir=", "Override output directory", v => commandOptions.OutputDirectory = v },
                { "libs", "Rebuild package library if necessary", v => commandOptions.Library = true },
            };

            try
            {
                var extra = p.Parse(args);
                commandOptions.Target  = BuildTargets.Get(targetName, extra);
                commandOptions.Paths   = extra;
                commandOptions.Verbose = verbose;

                if (verbose && quiet)
                {
                    throw new ArgumentException("Cannot specify both -q and -v");
                }
            }
            catch (OptionException e)
            {
                Console.WriteLine(e);
                PrintHelp(p);
                return(null);
            }

            if (help)
            {
                PrintHelp(p);
                return(null);
            }

            return(commandOptions);
        }
Esempio n. 2
0
        public override void Execute(IEnumerable <string> args)
        {
            string targetName    = null;
            string outputDir     = null;
            var    configuration = BuildConfiguration.Debug;
            var    nativeArgs    = new List <string>();
            var    runArgs       = new List <string>();
            var    build         = false;
            var    run           = false;
            var    input         = new OptionSet
            {
                { "t=|target=", value => targetName = value },
                { "c=|configuration=", value => configuration = value.ParseEnum <BuildConfiguration>("configuration") },
                { "o=|out-dir|output-dir=", value => outputDir = value },
                { "n=|native-args=", nativeArgs.Add },
                { "a=|run-args=", runArgs.Add },
                { "b|build", value => build = true },
                { "d|debug", value => runArgs.Add("debug") },
                { "r|run", value => run = true },
            }
            .Parse(args);

            var target  = BuildTargets.Get(targetName, input);
            var project = Project.Load(input.Path(".").GetProjectFile());

            if (string.IsNullOrEmpty(outputDir))
            {
                outputDir = project.GetOutputDirectory(configuration, target);
            }

            var file = new BuildFile(outputDir);

            if (!file.Exists)
            {
                throw new InvalidOperationException("Target was not built -- run 'uno build' first");
            }

            if (build || nativeArgs.Count > 0)
            {
                if (!target.CanBuild(file))
                {
                    // If the build script is missing it's probably not needed
                    Log.Warning("A build script was not found in " + outputDir.Quote());
                }
                else if (!target.Build(Shell, file, string.Join(" ", nativeArgs)))
                {
                    ExitCode = 1;
                    return;
                }
            }

            if (run || runArgs.Count > 0)
            {
                if (!target.CanRun(file) ||
                    !target.Run(Shell, file, string.Join(" ", runArgs)).Result)
                {
                    ExitCode = 1;
                }
            }
        }
Esempio n. 3
0
File: Test.cs Progetto: mortend/uno
        TestOptions Parse(IEnumerable <string> args)
        {
            var verbose = Log.IsVerbose;
            var quiet   = false;

            var options = new TestOptions();

            string targetName = null;
            var    p          = new OptionSet
            {
                { "r|reporter=", v => Log.Warning("--reporter is deprecated and has no effect.") },
                { "l|logfile=", v => options.LogFile = v },
                { "t|target=", v => targetName = v },
                { "v|verbose", v => verbose = v != null },
                { "q|quiet", v => quiet = v != null },
                { "f|filter=", v => options.Filter = Regex.Escape(v) },
                { "e|regex-filter=", v => options.Filter = v },
                { "timeout=", v => Log.Warning("--timeout is deprecated and has no effect.") },
                { "startup-timeout=", v => Log.Warning("--startup-timeout is deprecated and has no effect.") },
                { "trace", v => { options.Trace = v != null; } },
                { "b|build-only|only-build", v => options.OnlyBuild = v != null },
                { "g|gen-only", v => options.OnlyGenerate = v != null },
                { "allow-debugger", v => Log.Warning("--allow-debugger is deprecated and has no effect.") },
                { "d|debug", v => Log.Warning("--debug is deprecated and has no effect.") },
                { "run-local", v => Log.Warning("--run-local is deprecated and has no effect.") },
                { "no-uninstall", v => options.DontUninstall = v != null },
                { "D=|define=", options.Defines.Add },
                { "U=|undefine=", options.Undefines.Add },
                { "o=|out-dir=|output-dir=", v => options.OutputDirectory = v },
                { "libs", v => options.UpdateLibrary = true },
            };

            try
            {
                var extra = p.Parse(args);
                options.Target  = BuildTargets.Get(targetName, extra);
                options.Paths   = extra;
                options.Verbose = verbose;

                if (verbose && quiet)
                {
                    throw new ArgumentException("Cannot specify both -q and -v");
                }
            }
            catch (OptionException e)
            {
                Log.WriteErrorLine(e.ToString());
                Help();
                return(null);
            }

            return(options);
        }
Esempio n. 4
0
        public override void Execute(IEnumerable <string> args)
        {
            var                recursive     = false;
            string             targetName    = null;
            BuildConfiguration configuration = 0;

            var input = new OptionSet {
                { "t=|target=", value => targetName = value },
                { "c=|configuration=", value => configuration = value.ParseEnum <BuildConfiguration>("configuration") },
                { "r|recursive", value => recursive = true }
            }.Parse(args);
            var target = BuildTargets.Get(targetName, input, canReturnNull: true);
            var files  = input.Paths(".").GetProjectFiles(recursive);

            new ProjectCleaner(Log, target, configuration)
            .Clean(files);
        }
Esempio n. 5
0
        public static BuildArguments Parse(IEnumerable <string> args, Log log = null)
        {
            if (log == null)
            {
                log = Log;
            }

            string targetName = null;
            var    options    = new BuildOptions {
                PackageTarget = BuildTargets.Package
            };
            var nativeArgs = new List <string>();
            var runArgs    = new List <string>();
            var run        = false;
            var input      = new OptionSet {
                { "t=|target=", value => targetName = value },
                { "c=|configuration=", value => options.Configuration = value.ParseEnum <BuildConfiguration>("configuration") },
                { "s=|set=", value => value.ParseProperty("s|set", options.Settings) },
                { "p|print-internals", value => options.PrintInternals = true },
                { "o=|out-dir|output-dir=", value => options.OutputDirectory = value },
                { "m=|main=|main-class=", value => options.MainClass = value },
                { "n=|native-args=", nativeArgs.Add },
                { "a=|run-args=", runArgs.Add },
                { "test-server-url=", value => options.TestServerUrl = value },
                { "P|no-parallel", value => options.Parallel = false },
                { "N|q|no-native", value => options.Native = false },
                { "S|e|no-strip", value => options.Strip = false },
                { "E=|max-errors=", value => Log.MaxErrorCount = value.ParseInt("E") },
                { "W=", value => options.WarningLevel = value.ParseInt("W") },
                { "O=", value => options.OptimizeLevel = value.ParseInt("O") },
                { "D=|define=", options.Defines.Add },
                { "U=|undefine=", options.Undefines.Add },
                { "release", value => options.Configuration = BuildConfiguration.Release },
                { "test", value => options.Test = true },
                { "z|clean", value => options.Clean = true },
                { "d|debug", value => runArgs.Add("debug") },
                { "r|run", value => run = true },
                { "l|libs", value => options.Library = true },
                { "f|force", value => options.Force = true },
                { "cd=", value => Directory.SetCurrentDirectory(value.ParseString("cd")) },
                { "v", value => log.Level++ },
                { "x", value => Log.EnableExperimental = true }
            }.Parse(args);

            var target  = BuildTargets.Get(targetName, input);
            var project = input.Path(".").GetProjectFile();

            options.NativeArguments = string.Join(" ", nativeArgs);
            options.RunArguments    = string.Join(" ", runArgs);

            if (runArgs.Count > 0 && runArgs[0] == "debug")
            {
                options.Native = false;              // disable native build
                options.Defines.Add("DEBUG_NATIVE"); // disable native optimizations (debug build)
            }

            return(new BuildArguments
            {
                Log = log,
                Options = options,
                Target = target,
                ProjectFile = project,
                Run = run || runArgs.Count > 0,
            });
        }
Esempio n. 6
0
        public static CommandLineOptions From(string[] args)
        {
            var help    = false;
            var verbose = false;
            var quiet   = false;

            var commandOptions = new CommandLineOptions
            {
                Reporter       = "console",
                TestTimeout    = TimeSpan.FromSeconds(10),
                StartupTimeout = TimeSpan.FromMinutes(1),
            };

            string targetName = null;
            var    p          = new OptionSet
            {
                { "h|?|help", "Show help", v => help = v != null },
                { "r|reporter=", "Reporter type. teamcity|console", v => commandOptions.Reporter = v },
                { "l|logfile=", "Write output to this file instead of stdout", v => commandOptions.LogFileName = v },
                { "t|target=", "Build target. Currently supports DotNet|Android|CMake", v => targetName = v },
                { "v|verbose", "Verbose, always prints output from compiler and debug_log", v => verbose = v != null },
                { "q|quiet", "Quiet, only prints output from compiler and debug_log in case of errors.", v => quiet = v != null },
                { "f|filter=", "Only run tests matching this string", v => commandOptions.Filter = Regex.Escape(v) },
                { "e|regex-filter=", "Only run tests matching this regular expression", v => commandOptions.Filter = v },
                { "o|timeout=", "Timeout for individual tests (in seconds)", (int v) => { commandOptions.TestTimeout = TimeSpan.FromSeconds(v); } },
                { "startup-timeout=", "Timeout for connection from uno process (in seconds)", (int v) => { commandOptions.StartupTimeout = TimeSpan.FromSeconds(v); } },
                { "trace", "Print trace information from unotest", v => { commandOptions.Trace = v != null; } },
                { "allow-debugger", "Don't run compiled program, allow user to start it from a debugger.", v => commandOptions.AllowDebugger = v != null },
                { "d|debug", "Open IDE for debugging tests.", v => commandOptions.OpenDebugger = v != null },
                { "run-local", "Run the test directly, without using HTTP", v => commandOptions.RunLocal = v != null },
                { "no-uninstall", "Don't uninstall tests after running on device", v => commandOptions.NoUninstall = v != null },
                { "D=|define=", "Add define, to enable a feature", commandOptions.Defines.Add },
                { "U=|undefine=", "Remove define, to disable a feature", commandOptions.Undefines.Add },
                { "output-dir=", "Override output directory", v => commandOptions.OutputDirectory = v },
                { "libs", "Rebuild package library if necessary", v => commandOptions.Library = true },
            };

            try
            {
                var extra = p.Parse(args);
                commandOptions.Target  = BuildTargets.Get(targetName, extra, DefaultTarget);
                commandOptions.Paths   = extra;
                commandOptions.Verbose = verbose;

                if (verbose && quiet)
                {
                    throw new ArgumentException("Cannot specify both -q and -v");
                }

                if (commandOptions.AllowDebugger || commandOptions.OpenDebugger)
                {
                    commandOptions.StartupTimeout = TimeSpan.FromDays(1);
                    commandOptions.TestTimeout    = TimeSpan.FromDays(1);
                }
            }
            catch (OptionException e)
            {
                Console.WriteLine(e);
                PrintHelp(p);
                return(null);
            }

            if (help)
            {
                PrintHelp(p);
                return(null);
            }

            return(commandOptions);
        }