From 6e9a47caacf7facb74ec94910ce57e6c176a9aa4 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 5 Sep 2024 19:16:58 +0100 Subject: [PATCH 1/4] And Android Test Task --- Tasks.cs | 1 + Tasks/TestAndroidTask.cs | 90 ++++++++++++++++++++++++++++++++++++++++ Tasks/TestLinuxTask.cs | 14 +++---- 3 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 Tasks/TestAndroidTask.cs diff --git a/Tasks.cs b/Tasks.cs index d33eae7..717aab6 100644 --- a/Tasks.cs +++ b/Tasks.cs @@ -8,6 +8,7 @@ public class BuildLibraryTask : FrostingTask { } [IsDependentOn(typeof(TestWindowsTask))] [IsDependentOn(typeof(TestMacOSTask))] [IsDependentOn(typeof(TestLinuxTask))] +[IsDependentOn(typeof(TestAndroidTask))] public class TestLibraryTask : FrostingTask { } [TaskName("Default")] diff --git a/Tasks/TestAndroidTask.cs b/Tasks/TestAndroidTask.cs new file mode 100644 index 0000000..3d4b221 --- /dev/null +++ b/Tasks/TestAndroidTask.cs @@ -0,0 +1,90 @@ + +namespace BuildScripts; + +[TaskName("Test Android")] +public sealed class TestAndroidTask : FrostingTask +{ + private static readonly string[] ValidLibs = { + "linux-vdso.so", + "libstdc++.so", + "libgcc_s.so", + "libc.so", + "libm.so", + "libdl.so", + "libpthread.so", + "/lib/ld-linux-", + "/lib64/ld-linux-", + "linux-gate.so.1", + "libOpenSLES.so", + "liblog.so" + }; + + public override bool ShouldRun(BuildContext context) => context.IsRunningOnLinux(); + + public override void Run(BuildContext context) + { + var ndk = System.Environment.GetEnvironmentVariable ("ANDROID_NDK_HOME"); + if (string.IsNullOrEmpty (ndk)) { + context.Information($"SKIP: no ANDROID_NDK+HOME found."); + return; + } + ///toolchains/llvm/prebuilt/*/bin/lld + string readelf = string.Empty; + var files = Directory.GetFiles (System.IO.Path.Combine(ndk, "toolchains/llvm/prebuilt"), "llvm-readelf", SearchOption.AllDirectories); + if (files.Length > 0) { + readelf = files.First (l => l == "llvm-readelf"); + } + if (string.IsNullOrEmpty (readelf)) { + context.Information($"SKIP: could not find llvm-readelf"); + return; + } + + foreach (var filePath in Directory.GetFiles(context.ArtifactsDir, "android-*", SearchOption.AllDirectories)) + { + context.Information($"Checking: {filePath}"); + context.StartProcess( + readelf, + new ProcessSettings + { + Arguments = $"--needed-libs {filePath}", + RedirectStandardOutput = true + }, + out IEnumerable processOutput); + + var passedTests = true; + foreach (var line in processOutput) + { + if (line.Contains('[') || line.Contains(']')) + continue; + var libPath = line.Trim(); + + var isValidLib = false; + foreach (var validLib in ValidLibs) + { + if (libPath.StartsWith(validLib)) + { + isValidLib = true; + break; + } + } + + if (isValidLib) + { + context.Information($"VALID: {libPath}"); + } + else + { + context.Information($"INVALID: {libPath}"); + passedTests = false; + } + } + + if (!passedTests) + { + throw new Exception("Invalid library linkage detected!"); + } + + context.Information(""); + } + } +} diff --git a/Tasks/TestLinuxTask.cs b/Tasks/TestLinuxTask.cs index 1ee58a0..8aa589f 100644 --- a/Tasks/TestLinuxTask.cs +++ b/Tasks/TestLinuxTask.cs @@ -14,17 +14,15 @@ public sealed class TestLinuxTask : FrostingTask "libpthread.so", "/lib/ld-linux-", "/lib64/ld-linux-", - // android - "linux-gate.so.1", - "libOpenSLES.so", - "liblog.so" }; public override bool ShouldRun(BuildContext context) => context.IsRunningOnLinux(); public override void Run(BuildContext context) { - foreach (var filePath in Directory.GetFiles(context.ArtifactsDir, "*", SearchOption.AllDirectories)) + var rootFiles = Directory.GetFiles(context.ArtifactsDir); + var linuxFiles = Directory.GetFiles(context.ArtifactsDir, "linux-*", SearchOption.AllDirectories); + foreach (var filePath in rootFiles.Union (linuxFiles)) { context.Information($"Checking: {filePath}"); context.StartProcess( @@ -57,10 +55,8 @@ public override void Run(BuildContext context) } else { - if (!libPath.Contains ("android-arm")) { - context.Information($"INVALID: {libPath}"); - passedTests = false; - } + context.Information($"INVALID: {libPath}"); + passedTests = false; } } From 7872ad38f70b2ead4a22c336cc813a78bdb0f566 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 5 Sep 2024 22:28:52 +0100 Subject: [PATCH 2/4] Fix android error --- Tasks/TestAndroidTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/TestAndroidTask.cs b/Tasks/TestAndroidTask.cs index 3d4b221..00e768d 100644 --- a/Tasks/TestAndroidTask.cs +++ b/Tasks/TestAndroidTask.cs @@ -32,7 +32,7 @@ public override void Run(BuildContext context) string readelf = string.Empty; var files = Directory.GetFiles (System.IO.Path.Combine(ndk, "toolchains/llvm/prebuilt"), "llvm-readelf", SearchOption.AllDirectories); if (files.Length > 0) { - readelf = files.First (l => l == "llvm-readelf"); + readelf = files.First (l => l.EndsWith ("llvm-readelf")); } if (string.IsNullOrEmpty (readelf)) { context.Information($"SKIP: could not find llvm-readelf"); From 21ecb3f0b8b347ef21fd134d84f07db84e0ebad7 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Fri, 6 Sep 2024 13:56:56 +0100 Subject: [PATCH 3/4] Add logging --- Tasks/PublishLibraryTask.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Tasks/PublishLibraryTask.cs b/Tasks/PublishLibraryTask.cs index 506c61b..374985a 100644 --- a/Tasks/PublishLibraryTask.cs +++ b/Tasks/PublishLibraryTask.cs @@ -37,8 +37,10 @@ public override async Task RunAsync(BuildContext context) } } - foreach (var r in availableRids) + foreach (var r in availableRids) { + context.Information($"Uploading: {context.ArtifactsDir}/{r} to artifacts-{r}"); await context.BuildSystem().GitHubActions.Commands.UploadArtifact(DirectoryPath.FromString($"{context.ArtifactsDir}/{r}"), $"artifacts-{r}"); + } if (availableRids.Any ()) return; @@ -58,6 +60,7 @@ public override async Task RunAsync(BuildContext context) _ => "-x64", }; } + context.Information($"Uploading: {context.ArtifactsDir} to artifacts-{rid}"); await context.BuildSystem().GitHubActions.Commands.UploadArtifact(DirectoryPath.FromString(context.ArtifactsDir), $"artifacts-{rid}"); } } From b7cc4af58ac840eae88fe3762abe321b62752781 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Fri, 6 Sep 2024 14:12:44 +0100 Subject: [PATCH 4/4] Fix universalbinary check to only work on osx --- Tasks/TestMacOSTask.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tasks/TestMacOSTask.cs b/Tasks/TestMacOSTask.cs index 99cf0ba..5183842 100644 --- a/Tasks/TestMacOSTask.cs +++ b/Tasks/TestMacOSTask.cs @@ -81,7 +81,7 @@ public override void Run(BuildContext context) context.Information($"ARCHITECTURE: arm64"); } - if (context.IsUniversalBinary && !(arm64 && x86_64)) + if (context.IsUniversalBinary && filePath.Contains ("osx") && !(arm64 && x86_64)) { context.Information($"INVALID universal binary"); throw new Exception("An universal binary hasn't been generated!");