public override bool Execute() { LoadConfiguration(); var supportedProjectConfigurations = new HashSet <Configuration>( SupportedConfigurations.Where(c => !string.IsNullOrWhiteSpace(c)).Select(c => ConfigurationFactory.ParseConfiguration(c)), Configuration.CompatibleComparer); var ignoredBuildConfigurations = new HashSet <string>(SupportedConfigurations.Where(c => c.StartsWith(ConfigurationFactory.NopConfigurationPrefix))); var bestConfigurations = new List <ITaskItem>(); foreach (var configurationItem in Configurations) { var buildConfiguration = ConfigurationFactory.ParseConfiguration(configurationItem.ItemSpec); var compatibleConfigurations = ConfigurationFactory.GetCompatibleConfigurations(buildConfiguration, DoNotAllowCompatibleValues); var bestConfiguration = compatibleConfigurations.FirstOrDefault(c => supportedProjectConfigurations.Contains(c)); if (bestConfiguration == null) { Log.LogMessage(MessageImportance.Low, $"Could not find any applicable configuration for '{buildConfiguration}' among projectConfigurations {string.Join(", ", supportedProjectConfigurations.Select(c => c.ToString()))}"); Log.LogMessage(MessageImportance.Low, $"Compatible configurations: {string.Join(", ", compatibleConfigurations.Select(c => c.ToString()))}"); } else { if (ignoredBuildConfigurations.Contains($"{ConfigurationFactory.NopConfigurationPrefix}{bestConfiguration}")) { BestConfigurations = Array.Empty <ITaskItem>(); return(!Log.HasLoggedErrors); } Log.LogMessage(MessageImportance.Low, $"Chose configuration {bestConfiguration}"); var bestConfigurationItem = new TaskItem(bestConfiguration.ToString(), (IDictionary)bestConfiguration.GetProperties()); // preserve metadata on the configuration that selected this configurationItem.CopyMetadataTo(bestConfigurationItem); // preserve the configuration that selected this bestConfigurationItem.SetMetadata("BuildConfiguration", configurationItem.ItemSpec); foreach (var additionalProperty in buildConfiguration.GetProperties()) { bestConfigurationItem.SetMetadata("BuildConfiguration_" + additionalProperty.Key, additionalProperty.Value); } bestConfigurations.Add(bestConfigurationItem); } } BestConfigurations = bestConfigurations.ToArray(); return(!Log.HasLoggedErrors); }
public override bool Execute() { LoadConfiguration(); Dictionary <Configuration, Configuration> supportedProjectConfigurations = SupportedConfigurations.Where(c => !string.IsNullOrWhiteSpace(c)) .Distinct(StringComparer.OrdinalIgnoreCase) .Select(c => ConfigurationFactory.ParseConfiguration(c)) .ToDictionary(c => c, Configuration.CompatibleComparer); var bestConfigurations = new List <ITaskItem>(); foreach (var configurationItem in Configurations) { var buildConfiguration = ConfigurationFactory.ParseConfiguration(configurationItem.ItemSpec); var compatibleConfigurations = ConfigurationFactory.GetCompatibleConfigurations(buildConfiguration, DoNotAllowCompatibleValues); Configuration supportedProjectConfiguration = null; var bestConfiguration = compatibleConfigurations.FirstOrDefault(c => supportedProjectConfigurations.TryGetValue(c, out supportedProjectConfiguration)); if (bestConfiguration == null) { Log.LogMessage(LogImportance.Low, $"Could not find any applicable configuration for '{buildConfiguration}' among projectConfigurations {string.Join(", ", supportedProjectConfigurations.Select(c => c.ToString()))}"); Log.LogMessage(LogImportance.Low, $"Compatible configurations: {string.Join(", ", compatibleConfigurations.Select(c => c.ToString()))}"); } else { if (supportedProjectConfiguration.IsPlaceHolderConfiguration) { Log.LogMessage($"Skipped configuration: {supportedProjectConfiguration.ToString()} because was marked as a placeholder configuration"); continue; } Log.LogMessage(LogImportance.Low, $"Chose configuration {bestConfiguration}"); var bestConfigurationItem = new TaskItem(bestConfiguration.ToString(), (IDictionary)bestConfiguration.GetProperties()); // preserve metadata on the configuration that selected this configurationItem.CopyMetadataTo(bestConfigurationItem); // preserve the configuration that selected this bestConfigurationItem.SetMetadata("BuildConfiguration", configurationItem.ItemSpec); foreach (var additionalProperty in buildConfiguration.GetProperties()) { bestConfigurationItem.SetMetadata("BuildConfiguration_" + additionalProperty.Key, additionalProperty.Value); } bestConfigurations.Add(bestConfigurationItem); } } BestConfigurations = bestConfigurations.ToArray(); return(!Log.HasLoggedErrors); }
private void WriteLaunchFile() { JsonFile OutFile = new JsonFile(); EDebugMode DebugMode = (HostPlatform == UnrealTargetPlatform.Win64) ? EDebugMode.VS : EDebugMode.GDB; OutFile.BeginRootObject(); { OutFile.AddField("version", "0.2.0"); OutFile.BeginArray("configurations"); { List <ProjectFile> Projects = new List <ProjectFile>(GeneratedProjectFiles); Projects.Sort((A, B) => { return(A.ProjectFilePath.GetFileNameWithoutExtension().CompareTo(B.ProjectFilePath.GetFileNameWithoutExtension())); }); foreach (ProjectFile Project in AllProjectFiles) { if (Project.ProjectFilePath.GetExtension() == ProjectFileExtension) { foreach (ProjectTarget Target in Project.ProjectTargets) { List <UnrealTargetConfiguration> Configs = new List <UnrealTargetConfiguration>(); Target.TargetRules.GetSupportedConfigurations(ref Configs, true); foreach (UnrealTargetConfiguration Config in Configs) { if (SupportedConfigurations.Contains(Config)) { FileReference Executable = GetExecutableFilename(Project, Target, HostPlatform, Config); string Name = Target.TargetRules == null?Project.ProjectFilePath.GetFileNameWithoutExtension() : Target.TargetRules.Name; string LaunchTaskName = $"{Name} {HostPlatform} {Config} Build"; string ExecutableDirectory = "${workspaceRoot}/" + Executable.Directory.MakeRelativeTo(UnrealBuildTool.RootDirectory).ToString().Replace("\\", "/"); OutFile.BeginObject(); { OutFile.AddField("name", Target.TargetRules.Name + " (" + Config.ToString() + ")"); OutFile.AddField("request", "launch"); OutFile.AddField("preLaunchTask", LaunchTaskName); OutFile.AddField("program", ExecutableDirectory + "/" + Executable.GetFileName()); OutFile.BeginArray("args"); { } OutFile.EndArray(); OutFile.AddField("stopAtEntry", true); OutFile.AddField("cwd", ExecutableDirectory); OutFile.BeginArray("environment"); { } OutFile.EndArray(); OutFile.AddField("externalConsole", true); switch (DebugMode) { case EDebugMode.VS: { OutFile.AddField("type", "cppvsdbg"); break; } case EDebugMode.GDB: { OutFile.AddField("type", "cppdbg"); OutFile.AddField("MIMode", "lldb"); break; } } } OutFile.EndObject(); } } } } else if (Project.ProjectFilePath.GetExtension() == ".csproj") { /* * foreach (ProjectTarget Target in Project.ProjectTargets) * { * foreach (UnrealTargetConfiguration Config in Target.ExtraSupportedConfigurations) * { * string TaskName = $"{Project.ProjectFilePath.GetFileNameWithoutExtension()} ({Config})"; * string BuildTaskName = $"{Project.ProjectFilePath.GetFileNameWithoutExtension()} {HostPlatform} {Config} Build"; * FileReference Executable = GetExecutableFilename(Project, Target, HostPlatform, Config); * * OutFile.BeginObject(); * { * OutFile.AddField("name", TaskName); * OutFile.AddField("type", "coreclr"); * OutFile.AddField("request", "launch"); * OutFile.AddField("preLaunchTask", BuildTaskName); * OutFile.AddField("program", Executable.ToString()); * OutFile.BeginArray("args"); * { * * } * OutFile.EndArray(); * } * OutFile.EndObject(); * } * } */ } } } OutFile.EndArray(); } OutFile.EndRootObject(); OutFile.Write(FileReference.Combine(VSCodeDir, "launch.json")); }