mirror of
https://github.com/google/cpu_features.git
synced 2025-07-01 21:31:15 +02:00
Update badges
This commit is contained in:
@ -2,12 +2,17 @@
|
||||
// 1. copy paste the whole code to https://run.dlang.io/ then click `run`
|
||||
// 2. `docker run --rm -it -v $(pwd):/src dlanguage/dmd dmd -run generate_badges.d`
|
||||
import std.algorithm : each, map, cartesianProduct, filter, joiner, sort, uniq;
|
||||
import std.array : array;
|
||||
import std.array;
|
||||
import std.conv : to;
|
||||
import std.format;
|
||||
import std.range : chain, only;
|
||||
import std.stdio;
|
||||
import std.traits : EnumMembers;
|
||||
import std.string : representation;
|
||||
import std.base64 : Base64;
|
||||
|
||||
immutable string bazel_svg = `<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M6 .16l5.786 5.786L6 11.732.214 5.946 6 .161zM0 6.214V12l5.786 5.786V12L0 6.214zM18 .16l5.786 5.786L18 11.732l-5.786-5.786L18 .161zM24 6.214V12l-5.786 5.786V12L24 6.214zM12 6.16l5.786 5.786L12 17.732l-5.786-5.786L12 6.161zM11.84 18.054v5.785l-5.786-5.785v-5.786l5.785 5.786zM12.16 18.054l5.786-5.786v5.786l-5.785 5.785v-5.785z" stroke="transparent" fill="white"/></svg>`;
|
||||
const string bazel_svg_base64 = Base64.encode(representation(bazel_svg));
|
||||
|
||||
enum BuildSystem
|
||||
{
|
||||
@ -45,7 +50,8 @@ const:
|
||||
|
||||
string id()
|
||||
{
|
||||
return format("%d%c%d", cast(uint)(os) + 1, cast(char)('a' + cpu), cast(uint)(build_system));
|
||||
return format("%d%c%d", cast(uint)(os) + 1, cast(char)('a' + cpu),
|
||||
cast(uint)(build_system));
|
||||
}
|
||||
|
||||
string disabled_image_ref()
|
||||
@ -65,6 +71,8 @@ const:
|
||||
|
||||
bool enabled()
|
||||
{
|
||||
if (cpu == Cpu.LOONGARCH)
|
||||
return false;
|
||||
final switch (build_system)
|
||||
{
|
||||
case BuildSystem.CMake:
|
||||
@ -81,9 +89,21 @@ const:
|
||||
return format("![]%s", disabled_image_ref);
|
||||
}
|
||||
|
||||
string append_logo(string url)
|
||||
{
|
||||
final switch (build_system)
|
||||
{
|
||||
case BuildSystem.CMake:
|
||||
return url ~ "&logo=cmake";
|
||||
case BuildSystem.Bazel:
|
||||
return url ~ "&logo=data:image/svg%2bxml;base64," ~ bazel_svg_base64;
|
||||
}
|
||||
}
|
||||
|
||||
string disabled_image_link()
|
||||
{
|
||||
return format("%s: https://img.shields.io/badge/%s-N%%2FA-lightgrey", disabled_image_ref, build_system);
|
||||
return append_logo(format("%s: https://img.shields.io/badge/n%%2Fa-lightgrey?",
|
||||
disabled_image_ref));
|
||||
}
|
||||
|
||||
string filename()
|
||||
@ -95,14 +115,16 @@ const:
|
||||
|
||||
string link_decl()
|
||||
{
|
||||
return format("%s: https://github.com/google/cpu_features/actions/workflows/%s", link_ref, filename());
|
||||
return format("%s: https://github.com/google/cpu_features/actions/workflows/%s",
|
||||
link_ref, filename());
|
||||
}
|
||||
|
||||
string image_decl()
|
||||
{
|
||||
return format(
|
||||
"%s: https://img.shields.io/github/actions/workflow/status/google/cpu_features/%s?branch=main&label=%s", image_ref, filename(), build_system);
|
||||
return append_logo(format("%s: https://img.shields.io/github/actions/workflow/status/google/cpu_features/%s?branch=main&event=push&label=",
|
||||
image_ref, filename()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
auto tableHeader(in Cpu[] cpus)
|
||||
@ -117,11 +139,9 @@ auto tableAlignment(in Cpu[] cpus)
|
||||
|
||||
auto tableCell(Range)(in Os os, in Cpu cpu, Range badges)
|
||||
{
|
||||
return badges
|
||||
.filter!(b => b.cpu == cpu && b.os == os)
|
||||
return badges.filter!(b => b.cpu == cpu && b.os == os)
|
||||
.map!(b => b.text())
|
||||
.joiner("<br/>")
|
||||
.to!string;
|
||||
.joiner("<br/>").to!string;
|
||||
}
|
||||
|
||||
auto tableRow(Range)(in Os os, in Cpu[] cpus, Range badges)
|
||||
@ -136,7 +156,8 @@ auto tableRows(Range)(in Os[] oses, in Cpu[] cpus, Range badges)
|
||||
|
||||
auto table(Range)(in Os[] oses, in Cpu[] cpus, Range badges)
|
||||
{
|
||||
return chain(only(tableHeader(cpus)), only(tableAlignment(cpus)), tableRows(oses, cpus, badges));
|
||||
return chain(only(tableHeader(cpus)), only(tableAlignment(cpus)),
|
||||
tableRows(oses, cpus, badges));
|
||||
}
|
||||
|
||||
void main()
|
||||
@ -144,26 +165,17 @@ void main()
|
||||
immutable allCpus = [EnumMembers!Cpu];
|
||||
immutable allOses = [EnumMembers!Os];
|
||||
immutable allBuildSystems = [EnumMembers!BuildSystem];
|
||||
|
||||
auto badges = cartesianProduct(allCpus, allOses, allBuildSystems).map!(
|
||||
t => Badge(t[0], t[1], t[2]));
|
||||
|
||||
writefln("%(|%-( %s |%) |\n%) |", table(allOses, allCpus, badges));
|
||||
writeln();
|
||||
badges
|
||||
.filter!(b => !b.enabled)
|
||||
badges.filter!(b => !b.enabled)
|
||||
.map!(b => b.disabled_image_link())
|
||||
.array
|
||||
.sort
|
||||
.uniq
|
||||
.each!writeln;
|
||||
|
||||
badges
|
||||
.filter!(b => b.enabled)
|
||||
badges.filter!(b => b.enabled)
|
||||
.map!(b => [b.link_decl(), b.image_decl()])
|
||||
.joiner()
|
||||
.array
|
||||
.sort
|
||||
.uniq
|
||||
.each!writeln;
|
||||
.joiner().array.sort.uniq.each!writeln;
|
||||
}
|
||||
|
Reference in New Issue
Block a user