diff --git a/src/AXSharp.compiler/src/AXSharp.Compiler/LegalAcrobatics.cs b/src/AXSharp.compiler/src/AXSharp.Compiler/LegalAcrobatics.cs index ddb3e065..1d6712a9 100644 --- a/src/AXSharp.compiler/src/AXSharp.Compiler/LegalAcrobatics.cs +++ b/src/AXSharp.compiler/src/AXSharp.Compiler/LegalAcrobatics.cs @@ -1,59 +1,59 @@ -using CliWrap; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; +using System.Reflection; using System.Runtime.InteropServices; using System.Text; -using System.Threading.Tasks; +using CliWrap; +using static AXSharp.Compiler.AxProject; -namespace AXSharp.Compiler +namespace AXSharp.Compiler; + +public static class LegalAcrobatics { - public static class LegalAcrobatics -{ + private static IEnumerable AXAssemblies { get; set; } + + public static string? StcVersion { get; private set; } + public static async Task LegalComplianceAcrobatics(string entryAssemblyLocation) { /* We need this to comply with the Siemens legal requirement to allow only users that have access to simatic-ax to some APIs. */ - - var stcapipath = Path.GetFullPath(Path.Combine(entryAssemblyLocation, $".apax//.apax//packages//@ax//{GetStcNameByPlatform()}//bin//")); - if(!Directory.Exists(stcapipath)) - { - await ApaxInstallLegalAcrobatics(entryAssemblyLocation); - } - + var stcapipath = Path.GetFullPath(Path.Combine(entryAssemblyLocation, + $".apax//.apax//packages//@ax//{GetStcNameByPlatform()}//bin//")); + + if (!Directory.Exists(stcapipath)) await ApaxInstallLegalAcrobatics(entryAssemblyLocation); + SetupAssemblyResolverLegalAcrobatics(entryAssemblyLocation); } - static IEnumerable AXAssemblies { get; set; } - - static void SetupAssemblyResolverLegalAcrobatics(string entryAssemblyLocation) + private static void SetupAssemblyResolverLegalAcrobatics(string entryAssemblyLocation) { var axAssemblies = new List(); foreach (var assemblyFile in Directory.EnumerateFiles( - Path.GetFullPath(Path.Combine(entryAssemblyLocation, $".apax//.apax//packages//@ax//{GetStcNameByPlatform()}//bin//")), "*.dll")) - { + Path.GetFullPath(Path.Combine(entryAssemblyLocation, + $".apax//.apax//packages//@ax//{GetStcNameByPlatform()}//bin//")), "*.dll")) try { axAssemblies.Add(Assembly.LoadFile(assemblyFile)); } - catch (System.BadImageFormatException) + catch (BadImageFormatException) { // We just ignore this...there might be some libraries that we just cannot load, but we do not need them. } - } AXAssemblies = axAssemblies; + StcVersion = AXAssemblies.FirstOrDefault()?.GetName().Version?.ToString(); + + + AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; } - static async Task ApaxInstallLegalAcrobatics(string entryAssemblyLocation) + private static async Task ApaxInstallLegalAcrobatics(string entryAssemblyLocation) { var stdOutBuffer = new StringBuilder(); var stdErrBuffer = new StringBuilder(); @@ -71,7 +71,7 @@ static async Task ApaxInstallLegalAcrobatics(string entryAssemblyLocation) .WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrBuffer)) .ExecuteAsync(); } - catch(Exception ex) + catch (Exception ex) { Log.Logger.Error("There was a problem restoring apax packages.", ex); } @@ -82,12 +82,13 @@ static async Task ApaxInstallLegalAcrobatics(string entryAssemblyLocation) } } - static Assembly? CurrentDomain_AssemblyResolve(object? sender, ResolveEventArgs args) + private static Assembly? CurrentDomain_AssemblyResolve(object? sender, ResolveEventArgs args) { return AXAssemblies.FirstOrDefault(p => p.FullName == args.Name); } - static string GetStcNameByPlatform() - => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "stc-linux-x64" : "stc-win-x64"; -} -} + private static string GetStcNameByPlatform() + { + return RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "stc-linux-x64" : "stc-win-x64"; + } +} \ No newline at end of file diff --git a/src/AXSharp.compiler/src/ixc/Program.cs b/src/AXSharp.compiler/src/ixc/Program.cs index 06d420f1..c7a7418b 100644 --- a/src/AXSharp.compiler/src/ixc/Program.cs +++ b/src/AXSharp.compiler/src/ixc/Program.cs @@ -104,9 +104,9 @@ private static void DisplayInfo() "THIRD PARTY LICENSES CAN BE FOUND AT \n" + "https://github.com/ix-ax/axsharp/blob/master/notices.md"); - Console.ForegroundColor = ConsoleColor.Magenta; - Console.WriteLine("ATTENTION: This version requires the usage of `apax sld` v0.14.2 or later!"); + Console.ForegroundColor = ConsoleColor.Magenta; + Console.WriteLine($"Using version '{LegalAcrobatics.StcVersion}' of stc."); Console.ForegroundColor = originalColor; if (int.Parse(GitVersionInformation.Major) < 1 || string.IsNullOrEmpty(GitVersionInformation.PreReleaseLabel)) diff --git a/src/apax/apax-lock.json b/src/apax/apax-lock.json index edf3f569..4e8a1985 100644 --- a/src/apax/apax-lock.json +++ b/src/apax/apax-lock.json @@ -7,25 +7,25 @@ "name": "s", "version": "0.0.0", "devDependencies": { - "@ax/stc": "7.1.81" + "@ax/stc": "8.0.17" } }, "packages": { "@ax/stc": { "name": "@ax/stc", - "version": "7.1.81", - "integrity": "sha512-1UTt8x3dca10TrUv5zdzulnVvJlb6zqc7UJJXTVP9+slwxqcTCedt1Pmch1JAHpBDdrnGh1MRBpH8egFsEJ8Gg==", - "resolved": "https://registry.simatic-ax.siemens.io/@ax/stc/-/stc-7.1.81.tgz", + "version": "8.0.17", + "integrity": "sha512-Ym2uWEmfrkhm2Z/ODujUwQOiAwQ2p0fv9hLTJGL+zwYMjAwja71JayMLSOO+cX0gv8VexrxISDa66jouT+XySA==", + "resolved": "https://registry.simatic-ax.siemens.io/@ax/stc/-/stc-8.0.17.tgz", "dependencies": { - "@ax/stc-win-x64": "7.1.81", - "@ax/stc-linux-x64": "7.1.81" + "@ax/stc-win-x64": "8.0.17", + "@ax/stc-linux-x64": "8.0.17" } }, "@ax/stc-win-x64": { "name": "@ax/stc-win-x64", - "version": "7.1.81", - "integrity": "sha512-JRbpVh3SL1GoEsbfoJ52/1BSU082HjS1t64N2N5x1sg+X3bC0waAG6Sjub03D+fOPSAHKS5e/Lgd0p7WLedCPQ==", - "resolved": "https://registry.simatic-ax.siemens.io/@ax/stc-win-x64/-/stc-win-x64-7.1.81.tgz", + "version": "8.0.17", + "integrity": "sha512-vOnWIY+dLfASN2s7exuy7pQU/KKTp9ej3uMn86vLTXtjF5YUECInNYOM9kY6hQdnJFJH6RirxzbiRJftjvLHuw==", + "resolved": "https://registry.simatic-ax.siemens.io/@ax/stc-win-x64/-/stc-win-x64-8.0.17.tgz", "os": [ "win32" ], @@ -33,14 +33,14 @@ "x64" ], "dependencies": { - "@ax/st-docs": "7.1.81" + "@ax/st-docs": "8.0.17" } }, "@ax/stc-linux-x64": { "name": "@ax/stc-linux-x64", - "version": "7.1.81", - "integrity": "sha512-gHajdPn05TMvwCBg/pyHlZmMByNIo5mlQ36AvTm+YaupoxwaJfzX9QIR7mWQ/RbJ4ycaxKwaxgh5H1eG7MCAcg==", - "resolved": "https://registry.simatic-ax.siemens.io/@ax/stc-linux-x64/-/stc-linux-x64-7.1.81.tgz", + "version": "8.0.17", + "integrity": "sha512-BnpkLdkExZ6n6wyKHprrCPfQOu4FK6FTTt8ieVbrjOwABSJxez3ls9GBEpUOJKxqJa05epbR2nIHYoOO1pFKtQ==", + "resolved": "https://registry.simatic-ax.siemens.io/@ax/stc-linux-x64/-/stc-linux-x64-8.0.17.tgz", "os": [ "linux" ], @@ -48,16 +48,15 @@ "x64" ], "dependencies": { - "@ax/st-docs": "7.1.81" + "@ax/st-docs": "8.0.17" } }, "@ax/st-docs": { "name": "@ax/st-docs", - "version": "7.1.81", - "integrity": "sha512-7ps4hmJoHkSjhK0jH4mCu03qsCALSy9pe/FMWdNfBQMXt7PEq7uN4LML0r8orDlyOQgVb2vOcvorZ+n0EtrgKw==", - "resolved": "https://registry.simatic-ax.siemens.io/@ax/st-docs/-/st-docs-7.1.81.tgz", - "dependencies": {}, - "deprecated": "" + "version": "8.0.17", + "integrity": "sha512-bvMaT+GcSwF9ahzqI+wHBlCDfASqnJTDHwuBgVuR68u3R9cLaoOLnosw4HBoJRlBxWyooKB9bn+u++jRaekRNg==", + "resolved": "https://registry.simatic-ax.siemens.io/@ax/st-docs/-/st-docs-8.0.17.tgz", + "dependencies": {} } }, "workspaces": {} diff --git a/src/apax/apax.yml b/src/apax/apax.yml index f4c2ae00..8dbc57e3 100644 --- a/src/apax/apax.yml +++ b/src/apax/apax.yml @@ -5,6 +5,6 @@ targets: - "1500" - axunit-llvm devDependencies: - "@ax/stc": 7.1.81 + "@ax/stc": 8.0.17 installStrategy: strict apaxVersion: 3.1.1