-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathProjectOrSolution.cs
More file actions
58 lines (50 loc) · 1.99 KB
/
ProjectOrSolution.cs
File metadata and controls
58 lines (50 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Collections.Generic;
using System.Linq;
using Semmle.Util;
namespace Semmle.Autobuild.Shared
{
/// <summary>
/// A file that can be the target in an invocation of `msbuild` or `dotnet build`.
/// Either a solution file or a project file (`.proj`, `.csproj`, or `.vcxproj`).
/// </summary>
public interface IProjectOrSolution
{
/// <summary>
/// Gets the full path of this file.
/// </summary>
string FullPath { get; }
/// <summary>
/// Gets a list of other projects directly included by this file.
/// </summary>
IEnumerable<IProjectOrSolution> IncludedProjects { get; }
}
public abstract class ProjectOrSolution<TAutobuildOptions> : IProjectOrSolution where TAutobuildOptions : AutobuildOptionsShared
{
public string FullPath { get; }
public string DirectoryName { get; }
protected ProjectOrSolution(Autobuilder<TAutobuildOptions> builder, string path)
{
FullPath = builder.Actions.GetFullPath(path);
DirectoryName = builder.Actions.GetDirectoryName(path) ?? "";
}
public abstract IEnumerable<IProjectOrSolution> IncludedProjects { get; }
public override string ToString() => FullPath;
}
public static class IProjectOrSolutionExtensions
{
/// <summary>
/// Holds if this file includes a project with code from language <paramref name="l"/>.
/// </summary>
public static bool HasLanguage(this IProjectOrSolution p, Language l)
{
bool HasLanguage(IProjectOrSolution p0, HashSet<string> seen)
{
if (seen.Contains(p0.FullPath))
return false;
seen.Add(p0.FullPath); // guard against cyclic includes
return l.ProjectFileHasThisLanguage(p0.FullPath) || p0.IncludedProjects.Any(p1 => HasLanguage(p1, seen));
}
return HasLanguage(p, new HashSet<string>());
}
}
}