Skip to content

Commit

Permalink
Rename LEGACY to CECIL0_9 (and CECIL0_10 for future)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ade committed Nov 8, 2018
1 parent cb6aeaa commit f71b022
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion MonoMod.BaseLoader/ModRelinker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static Assembly GetRelinkedAssembly(ModMetadata meta, Stream stream,
return null;
} finally {
Modder.ClearCaches(moduleSpecific: true);
#if !LEGACY
#if !CECIL0_9
Modder.Module.Dispose();
#endif
Modder.Module = null;
Expand Down
2 changes: 1 addition & 1 deletion MonoMod.BaseLoader/RelinkerSymbolReaderProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ISymbolReader GetSymbolReader(ModuleDefinition module, Stream symbolStrea
return new MdbReaderProvider().GetSymbolReader(module, symbolStream);

case DebugSymbolFormat.PDB:
#if !LEGACY
#if !CECIL0_9
if (IsPortablePdb(symbolStream))
return new PortablePdbReaderProvider().GetSymbolReader(module, symbolStream);
return new NativePdbReaderProvider().GetSymbolReader(module, symbolStream);
Expand Down
18 changes: 11 additions & 7 deletions MonoMod.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,19 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>DEBUG;TRACE;$(DefineConstants)</DefineConstants>
</PropertyGroup>

<!-- Release -->
<PropertyGroup Condition="'$(Configuration)' == 'Release' Or '$(Configuration)' == 'ReleaseLegacy'">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>TRACE;$(DefineConstants)</DefineConstants>
</PropertyGroup>

<!-- Legacy -->
<PropertyGroup Condition="'$(Configuration)' == 'DebugLegacy' Or '$(Configuration)' == 'ReleaseLegacy'">
<CecilLegacy>true</CecilLegacy>
<DefineConstants>LEGACY</DefineConstants>
</PropertyGroup>

<!-- Common references. -->
Expand All @@ -75,6 +74,8 @@
<NETStandard1X Condition="$(TargetFramework.StartsWith('netstandard1')) Or $(TargetFramework.StartsWith('netcoreapp1'))">true</NETStandard1X>
<DefineConstants>NETSTANDARD;$(DefineConstants)</DefineConstants>
<DefineConstants Condition="$(NETStandard1X)">NETSTANDARD1_X;$(DefineConstants)</DefineConstants>
<DefineConstants Condition="$(CecilLegacy)">CECIL0_10;$(DefineConstants)</DefineConstants>
<CecilVersion Condition="$(CecilLegacy) And '$(CecilVersion)' == ''">0.10.0</CecilVersion>
</PropertyGroup>
<ItemGroup>
<!-- These are also required when targeting .NET Standard 2.0 to resolve a version conflict with Mono.Cecil, which targets .NET Standard 1.0 -->
Expand All @@ -91,7 +92,9 @@
<PropertyGroup>
<NETFramework>true</NETFramework>
<DefineConstants>NETFRAMEWORK;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<DefineConstants Condition="$(CecilLegacy)">CECIL0_9;$(DefineConstants)</DefineConstants>
<CecilVersion Condition="$(CecilLegacy) And '$(CecilVersion)' == ''">0.9.6</CecilVersion>
</PropertyGroup>
<ItemGroup>
<!-- <Reference Include="mscorlib" /> -->
<Reference Include="System" />
Expand All @@ -100,11 +103,12 @@
</Choose>

<!-- Mono.Cecil reference. -->
<PropertyGroup>
<CecilVersion Condition="'$(CecilVersion)' == ''">0.10.0</CecilVersion>
</PropertyGroup>
<ItemGroup Condition="$(Cecil)">
<PackageReference Include="Mono.Cecil">
<Version>0.10.0</Version>
<Version Condition="$(CecilLegacy)">0.9.6</Version>
<Version Condition="$(CecilLegacy) And $(NETStandard)">0.10.0</Version>
<Version>$(CecilVersion)</Version>
</PackageReference>
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion MonoMod.DebugIL/DebugILGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !LEGACY
#if !CECIL0_9
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Utils;
Expand Down
2 changes: 1 addition & 1 deletion MonoMod.DebugIL/DebugILGeneratorExt.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !LEGACY
#if !CECIL0_9
using Mono.Cecil;
using Mono.Cecil.Cil;
using System;
Expand Down
2 changes: 1 addition & 1 deletion MonoMod.DebugIL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace MonoMod.DebugIL {
class Program {

public static void Main(string[] args) {
#if LEGACY
#if CECIL0_9
throw new NotSupportedException();
#else
Console.WriteLine("MonoMod.DebugIL " + typeof(Program).GetTypeInfo().Assembly.GetName().Version);
Expand Down
2 changes: 1 addition & 1 deletion MonoMod.RuntimeDetour.HookGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static void Main(string[] args) {

mm.Log("[HookGen] Starting HookGenerator");
HookGenerator gen = new HookGenerator(mm, Path.GetFileName(pathOut));
#if !LEGACY
#if !CECIL0_9
using (ModuleDefinition mOut = gen.OutputModule) {
#else
ModuleDefinition mOut = gen.OutputModule;
Expand Down
8 changes: 4 additions & 4 deletions MonoMod.Utils/DynamicMethodDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void Reload(Func<AssemblyName, ModuleDefinition> moduleGen = null, bool f
if (_Module != null && !force) {
module = _Module;
} else {
#if !LEGACY
#if !CECIL0_9
_Module?.Dispose();
#endif
_Module = null;
Expand All @@ -107,7 +107,7 @@ public void Reload(Func<AssemblyName, ModuleDefinition> moduleGen = null, bool f

bool _DisposeEarly() {
if (moduleTmp != null) {
#if !LEGACY
#if !CECIL0_9
moduleTmp.Dispose();
#endif
_Module = null;
Expand Down Expand Up @@ -238,7 +238,7 @@ public DynamicMethod Generate() {

public void Dispose() {
if (_Module != null && (--_ModuleRef) == 0) {
#if !LEGACY
#if !CECIL0_9
_Module.Dispose();
#endif
_Module = null;
Expand Down Expand Up @@ -267,7 +267,7 @@ public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters p
return Cache[name.FullName] = Gen(new AssemblyName(name.FullName)).Assembly ?? Fallback.Resolve(name, parameters);
}

#if LEGACY
#if CECIL0_9

public AssemblyDefinition Resolve(string fullName) {
if (Cache.TryGetValue(fullName, out AssemblyDefinition asm))
Expand Down
4 changes: 2 additions & 2 deletions MonoMod.Utils/MonoModExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static MethodBody Clone(this MethodBody o, MethodDefinition m) {
c.ExceptionHandlers.AddRange(o.ExceptionHandlers);
c.Variables.AddRange(o.Variables);

#if !LEGACY
#if !CECIL0_9
m.CustomDebugInformations.AddRange(o.Method.CustomDebugInformations);
m.DebugInformation.SequencePoints.AddRange(o.Method.DebugInformation.SequencePoints);
#endif
Expand Down Expand Up @@ -882,7 +882,7 @@ public static IMetadataTokenProvider ImportReference(this ModuleDefinition mod,
return mtp;
}

#if LEGACY
#if CECIL0_9
public static TypeReference ImportReference(this ModuleDefinition mod, TypeReference type)
=> mod.Import(type);
public static TypeReference ImportReference(this ModuleDefinition mod, Type type, IGenericParameterProvider context)
Expand Down
23 changes: 11 additions & 12 deletions MonoMod/MonoModder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public virtual WriterParameters WriterParameters {
_writerParameters = new WriterParameters() {
WriteSymbols = true,
SymbolWriterProvider =
#if !LEGACY
#if !CECIL0_9
pdb ? new NativePdbWriterProvider() :
#else
pdb ? new PdbWriterProvider() :
Expand Down Expand Up @@ -261,7 +261,7 @@ public MonoModder() {

public virtual void ClearCaches(bool all = false, bool shareable = false, bool moduleSpecific = false) {
if (all || shareable) {
#if !LEGACY
#if !CECIL0_9
foreach (KeyValuePair<string, ModuleDefinition> dep in DependencyCache)
dep.Value.Dispose();
#endif
Expand All @@ -277,17 +277,17 @@ public virtual void ClearCaches(bool all = false, bool shareable = false, bool m
public virtual void Dispose() {
ClearCaches(all: true);

#if !LEGACY
#if !CECIL0_9
Module?.Dispose();
#endif
Module = null;

#if !LEGACY
#if !CECIL0_9
AssemblyResolver?.Dispose();
#endif
AssemblyResolver = null;

#if !LEGACY
#if !CECIL0_9
foreach (ModuleDefinition mod in Mods)
mod?.Dispose();

Expand Down Expand Up @@ -406,7 +406,7 @@ public virtual void MapDependency(ModuleDefinition main, string name, string ful
dep = AssemblyResolver.Resolve(depRef)?.MainModule;
} catch { }
if (dep != null)
#if !LEGACY
#if !CECIL0_9
path = dep.FileName;
#else
path = dep.FullyQualifiedName;
Expand Down Expand Up @@ -451,7 +451,7 @@ public virtual void MapDependency(ModuleDefinition main, string name, string ful
dep = AssemblyResolver.Resolve(new AssemblyNameReference(fullName ?? name, new Version(0, 0, 0, 0)))?.MainModule;
} catch { }
if (dep != null)
#if !LEGACY
#if !CECIL0_9
path = dep.FileName;
#else
path = dep.FullyQualifiedName;
Expand Down Expand Up @@ -523,7 +523,7 @@ public virtual ReaderParameters GenReaderParameters(bool mainModule, string path
ReaderParameters rp = new ReaderParameters(_rp.ReadingMode);
rp.AssemblyResolver = _rp.AssemblyResolver;
rp.MetadataResolver = _rp.MetadataResolver;
#if !LEGACY
#if !CECIL0_9
rp.MetadataImporterProvider = _rp.MetadataImporterProvider;
rp.ReflectionImporterProvider = _rp.ReflectionImporterProvider;
#endif
Expand Down Expand Up @@ -1500,8 +1500,7 @@ public virtual MethodDefinition PatchMethod(TypeDefinition targetType, MethodDef

#region PatchRefs Pass
public virtual void PatchRefs() {
if (Environment.GetEnvironmentVariable("MONOMOD_LEGACY_RELINKMAP") != "0") {
// TODO: Make this "opt-in" in the future.
if (Environment.GetEnvironmentVariable("MONOMOD_LEGACY_RELINKMAP") == "1") {
_SplitUpgrade();
}

Expand Down Expand Up @@ -1578,7 +1577,7 @@ private void _SplitUpgrade() {
Log("[UpgradeSplit] It is only meant to preserve compatibility with mods during the transition to a \"split\" MonoMod.");

string root = Path.GetDirectoryName(DependencyCache["MonoMod"]
#if !LEGACY
#if !CECIL0_9
.FileName
#else
.FullyQualifiedName
Expand Down Expand Up @@ -1659,7 +1658,7 @@ public virtual void PatchRefsInType(TypeDefinition type) {

// Don't foreach when modifying the collection
for (int i = 0; i < type.Interfaces.Count; i++) {
#if !LEGACY
#if !CECIL0_9
InterfaceImplementation interf = type.Interfaces[i];
InterfaceImplementation newInterf = new InterfaceImplementation(interf.InterfaceType.Relink(Relinker, type));
foreach (CustomAttribute attrib in interf.CustomAttributes)
Expand Down

0 comments on commit f71b022

Please sign in to comment.