Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Added an option to IndexWithSrcTool (-t) #210

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ Wesley Eledui <[email protected]>
Marek Fišera <[email protected]>
Shai Nahum <[email protected]>
Amadeusz Wieczorek <[email protected]>
Adrien JUND <[email protected]>
Adrien JUND <[email protected]>
Raymond Wu <[email protected]>
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ Native PDBs (from C++ projects) are supported by using -a option:

All known C++ source files from your git depot will be indexed in the PDB.

### Indexing with SrcTool

Srctool is capable of listing the raw source file information from a .pdb file.
If you are dealing with a huge git repository and only need to index source files from a Native PDB that are found in git (And not the entire git depot) use the -t option:

GitLink.exe <pdbFile> -t

.NET PDBs (C#) are also supported.

### More options

There are many more parameters you can use. Display the usage doc with the following command line:
Expand Down
3 changes: 3 additions & 0 deletions src/GitLink/GitLink.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<None Include="winsdk.redist.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="srctool.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="Logo.ico" />
Expand Down
67 changes: 67 additions & 0 deletions src/GitLink/Helpers/SrcToolHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// <copyright file="SrcToolHelper.cs" company="CatenaLogic">
// Copyright (c) 2014 - 2016 CatenaLogic. All rights reserved.
// </copyright>

namespace GitLink
{
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Catel;
using Catel.Logging;
using GitTools.Git;

internal static class SrcToolHelper
{
private static readonly ILog Log = LogManager.GetCurrentClassLogger();

internal static List<string> GetSourceFiles(string srcToolFilePath, string projectPdbFile)
{
Argument.IsNotNullOrWhitespace(() => projectPdbFile);
List<string> sources = new List<string>();

var processStartInfo = new ProcessStartInfo(srcToolFilePath)
{
Arguments = string.Format("-r \"{0}\"", projectPdbFile),
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
};

using (var process = new Process())
{
process.OutputDataReceived += (s, e) =>
{
if (e.Data != null)
{
var sourceFile = e.Data.ToLower();

if (Linker.ValidExtension(sourceFile))
{
var repositoryDirectory = GitDirFinder.TreeWalkForGitDir(Path.GetDirectoryName(sourceFile));

if (repositoryDirectory != null)
{
sources.Add(sourceFile);
}
}
}
};

process.EnableRaisingEvents = true;
process.StartInfo = processStartInfo;
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();

var processExitCode = process.ExitCode;
if (processExitCode != 0)
{
throw Log.ErrorAndCreateException<GitLinkException>("SrcTool exited with unexpected error code '{0}'", processExitCode);
}
}

return sources;
}
}
}
2 changes: 2 additions & 0 deletions src/GitLink/LinkOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public struct LinkOptions

public bool IndexAllDepotFiles { get; set; }

public bool IndexWithSrcTool { get; set; }

public string IntermediateOutputPath { get; set; }
}
}
32 changes: 19 additions & 13 deletions src/GitLink/Linker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public static class Linker
private static readonly string FilenamePlaceholder = Uri.EscapeUriString("{filename}");
private static readonly string RevisionPlaceholder = Uri.EscapeUriString("{revision}");
private static readonly string PdbStrExePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "pdbstr.exe");
private static readonly string SrcToolExePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "srctool.exe");
private static readonly string[] ExtensionsToIgnore = new string[] { ".g.cs" };
private static readonly HashSet<string> SourceExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".cs", ".cpp", ".c", ".cc", ".cxx", ".c++", ".h", ".hh", ".inl", ".hpp" };
private static IReadOnlyList<string> _sourceFilesList = null;

public static bool LinkDirectory(string pdbFolderPath, LinkOptions options = default(LinkOptions))
Expand Down Expand Up @@ -81,11 +83,18 @@ public static class Linker
}
else
{
_sourceFilesList = GetSourceFilesFromPdb(pdbPath, !options.SkipVerify);
if (options.IndexWithSrcTool)
{
_sourceFilesList = SrcToolHelper.GetSourceFiles(SrcToolExePath, pdbPath);
}
else
{
_sourceFilesList = GetSourceFilesFromPdb(pdbPath, !options.SkipVerify);
}

if (!_sourceFilesList.Any())
{
Log.Error($"No source files were found in the PDB: {pdbPath}. If your PDB is native you should use the -a option.");
Log.Error($"No source files were found in the PDB: {pdbPath}. If your PDB is native you could use the -a or -t option.");
return false;
}

Expand Down Expand Up @@ -282,17 +291,7 @@ private static List<string> GetSourceFilesFromDepot(string repositoryDirectory)
{
sourceFiles = from file in Directory.GetFiles(repo.Info.WorkingDirectory, "*.*", SearchOption.AllDirectories)
where !repo.Ignore.IsPathIgnored(file)
let ext = Path.GetExtension(file)
where string.Equals(ext, ".cs", StringComparison.OrdinalIgnoreCase)
|| string.Equals(ext, ".cpp", StringComparison.OrdinalIgnoreCase)
|| string.Equals(ext, ".c", StringComparison.OrdinalIgnoreCase)
|| string.Equals(ext, ".cc", StringComparison.OrdinalIgnoreCase)
|| string.Equals(ext, ".cxx", StringComparison.OrdinalIgnoreCase)
|| string.Equals(ext, ".c++", StringComparison.OrdinalIgnoreCase)
|| string.Equals(ext, ".h", StringComparison.OrdinalIgnoreCase)
|| string.Equals(ext, ".hh", StringComparison.OrdinalIgnoreCase)
|| string.Equals(ext, ".inl", StringComparison.OrdinalIgnoreCase)
|| string.Equals(ext, ".hpp", StringComparison.OrdinalIgnoreCase)
where ValidExtension(file)
select file;
}

Expand Down Expand Up @@ -364,5 +363,12 @@ private static string ReplaceSlashes(IProvider provider, string relativePathForU

return relativePathForUrl;
}

public static Boolean ValidExtension(string sourceFile)
{
var ext = Path.GetExtension(sourceFile);

return SourceExtensions.Contains(ext);
}
}
}
3 changes: 3 additions & 0 deletions src/GitLink/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ private static int Main(string[] args)
string pdbPath = null;
bool skipVerify = false;
bool allDepotFiles = false;
bool useSrcTool = false;
LinkMethod method = LinkMethod.Http;
var arguments = ArgumentSyntax.Parse(args, syntax =>
{
Expand All @@ -41,6 +42,7 @@ private static int Main(string[] args)
syntax.DefineOption("baseDir", ref baseDir, "The path to the root of the git repo.");
syntax.DefineOption("s|skipVerify", ref skipVerify, "Verify all source files are available in source control.");
syntax.DefineOption("a|allDepotFiles", ref allDepotFiles, "Index all source files from depot. Add this option for native PDBs (C++).");
syntax.DefineOption("t|useSrcTool", ref useSrcTool, "Index all source files using SrcTool. This option supports .NET/native PDBs (Cannot be used with allDepotFiles).");
syntax.DefineParameter("pdb", ref pdbPath, "The PDB to add source indexing to.");

if (!string.IsNullOrEmpty(pdbPath) && !File.Exists(pdbPath) && !Directory.Exists(pdbPath))
Expand Down Expand Up @@ -68,6 +70,7 @@ private static int Main(string[] args)
SkipVerify = skipVerify,
Method = method,
IndexAllDepotFiles = allDepotFiles,
IndexWithSrcTool = useSrcTool,
};

if (File.Exists(pdbPath))
Expand Down
Binary file added src/GitLink/srctool.exe
Binary file not shown.
8 changes: 7 additions & 1 deletion src/GitLink/winsdk.redist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ dbghelp.dll
pdbstr.exe
===================

(1) You may redistribute pdbstr.exe version 6.12.2.633
(1) You may redistribute pdbstr.exe version 6.12.2.633

===================
srctool.exe
===================

(1) You may redistribute srctool.exe version 6.12.2.633
3 changes: 3 additions & 0 deletions src/GitLinkTask/LinkPdbToGitRemote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public string Method

public bool IndexAllDepotFiles { get; set; }

public bool IndexWithSrcTool { get; set; }

public string GitRemoteUrl { get; set; }

public string GitCommitId { get; set; }
Expand All @@ -48,6 +50,7 @@ public override bool Execute()
CommitId = GitCommitId,
GitWorkingDirectory = GitWorkingDirectory,
IndexAllDepotFiles = IndexAllDepotFiles,
IndexWithSrcTool = IndexWithSrcTool,
IntermediateOutputPath = Path.GetFullPath(AddTrailingSlash(IntermediateOutputPath)),
};
bool success = Linker.Link(PdbFile.GetMetadata("FullPath"), options);
Expand Down
1 change: 1 addition & 0 deletions src/GitLinkTask/build/GitLink.targets
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Method="$(GitLinkMethod)"
SkipVerify="$(GitLinkSkipVerify)"
IndexAllDepotFiles="$(GitLinkIndexAllDepotFiles)"
IndexWithSrcTool="$(GitLinkIndexWithSrcTool)"
GitRemoteUrl="$(GitLinkGitRemoteUrl)"
GitWorkingDirectory="$(GitWorkingDirectory)"
GitCommitId="$(GitCommitId)"
Expand Down