Skip to content

Commit 8656036

Browse files
committed
clang-format vs plugin: bake clang-format.exe into the vsix
This makes the clang-format plugin self-contained. Instead of requiring clang-format.exe to be available on the PATH, this includes it in the plugin's installer (.vsix file) and runs it from the install directory. Differential Revision: http://llvm-reviews.chandlerc.com/D2281 llvm-svn: 196122
1 parent 4b8d9e3 commit 8656036

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

clang/tools/clang-format-vs/ClangFormat/ClangFormat.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@
178178
<None Include="Resources\Images_32bit.bmp" />
179179
</ItemGroup>
180180
<ItemGroup>
181+
<Content Include="clang-format.exe">
182+
<IncludeInVSIX>true</IncludeInVSIX>
183+
</Content>
181184
<Content Include="Resources\Package.ico" />
182185
</ItemGroup>
183186
<ItemGroup>

clang/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.ComponentModel;
2323
using System.ComponentModel.Design;
2424
using System.IO;
25+
using System.Reflection;
2526
using System.Runtime.InteropServices;
2627
using System.Xml.Linq;
2728

@@ -128,9 +129,12 @@ private void MenuItemCallback(object sender, EventArgs args)
128129
/// </summary>
129130
private string RunClangFormat(string text, int offset, int length, string path)
130131
{
132+
string vsixPath = Path.GetDirectoryName(Uri.UnescapeDataString(
133+
new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path));
134+
131135
System.Diagnostics.Process process = new System.Diagnostics.Process();
132136
process.StartInfo.UseShellExecute = false;
133-
process.StartInfo.FileName = "clang-format.exe";
137+
process.StartInfo.FileName = vsixPath + "\\clang-format.exe";
134138
// Poor man's escaping - this will not work when quotes are already escaped
135139
// in the input (but we don't need more).
136140
string style = GetStyle().Replace("\"", "\\\"");

clang/tools/clang-format-vs/README.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ Build prerequisites are:
55
- Visual Studio 2012 Professional
66
- Visual Studio 2010 Professional
77
- Visual Studio 2010 SDK.
8+
9+
clang-format.exe must be copied into the ClangFormat/ directory before building.
10+
It will be bundled into the .vsix file.

0 commit comments

Comments
 (0)