Skip to content

Commit eacae0f

Browse files
authored
Merge pull request #1051 from Squirrel/only-generate-root-stubs
Only generate execution stubs for the top-level executables
2 parents 4dac714 + bceb89f commit eacae0f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/Squirrel/Utility.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,16 @@ public static bool FileIsLikelyPEImage(string name)
573573
return peExtensions.Any(x => ext.Equals(x, StringComparison.OrdinalIgnoreCase));
574574
}
575575

576+
public static bool IsFileTopLevelInPackage(string fullName, string pkgPath)
577+
{
578+
var fn = fullName.ToLowerInvariant();
579+
var pkg = pkgPath.ToLowerInvariant();
580+
var relativePath = fn.Replace(pkg, "");
581+
582+
// NB: We want to match things like `/lib/net45/foo.exe` but not `/lib/net45/bar/foo.exe`
583+
return relativePath.Split(Path.DirectorySeparatorChar).Length == 4;
584+
}
585+
576586
public static void LogIfThrows(this IFullLogger This, LogLevel level, string message, Action block)
577587
{
578588
try {

src/Update/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ public void Releasify(string package, string targetDir = null, string packagesDi
389389
new DirectoryInfo(pkgPath).GetAllFilesRecursively()
390390
.Where(x => x.Name.ToLowerInvariant().EndsWith(".exe"))
391391
.Where(x => !x.Name.ToLowerInvariant().Contains("squirrel.exe"))
392+
.Where(x => Utility.IsFileTopLevelInPackage(x.FullName, pkgPath))
392393
.Where(x => Utility.ExecutableUsesWin32Subsystem(x.FullName))
393394
.ForEachAsync(x => createExecutableStubForExe(x.FullName))
394395
.Wait();
@@ -405,7 +406,7 @@ public void Releasify(string package, string targetDir = null, string packagesDi
405406

406407
this.Log().Info("About to sign {0}", x.FullName);
407408
await signPEFile(x.FullName, signingOpts);
408-
})
409+
}, 1)
409410
.Wait();
410411
});
411412

test/UtilityTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ public void FileIsLikelyPEImageTest(string input, bool result)
142142
Assert.Equal(result, Utility.FileIsLikelyPEImage(input));
143143
}
144144

145+
[Theory]
146+
[InlineData("C:\\Users\\bob\\temp\\pkgPath\\lib\\net45\\foo.exe", "C:\\Users\\bob\\temp\\pkgPath", true)]
147+
[InlineData("C:\\Users\\bob\\temp\\pkgPath\\lib\\net45\\node_modules\\foo.exe", "C:\\Users\\bob\\temp\\pkgPath", false)]
148+
[InlineData("C:\\Users\\bob\\temp\\pkgPath\\lib\\net45\\node_modules\\foo\\foo.exe", "C:\\Users\\bob\\temp\\pkgPath", false)]
149+
[InlineData("foo.png", "C:\\Users\\bob\\temp\\pkgPath", false)]
150+
public void IsFileTopLevelInPackageTest(string input, string packagePath, bool result)
151+
{
152+
Assert.Equal(result, Utility.IsFileTopLevelInPackage(input, packagePath));
153+
}
154+
155+
156+
145157
[Fact]
146158
public void WeCanFetchAllProcesses()
147159
{

0 commit comments

Comments
 (0)