Skip to content

Commit 39f6bac

Browse files
committed
Add Source Index Project
1 parent edf2230 commit 39f6bac

File tree

7 files changed

+178
-0
lines changed

7 files changed

+178
-0
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "src/SourceBrowser"]
2+
path = src/SourceBrowser
3+
url = https://github.com/dotnet/SourceBrowser.git

.vscode/settings.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"files.exclude": {
4+
"bin": true
5+
}
6+
}

build.proj

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="src/index/index.proj"/>
4+
</Project>

dir.props

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<SourcesDir>$(MSBuildThisFileDirectory)src/</SourcesDir>
5+
<OutDir>$(MSBuildThisFileDirectory)bin/</OutDir>
6+
<RepositoryPath>$(OutDir)repo/</RepositoryPath>
7+
</PropertyGroup>
8+
</Project>

src/SourceBrowser

Submodule SourceBrowser added at 40522ce

src/index/index.proj

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" InitialTargets="EnsurePreconditions" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" TreatAsLocalProperty="WhatIf">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<WhatIf Condition="'$(WhatIf)' != 'true'">false</WhatIf>
6+
</PropertyGroup>
7+
<Import Project="$(MSBuildThisFileDirectory)repositories.props" />
8+
9+
<ItemDefinitionGroup>
10+
<Repository>
11+
<LocalPath>$(RepositoryPath)%(Identity)/</LocalPath>
12+
<ServerPath>%(Url)/tree/master/</ServerPath>
13+
</Repository>
14+
</ItemDefinitionGroup>
15+
16+
<Target Name="EnsurePreconditions">
17+
<Error Condition="'$(OS)' != 'Windows_NT'" Text="This tool can only be run on Windows_NT."/>
18+
</Target>
19+
20+
<Target Name="Clean">
21+
<RemoveDir Directories="$(OutDir)"/>
22+
</Target>
23+
24+
<Target Name="PrepareOutput">
25+
<MakeDir Condition="!Exists('$(OutDir)')" Directories="$(OutDir)"/>
26+
<MakeDir Condition="!Exists('$(RepositoryPath)')" Directories="$(RepositoryPath)"/>
27+
</Target>
28+
29+
<Target Name="Clone" DependsOnTargets="PrepareOutput" Outputs="%(Repository.Identity)">
30+
<PropertyGroup>
31+
<CloneCommand>git clone %(Repository.Url).git --depth 1 %(LocalPath)</CloneCommand>
32+
</PropertyGroup>
33+
<Exec Condition="!Exists('%(Repository.LocalPath)')" Command="$(CloneCommand)" />
34+
<Exec Command="git rev-parse HEAD 2>&amp;1" WorkingDirectory="%(Repository.LocalPath)" ConsoleToMSBuild="true">
35+
<Output TaskParameter="ConsoleOutput" PropertyName="CommitHash"/>
36+
</Exec>
37+
<ItemGroup>
38+
<ClonedRepository Include="@(Repository)">
39+
<ServerPath>%(Url)/tree/$(CommitHash)/</ServerPath>
40+
</ClonedRepository>
41+
</ItemGroup>
42+
</Target>
43+
44+
<Target Name="SelectProjects" DependsOnTargets="Clone" Outputs="@(SourceProject)">
45+
<SelectProjects Repositories="@(ClonedRepository)">
46+
<Output TaskParameter="SelectedProjects" ItemName="SourceProject"/>
47+
</SelectProjects>
48+
</Target>
49+
<UsingTask TaskName="SelectProjects" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
50+
<ParameterGroup>
51+
<Repositories ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true"/>
52+
<SelectedProjects ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true"/>
53+
</ParameterGroup>
54+
<Task>
55+
<Using Namespace="System"/>
56+
<Using Namespace="System.Collections.Generic"/>
57+
<Using Namespace="System.IO"/>
58+
<Using Namespace="System.Linq"/>
59+
<Using Namespace="System.Reflection"/>
60+
<Using Namespace="Microsoft.Build.Framework"/>
61+
<Code>
62+
<![CDATA[
63+
var matcherType = Type.GetType("Microsoft.Build.Shared.FileMatcher, Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
64+
var getFilesFunction = matcherType.GetMethod("GetFiles", BindingFlags.NonPublic | BindingFlags.Static, null, CallingConventions.Any, new Type[]{typeof(string), typeof(string)}, new ParameterModifier[0]);
65+
66+
var selectedProjects = new List<ITaskItem>();
67+
foreach (var repository in Repositories)
68+
{
69+
var projects = repository.GetMetadata("Projects");
70+
var localPath = repository.GetMetadata("LocalPath");
71+
foreach (var projectItemSpec in projects.Split(new char[]{';'}, StringSplitOptions.RemoveEmptyEntries))
72+
{
73+
var trimmed = projectItemSpec.Trim();
74+
if (!string.IsNullOrEmpty(trimmed))
75+
{
76+
var itemSpec = trimmed;
77+
var files = (string[])getFilesFunction.Invoke(null, new object[] {localPath, itemSpec});
78+
foreach (var file in files)
79+
{
80+
selectedProjects.Add(new TaskItem(localPath + file));
81+
}
82+
}
83+
}
84+
}
85+
SelectedProjects = selectedProjects.OrderBy(i => i.GetMetadata("Identity")).ToArray();
86+
Log.LogMessage("Selected Projects:");
87+
foreach (var project in SelectedProjects)
88+
{
89+
Log.LogMessage(project.GetMetadata("FullPath"));
90+
}
91+
]]>
92+
</Code>
93+
</Task>
94+
</UsingTask>
95+
96+
<Target Name="Validate" DependsOnTargets="SelectProjects">
97+
<Error Condition="!Exists('%(SourceProject.Identity)')" Text="Expected File '%(SourceProject.FullPath)' does not exist." Code="SB001"/>
98+
</Target>
99+
100+
<Target Name="Prepare" DependsOnTargets="Validate" Outputs="%(ClonedRepository.Identity)">
101+
<PropertyGroup>
102+
<PrepareCommand>$([System.String]::Copy('%(ClonedRepository.PrepareCommand)').Trim())</PrepareCommand>
103+
</PropertyGroup>
104+
<Exec Command="cmd /c &quot;$(PrepareCommand)&quot;" WorkingDirectory="%(ClonedRepository.LocalPath)" />
105+
</Target>
106+
107+
<Target Name="BuildGenerator">
108+
<MSBuild Projects="$(SourcesDir)SourceBrowser/src/HtmlGenerator/HtmlGenerator.csproj" Targets="Build">
109+
<Output TaskParameter="TargetOutputs" PropertyName="HtmlGeneratorExePath"/>
110+
</MSBuild>
111+
</Target>
112+
113+
<Target Name="Build" DependsOnTargets="BuildGenerator;Prepare">
114+
<Error Condition="!Exists('$(HtmlGeneratorExePath)')" Text="Html generator executable not found."/>
115+
<RemoveDuplicates Inputs="@(SourceProject)">
116+
<Output TaskParameter="Filtered" ItemName="_FilteredProject"/>
117+
</RemoveDuplicates>
118+
<RemoveDir Directories="$(OutDir)index/"/>
119+
<WriteLinesToFile Lines="@(_FilteredProject -> '%(FullPath)')" File="$(OutDir)index.list" Overwrite="true"/>
120+
<PropertyGroup>
121+
<SourceIndexCmd>$(HtmlGeneratorExePath)</SourceIndexCmd>
122+
<SourceIndexCmd>$(SourceIndexCmd) /out:$(OutDir)index/</SourceIndexCmd>
123+
<SourceIndexCmd>$(SourceIndexCmd) /in:$(OutDir)index.list</SourceIndexCmd>
124+
<SourceIndexCmd>$(SourceIndexCmd) /p:SourceIndex=true</SourceIndexCmd>
125+
<SourceIndexCmd>$(SourceIndexCmd)@(ClonedRepository -> ' /serverPath:"%(LocalPath)=%(ServerPath)"', '')</SourceIndexCmd>
126+
</PropertyGroup>
127+
<Exec Command="$(SourceIndexCmd)"/>
128+
</Target>
129+
130+
<Target Name="Rebuild" DependsOnTargets="Clean;Build"/>
131+
</Project>

src/index/repositories.props

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Repository Include="corefx">
5+
<Url>https://github.com/dotnet/corefx</Url>
6+
<Projects>
7+
src/*/src/*.csproj;
8+
src/*/src/*.vbproj;
9+
src/*/tests/*.csproj;
10+
src/*/tests/*.vbproj;
11+
</Projects>
12+
<PrepareCommand>
13+
sync
14+
build-managed -binaries
15+
</PrepareCommand>
16+
</Repository>
17+
<Repository Include="coreclr">
18+
<Url>https://github.com/dotnet/coreclr</Url>
19+
<Projects>
20+
src/mscorlib/System.Private.CoreLib.csproj
21+
</Projects>
22+
<PrepareCommand>sync</PrepareCommand>
23+
</Repository>
24+
</ItemGroup>
25+
</Project>

0 commit comments

Comments
 (0)