Skip to content

Commit

Permalink
New experimental feature: allow skipping FastBuild projects from the …
Browse files Browse the repository at this point in the history
…solution when they are not really necessary

The new behavior is activated by setting IncludeOnlyNeededFastBuildProjects to true in solution configure methods

By default, we'll add FastBuildAll, the fastbuild projects that output executables, those where VcxprojUserFile was set, and those we must build will be added to the sln
The user code can tweak the rules by setting AddFastBuildProjectToSolutionCallback to a method returning whether we want the project to be added or not, in project configure methods
  • Loading branch information
belkiss committed Jan 22, 2022
1 parent 0f45d66 commit d4fefed
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Sharpmake/Project.Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,37 @@ internal void AddMasterBff(string masterBff)
// If true, remove the source files from a FastBuild project's associated vcxproj file.
public bool StripFastBuildSourceFiles = true;

/// <summary>
/// Override this delegate with a method returning a bool letting sharpmake know if it needs to add the
/// project containing this FastBuild conf to the solution.
/// By default, sharpmake will only add it if the Output is executable, or if <see cref="VcxprojUserFile"/>
/// is not null.
/// </summary>
public Func<bool> AddFastBuildProjectToSolutionCallback => DefaultAddFastBuildProjectToSolution;

/// <summary>
/// Default method returning whether sharpmake will add the project containing this FastBuild conf to the solution
/// </summary>
public bool DefaultAddFastBuildProjectToSolution()
{
if (!IsFastBuild)
return true;

if (Project.IsFastBuildAll)
return true;

if (!DoNotGenerateFastBuild)
{
if (Output == OutputType.Exe)
return true;

if (VcxprojUserFile != null)
return true;
}

return false;
}

private Dictionary<KeyValuePair<Type, ITarget>, DependencySetting> _dependenciesSetting = new Dictionary<KeyValuePair<Type, ITarget>, DependencySetting>();

// These dependencies will not be propagated to other projects that depend on us
Expand Down
7 changes: 7 additions & 0 deletions Sharpmake/Solution.Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ public string PlatformName
}
}

/// <summary>
/// Experimental: only add to the solution the FastBuild projects that are really needed, or where
/// <see cref="Project.Configuration.AddFastBuildProjectToSolutionCallback"/> returned true.
/// Set to false to add all of them.
/// </summary>
public bool IncludeOnlyNeededFastBuildProjects = false;

public bool IncludeOnlyFilterProject = false;

public string CompileCommandLine = string.Empty;
Expand Down
11 changes: 11 additions & 0 deletions Sharpmake/Solution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ public IEnumerable<ResolvedProject> GetResolvedProjects(IEnumerable<Configuratio
projectsWereFiltered = true;
continue;
}
else if (solutionConfiguration.IncludeOnlyNeededFastBuildProjects)
{
if (!includedProjectInfo.Project.IsFastBuildAll &&
(includedProjectInfo.ToBuild == Solution.Configuration.IncludedProjectInfo.Build.No || includedProjectInfo.ToBuild == Solution.Configuration.IncludedProjectInfo.Build.YesThroughDependency) &&
includedProjectInfo.Configuration.IsFastBuild && !includedProjectInfo.Configuration.DoNotGenerateFastBuild &&
!(includedProjectInfo.Configuration.AddFastBuildProjectToSolutionCallback?.Invoke() ?? false))
{
projectsWereFiltered = true;
continue;
}
}

ResolvedProject resolvedProject = result.GetValueOrAdd(
includedProjectInfo.Configuration.ProjectFullFileName,
Expand Down

0 comments on commit d4fefed

Please sign in to comment.