Skip to content
Merged
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
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:
nuGetFeedType: external
packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
publishFeedCredentials: 'AzureArtifacts'
continueOnError: true
continueOnError: true
condition: succeeded()
displayName: Push NuGet packages to Azure Artifacts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Reference Include="Costura, Version=3.3.3.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\packages\Costura.Fody.3.3.3\lib\net40\Costura.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Mono.Cecil, Version=0.11.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.1\lib\net40\Mono.Cecil.dll</HintPath>
</Reference>
Expand Down
69 changes: 65 additions & 4 deletions source/MetadataProcessor.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//

using Mono.Cecil;
using nanoFramework.Tools.MetadataProcessor.Core;
using System;
using System.Collections.Generic;
using System.Globalization;
Expand All @@ -22,6 +23,7 @@ private sealed class MetadataProcessor
new Dictionary<string, string>(StringComparer.Ordinal);

private AssemblyDefinition _assemblyDefinition;
private nanoAssemblyBuilder _assemblyBuilder;

private List<string> _classNamesToExclude = new List<string>();

Expand Down Expand Up @@ -52,17 +54,17 @@ public void Compile(string fileName)
{
if (Verbose) System.Console.WriteLine("Compiling assembly...");

var builder = new nanoAssemblyBuilder(_assemblyDefinition, _classNamesToExclude, Minimize, Verbose);
_assemblyBuilder = new nanoAssemblyBuilder(_assemblyDefinition, _classNamesToExclude, Minimize, Verbose);

using (var stream = File.Open(fileName, FileMode.Create, FileAccess.ReadWrite))
using (var writer = new BinaryWriter(stream))
{
builder.Write(GetBinaryWriter(writer));
_assemblyBuilder.Write(GetBinaryWriter(writer));
}

using (var writer = XmlWriter.Create(Path.ChangeExtension(fileName, "pdbx")))
{
builder.Write(writer);
_assemblyBuilder.Write(writer);
}
}
catch (Exception)
Expand Down Expand Up @@ -90,6 +92,41 @@ public void AddClassToExclude(
{
_classNamesToExclude.Add(className);
}

public void GenerateSkeleton(
string file,
string name,
string project,
bool interopCode)
{
try
{
if (interopCode)
{
System.Console.Error.WriteLine("Generator for Interop stubs is not supported yet.");

Environment.Exit(1);
}

if (Verbose) System.Console.WriteLine("Generating skeleton files...");

var skeletonGenerator = new nanoSkeletonGenerator(
_assemblyBuilder.TablesContext,
file,
name,
project,
interopCode);

skeletonGenerator.GenerateSkeleton();
}
catch (Exception ex)
{
System.Console.Error.WriteLine(
"Unable to generate skeleton files");

Environment.Exit(1);
}
}
}

public static void Main(string[] args)
Expand Down Expand Up @@ -124,6 +161,7 @@ public static void Main(string[] args)
System.Console.WriteLine("-compile <path-to-PE-file> Compiles an assembly into nanoCLR format.");
System.Console.WriteLine("-loadHints <assembly-name> <path-to-assembly-file> Loads one (or more) assembly file(s) as a dependency(ies).");
System.Console.WriteLine("-excludeClassByName <class-name> Removes the class from an assembly.");
System.Console.WriteLine("-generateskeleton Generate skeleton files with stubs to add native code for an assembly.");
System.Console.WriteLine("-minimize Minimizes the assembly, removing unwanted elements.");
System.Console.WriteLine("-verbose Outputs each command before executing it.");
System.Console.WriteLine("");
Expand All @@ -136,7 +174,7 @@ public static void Main(string[] args)
{
md.Compile(args[++i]);
}
else if (arg == "-excludeclassbyName" && i + 1 < args.Length)
else if (arg == "-excludeclassbyname" && i + 1 < args.Length)
{
md.AddClassToExclude(args[++i]);
}
Expand All @@ -153,6 +191,29 @@ public static void Main(string[] args)
md.AddLoadHint(args[i + 1], args[i + 2]);
i += 2;
}
else if (arg == "-generateskeleton" && i + 2 < args.Length)
{
// fill in arguments
string file = args[i + 1];
string name = args[i + 2];
string project = args[i + 3];
bool interopCode = false;

if (!bool.TryParse(args[i + 4], out interopCode))
{
System.Console.Error.WriteLine("Bad parameter for generateSkeleton. Generate code without Interop support has to be 'true' or 'false'.");

Environment.Exit(1);
}

md.GenerateSkeleton(
file,
name,
project,
interopCode);

i += 4;
}
else
{
System.Console.Error.WriteLine("Unknown command line option '{0}' ignored.", arg);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Copyright (c) 2019 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

using Mono.Cecil;

namespace nanoFramework.Tools.MetadataProcessor.Core.Extensions
{
internal static class TypeDefinitionExtensions
{
public static bool IncludeInStub(this TypeDefinition value)
{
var typeDefFlags = nanoTypeDefinitionTable.GetFlags(value);

if (typeDefFlags.HasFlag(
nanoTypeDefinitionFlags.TD_Delegate |
nanoTypeDefinitionFlags.TD_MulticastDelegate))
{
return false;
}

// Only generate a stub for classes and value types.
if (value.IsClass ||
value.IsValueType)
{
return true;
}

return false;
}
}
}
21 changes: 21 additions & 0 deletions source/MetadataProcessor.Core/MetadataProcessor.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Mono.Cecil, Version=0.11.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.1\lib\net40\Mono.Cecil.dll</HintPath>
</Reference>
Expand All @@ -45,17 +46,34 @@
<Reference Include="Mono.Cecil.Rocks, Version=0.11.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.1\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
<Reference Include="Stubble.Core, Version=1.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Stubble.Core.1.6.3\lib\net45\Stubble.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Endianness\nanoBinaryWriter.cs" />
<Compile Include="Extensions\TypeDefinitionExtensions.cs" />
<Compile Include="InanoTable.cs" />
<Compile Include="Mono.Cecil\CodeWriter.cs" />
<Compile Include="nanoAssemblyBuilder.cs" />
<Compile Include="nanoAssemblyDefinition.cs" />
<Compile Include="nanoSkeletonGenerator.cs" />
<Compile Include="SkeletonGenerator\AssemblyClass.cs" />
<Compile Include="SkeletonGenerator\AssemblyClassStubs.cs" />
<Compile Include="SkeletonGenerator\AssemblyLookupTable.cs" />
<Compile Include="Tables\ICustomStringSorter.cs" />
<Compile Include="Tables\nanoAssemblyReferenceTable.cs" />
<Compile Include="Tables\nanoAttributesTable.cs" />
Expand All @@ -82,13 +100,16 @@
<Compile Include="Utility\nanoCLR_DataType.cs" />
<Compile Include="Utility\nanoFontProcessor.cs" />
<Compile Include="Utility\nanoPdbxFileWriter.cs" />
<Compile Include="Utility\nanoTypeDefinitionFlags.cs" />
<Compile Include="Utility\nanoSerializationType.cs" />
<Compile Include="Utility\nanoStringsConstants.cs" />
<Compile Include="Utility\NativeMethodsCrc.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<Compile Include="SkeletonGenerator\SkeletonTemplates.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Nerdbank.GitVersioning.3.0.28\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.0.28\build\Nerdbank.GitVersioning.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
47 changes: 47 additions & 0 deletions source/MetadataProcessor.Core/SkeletonGenerator/AssemblyClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// Copyright (c) 2019 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

using System.Collections.Generic;

namespace nanoFramework.Tools.MetadataProcessor.Core
{
public class AssemblyDeclaration
{
public string Name;
public string ShortName;
public string ShortNameUpper;

public List<Class> Classes = new List<Class>();
}

public class Class
{
public string Name;
public string AssemblyName;

public List<StaticField> StaticFields = new List<StaticField>();
public List<InstanceField> InstanceFields = new List<InstanceField>();
public List<Method> Methods = new List<Method>();
}

public class StaticField
{
public string Name;
public int ReferenceIndex;
}

public class InstanceField
{
public string Name;
public int ReferenceIndex;

public string FieldWarning;
}

public class Method
{
public string Declaration;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Copyright (c) 2019 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

using System.Collections.Generic;

namespace nanoFramework.Tools.MetadataProcessor.Core
{
public class AssemblyClassStubs
{
public string HeaderFileName;

public List<Method> Functions = new List<Method>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Copyright (c) 2019 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//

using System;
using System.Collections.Generic;

namespace nanoFramework.Tools.MetadataProcessor.Core
{
public class AssemblyLookupTable
{
public string Name;
public string AssemblyName;
public string HeaderFileName;
public string NativeCRC32;

public Version NativeVersion;

public List<Method> LookupTable = new List<Method>();
}
}
Loading