/// <summary> /// Processes command line arguments. /// </summary> /// <param name="args">The command line arguments.</param> /// <returns>Whether to run compilation.</returns> private static bool ProcessArguments(string[] args) { for (int i = 0; i < args.Length; i++) { Debug.Assert(args[i].Length > 0); // option: if (args[i][0] == '/') { int colon = args[i].IndexOf(':'); if (colon >= 0) { // option having format "/name:value" string name = args[i].Substring(1, colon - 1).Trim(); string value = args[i].Substring(colon + 1).Trim(); switch (name) { case "compiler": if (compiler != null) { throw new InvalidArgumentException(String.Format("Option {0} specified twice.", name)); } compiler = Path.GetFullPath(value); if (!File.Exists(compiler)) { throw new InvalidArgumentException(String.Format("Compiler {0} not found.", compiler)); } break; case "loader": if (loader != null) { throw new InvalidArgumentException(String.Format("Option {0} specified twice.", name)); } loader = Path.GetFullPath(value); if (!File.Exists(loader)) { throw new InvalidArgumentException(String.Format("Compiler {0} not found.", loader)); } break; case "out": if (outputDir != null) { throw new InvalidArgumentException(String.Format("Option {0} specified twice.", name)); } outputDir = Path.GetFullPath(value); if (!Directory.Exists(outputDir)) { throw new InvalidArgumentException(String.Format("Output directory {0} not found.", outputDir)); } break; case "php": if (php != null) { throw new InvalidArgumentException(String.Format("Option {0} specified twice.", name)); } php = Path.GetFullPath(value); if (!File.Exists(php)) { throw new InvalidArgumentException(String.Format("PHP (original) executable file {0} not found.", php)); } break; case "log": if (value == "full") { fullLog = true; } else if (value == "short") { fullLog = false; } else { throw new InvalidArgumentException(String.Format("Illegal /log:{0} option.", value)); } break; case "benchmark": if (benchmarks) { throw new InvalidArgumentException("/benchmark option specified twice"); } benchmarks = true; try { int slash = value.IndexOf('/'); if (slash < 0) { numberOfBenchmarkRuns = Int32.Parse(value); } else { numberOfBenchmarkRuns = Int32.Parse(value.Substring(0, slash)); benchmarkWarmup = Int32.Parse(value.Substring(slash + 1)); } } catch (Exception) { throw new TestException("Error /benchmark value."); } break; case "j": maxThreads = Math.Max(Int32.Parse(value), 1); break; case "p": switch (value) { case "none": maxThreads = 1; concurrencyLevel = TestsCollection.ConcurrencyLevel.None; break; case "folder": concurrencyLevel = TestsCollection.ConcurrencyLevel.Folder; break; case "compile": concurrencyLevel = TestsCollection.ConcurrencyLevel.Compile; break; case "skipif": concurrencyLevel = TestsCollection.ConcurrencyLevel.SkipIf; break; case "full": concurrencyLevel = TestsCollection.ConcurrencyLevel.Full; break; default: throw new InvalidArgumentException( String.Format( "Invalid value for conncurrency-level [{0}] in option [{1}].", value, name)); } break; default: throw new InvalidArgumentException(String.Format("Invalid option {0}.", name)); } } else { // option without ':' string name = args[i].Substring(1).Trim(); switch (name) { case "verbose": verbose = true; break; case "clean": clean = true; break; case "compileonly": compileOnly = true; break; case "j": maxThreads = Environment.ProcessorCount; break; default: throw new InvalidArgumentException(String.Format("Invalid option {0}.", args[i])); } } } else { // arguments testDirsAndFiles.Add(args[i]); } } if (maxThreads <= 1) { concurrencyLevel = TestsCollection.ConcurrencyLevel.None; } else if (concurrencyLevel == TestsCollection.ConcurrencyLevel.None) { maxThreads = 1; } // default values if (testDirsAndFiles.Count == 0) { testDirsAndFiles.Add(Directory.GetCurrentDirectory()); } if (compiler == null) { compiler = Path.Combine(Directory.GetCurrentDirectory(), "phpc.exe"); } if (php == null) { php = Path.Combine(Directory.GetCurrentDirectory(), "php.exe"); } if (outputDir == null) { outputDir = Directory.GetCurrentDirectory(); } return(true); }
/// <summary> /// Processes command line arguments. /// </summary> /// <param name="args">The command line arguments.</param> /// <returns>Whether to run compilation.</returns> private static bool ProcessArguments(string[] args) { for (int i = 0; i < args.Length; i++) { Debug.Assert(args[i].Length > 0); // option: if (args[i][0] == '/') { int colon = args[i].IndexOf(':'); if (colon >= 0) { // option having format "/name:value" string name = args[i].Substring(1, colon - 1).Trim(); string value = args[i].Substring(colon + 1).Trim(); switch (name) { case "compiler": if (compiler != null) throw new InvalidArgumentException(String.Format("Option {0} specified twice.", name)); compiler = Path.GetFullPath(value); if (!File.Exists(compiler)) throw new InvalidArgumentException(String.Format("Compiler {0} not found.", compiler)); break; case "loader": if (loader != null) throw new InvalidArgumentException(String.Format("Option {0} specified twice.", name)); loader = Path.GetFullPath(value); if (!File.Exists(loader)) throw new InvalidArgumentException(String.Format("Compiler {0} not found.", loader)); break; case "out": if (outputDir != null) throw new InvalidArgumentException(String.Format("Option {0} specified twice.", name)); outputDir = Path.GetFullPath(value); if (!Directory.Exists(outputDir)) throw new InvalidArgumentException(String.Format("Output directory {0} not found.", outputDir)); break; case "php": if (php != null) throw new InvalidArgumentException(String.Format("Option {0} specified twice.", name)); php = Path.GetFullPath(value); if (!File.Exists(php)) throw new InvalidArgumentException(String.Format("PHP (original) executable file {0} not found.", php)); break; case "log": if (value == "full") fullLog = true; else if (value == "short") fullLog = false; else throw new InvalidArgumentException(String.Format("Illegal /log:{0} option.", value)); break; case "benchmark": if (benchmarks) { throw new InvalidArgumentException("/benchmark option specified twice"); } benchmarks = true; try { int slash = value.IndexOf('/'); if (slash < 0) { numberOfBenchmarkRuns = Int32.Parse(value); } else { numberOfBenchmarkRuns = Int32.Parse(value.Substring(0, slash)); benchmarkWarmup = Int32.Parse(value.Substring(slash + 1)); } } catch (Exception) { throw new TestException("Error /benchmark value."); } break; case "j": maxThreads = Math.Max(Int32.Parse(value), 1); break; case "p": switch (value) { case "none": maxThreads = 1; concurrencyLevel = TestsCollection.ConcurrencyLevel.None; break; case "folder": concurrencyLevel = TestsCollection.ConcurrencyLevel.Folder; break; case "compile": concurrencyLevel = TestsCollection.ConcurrencyLevel.Compile; break; case "skipif": concurrencyLevel = TestsCollection.ConcurrencyLevel.SkipIf; break; case "full": concurrencyLevel = TestsCollection.ConcurrencyLevel.Full; break; default: throw new InvalidArgumentException( String.Format( "Invalid value for conncurrency-level [{0}] in option [{1}].", value, name)); } break; default: throw new InvalidArgumentException(String.Format("Invalid option {0}.", name)); } } else { // option without ':' string name = args[i].Substring(1).Trim(); switch (name) { case "verbose": verbose = true; break; case "clean": clean = true; break; case "compileonly": compileOnly = true; break; case "j": maxThreads = Environment.ProcessorCount; break; default: throw new InvalidArgumentException(String.Format("Invalid option {0}.", args[i])); } } } else { // arguments testDirsAndFiles.Add(args[i]); } } if (maxThreads <= 1) { concurrencyLevel = TestsCollection.ConcurrencyLevel.None; } else if (concurrencyLevel == TestsCollection.ConcurrencyLevel.None) { maxThreads = 1; } // default values if (testDirsAndFiles.Count == 0) { testDirsAndFiles.Add(Directory.GetCurrentDirectory()); } if (compiler == null) { compiler = Path.Combine(Directory.GetCurrentDirectory(), "phpc.exe"); } if (php == null) { php = Path.Combine(Directory.GetCurrentDirectory(), "php.exe"); } if (outputDir == null) { outputDir = Directory.GetCurrentDirectory(); } return true; }