private static CSharpCompilationOptions GetCompilationOptions(ICompilerOptions compilerOptions, string projectDirectory) { var outputKind = compilerOptions.EmitEntryPoint.GetValueOrDefault() ? OutputKind.ConsoleApplication : OutputKind.DynamicallyLinkedLibrary; var options = new CSharpCompilationOptions(outputKind); string platformValue = compilerOptions.Platform; bool allowUnsafe = compilerOptions.AllowUnsafe ?? false; bool optimize = compilerOptions.Optimize ?? false; bool warningsAsErrors = compilerOptions.WarningsAsErrors ?? false; Platform platform; if (!Enum.TryParse(value: platformValue, ignoreCase: true, result: out platform)) { platform = Platform.AnyCpu; } options = options .WithAllowUnsafe(allowUnsafe) .WithPlatform(platform) .WithGeneralDiagnosticOption(warningsAsErrors ? ReportDiagnostic.Error : ReportDiagnostic.Default) .WithOptimizationLevel(optimize ? OptimizationLevel.Release : OptimizationLevel.Debug); return AddSigningOptions(options, compilerOptions, projectDirectory); }
private static CompilationSettings ToCompilationSettings(ICompilerOptions compilerOptions, FrameworkName targetFramework) { var options = GetCompilationOptions(compilerOptions); // Disable 1702 until roslyn turns this off by default options = options.WithSpecificDiagnosticOptions(new Dictionary <string, ReportDiagnostic> { { "CS1702", ReportDiagnostic.Suppress }, { "CS1705", ReportDiagnostic.Suppress } }); AssemblyIdentityComparer assemblyIdentityComparer = #if DNX451 IsDesktop(targetFramework) ? DesktopAssemblyIdentityComparer.Default : #endif null; options = options.WithAssemblyIdentityComparer(assemblyIdentityComparer); LanguageVersion languageVersion; if (!Enum.TryParse(value: compilerOptions.LanguageVersion, ignoreCase: true, result: out languageVersion)) { languageVersion = LanguageVersion.CSharp6; } var settings = new CompilationSettings { LanguageVersion = languageVersion, Defines = compilerOptions.Defines ?? Enumerable.Empty <string>(), CompilationOptions = options }; return(settings); }
private static CSharpCompilationOptions GetCompilationOptions(ICompilerOptions compilerOptions) { var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); string platformValue = compilerOptions.Platform; bool allowUnsafe = compilerOptions.AllowUnsafe ?? false; bool optimize = compilerOptions.Optimize ?? false; bool warningsAsErrors = compilerOptions.WarningsAsErrors ?? false; bool strongName = compilerOptions.StrongName ?? false; Platform platform; if (!Enum.TryParse(value: platformValue, ignoreCase: true, result: out platform)) { platform = Platform.AnyCpu; } return(options.WithAllowUnsafe(allowUnsafe) .WithPlatform(platform) .WithGeneralDiagnosticOption(warningsAsErrors ? ReportDiagnostic.Error : ReportDiagnostic.Default) .WithOptimizationLevel(optimize ? OptimizationLevel.Release : OptimizationLevel.Debug) .WithCryptoKeyFile(compilerOptions.KeyFile) .WithDelaySign(compilerOptions.DelaySign) .WithCryptoPublicKey(strongName ? StrongNameKey : ImmutableArray <byte> .Empty)); }
public CompilationProjectContext( CompilationTarget target, string projectDirectory, string projectFilePath, string title, string description, string copyright, string version, Version assemblyFileVersion, bool embedInteropTypes, CompilationFiles files, ICompilerOptions compilerOptions) { Target = target; ProjectDirectory = projectDirectory; ProjectFilePath = projectFilePath; Files = files; Title = title; Description = description; Copyright = copyright; Version = version; AssemblyFileVersion = assemblyFileVersion; EmbedInteropTypes = embedInteropTypes; CompilerOptions = compilerOptions; }
private static CSharpCompilationOptions GetCompilationOptions(ICompilerOptions compilerOptions) { var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); string platformValue = compilerOptions.Platform; bool allowUnsafe = compilerOptions.AllowUnsafe ?? false; bool optimize = compilerOptions.Optimize ?? false; bool warningsAsErrors = compilerOptions.WarningsAsErrors ?? false; Platform platform; if (!Enum.TryParse <Platform>(value: platformValue, ignoreCase: true, result: out platform)) { platform = Platform.AnyCpu; } ReportDiagnostic warningOption = warningsAsErrors ? ReportDiagnostic.Error : ReportDiagnostic.Default; return(options.WithAllowUnsafe(allowUnsafe) .WithPlatform(platform) .WithGeneralDiagnosticOption(warningOption) .WithOptimizationLevel(optimize ? OptimizationLevel.Release : OptimizationLevel.Debug)); }
private static CSharpCompilationOptions GetCompilationOptions(ICompilerOptions compilerOptions, string projectDirectory) { var outputKind = compilerOptions.EmitEntryPoint.GetValueOrDefault() ? OutputKind.ConsoleApplication : OutputKind.DynamicallyLinkedLibrary; var options = new CSharpCompilationOptions(outputKind); string platformValue = compilerOptions.Platform; bool allowUnsafe = compilerOptions.AllowUnsafe ?? false; bool optimize = compilerOptions.Optimize ?? false; bool warningsAsErrors = compilerOptions.WarningsAsErrors ?? false; Platform platform; if (!Enum.TryParse(value: platformValue, ignoreCase: true, result: out platform)) { platform = Platform.AnyCpu; } options = options .WithAllowUnsafe(allowUnsafe) .WithPlatform(platform) .WithGeneralDiagnosticOption(warningsAsErrors ? ReportDiagnostic.Error : ReportDiagnostic.Default) .WithOptimizationLevel(optimize ? OptimizationLevel.Release : OptimizationLevel.Debug); return(AddSigningOptions(options, compilerOptions, projectDirectory)); }
private static void PrepareCompilation(ICompilerOptions compilerOptions, out RoslynCompiler compiler, out CompilationProjectContext projectContext) { var cacheContextAccessor = new FakeCacheContextAccessor { Current = new CacheContext(null, (d) => { }) }; compiler = new RoslynCompiler(null, cacheContextAccessor, new FakeNamedDependencyProvider(), null, null, null); var compilationTarget = new CompilationTarget("test", new FrameworkName(".NET Framework, Version=4.0"), "Release", null); projectContext = new CompilationProjectContext( compilationTarget, Directory.GetCurrentDirectory(), "project.json", "title", "description", "copyright", "1.0.0", new System.Version(1, 0), false, new CompilationFiles(Enumerable.Empty<string>(), Enumerable.Empty<string>()), compilerOptions); }
private static IConverter <IType, string> GetTypeNamer(ICompilerOptions Options) { switch (Options.GetOption <string>("type-names", "default")) { case "trivial": case "prefer-trivial": case "precise": case "default": default: return(new TypeNamerBase()); } }
private static void PrepareCompilation(ICompilerOptions compilerOptions, out RoslynCompiler compiler, out CompilationProjectContext projectContext) { var cacheContextAccessor = new FakeCacheContextAccessor { Current = new CacheContext(null, (d) => { }) }; compiler = new RoslynCompiler(null, cacheContextAccessor, new FakeNamedDependencyProvider(), null, null, null); var compilationTarget = new CompilationTarget("test", new FrameworkName(".NET Framework, Version=4.0"), "Release", null); projectContext = new CompilationProjectContext( compilationTarget, Directory.GetCurrentDirectory(), "project.json", "title", "description", "copyright", "1.0.0", new System.Version(1, 0), false, new CompilationFiles(Enumerable.Empty <string>(), Enumerable.Empty <string>()), compilerOptions); }
public static CompilationSettings ToCompilationSettings(this ICompilerOptions compilerOptions, FrameworkName targetFramework, string projectDirectory) { var options = GetCompilationOptions(compilerOptions, projectDirectory); // Disable 1702 until roslyn turns this off by default options = options.WithSpecificDiagnosticOptions(new Dictionary <string, ReportDiagnostic> { { "CS1701", ReportDiagnostic.Suppress }, // Binding redirects { "CS1702", ReportDiagnostic.Suppress }, { "CS1705", ReportDiagnostic.Suppress } }); if (RuntimeEnvironmentHelper.IsMono) { options = options.WithConcurrentBuild(concurrentBuild: false); } AssemblyIdentityComparer assemblyIdentityComparer = #if NET451 IsDesktop(targetFramework) ? DesktopAssemblyIdentityComparer.Default : #endif null; options = options.WithAssemblyIdentityComparer(assemblyIdentityComparer); LanguageVersion languageVersion; if (!Enum.TryParse <LanguageVersion>(value: compilerOptions.LanguageVersion, ignoreCase: true, result: out languageVersion)) { languageVersion = LanguageVersion.CSharp6; } var settings = new CompilationSettings { LanguageVersion = languageVersion, Defines = compilerOptions.Defines ?? Enumerable.Empty <string>(), CompilationOptions = options }; return(settings); }
public CompilationProjectContext( CompilationTarget target, string projectDirectory, string projectFilePath, string version, Version assemblyFileVersion, bool embedInteropTypes, CompilationFiles files, ICompilerOptions compilerOptions) { Target = target; ProjectDirectory = projectDirectory; ProjectFilePath = projectFilePath; Files = files; Version = version; AssemblyFileVersion = assemblyFileVersion; EmbedInteropTypes = embedInteropTypes; CompilerOptions = compilerOptions; }
private static CSharpCompilationOptions GetCompilationOptions(ICompilerOptions compilerOptions) { var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); string platformValue = compilerOptions.Platform; bool allowUnsafe = compilerOptions.AllowUnsafe ?? false; bool optimize = compilerOptions.Optimize ?? false; bool warningsAsErrors = compilerOptions.WarningsAsErrors ?? false; Platform platform; if (!Enum.TryParse<Platform>(value: platformValue, ignoreCase: true, result: out platform)) { platform = Platform.AnyCpu; } ReportDiagnostic warningOption = warningsAsErrors ? ReportDiagnostic.Error : ReportDiagnostic.Default; return options.WithAllowUnsafe(allowUnsafe) .WithPlatform(platform) .WithGeneralDiagnosticOption(warningOption) .WithOptimizationLevel(optimize ? OptimizationLevel.Release : OptimizationLevel.Debug); }
public static ModuleKind GetEmitModuleKind(ICompilerOptions compilerOptions) { return(compilerOptions.Module.HasValue ? compilerOptions.Module.Value : GetEmitScriptTarget(compilerOptions) == ScriptTarget.Es6 ? ModuleKind.Es6 : ModuleKind.None); }
public static ScriptTarget GetEmitScriptTarget(ICompilerOptions compilerOptions) { return(compilerOptions.Target.HasValue ? compilerOptions.Target.Value : ScriptTarget.Es3); }
private static CSharpCompilationOptions AddSigningOptions(CSharpCompilationOptions options, ICompilerOptions compilerOptions, string projectDirectory) { var useOssSigning = compilerOptions.UseOssSigning == true; var keyFile = Environment.GetEnvironmentVariable(EnvironmentNames.BuildKeyFile) ?? compilerOptions.KeyFile; if (!string.IsNullOrEmpty(keyFile)) { keyFile = Path.GetFullPath(Path.Combine(projectDirectory, compilerOptions.KeyFile)); #if DOTNET5_4 return(options.WithCryptoPublicKey( SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile)))); #else if (RuntimeEnvironmentHelper.IsMono || useOssSigning) { return(options.WithCryptoPublicKey( SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile)))); } options = options.WithCryptoKeyFile(keyFile); var delaySignString = Environment.GetEnvironmentVariable(EnvironmentNames.BuildDelaySign); var delaySign = delaySignString == null ? compilerOptions.DelaySign : string.Equals(delaySignString, "true", StringComparison.OrdinalIgnoreCase) || string.Equals(delaySignString, "1", StringComparison.Ordinal); return(options.WithDelaySign(delaySign)); #endif } return(useOssSigning ? options.WithCryptoPublicKey(StrongNameKey) : options); }
private static CSharpCompilationOptions AddSigningOptions(CSharpCompilationOptions options, ICompilerOptions compilerOptions, string projectDirectory) { var useOssSigning = compilerOptions.UseOssSigning == true; var keyFile = Environment.GetEnvironmentVariable(EnvironmentNames.BuildKeyFile) ?? GetKeyFileFullPath(projectDirectory, compilerOptions.KeyFile); if (!string.IsNullOrWhiteSpace(keyFile)) { #if DOTNET5_4 return options.WithCryptoPublicKey( SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile))); #else if (RuntimeEnvironmentHelper.IsMono || useOssSigning) { return options.WithCryptoPublicKey( SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile))); } options = options.WithCryptoKeyFile(keyFile); var delaySignString = Environment.GetEnvironmentVariable(EnvironmentNames.BuildDelaySign); var delaySign = delaySignString == null ? compilerOptions.DelaySign : string.Equals(delaySignString, "true", StringComparison.OrdinalIgnoreCase) || string.Equals(delaySignString, "1", StringComparison.Ordinal); return options.WithDelaySign(delaySign); #endif } return useOssSigning ? options.WithCryptoPublicKey(StrongNameKey) : options; }
private static IParsingService GetParsingService(ICompilerOptions Options, string Key, IParsingService Default) { switch (Options.GetOption<string>(Key, "").ToLower()) { case "les": return LesLanguageService.Value; case "ecs": return EcsLanguageService.Value; case "cs": return EcsLanguageService.WithPlainCSharpPrinter; default: return Default; } }
private static CSharpCompilationOptions GetCompilationOptions(ICompilerOptions compilerOptions) { var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); string platformValue = compilerOptions.Platform; bool allowUnsafe = compilerOptions.AllowUnsafe ?? false; bool optimize = compilerOptions.Optimize ?? false; bool warningsAsErrors = compilerOptions.WarningsAsErrors ?? false; bool strongName = compilerOptions.StrongName ?? false; Platform platform; if (!Enum.TryParse(value: platformValue, ignoreCase: true, result: out platform)) { platform = Platform.AnyCpu; } return options.WithAllowUnsafe(allowUnsafe) .WithPlatform(platform) .WithGeneralDiagnosticOption(warningsAsErrors ? ReportDiagnostic.Error : ReportDiagnostic.Default) .WithOptimizationLevel(optimize ? OptimizationLevel.Release : OptimizationLevel.Debug) .WithCryptoKeyFile(compilerOptions.KeyFile) .WithDelaySign(compilerOptions.DelaySign) .WithCryptoPublicKey(strongName ? StrongNameKey : ImmutableArray<byte>.Empty); }
/// <inheritdoc/> public FlameLLVMCompiler(CompilerName Name, IOptionParser <string> OptionParser, ICompilerOptions DefaultOptions) : base(Name, OptionParser, DefaultOptions) { }