Skip to content

Commit

Permalink
And Android Test Task (#5)
Browse files Browse the repository at this point in the history
* And Android Test Task

* Fix android error

* Add logging

* Fix universalbinary check to only work on osx
  • Loading branch information
dellis1972 authored Sep 13, 2024
1 parent ad9d6c2 commit 388432d
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 11 deletions.
1 change: 1 addition & 0 deletions Tasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
5 changes: 4 additions & 1 deletion Tasks/PublishLibraryTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}");
}
}
90 changes: 90 additions & 0 deletions Tasks/TestAndroidTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

namespace BuildScripts;

[TaskName("Test Android")]
public sealed class TestAndroidTask : FrostingTask<BuildContext>
{
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.EndsWith ("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<string> 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("");
}
}
}
14 changes: 5 additions & 9 deletions Tasks/TestLinuxTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ public sealed class TestLinuxTask : FrostingTask<BuildContext>
"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(
Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tasks/TestMacOSTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down

0 comments on commit 388432d

Please sign in to comment.