Skip to content

Commit 388432d

Browse files
authored
And Android Test Task (#5)
* And Android Test Task * Fix android error * Add logging * Fix universalbinary check to only work on osx
1 parent ad9d6c2 commit 388432d

File tree

5 files changed

+101
-11
lines changed

5 files changed

+101
-11
lines changed

Tasks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public class BuildLibraryTask : FrostingTask { }
88
[IsDependentOn(typeof(TestWindowsTask))]
99
[IsDependentOn(typeof(TestMacOSTask))]
1010
[IsDependentOn(typeof(TestLinuxTask))]
11+
[IsDependentOn(typeof(TestAndroidTask))]
1112
public class TestLibraryTask : FrostingTask { }
1213

1314
[TaskName("Default")]

Tasks/PublishLibraryTask.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ public override async Task RunAsync(BuildContext context)
3737
}
3838
}
3939

40-
foreach (var r in availableRids)
40+
foreach (var r in availableRids) {
41+
context.Information($"Uploading: {context.ArtifactsDir}/{r} to artifacts-{r}");
4142
await context.BuildSystem().GitHubActions.Commands.UploadArtifact(DirectoryPath.FromString($"{context.ArtifactsDir}/{r}"), $"artifacts-{r}");
43+
}
4244

4345
if (availableRids.Any ())
4446
return;
@@ -58,6 +60,7 @@ public override async Task RunAsync(BuildContext context)
5860
_ => "-x64",
5961
};
6062
}
63+
context.Information($"Uploading: {context.ArtifactsDir} to artifacts-{rid}");
6164
await context.BuildSystem().GitHubActions.Commands.UploadArtifact(DirectoryPath.FromString(context.ArtifactsDir), $"artifacts-{rid}");
6265
}
6366
}

Tasks/TestAndroidTask.cs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
namespace BuildScripts;
3+
4+
[TaskName("Test Android")]
5+
public sealed class TestAndroidTask : FrostingTask<BuildContext>
6+
{
7+
private static readonly string[] ValidLibs = {
8+
"linux-vdso.so",
9+
"libstdc++.so",
10+
"libgcc_s.so",
11+
"libc.so",
12+
"libm.so",
13+
"libdl.so",
14+
"libpthread.so",
15+
"/lib/ld-linux-",
16+
"/lib64/ld-linux-",
17+
"linux-gate.so.1",
18+
"libOpenSLES.so",
19+
"liblog.so"
20+
};
21+
22+
public override bool ShouldRun(BuildContext context) => context.IsRunningOnLinux();
23+
24+
public override void Run(BuildContext context)
25+
{
26+
var ndk = System.Environment.GetEnvironmentVariable ("ANDROID_NDK_HOME");
27+
if (string.IsNullOrEmpty (ndk)) {
28+
context.Information($"SKIP: no ANDROID_NDK+HOME found.");
29+
return;
30+
}
31+
///toolchains/llvm/prebuilt/*/bin/lld
32+
string readelf = string.Empty;
33+
var files = Directory.GetFiles (System.IO.Path.Combine(ndk, "toolchains/llvm/prebuilt"), "llvm-readelf", SearchOption.AllDirectories);
34+
if (files.Length > 0) {
35+
readelf = files.First (l => l.EndsWith ("llvm-readelf"));
36+
}
37+
if (string.IsNullOrEmpty (readelf)) {
38+
context.Information($"SKIP: could not find llvm-readelf");
39+
return;
40+
}
41+
42+
foreach (var filePath in Directory.GetFiles(context.ArtifactsDir, "android-*", SearchOption.AllDirectories))
43+
{
44+
context.Information($"Checking: {filePath}");
45+
context.StartProcess(
46+
readelf,
47+
new ProcessSettings
48+
{
49+
Arguments = $"--needed-libs {filePath}",
50+
RedirectStandardOutput = true
51+
},
52+
out IEnumerable<string> processOutput);
53+
54+
var passedTests = true;
55+
foreach (var line in processOutput)
56+
{
57+
if (line.Contains('[') || line.Contains(']'))
58+
continue;
59+
var libPath = line.Trim();
60+
61+
var isValidLib = false;
62+
foreach (var validLib in ValidLibs)
63+
{
64+
if (libPath.StartsWith(validLib))
65+
{
66+
isValidLib = true;
67+
break;
68+
}
69+
}
70+
71+
if (isValidLib)
72+
{
73+
context.Information($"VALID: {libPath}");
74+
}
75+
else
76+
{
77+
context.Information($"INVALID: {libPath}");
78+
passedTests = false;
79+
}
80+
}
81+
82+
if (!passedTests)
83+
{
84+
throw new Exception("Invalid library linkage detected!");
85+
}
86+
87+
context.Information("");
88+
}
89+
}
90+
}

Tasks/TestLinuxTask.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ public sealed class TestLinuxTask : FrostingTask<BuildContext>
1414
"libpthread.so",
1515
"/lib/ld-linux-",
1616
"/lib64/ld-linux-",
17-
// android
18-
"linux-gate.so.1",
19-
"libOpenSLES.so",
20-
"liblog.so"
2117
};
2218

2319
public override bool ShouldRun(BuildContext context) => context.IsRunningOnLinux();
2420

2521
public override void Run(BuildContext context)
2622
{
27-
foreach (var filePath in Directory.GetFiles(context.ArtifactsDir, "*", SearchOption.AllDirectories))
23+
var rootFiles = Directory.GetFiles(context.ArtifactsDir);
24+
var linuxFiles = Directory.GetFiles(context.ArtifactsDir, "linux-*", SearchOption.AllDirectories);
25+
foreach (var filePath in rootFiles.Union (linuxFiles))
2826
{
2927
context.Information($"Checking: {filePath}");
3028
context.StartProcess(
@@ -57,10 +55,8 @@ public override void Run(BuildContext context)
5755
}
5856
else
5957
{
60-
if (!libPath.Contains ("android-arm")) {
61-
context.Information($"INVALID: {libPath}");
62-
passedTests = false;
63-
}
58+
context.Information($"INVALID: {libPath}");
59+
passedTests = false;
6460
}
6561
}
6662

Tasks/TestMacOSTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public override void Run(BuildContext context)
8181
context.Information($"ARCHITECTURE: arm64");
8282
}
8383

84-
if (context.IsUniversalBinary && !(arm64 && x86_64))
84+
if (context.IsUniversalBinary && filePath.Contains ("osx") && !(arm64 && x86_64))
8585
{
8686
context.Information($"INVALID universal binary");
8787
throw new Exception("An universal binary hasn't been generated!");

0 commit comments

Comments
 (0)