Skip to content

Commit 60ff91e

Browse files
committed
Add GitBranch checking for the compiler
1 parent e430190 commit 60ff91e

5 files changed

Lines changed: 28 additions & 68 deletions

File tree

src/CSharpPluginLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public CSharpPluginLoader(CSharpExtension extension)
4242
{
4343
Instance = this;
4444
CSharpPluginLoader.extension = extension;
45-
compiler = new CompilerService();
45+
compiler = new CompilerService(extension);
4646
}
4747

4848
public void OnModLoaded()

src/CompilerService.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
using System.Text;
1919
using System.Text.RegularExpressions;
2020
using System.Threading;
21+
using Oxide.Core.Extensions;
2122

2223
namespace Oxide.CSharp
2324
{
2425
internal class CompilerService
2526
{
26-
private const string baseUrl = "https://downloads.oxidemod.com/artifacts/Oxide.Compiler/master/";
27+
private const string baseUrl = "https://downloads.oxidemod.com/artifacts/Oxide.Compiler/{0}/";
2728
private Hash<int, Compilation> compilations;
2829
private Queue<CompilerMessage> messageQueue;
2930
private Process process;
@@ -37,36 +38,37 @@ internal class CompilerService
3738
private static Regex fileErrorRegex = new Regex(@"^\[(?'Severity'\S+)\]\[(?'Code'\S+)\]\[(?'File'\S+)\] (?'Message'.+)$", RegexOptions.Compiled);
3839
public bool Installed => File.Exists(filePath);
3940

40-
public CompilerService()
41+
public CompilerService(Extension extension)
4142
{
4243
compilations = new Hash<int, Compilation>();
4344
messageQueue = new Queue<CompilerMessage>();
4445
string arc = IntPtr.Size == 8 ? "x64" : "x86";
4546
filePath = Path.Combine(Interface.Oxide.RootDirectory, $"Oxide.Compiler");
47+
string downloadUrl = string.Format(baseUrl, extension.Branch);
4648
switch (Environment.OSVersion.Platform)
4749
{
4850
case PlatformID.Win32NT:
4951
case PlatformID.Win32S:
5052
case PlatformID.Win32Windows:
5153
filePath += ".exe";
52-
remoteName = baseUrl + $"win-{arc}.Compiler.exe";
54+
remoteName = downloadUrl + $"win-{arc}.Compiler.exe";
5355
break;
5456

5557
case PlatformID.MacOSX:
56-
remoteName = baseUrl + "osx-x64.Compiler";
58+
remoteName = downloadUrl + "osx-x64.Compiler";
5759
break;
5860

5961
case PlatformID.Unix:
60-
remoteName = baseUrl + "linux-x64.Compiler";
62+
remoteName = downloadUrl + "linux-x64.Compiler";
6163
break;
6264
}
6365

64-
EnvironmentHelper.SetOxideEnvironmentalVariable("Path:Root", Interface.Oxide.RootDirectory);
65-
EnvironmentHelper.SetOxideEnvironmentalVariable("Path:Logging", Interface.Oxide.LogDirectory);
66-
EnvironmentHelper.SetOxideEnvironmentalVariable("Path:Plugins", Interface.Oxide.PluginDirectory);
67-
EnvironmentHelper.SetOxideEnvironmentalVariable("Path:Configuration", Interface.Oxide.ConfigDirectory);
68-
EnvironmentHelper.SetOxideEnvironmentalVariable("Path:Data", Interface.Oxide.DataDirectory);
69-
EnvironmentHelper.SetOxideEnvironmentalVariable("Path:Libraries", Interface.Oxide.ExtensionDirectory);
66+
EnvironmentHelper.SetVariable("Path:Root", Interface.Oxide.RootDirectory);
67+
EnvironmentHelper.SetVariable("Path:Logging", Interface.Oxide.LogDirectory);
68+
EnvironmentHelper.SetVariable("Path:Plugins", Interface.Oxide.PluginDirectory);
69+
EnvironmentHelper.SetVariable("Path:Configuration", Interface.Oxide.ConfigDirectory);
70+
EnvironmentHelper.SetVariable("Path:Data", Interface.Oxide.DataDirectory);
71+
EnvironmentHelper.SetVariable("Path:Libraries", Interface.Oxide.ExtensionDirectory);
7072
}
7173

7274
private void ExpireFileCache()
@@ -592,7 +594,7 @@ private static bool DownloadFile(string url, string path, int retries = 3)
592594
{
593595
fs.Write(data, 0, data.Length);
594596
}
595-
597+
596598
if (newerFound)
597599
{
598600
string checkVerb = md5 != null ? $"Remote MD5: {md5}" : "Newer found";

src/Oxide.CSharp.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,23 @@
1818
</PropertyGroup>
1919
<ItemGroup>
2020
<PackageReference Include="Oxide.Core" Version="2.0.*" />
21+
<PackageReference Include="Oxide.Common" Version="2.0.*" />
2122
<PackageReference Include="Oxide.References" Version="2.0.*">
2223
<PrivateAssets>contentfiles;analyzers;build</PrivateAssets>
2324
</PackageReference>
2425
<None Include="..\resources\icon.png" Pack="true" PackagePath="\" />
2526
</ItemGroup>
27+
<Target Name="AddGitMetadaAssemblyAttributes" BeforeTargets="CoreGenerateAssemblyInfo">
28+
<Exec Command="git name-rev --name-only HEAD" WorkingDirectory="$(MSBuildProjectDirectory)" ConsoleToMSBuild="True">
29+
<Output TaskParameter="ConsoleOutput" PropertyName="GitBranch" />
30+
</Exec>
31+
<ItemGroup>
32+
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="$(GitBranch) != ''">
33+
<_Parameter1>GitBranch</_Parameter1>
34+
<_Parameter2>$(GitBranch)</_Parameter2>
35+
</AssemblyAttribute>
36+
</ItemGroup>
37+
</Target>
2638
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
2739
<Target Name="ChangeAliasesOfStrongNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
2840
<ItemGroup>

src/Patching/Validation/HasEnvironmentalVariableAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ public HasEnvironmentalVariableAttribute(string rule)
1212
VariableName = rule ?? throw new ArgumentNullException(nameof(rule));
1313
}
1414

15-
protected override bool IsValid(object item) => !string.IsNullOrEmpty(EnvironmentHelper.GetOxideEnvironmentalVariable(VariableName));
15+
protected override bool IsValid(object item) => !string.IsNullOrEmpty(EnvironmentHelper.GetVariable(VariableName));
1616
}
1717
}

src/Utility.cs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -83,58 +83,4 @@ public TValue this[TKey key]
8383

8484
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
8585
}
86-
87-
internal static class EnvironmentHelper
88-
{
89-
public static void SetOxideEnvironmentalVariable(string name, string value, bool force = false)
90-
{
91-
if (string.IsNullOrEmpty(name))
92-
{
93-
return;
94-
}
95-
96-
name = NormalizeKey(name);
97-
98-
if (force)
99-
{
100-
Environment.SetEnvironmentVariable(name, value);
101-
Interface.Oxide.RootLogger.WriteDebug(Core.Logging.LogType.Info, null, "CSharp", $"Setting environmental variable: {name} => {value ?? "null"}");
102-
}
103-
else if (GetOxideEnvironmentalVariable(name) == null)
104-
{
105-
Environment.SetEnvironmentVariable(name, value);
106-
Interface.Oxide.RootLogger.WriteDebug(Core.Logging.LogType.Info, null, "CSharp", $"Setting environmental variable: {name} => {value ?? "null"}");
107-
}
108-
else
109-
{
110-
Interface.Oxide.RootLogger.WriteDebug(Core.Logging.LogType.Warning, null, "CSharp", $"Failed to set environmental variable: {name} => {value ?? "null"} | Value is already set, please use force parameter to force it");
111-
}
112-
}
113-
114-
public static string GetOxideEnvironmentalVariable(string name)
115-
{
116-
if (string.IsNullOrEmpty(name))
117-
{
118-
return null;
119-
}
120-
name = NormalizeKey(name);
121-
string value = Environment.GetEnvironmentVariable(name);
122-
Interface.Oxide.RootLogger.WriteDebug(Core.Logging.LogType.Warning, null, "CSharp", $"Retrieving environmental variable: {name} => {value ?? "null"}");
123-
return value;
124-
}
125-
126-
private static string NormalizeKey(string key)
127-
{
128-
if (key.StartsWith("OXIDE:", StringComparison.InvariantCultureIgnoreCase))
129-
{
130-
key = key.Replace("oxide:", "OXIDE:");
131-
}
132-
else
133-
{
134-
key = "OXIDE:" + key;
135-
}
136-
137-
return key;
138-
}
139-
}
14086
}

0 commit comments

Comments
 (0)