public int RunMain(string[] args) { ConsoleText.WriteStatus("Orleans-CodeGen - command-line = {0}", Environment.CommandLine); if (args.Length < 1) { Console.WriteLine( "Usage: ClientGenerator.exe <grain interface dll path> [<client dll path>] [<key file>] [<referenced assemblies>]"); Console.WriteLine( " ClientGenerator.exe /server <grain dll path> [<factory dll path>] [<key file>] [<referenced assemblies>]"); return(1); } try { var options = new CodeGenOptions(); // STEP 1 : Parse parameters if (args.Length == 1 && args[0].StartsWith("@")) { // Read command line args from file string arg = args[0]; string argsFile = arg.Trim('"').Substring(1).Trim('"'); Console.WriteLine("Orleans-CodeGen - Reading code-gen params from file={0}", argsFile); AssertWellFormed(argsFile, true); args = File.ReadAllLines(argsFile); } int i = 1; foreach (string a in args) { string arg = a.Trim('"').Trim().Trim('"'); if (GrainClientGeneratorFlags.Verbose) { Console.WriteLine("Orleans-CodeGen - arg #{0}={1}", i++, arg); } if (string.IsNullOrEmpty(arg) || string.IsNullOrWhiteSpace(arg)) { continue; } if (arg.StartsWith("/")) { if (arg.StartsWith("/reference:") || arg.StartsWith("/r:")) { // list of references passed from from project file. separator =';' string refstr = arg.Substring(arg.IndexOf(':') + 1); string[] references = refstr.Split(';'); foreach (string rp in references) { AssertWellFormed(rp, true); options.ReferencedAssemblies.Add(rp); } } else if (arg.StartsWith("/in:")) { var infile = arg.Substring(arg.IndexOf(':') + 1); AssertWellFormed(infile); options.InputLib = new FileInfo(infile); } else if (arg.StartsWith("/bootstrap") || arg.StartsWith("/boot")) { // special case for building circular dependecy in preprocessing: // Do not build the input assembly, assume that some other build step options.CodeGenFile = Path.GetFullPath(CodeGenFileRelativePathCSharp); if (GrainClientGeneratorFlags.Verbose) { Console.WriteLine( "Orleans-CodeGen - Set CodeGenFile={0} from bootstrap", options.CodeGenFile); } } else if (arg.StartsWith("/sources:") || arg.StartsWith("/src:")) { var sourcesStr = arg.Substring(arg.IndexOf(':') + 1); string[] sources = sourcesStr.Split(';'); foreach (var source in sources) { HandleSourceFile(source, options); } } } else { HandleSourceFile(arg, options); } } if (options.InvalidLanguage) { ConsoleText.WriteLine( "ERROR: Compile-time code generation is supported for C# only. " + "Remove code generation from your project in order to use run-time code generation."); return(2); } // STEP 2 : Validate and calculate unspecified parameters if (options.InputLib == null) { Console.WriteLine("ERROR: Orleans-CodeGen - no input file specified."); return(2); } if (string.IsNullOrEmpty(options.CodeGenFile)) { Console.WriteLine( "ERROR: No codegen file. Add a file '{0}' to your project", Path.Combine("Properties", "orleans.codegen.cs")); return(2); } options.SourcesDir = Path.Combine(options.InputLib.DirectoryName, "Generated"); // STEP 3 : Dump useful info for debugging Console.WriteLine( "Orleans-CodeGen - Options " + Environment.NewLine + "\tInputLib={0} " + Environment.NewLine + "\tCodeGenFile={1}", options.InputLib.FullName, options.CodeGenFile); if (options.ReferencedAssemblies != null) { Console.WriteLine("Orleans-CodeGen - Using referenced libraries:"); foreach (string assembly in options.ReferencedAssemblies) { Console.WriteLine("\t{0} => {1}", Path.GetFileName(assembly), assembly); } } // STEP 5 : Finally call code generation if (!CreateGrainClientAssembly(options)) { return(-1); } // DONE! return(0); } catch (Exception ex) { File.WriteAllText("error.txt", ex.Message + Environment.NewLine + ex.StackTrace); Console.WriteLine("-- Code-gen FAILED -- \n{0}", LogFormatter.PrintException(ex)); return(3); } }
public int RunMain(string[] args) { ConsoleText.WriteStatus("Orleans-CodeGen - command-line = {0}", Environment.CommandLine); if (args.Length < 1) { PrintUsage(); return(1); } try { var options = new CodeGenOptions(); // STEP 1 : Parse parameters if (args.Length == 1 && args[0].StartsWith("@")) { // Read command line args from file string arg = args[0]; string argsFile = arg.Trim('"').Substring(1).Trim('"'); Console.WriteLine("Orleans-CodeGen - Reading code-gen params from file={0}", argsFile); AssertWellFormed(argsFile, true); args = File.ReadAllLines(argsFile); } int i = 1; foreach (string a in args) { string arg = a.Trim('"').Trim().Trim('"'); if (GrainClientGeneratorFlags.Verbose) { Console.WriteLine("Orleans-CodeGen - arg #{0}={1}", i++, arg); } if (string.IsNullOrEmpty(arg) || string.IsNullOrWhiteSpace(arg)) { continue; } if (arg.StartsWith("/")) { if (arg.StartsWith("/reference:") || arg.StartsWith("/r:")) { // list of references passed from from project file. separator =';' string refstr = arg.Substring(arg.IndexOf(':') + 1); string[] references = refstr.Split(';'); foreach (string rp in references) { AssertWellFormed(rp, true); options.ReferencedAssemblies.Add(rp); } } else if (arg.StartsWith("/in:")) { var infile = arg.Substring(arg.IndexOf(':') + 1); AssertWellFormed(infile); options.InputAssembly = new FileInfo(infile); } else if (arg.StartsWith("/out:")) { var outfile = arg.Substring(arg.IndexOf(':') + 1); AssertWellFormed(outfile, false); options.OutputFileName = outfile; } } else { Console.WriteLine($"Invalid argument: {arg}."); PrintUsage(); return(1); } } // STEP 2 : Validate and calculate unspecified parameters if (options.InputAssembly == null) { Console.WriteLine("ERROR: Orleans-CodeGen - no input file specified."); return(2); } if (String.IsNullOrEmpty(options.OutputFileName)) { Console.WriteLine("ERROR: Orleans-Codegen - no output filename specified"); return(2); } // STEP 3 : Dump useful info for debugging Console.WriteLine($"Orleans-CodeGen - Options {Environment.NewLine}\tInputLib={options.InputAssembly.FullName}{Environment.NewLine}\tOutputFileName={options.OutputFileName}"); if (options.ReferencedAssemblies != null) { Console.WriteLine("Orleans-CodeGen - Using referenced libraries:"); foreach (string assembly in options.ReferencedAssemblies) { Console.WriteLine("\t{0} => {1}", Path.GetFileName(assembly), assembly); } } // STEP 5 : Finally call code generation if (!CreateGrainClientAssembly(options)) { return(-1); } // DONE! return(0); } catch (Exception ex) { Console.WriteLine("-- Code-gen FAILED -- \n{0}", LogFormatter.PrintException(ex)); return(3); } }
public int RunMain(string[] args) { ConsoleText.WriteStatus("Orleans-CodeGen - command-line = {0}", Environment.CommandLine); if (args.Length < 1) { Console.WriteLine( "Usage: ClientGenerator.exe <grain interface dll path> [<client dll path>] [<key file>] [<referenced assemblies>]"); Console.WriteLine( " ClientGenerator.exe /server <grain dll path> [<factory dll path>] [<key file>] [<referenced assemblies>]"); return(1); } try { var options = new CodeGenOptions(); // STEP 1 : Parse parameters if (args.Length == 1 && args[0].StartsWith("@")) { // Read command line args from file string arg = args[0]; string argsFile = arg.Trim('"').Substring(1).Trim('"'); Console.WriteLine("Orleans-CodeGen - Reading code-gen params from file={0}", argsFile); AssertWellFormed(argsFile, true); args = File.ReadAllLines(argsFile); } int i = 1; foreach (string a in args) { string arg = a.Trim('"').Trim().Trim('"'); if (GrainClientGeneratorFlags.Verbose) { Console.WriteLine("Orleans-CodeGen - arg #{0}={1}", i++, arg); } if (string.IsNullOrEmpty(arg) || string.IsNullOrWhiteSpace(arg)) { continue; } if (arg.StartsWith("/")) { if (arg.StartsWith("/reference:") || arg.StartsWith("/r:")) { // list of references passed from from project file. separator =';' string refstr = arg.Substring(arg.IndexOf(':') + 1); string[] references = refstr.Split(';'); foreach (string rp in references) { AssertWellFormed(rp, true); options.ReferencedAssemblies.Add(rp); } } else if (arg.StartsWith("/cwd:")) { options.WorkingDirectory = arg.Substring(arg.IndexOf(':') + 1); } else if (arg.StartsWith("/in:")) { var infile = arg.Substring(arg.IndexOf(':') + 1); AssertWellFormed(infile); options.InputLib = new FileInfo(infile); } else if (arg.StartsWith("/keyfile:") || arg.StartsWith("/key:")) { string keyFile = arg.Substring(arg.IndexOf(':') + 1); if (!string.IsNullOrWhiteSpace(keyFile)) { AssertWellFormed(keyFile, true); options.SigningKey = new FileInfo(keyFile); } } else if (arg.StartsWith("/config:")) { options.Config = arg.Substring(arg.IndexOf(':') + 1); } else if (arg.StartsWith("/fsharp:")) { var path = arg.Substring(arg.IndexOf(':') + 1); if (!string.IsNullOrEmpty(path)) { Console.WriteLine("F# compiler path = '{0}' ", path); options.FSharpCompilerPath = path; } else { Console.WriteLine("F# compiler path not set."); } } else if (arg.StartsWith("/rootns:") || arg.StartsWith("/rns:")) { options.RootNamespace = arg.Substring(arg.IndexOf(':') + 1); } else if (arg.StartsWith("/bootstrap") || arg.StartsWith("/boot")) { // special case for building circular dependecy in preprocessing: // Do not build the input assembly, assume that some other build step options.CodeGenFile = Path.GetFullPath(CodeGenFileRelativePathCSharp); if (GrainClientGeneratorFlags.Verbose) { Console.WriteLine( "Orleans-CodeGen - Set CodeGenFile={0} from bootstrap", options.CodeGenFile); } } else if (arg.StartsWith("/define:") || arg.StartsWith("/d:")) { // #define constants passed from project file. separator =';' var definsStr = arg.Substring(arg.IndexOf(':') + 1); if (!string.IsNullOrWhiteSpace(definsStr)) { string[] defines = definsStr.Split(';'); foreach (var define in defines) { options.Defines.Add(define); } } } else if (arg.StartsWith("/imports:") || arg.StartsWith("/i:")) { // Standard VB imports passed from project file. separator =';' string importsStr = arg.Substring(arg.IndexOf(':') + 1); if (!string.IsNullOrWhiteSpace(importsStr)) { string[] imports = importsStr.Split(';'); foreach (var import in imports) { options.Imports.Add(import); } } } else if (arg.StartsWith("/Option")) // VB-specific options { if (arg.StartsWith("/OptionExplicit:")) { options.OptionExplicit = arg.Substring(arg.IndexOf(':') + 1); } else if (arg.StartsWith("/OptionStrict:")) { options.OptionStrict = arg.Substring(arg.IndexOf(':') + 1); } else if (arg.StartsWith("/OptionInfer:")) { options.OptionInfer = arg.Substring(arg.IndexOf(':') + 1); } else if (arg.StartsWith("/OptionCompare:")) { options.OptionCompare = arg.Substring(arg.IndexOf(':') + 1); } } else if (arg.StartsWith("/MyType:")) // VB-specific option { options.MyType = arg.Substring(arg.IndexOf(':') + 1); } else if (arg.StartsWith("/sources:") || arg.StartsWith("/src:")) { // C# sources passed from from project file. separator = ';' //if (GrainClientGeneratorFlags.Verbose) // Console.WriteLine("Orleans-CodeGen - Unpacking source file list arg={0}", arg); var sourcesStr = arg.Substring(arg.IndexOf(':') + 1); //if (GrainClientGeneratorFlags.Verbose) // Console.WriteLine("Orleans-CodeGen - Splitting source file list={0}", sourcesStr); string[] sources = sourcesStr.Split(';'); foreach (var source in sources) { AddSourceFile( options.SourceFiles, ref options.LanguageConflict, ref options.TargetLanguage, ref options.CodeGenFile, source); } } } else { // files passed in without associated flags , we'll make the best guess. if (arg.ToLowerInvariant().EndsWith(".snk", StringComparison.InvariantCultureIgnoreCase)) { options.SigningKey = new FileInfo(arg); } else { AddSourceFile( options.SourceFiles, ref options.LanguageConflict, ref options.TargetLanguage, ref options.CodeGenFile, arg); } } } if (!options.TargetLanguage.HasValue) { Console.WriteLine("ERROR: Unable to determine source code language to use for code generation."); return(2); } // STEP 2 : Validate and calculate unspecified parameters if (options.InputLib == null) { Console.WriteLine("ERROR: Orleans-CodeGen - no input file specified."); return(2); } if (string.IsNullOrEmpty(options.CodeGenFile)) { Console.WriteLine( "ERROR: No codegen file. Add a file '{0}' to your project", Path.Combine("Properties", "orleans.codegen.cs")); return(2); } // STEP 3 : Check timestamps and skip if output is up-to-date wrt to all inputs /* if (!bootstrap && IsProjectUpToDate(options.InputLib, options.SourceFiles, options.ReferencedAssemblies) * && !Debugger.IsAttached) * { * Console.WriteLine( * "Orleans-CodeGen - Skipping because all output files are up-to-date with respect to the input files."); * return 0; * }*/ options.SourcesDir = Path.Combine(options.InputLib.DirectoryName, "Generated"); // STEP 4 : Dump useful info for debugging Console.WriteLine( "Orleans-CodeGen - Options " + Environment.NewLine + "\tInputLib={0} " + Environment.NewLine + "\tSigningKey={1} " + Environment.NewLine + "\tCodeGenFile={2}", options.InputLib.FullName, options.SigningKey != null ? options.SigningKey.FullName : "", options.CodeGenFile); if (options.ReferencedAssemblies != null) { Console.WriteLine("Orleans-CodeGen - Using referenced libraries:"); foreach (string assembly in options.ReferencedAssemblies) { Console.WriteLine("\t{0} => {1}", Path.GetFileName(assembly), assembly); } } // STEP 5 : // if (!bootstrap) BuildInputAssembly(options); // STEP 6 : Finally call code generation if (!CreateGrainClientAssembly(options)) { return(-1); } // DONE! return(0); } catch (Exception ex) { Console.WriteLine("-- Code-gen FAILED -- \n{0}", TraceLogger.PrintException(ex)); return(3); } }
private string GenerateCodeInCurrentAppDomain(CodeGenOptions options) { return(GenerateCodeInternal(options)); }
public static int Main(string[] args) { CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture; CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture; Console.WriteLine("Orleans-CodeGen - command-line = {0}", Environment.CommandLine); if (args.Length < 1) { PrintUsage(); return(1); } try { var options = new CodeGenOptions(); // STEP 1 : Parse parameters if (args.Length == 1 && args[0].StartsWith("@")) { // Read command line args from file string arg = args[0]; string argsFile = arg.Trim('"').Substring(1).Trim('"'); Console.WriteLine("Orleans-CodeGen - Reading code-gen params from file={0}", argsFile); AssertWellFormed(argsFile); args = File.ReadAllLines(argsFile); } foreach (string a in args) { string arg = a.Trim('"').Trim().Trim('"'); if (string.IsNullOrEmpty(arg) || string.IsNullOrWhiteSpace(arg)) { continue; } if (arg.StartsWith("/")) { if (arg.StartsWith("/reference:") || arg.StartsWith("/r:")) { // list of references passed from from project file. separator =';' string refstr = arg.Substring(arg.IndexOf(':') + 1); string[] references = refstr.Split(';'); foreach (string rp in references) { AssertWellFormed(rp); options.ReferencedAssemblies.Add(rp); } } else if (arg.StartsWith("/in:")) { var infile = arg.Substring(arg.IndexOf(':') + 1); AssertWellFormed(infile); options.InputAssembly = new FileInfo(infile); } else if (arg.StartsWith("/out:")) { var outfile = arg.Substring(arg.IndexOf(':') + 1); AssertWellFormed(outfile); options.OutputFileName = outfile; } else if (arg.StartsWith("/loglevel:")) { var levelString = arg.Substring(arg.IndexOf(':') + 1); if (!Enum.TryParse(ignoreCase: true, value: levelString, result: out LogLevel level)) { var validValues = string.Join(", ", Enum.GetNames(typeof(LogLevel)).Select(v => v.ToString())); Console.WriteLine($"ERROR: \"{levelString}\" is not a valid log level. Valid values are {validValues}"); return(1); } options.LogLevel = level; } } else { Console.WriteLine($"Invalid argument: {arg}."); PrintUsage(); return(1); } } // STEP 2 : Validate and calculate unspecified parameters if (options.InputAssembly == null) { Console.WriteLine("ERROR: Orleans-CodeGen - no input file specified."); return(2); } if (String.IsNullOrEmpty(options.OutputFileName)) { Console.WriteLine("ERROR: Orleans-Codegen - no output filename specified"); return(2); } // STEP 3 : Dump useful info for debugging Console.WriteLine($"Orleans-CodeGen - Options {Environment.NewLine}\tInputLib={options.InputAssembly.FullName}{Environment.NewLine}\tOutputFileName={options.OutputFileName}"); bool referencesOrleans = options.InputAssembly.Name.Equals(CodeGenerator.OrleansAssemblyFileName); foreach (string assembly in options.ReferencedAssemblies) { var fileName = Path.GetFileName(assembly); Console.WriteLine("\t{0} => {1}", fileName, assembly); if (fileName != null && fileName.Equals(CodeGenerator.OrleansAssemblyFileName)) { referencesOrleans = true; } } // STEP 5 : Finally call code generation var stopWatch = Stopwatch.StartNew(); if (referencesOrleans) { if (!CodeGenerator.GenerateCode(options)) { Console.WriteLine("WARNING: Orleans-CodeGen - the input assembly contained no types which required code generation."); } } else { Console.WriteLine("ERROR: Orleans-CodeGen - the input assembly does not reference Orleans and therefore code can not be generated."); return(-2); } stopWatch.Stop(); Console.WriteLine($"Build time code generation for assembly {options.InputAssembly} took {stopWatch.ElapsedMilliseconds} milliseconds"); // DONE! return(0); } catch (Exception ex) { Console.WriteLine("-- Code Generation FAILED -- \n{0}", LogFormatter.PrintException(ex)); return(3); } }