Skip to content

Commit

Permalink
Merge pull request #1499 from peppy/dynamic-compilation-override-fix
Browse files Browse the repository at this point in the history
Explicitly define the dynamic compilation namespace to avoid crosstalk
  • Loading branch information
smoogipoo authored Apr 6, 2018
2 parents e4b0b57 + 77b1b69 commit 02d7a0f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
3 changes: 1 addition & 2 deletions osu.Framework/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System.Runtime.CompilerServices;
using osu.Framework.Testing;

// We publish our internal attributes to other sub-projects of the framework.
// Note, that we omit visual tests as they are meant to test the framework
// behavior "in the wild".

[assembly: InternalsVisibleTo("osu.Framework.Tests")]
[assembly: InternalsVisibleTo(DynamicClassCompiler.DYNAMIC_ASSEMBLY_NAME)]
[assembly: InternalsVisibleTo("osu.Framework.Tests.Dynamic")]
10 changes: 3 additions & 7 deletions osu.Framework/Testing/DynamicClassCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@

namespace osu.Framework.Testing
{
public class DynamicClassCompiler
{
public const string DYNAMIC_ASSEMBLY_NAME = "osu.DynamicTestAssembly";
}

public class DynamicClassCompiler<T> : DynamicClassCompiler
public class DynamicClassCompiler<T>
where T : IDynamicallyCompile
{
public Action CompilationStarted;
Expand Down Expand Up @@ -143,9 +138,10 @@ private void recompile()
CompilationStarted?.Invoke();

string assemblyVersion = $"{++currentVersion}.0.*";
string dynamicNamespace = $"{checkpointObject.GetType().Assembly.GetName().Name}.Dynamic";

var compilation = CSharpCompilation.Create(
DYNAMIC_ASSEMBLY_NAME,
dynamicNamespace,
requiredFiles.Select(file => CSharpSyntaxTree.ParseText(File.ReadAllText(file), null, file))
// Compile the assembly with a new version so that it replaces the existing one
.Append(CSharpSyntaxTree.ParseText($"using System.Reflection; [assembly: AssemblyVersion(\"{assemblyVersion}\")]"))
Expand Down
8 changes: 5 additions & 3 deletions osu.Framework/Testing/TestBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,15 @@ public void LoadTest(Type testType = null, Action onCompletion = null, bool isDy

var dropdown = toolbar.AssemblyDropdown;

dropdown.RemoveDropdownItem(dropdown.Items.LastOrDefault(i => i.Value.FullName.Contains(DynamicClassCompiler.DYNAMIC_ASSEMBLY_NAME)).Value);
const string dynamic = "dynamic";

dropdown.RemoveDropdownItem(dropdown.Items.LastOrDefault(i => i.Value.FullName.Contains(dynamic)).Value);

// if we are a dynamically compiled type (via DynamicClassCompiler) we should update the dropdown accordingly.
if (isDynamicLoad)
dropdown.AddDropdownItem($"dynamic ({testType.Name})", testType.Assembly);
dropdown.AddDropdownItem($"{dynamic} ({testType.Name})", testType.Assembly);
else
TestTypes.RemoveAll(t => t.Assembly.FullName.Contains(DynamicClassCompiler.DYNAMIC_ASSEMBLY_NAME));
TestTypes.RemoveAll(t => t.Assembly.FullName.Contains(dynamic));

dropdown.Current.Value = testType.Assembly;

Expand Down

0 comments on commit 02d7a0f

Please sign in to comment.