Skip to content

Commit

Permalink
Prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl committed Oct 27, 2016
1 parent 9bcc002 commit b687fa6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/XMakeBuildEngine/BackEnd/BuildManager/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ internal void LoadSolutionIntoConfiguration(BuildRequestConfiguration config, Bu
}

ErrorUtilities.VerifyThrow(FileUtilities.IsSolutionFilename(config.ProjectFullPath), "{0} is not a solution", config.ProjectFullPath);
ProjectInstance[] instances = ProjectInstance.LoadSolutionForBuild(config.ProjectFullPath, config.Properties, config.ExplicitToolsVersionSpecified ? config.ToolsVersion : null, _buildParameters, ((IBuildComponentHost)this).LoggingService, buildEventContext, false /* loaded by solution parser*/);
ProjectInstance[] instances = ProjectInstance.LoadSolutionForBuild(config.ProjectFullPath, config.Properties, config.ExplicitToolsVersionSpecified ? config.ToolsVersion : null, _buildParameters, ((IBuildComponentHost)this).LoggingService, buildEventContext, false /* loaded by solution parser*/, config.TargetNames);

// The first instance is the traversal project, which goes into this configuration
config.Project = instances[0];
Expand Down
10 changes: 10 additions & 0 deletions src/XMakeBuildEngine/BackEnd/Shared/BuildRequestConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Text;
using Microsoft.Build.Construction;
Expand All @@ -18,6 +19,7 @@
using Microsoft.Build.Internal;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Xml;
using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Evaluation;
Expand Down Expand Up @@ -140,6 +142,12 @@ internal class BuildRequestConfiguration : IEquatable<BuildRequestConfiguration>

#endregion

internal Collection<string> TargetNames
{
get;
private set;
}

/// <summary>
/// Initializes a configuration from a BuildRequestData structure. Used by the BuildManager.
/// Figures out the correct tools version to use, falling back to the provided default if necessary.
Expand Down Expand Up @@ -172,6 +180,7 @@ internal BuildRequestConfiguration(int configId, BuildRequestData data, string d
_explicitToolsVersionSpecified = data.ExplicitToolsVersionSpecified;
_toolsVersion = ResolveToolsVersion(data, defaultToolsVersion, getToolset);
_globalProperties = data.GlobalPropertiesDictionary;
TargetNames = new Collection<string>(data.TargetNames.ToArray());

// The following information only exists when the request is populated with an existing project.
if (data.ProjectInstance != null)
Expand Down Expand Up @@ -237,6 +246,7 @@ private BuildRequestConfiguration(int configId, BuildRequestConfiguration other)
_globalProperties = other._globalProperties;
this.IsCacheable = other.IsCacheable;
_configId = configId;
TargetNames = other.TargetNames;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;

Expand Down Expand Up @@ -103,6 +104,8 @@ internal class SolutionProjectGenerator
/// </summary>
private ILoggingService _loggingService;

private readonly ICollection<string> _targetNames;

/// <summary>
/// The solution configuration selected for this build.
/// </summary>
Expand All @@ -121,14 +124,16 @@ private SolutionProjectGenerator
IDictionary<string, string> globalProperties,
string toolsVersionOverride,
BuildEventContext projectBuildEventContext,
ILoggingService loggingService
ILoggingService loggingService,
ICollection<string> targetNames
)
{
_solutionFile = solution;
_globalProperties = globalProperties ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
_toolsVersionOverride = toolsVersionOverride;
_projectBuildEventContext = projectBuildEventContext;
_loggingService = loggingService;
_targetNames = targetNames;
}

#endregion // Constructors
Expand All @@ -151,7 +156,8 @@ internal static ProjectInstance[] Generate
IDictionary<string, string> globalProperties,
string toolsVersionOverride,
BuildEventContext projectBuildEventContext,
ILoggingService loggingService
ILoggingService loggingService,
ICollection<string> targetNames = default(ICollection<string>)
)
{
SolutionProjectGenerator projectGenerator = new SolutionProjectGenerator
Expand All @@ -160,7 +166,8 @@ ILoggingService loggingService
globalProperties,
toolsVersionOverride,
projectBuildEventContext,
loggingService
loggingService,
targetNames
);

return projectGenerator.Generate();
Expand Down Expand Up @@ -744,6 +751,11 @@ private void EvaluateAndAddProjects(List<ProjectInSolution> projectsInOrder, Lis
AddTraversalTargetForProject(traversalInstance, project, projectConfiguration, "Clean", null, canBuildDirectly);
AddTraversalTargetForProject(traversalInstance, project, projectConfiguration, "Rebuild", "BuildOutput", canBuildDirectly);
AddTraversalTargetForProject(traversalInstance, project, projectConfiguration, "Publish", null, canBuildDirectly);

foreach (string targetName in _targetNames.Where(i => !_knownTargetNames.Any(x => x.Equals(i, StringComparison.OrdinalIgnoreCase))))
{
AddTraversalTargetForProject(traversalInstance, project, projectConfiguration, targetName, null, canBuildDirectly);
}

// If we cannot build the project directly, then we need to generate a metaproject for it.
if (!canBuildDirectly)
Expand All @@ -754,6 +766,8 @@ private void EvaluateAndAddProjects(List<ProjectInSolution> projectsInOrder, Lis
}
}

private readonly string[] _knownTargetNames = new[] { "Build", "Clean", "Rebuild", "Publish" };

/// <summary>
/// Adds the standard targets to the traversal project.
/// </summary>
Expand All @@ -767,6 +781,10 @@ private void AddStandardTraversalTargets(ProjectInstance traversalInstance, List
AddTraversalReferencesTarget(traversalInstance, "Clean", null);
AddTraversalReferencesTarget(traversalInstance, "Rebuild", "CollectedBuildOutput");
AddTraversalReferencesTarget(traversalInstance, "Publish", null);
foreach (string targetName in _targetNames.Where(i => !_knownTargetNames.Any(x => x.Equals(i, StringComparison.OrdinalIgnoreCase))))
{
AddTraversalReferencesTarget(traversalInstance, targetName, null);
}
}

/// <summary>
Expand Down
11 changes: 6 additions & 5 deletions src/XMakeBuildEngine/Instance/ProjectInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ void INodePacketTranslatable.Translate(INodePacketTranslator translator)
/// <summary>
/// Creates a set of project instances which represent the project dependency graph for a solution build.
/// </summary>
internal static ProjectInstance[] LoadSolutionForBuild(string projectFile, PropertyDictionary<ProjectPropertyInstance> globalPropertiesInstances, string toolsVersion, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext projectBuildEventContext, bool isExplicitlyLoaded)
internal static ProjectInstance[] LoadSolutionForBuild(string projectFile, PropertyDictionary<ProjectPropertyInstance> globalPropertiesInstances, string toolsVersion, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext projectBuildEventContext, bool isExplicitlyLoaded, ICollection<string> targetNames)
{
ErrorUtilities.VerifyThrowArgumentLength(projectFile, "projectFile");
ErrorUtilities.VerifyThrowArgumentNull(globalPropertiesInstances, "globalPropertiesInstances");
Expand Down Expand Up @@ -1748,7 +1748,7 @@ internal static ProjectInstance[] LoadSolutionForBuild(string projectFile, Prope
}
else
{
projectInstances = GenerateSolutionWrapper(projectFile, globalProperties, toolsVersion, loggingService, projectBuildEventContext);
projectInstances = GenerateSolutionWrapper(projectFile, globalProperties, toolsVersion, loggingService, projectBuildEventContext, targetNames);
}
}

Expand Down Expand Up @@ -1785,7 +1785,7 @@ internal static ProjectInstance[] LoadSolutionForBuild(string projectFile, Prope
}

string toolsVersionToUse = Utilities.GenerateToolsVersionToUse(explicitToolsVersion: null, toolsVersionFromProject: toolsVersion, getToolset: buildParameters.GetToolset, defaultToolsVersion: Constants.defaultSolutionWrapperProjectToolsVersion);
projectInstances = GenerateSolutionWrapper(projectFile, globalProperties, toolsVersionToUse, loggingService, projectBuildEventContext);
projectInstances = GenerateSolutionWrapper(projectFile, globalProperties, toolsVersionToUse, loggingService, projectBuildEventContext, targetNames);
}
}

Expand Down Expand Up @@ -2017,7 +2017,8 @@ private static ProjectInstance[] GenerateSolutionWrapper
IDictionary<string, string> globalProperties,
string toolsVersion,
ILoggingService loggingService,
BuildEventContext projectBuildEventContext
BuildEventContext projectBuildEventContext,
ICollection<string> targetNames
)
{
SolutionFile sp = SolutionFile.Parse(projectFile);
Expand All @@ -2035,7 +2036,7 @@ BuildEventContext projectBuildEventContext
// It's needed to determine which <UsingTask> tags to put in, whether to put a ToolsVersion parameter
// on the <MSBuild> task tags, and what MSBuildToolsPath to use when scanning child projects
// for dependency information.
ProjectInstance[] instances = SolutionProjectGenerator.Generate(sp, globalProperties, toolsVersion, projectBuildEventContext, loggingService);
ProjectInstance[] instances = SolutionProjectGenerator.Generate(sp, globalProperties, toolsVersion, projectBuildEventContext, loggingService, targetNames);
return instances;
}

Expand Down

0 comments on commit b687fa6

Please sign in to comment.