/// <summary> /// Creates a new debuggee instance. This will copy the debuggee into a new folder based on the debuggeeMoniker. /// This should only be called once per debuggee. /// </summary> public static IDebuggee Create(ILoggingComponent logger, ICompilerSettings settings, string debuggeeName, int debuggeeMoniker, string outputName = null, CompilerOutputType outputType = CompilerOutputType.Executable) { Debuggee newDebuggee = new Debuggee(logger, settings, debuggeeName, debuggeeMoniker, outputName, outputType); newDebuggee.CopySource(); return(newDebuggee); }
private Debuggee(ILoggingComponent logger, ICompilerSettings settings, string debuggeeName, int debuggeeMoniker, string outputName, CompilerOutputType outputType) { Parameter.ThrowIfNull(logger, nameof(logger)); Parameter.ThrowIfNullOrWhiteSpace(debuggeeName, nameof(debuggeeName)); Parameter.ThrowIfNegativeOrZero(debuggeeMoniker, nameof(debuggeeMoniker)); Parameter.ThrowIfNull(settings, nameof(settings)); this.OutputHelper = logger.OutputHelper; this.compilerDefineConstants = new Dictionary <string, string>(); this.debuggeeName = debuggeeName; this.debuggeeMoniker = debuggeeMoniker; this.CompilerOptions = CompilerOption.GenerateSymbols; this.libraries = new List <string>(); this.outputType = outputType; this.settings = settings; this.sourceFilePaths = new List <string>(); if (String.IsNullOrEmpty(outputName)) { // If the outputName was not provided, assume it is called "a.out" and update the extension outputName = Debuggee.UpdateOutputName("a.out", outputType); } else if (String.IsNullOrEmpty(Path.GetExtension(outputName))) { // If the outputName has no extension, add the appropriate extension outputName = Debuggee.UpdateOutputName(outputName, outputType); } this.outputName = outputName; }
public static IDebuggee Open(ILoggingComponent logger, ICompilerSettings settings, int moniker, string name, string outputname) { lock (s_lock) { IDebuggee debuggee = Debuggee.Open(logger, settings, name, moniker, outputname); Assert.True(File.Exists(debuggee.OutputPath), "The debuggee was not compiled. Missing " + debuggee.OutputPath); return(debuggee); } }
public CompilerBase(ILoggingComponent logger, ICompilerSettings settings, bool addDebuggerDirToPath) { Parameter.ThrowIfNull(logger, nameof(logger)); Parameter.ThrowIfNull(settings, nameof(settings)); this.addDebuggerDirToPath = addDebuggerDirToPath; this.OutputHelper = logger.OutputHelper; this.Settings = settings; }
private static string ExpandedCode(string shaderCode, string shaderFileDir, ICompilerSettings settings, HashSet <string> includedFiles = null) { if (includedFiles is null) { includedFiles = new HashSet <string>(); } string SpecialCommentReplacement(string code, string specialComment) { var lines = code.Split(new[] { '\n' }, StringSplitOptions.None); //if UNIX style line endings still working so do not use Envirnoment.NewLine for (int i = 0; i < lines.Length; ++i) { var index = lines[i].IndexOf(specialComment); // search for special comment if (-1 != index) { lines[i] = lines[i].Substring(index + specialComment.Length); // remove everything before special comment } } return(string.Join("\n", lines)); } string GetIncludeCode(string includeName) { var includeFileName = Path.GetFullPath(Path.Combine(shaderFileDir, includeName)); if (File.Exists(includeFileName)) { var includeCode = File.ReadAllText(includeFileName); if (includedFiles.Contains(includeFileName)) { return(includeCode); } includedFiles.Add(includeFileName); return(ExpandedCode(includeCode, Path.GetDirectoryName(includeFileName), settings, includedFiles: includedFiles)); } return($"#error include file '{includeName}' not found"); } shaderCode = SpecialCommentReplacement(shaderCode, "//!"); if (includedFiles.Count == 0) { shaderCode = SpecialCommentReplacement(shaderCode, "//?"); } if (settings.ExpandIncludes) { return(GLSLhelper.Transformation.ExpandIncludes(shaderCode, GetIncludeCode)); } else { return(shaderCode); } }
public static IDebuggee OpenAndCompile(ILoggingComponent logger, ICompilerSettings settings, int moniker, string name, string outputname, Action <IDebuggee> addSourceFiles) { Assert.NotNull(addSourceFiles); lock (s_lock) { IDebuggee debuggee = Debuggee.Create(logger, settings, name, moniker, outputname); addSourceFiles(debuggee); debuggee.Compile(); return(debuggee); } }
static CompilationSettingsHelper() { var ttl = DefaultCompilerServerTTL; var devEnvironmentSetting = Environment.GetEnvironmentVariable(DevEnvironmentVariableName, EnvironmentVariableTarget.Process); var debuggerAttachedEnvironmentSetting = Environment.GetEnvironmentVariable(DebuggerAttachedEnvironmentVariable, EnvironmentVariableTarget.Process); var customTtlSetting = Environment.GetEnvironmentVariable(CustomTTLEnvironmentVariableName, EnvironmentVariableTarget.Process); var isDebuggerAttached = IsDebuggerAttached; int customTtl; // custom TTL setting always win if (int.TryParse(customTtlSetting, out customTtl)) { ttl = customTtl; } else { if (!string.IsNullOrEmpty(devEnvironmentSetting) || !string.IsNullOrEmpty(debuggerAttachedEnvironmentSetting) || isDebuggerAttached) { ttl = DefaultCompilerServerTTLInDevEnvironment; } } // locate Roslyn compilers order: 1. environment variable 2. appsetting 3. default location var customRoslynCompilerLocation = Environment.GetEnvironmentVariable(CustomRoslynCompilerLocation, EnvironmentVariableTarget.Process); if (string.IsNullOrEmpty(customRoslynCompilerLocation)) { customRoslynCompilerLocation = AppSettings.RoslynCompilerLocation; } if (!string.IsNullOrEmpty(customRoslynCompilerLocation)) { _csc = new CompilerSettings($"{customRoslynCompilerLocation}\\csc.exe", ttl); _vb = new CompilerSettings($"{customRoslynCompilerLocation}\\vbc.exe", ttl); } else { _csc = new CompilerSettings(CompilerFullPath(@"bin\roslyn\csc.exe"), ttl); _vb = new CompilerSettings(CompilerFullPath(@"bin\roslyn\vbc.exe"), ttl); } if (isDebuggerAttached) { Environment.SetEnvironmentVariable(DebuggerAttachedEnvironmentVariable, "1", EnvironmentVariableTarget.Process); } }
static CompilationSettingsHelper() { var ttl = DefaultCompilerServerTTL; var devEnvironmentSetting = Environment.GetEnvironmentVariable(DevEnvironmentVariableName, EnvironmentVariableTarget.Process); var debuggerAttachedEnvironmentSetting = Environment.GetEnvironmentVariable(DebuggerAttachedEnvironmentVariable, EnvironmentVariableTarget.Process); var customTtlSetting = Environment.GetEnvironmentVariable(CustomTTLEnvironmentVariableName, EnvironmentVariableTarget.Process); var isDebuggerAttached = IsDebuggerAttached; int customTtl; // custom TTL setting always win if (int.TryParse(customTtlSetting, out customTtl)) { ttl = customTtl; } else { if (!string.IsNullOrEmpty(devEnvironmentSetting) || !string.IsNullOrEmpty(debuggerAttachedEnvironmentSetting) || isDebuggerAttached) { ttl = DefaultCompilerServerTTLInDevEnvironment; } } var customRoslynCompilerLocation = Environment.GetEnvironmentVariable(CustomRoslynCompilerLocation, EnvironmentVariableTarget.Process); if (customRoslynCompilerLocation != null) { var bin = @"c:\Work_Exe\prekesweb.v3\bin\roslyn"; if (!File.Exists($"{customRoslynCompilerLocation}\\csc.exe") && File.Exists($"{bin}\\csc.exe")) { customRoslynCompilerLocation = bin; } _csc = new CompilerSettings($"{customRoslynCompilerLocation}\\csc.exe", ttl); } else { _csc = new CompilerSettings(CompilerFullPath(@"bin\roslyn\csc.exe"), ttl); } if (isDebuggerAttached) { Environment.SetEnvironmentVariable(DebuggerAttachedEnvironmentVariable, "1", EnvironmentVariableTarget.Process); } }
private static CompilerBase CreateCompiler(ILoggingComponent logger, ICompilerSettings settings) { switch (settings.CompilerType) { case SupportedCompiler.GPlusPlus: return(new GppCompiler(logger, settings)); case SupportedCompiler.ClangPlusPlus: return(new ClangCompiler(logger, settings)); case SupportedCompiler.VisualCPlusPlus: return(new VisualCPlusPlusCompiler(logger, settings)); default: throw new ArgumentOutOfRangeException(nameof(settings.CompilerType), "Unhandled compiler toolset: " + settings.CompilerType); } }
public VBCodeProvider(ICompilerSettings compilerSettings = null) { _providerOptions = compilerSettings == null ? CompilationUtil.VBC2 : new ProviderOptions(compilerSettings); }
/// <summary> /// Creates an instance using the given ICompilerSettings /// </summary> /// <param name="compilerSettings"></param> public VBCodeProvider(ICompilerSettings compilerSettings = null) { _compilerSettings = compilerSettings == null ? CompilationSettingsHelper.VBC2 : compilerSettings; }
public static IDebuggee OpenAndCompile(ILoggingComponent logger, ICompilerSettings settings, int moniker) { return(DebuggeeHelper.OpenAndCompile(logger, settings, moniker, SinkHelper.Name, SinkHelper.OutputName, SinkHelper.AddSourceFiles)); }
public SquiggleTaggerProvider(ShaderCompiler shaderCompiler, ICompilerSettings settings) { this.shaderCompiler = shaderCompiler ?? throw new ArgumentNullException(nameof(shaderCompiler)); this.settings = settings ?? throw new ArgumentNullException(nameof(settings)); }
public GppCompiler(ILoggingComponent logger, ICompilerSettings settings) : base(logger, settings) { }
private static string CompileExternal(string shaderCode, string shaderContentType, ILogger logger, ICompilerSettings settings) { //create temp shader file for external compiler var tempPath = Path.GetTempPath(); var shaderFileName = Path.Combine(tempPath, $"shader{ShaderContentTypes.DefaultFileExtension(shaderContentType)}"); try { File.WriteAllText(shaderFileName, shaderCode); using (var process = new Process()) { process.StartInfo.FileName = VsExpand.EnvironmentVariables(settings.ExternalCompilerExeFilePath); var arguments = VsExpand.EnvironmentVariables(settings.ExternalCompilerArguments); process.StartInfo.Arguments = $"{arguments} \"{shaderFileName}\""; //arguments process.StartInfo.WorkingDirectory = tempPath; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.CreateNoWindow = true; //do not display a windows logger.Log($"Using external compiler '{settings.ExternalCompilerExeFilePath}' with arguments '{arguments}' on temporal shader file '{shaderFileName}'", true); process.Start(); if (!process.WaitForExit(10000)) { logger.Log("External compiler did take more than 10 seconds to finish. Aborting!", true); } return(process.StandardOutput.ReadToEnd() + process.StandardError.ReadToEnd()); //The output result } } catch (Exception e) { var message = "Error executing external compiler with message\n" + e.ToString(); logger.Log(message, true); return(string.Empty); } }
public MSVCCompiler(ICompilerSettings settings, string defFile) { this.m_Settings = settings; this.m_DefFile = defFile; }
public ClangCompiler(ICompilerSettings settings) { this.m_Settings = settings; }
public GccCompiler(ICompilerSettings settings) { this.m_Settings = settings; }
public Compiler(CodeDomProvider codeDomProvider, ICompilerSettings compilerSettings) { this._codeDomProvider = codeDomProvider; this._compilerSettings = compilerSettings; }
/// <summary> /// Opens an existing debuggee instance. /// </summary> public static IDebuggee Open(ILoggingComponent logger, ICompilerSettings settings, string debuggeeName, int debuggeeMoniker, string outputName = null, CompilerOutputType outputType = CompilerOutputType.Executable) { return(new Debuggee(logger, settings, debuggeeName, debuggeeMoniker, outputName, outputType)); }
private static bool Matches(this IEnumerable <SupportedCompilerAttribute> compilers, ICompilerSettings settings) { return(compilers.Any(ca => ca.Compiler.HasFlag(settings.CompilerType) && ca.Architecture.HasFlag(settings.DebuggeeArchitecture))); }
private string GetOutputRoot(ICompilerSettings settings) { return(Path.Combine(this.DebuggeeInstance, "out", settings.CompilerName, settings.DebuggeeArchitecture.ToArchitectureString())); }
public CSharpCompiler(CodeDomProvider codeDomProvider, ICompilerSettings compilerSettings = null) : base(codeDomProvider, compilerSettings) { }
#pragma warning disable CS0618 internal ProviderOptions(ICompilerSettings settings) : this(settings.CompilerFullPath, settings.CompilerServerTimeToLive) { }
public static IDebuggee Open(ILoggingComponent logger, ICompilerSettings settings, int moniker) { return(DebuggeeHelper.Open(logger, settings, moniker, SourceMappingHelper.Name, SourceMappingHelper.OutputName)); }
private static string Compile(string shaderCode, string shaderContentType, ILogger logger, ICompilerSettings settings) { if (ShaderContentTypes.AutoDetect == shaderContentType) { shaderContentType = AutoDetectShaderContentType(shaderCode); logger.Log($"Auto detecting shader type to '{shaderContentType}'", true); } if (string.IsNullOrWhiteSpace(settings.ExternalCompilerExeFilePath)) { return(CompileOnGPU(shaderCode, shaderContentType, logger)); } else { return(CompileExternal(shaderCode, shaderContentType, logger, settings)); } }
/// <summary> /// Creates an instance using the given ICompilerSettings /// </summary> /// <param name="compilerSettings"></param> public CSharpCodeProvider(ICompilerSettings compilerSettings = null) { _compilerSettings = compilerSettings == null ? CompilationSettingsHelper.CSC2 : compilerSettings; }
public ShaderCompiler(ICompilerSettings settings, ILogger logger) { this.settings = settings ?? throw new ArgumentNullException(nameof(settings)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public GppStyleCompiler(ILoggingComponent logger, ICompilerSettings settings) : base(logger, settings, PlatformUtilities.IsWindows) { }
public VisualCPlusPlusCompiler(ILoggingComponent logger, ICompilerSettings settings) : base(logger, settings, addDebuggerDirToPath: false) { }