Skip to content

Commit

Permalink
Add an option not to repack assemblies
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev committed Jun 28, 2021
1 parent 415a8f0 commit 4663d80
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Tools/SetupUnityPackage/CommandLineOptions/OptionsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
////////////////////////////////////////////////////////////////////////////

using System.Collections.Generic;
using CommandLine;

namespace SetupUnityPackage
{
internal abstract class OptionsBase
{
[Option("no-ilrepack", Default = true, Required = false, HelpText = "Specify whether to skip bundling dependencies into the main package. This should not be used for release builds")]
public bool NoRepack { get; set; }

public abstract PackageInfo[] Files { get; }

public abstract string PackageBasePath { get; }
Expand Down
2 changes: 1 addition & 1 deletion Tools/SetupUnityPackage/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void CopyFiles(string from, string to, Func<string, bool> shouldIn
foreach (var file in testFiles)
{
var relativePath = Path.GetRelativePath(from, file);
if (shouldIncludeFile != null && !shouldIncludeFile(relativePath))
if (shouldIncludeFile?.Invoke(relativePath) == false)
{
continue;
}
Expand Down
31 changes: 20 additions & 11 deletions Tools/SetupUnityPackage/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,29 @@ private static async Task CopyDependencies(OptionsBase opts, Queue<PackageDepend
}
}

var assembliesToRepack = new List<string> { Path.Combine(opts.PackageBasePath, opts.MainPackagePath) };
assembliesToRepack.AddRange(Directory.EnumerateFiles(tempPath));
if (opts.NoRepack)
{
var targetFolder = Path.Combine(opts.PackageBasePath, Path.GetDirectoryName(opts.MainPackagePath), "Dependencies");

var repack = new ILRepack(new RepackOptions
Helpers.CopyFiles(tempPath, targetFolder);
}
else
{
InputAssemblies = assembliesToRepack.ToArray(),
Internalize = true,
OutputFile = assembliesToRepack[0],
SearchDirectories = searchDirectories,
XmlDocumentation = false,
ExcludeInternalizeMatches = { new Regex("MongoDB\\.Bson") }
});
var assembliesToRepack = new List<string> { Path.Combine(opts.PackageBasePath, opts.MainPackagePath) };
assembliesToRepack.AddRange(Directory.EnumerateFiles(tempPath));

repack.Repack();
var repack = new ILRepack(new RepackOptions
{
InputAssemblies = assembliesToRepack.ToArray(),
Internalize = true,
OutputFile = assembliesToRepack[0],
SearchDirectories = searchDirectories,
XmlDocumentation = false,
ExcludeInternalizeMatches = { new Regex("MongoDB\\.Bson") }
});

repack.Repack();
}

Directory.Delete(tempPath, recursive: true);
}
Expand Down

0 comments on commit 4663d80

Please sign in to comment.