Backend/RiderPlugin/ForTea.RiderPlugin/Psi/Resolve/Macros/FeatureAware/T4FeatureAwareLightMacroResolver.cs (68 lines of code) (raw):

using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; using JetBrains.Application.Parts; using JetBrains.ForTea.RiderPlugin.Psi.Resolve.Macros.Impl; using JetBrains.HabitatDetector; using JetBrains.Platform.MsBuildHost.Autodetect.Advanced; using JetBrains.ProjectModel; using JetBrains.RdBackend.Common.Features.Processes; using JetBrains.RdBackend.Common.Features.Toolset.Detecting; using JetBrains.Util; namespace JetBrains.ForTea.RiderPlugin.Psi.Resolve.Macros.FeatureAware { [SolutionComponent(Instantiation.DemandAnyThreadSafe)] public sealed class T4FeatureAwareLightMacroResolver : T4LightMacroResolver { [NotNull] private IBuildToolWellKnownPropertiesStore MsBuildProperties { get; } [NotNull] private ISolutionToolset SolutionToolset { get; } [NotNull] private RiderProcessStartInfoEnvironment Environment { get; } public T4FeatureAwareLightMacroResolver( [NotNull] ISolution solution, [NotNull] ISolutionToolset solutionToolset, [NotNull] IBuildToolWellKnownPropertiesStore msBuildProperties, [NotNull] RiderProcessStartInfoEnvironment environment ) : base(solution) { SolutionToolset = solutionToolset; MsBuildProperties = msBuildProperties; Environment = environment; } public override Dictionary<string, string> ResolveAllLightMacros(IProjectFile file) { var result = base.ResolveAllLightMacros(file); AddMsBuildMacros(result); AddPlatformMacros(result); return result; } private void AddPlatformMacros([NotNull] Dictionary<string, string> result) { switch (Environment.Platform) { case JetPlatform.Windows: result.Add("Platform", "Win32"); break; case JetPlatform.MacOsX: result.Add("Platform", "MacOsX"); break; case JetPlatform.Linux: result.Add("Platform", "Linux"); break; } result.Add("PlatformShortName", "x64"); } private void AddMsBuildMacros(Dictionary<string, string> result) { var buildTool = SolutionToolset.GetBuildTool(); if (buildTool == null) return; var container = MsBuildProperties.Get(buildTool); if (container == null) return; foreach (string macro in container.GetKeys()) { string value = container.GetValues(macro).FirstOrDefault(); if (value == null) continue; result.Add(macro, value); } } } }