Skip to content

Commit

Permalink
Merge dfa1b96 into b53f353
Browse files Browse the repository at this point in the history
  • Loading branch information
Vogel612 committed Sep 15, 2022
2 parents b53f353 + dfa1b96 commit 5e72e24
Show file tree
Hide file tree
Showing 230 changed files with 143 additions and 54,917 deletions.
2 changes: 2 additions & 0 deletions Rubberduck.Core/Rubberduck.Core.csproj
Expand Up @@ -13,6 +13,8 @@
<ApplicationIcon>Ducky.ico</ApplicationIcon>
<UseWpf>true</UseWpf>
<UseWindowsForms>true</UseWindowsForms>
<!-- FIXME we shouldn't be using resources in this? -->
<GenerateResourceUsePreserializedResources>True</GenerateResourceUsePreserializedResources>
</PropertyGroup>
<Import Project="..\RubberduckBaseProject.csproj" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugAccess|AnyCPU'">
Expand Down
78 changes: 78 additions & 0 deletions Rubberduck.Deployment.Build/ContextAwareTask.cs
@@ -0,0 +1,78 @@
/**
Shamelessly stolen from https://github.com/dotnet/Nerdbank.GitVersioning/blob/3e4e1f8249ba70fd576b524ce12398ee398884fc/src/Nerdbank.GitVersioning.Tasks/ContextAwareTask.cs
*/

namespace Rubberduck.Deployment.Build
{
using System;
using System.IO;
using System.Linq;
using System.Reflection;
#if NETCOREAPP
using System.Runtime.Loader;
#endif
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
#if NETCOREAPP
using Nerdbank.GitVersioning;
#endif

public abstract class ContextAwareTask : AppDomainIsolatedTask
{
protected virtual string ManagedDllDirectory => Path.GetDirectoryName(new Uri(this.GetType().GetTypeInfo().Assembly.CodeBase).LocalPath);

protected virtual string UnmanagedDllDirectory => null;

public override bool Execute()
{
#if NETCOREAPP
string taskAssemblyPath = new Uri(this.GetType().GetTypeInfo().Assembly.CodeBase).LocalPath;

Assembly inContextAssembly = GitLoaderContext.Instance.LoadFromAssemblyPath(taskAssemblyPath);
Type innerTaskType = inContextAssembly.GetType(this.GetType().FullName);
object innerTask = Activator.CreateInstance(innerTaskType);

var outerProperties = this.GetType().GetRuntimeProperties().ToDictionary(i => i.Name);
var innerProperties = innerTaskType.GetRuntimeProperties().ToDictionary(i => i.Name);
var propertiesDiscovery = from outerProperty in outerProperties.Values
where outerProperty.SetMethod != null && outerProperty.GetMethod != null
let innerProperty = innerProperties[outerProperty.Name]
select new { outerProperty, innerProperty };
var propertiesMap = propertiesDiscovery.ToArray();
var outputPropertiesMap = propertiesMap.Where(pair => pair.outerProperty.GetCustomAttribute<OutputAttribute>() != null).ToArray();

foreach (var propertyPair in propertiesMap)
{
object outerPropertyValue = propertyPair.outerProperty.GetValue(this);
propertyPair.innerProperty.SetValue(innerTask, outerPropertyValue);
}

var executeInnerMethod = innerTaskType.GetMethod(nameof(ExecuteInner), BindingFlags.Instance | BindingFlags.NonPublic);
bool result = (bool)executeInnerMethod.Invoke(innerTask, new object[0]);

foreach (var propertyPair in outputPropertiesMap)
{
propertyPair.outerProperty.SetValue(this, propertyPair.innerProperty.GetValue(innerTask));
}

return result;
#else
// On .NET Framework (on Windows), we find native binaries by adding them to our PATH.
if (this.UnmanagedDllDirectory != null)
{
string pathEnvVar = Environment.GetEnvironmentVariable("PATH");
string[] searchPaths = pathEnvVar.Split(Path.PathSeparator);
if (!searchPaths.Contains(this.UnmanagedDllDirectory, StringComparer.OrdinalIgnoreCase))
{
pathEnvVar += Path.PathSeparator + this.UnmanagedDllDirectory;
Environment.SetEnvironmentVariable("PATH", pathEnvVar);
}
}

return this.ExecuteInner();
#endif
}

protected abstract bool ExecuteInner();
}
}
8 changes: 3 additions & 5 deletions Rubberduck.Deployment.Build/IdlGeneration/IdlGenerator.cs
@@ -1,7 +1,7 @@
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using dSPACE.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Org.Benf.OleWoo;
using Org.Benf.OleWoo.Typelib;
Expand Down Expand Up @@ -33,8 +33,7 @@ public string GenerateIdl(Assembly assembly)
{
var converter = new TypeLibConverter();
var sink = new TypeLibExporterNotifySink();
var lib = (ITypeLib) converter.ConvertAssemblyToTypeLib(assembly, assembly.GetName().Name,
TypeLibExporterFlags.None, sink);
var lib = (ITypeLib) converter.ConvertAssemblyToTypeLib(assembly, assembly.GetName().Name, sink);
var formatter = new PlainIDLFormatter();
var owLib = new OWTypeLib(lib);
owLib.Listeners.Add(new IdlListener());
Expand All @@ -57,8 +56,7 @@ public void ReportEvent(ExporterEventKind eventKind, int eventCode, string event
public object ResolveRef(Assembly assembly)
{
var converter = new TypeLibConverter();
var lib = converter.ConvertAssemblyToTypeLib(assembly, assembly.GetName().Name,
TypeLibExporterFlags.None, this);
var lib = converter.ConvertAssemblyToTypeLib(assembly, assembly.GetName().Name, this);
return lib;
}
}
Expand Down
14 changes: 6 additions & 8 deletions Rubberduck.Deployment.Build/Rubberduck.Deployment.Build.csproj
Expand Up @@ -9,14 +9,12 @@
</PropertyGroup>
<Import Project="..\RubberduckBaseMetaProject.csproj" />
<ItemGroup>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Tasks.v4.0" />
<Reference Include="Microsoft.Build.Utilities.v4.0">
<HintPath>$(MSBuildBinPath)\Microsoft.Build.Utilities.v4.0.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.Setup.Configuration.Interop">
<HintPath>VisualStudioSetup\Microsoft.VisualStudio.Setup.Configuration.Interop.dll</HintPath>
</Reference>
<PackageReference Include="Microsoft.Build.Framework" version="17.*" />
<PackageReference Include="Microsoft.Build.Tasks.Core" version="17.*" />
<PackageReference Include="Microsoft.Build.Utilities.Core" version="17.*" />
<PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop" version="3.3.2180" />

<PackageReference Include="dSPACE.Runtime.InteropServices" version="0.15.0" />
<Reference Include="olewoo">
<HintPath>OleWoo\olewoo.dll</HintPath>
</Reference>
Expand Down
12 changes: 7 additions & 5 deletions Rubberduck.Deployment.Build/RubberduckPostBuildTask.cs
Expand Up @@ -58,7 +58,7 @@ public class RubberduckPostBuildTask : AppDomainIsolatedTask
/// Full path to NetFX SDK directory
/// </summary>
[Required]
public string NetToolsDir { get; set; }
public string TlbToolDir { get; set; }

/// <summary>
/// Full path to WiX SDK directory
Expand Down Expand Up @@ -125,7 +125,9 @@ public override bool Execute()

foreach (var dllFile in dllFiles)
{
ProcessDll(dllFile, batchPath);
// FIXME reinstate advanced IDL manipulation using olewoo
// ProcessDll(dllFile, batchPath);
ProcessDll(dllFile, null);
}

if (Config == "Debug")
Expand All @@ -147,7 +149,7 @@ private string FormatParameterList()
var sb = new StringBuilder();
sb.AppendLine("Parameters provided:")
.AppendLine($" Config: {Config}")
.AppendLine($" NetToolsDir: {NetToolsDir}")
.AppendLine($" TlbToolDir: {TlbToolDir}")
.AppendLine($" WixToolsDir: {WixToolsDir}")
.AppendLine($" SourceDir: {SourceDir}")
.AppendLine($" TargetDir: {TargetDir}")
Expand Down Expand Up @@ -308,10 +310,10 @@ private static void MoveFileWithOverwrite(string sourceFile, string destFile)

private void CompileWithTlbExp(DllFileParameters parameters)
{
var command = $"\"{NetToolsDir}tlbexp.exe\" \"{parameters.SourceDll}\" /win32 /out:\"{parameters.SourceTlb32}\"";
var command = $"\"{TlbToolDir}tlbexp.exe\" \"{parameters.SourceDll}\" /win32 /out:\"{parameters.SourceTlb32}\"";
ExecuteTask(command);

command = $"\"{NetToolsDir}tlbexp.exe\" \"{parameters.SourceDll}\" /win64 /out:\"{parameters.SourceTlb64}\"";
command = $"\"{TlbToolDir}tlbexp.exe\" \"{parameters.SourceDll}\" /win64 /out:\"{parameters.SourceTlb64}\"";
ExecuteTask(command);
}

Expand Down
Binary file not shown.

0 comments on commit 5e72e24

Please sign in to comment.