From fa7a7eb960e550bcb74d9ddcc3d734e10303a5d8 Mon Sep 17 00:00:00 2001
From: Stefan Schmidt <stefan.schmidt@huawei.com>
Date: Mon, 21 Feb 2022 17:52:01 +0100
Subject: [PATCH] gn: add gn recipe from meta-arm to offer gn-native

With OpenHarmony and Matter we have two projects using GN as their build
system. To support the gn.bbclass we have in Oniro we need a gn-native
recipe as well to support building these projects.

While progress is being made to upstream gn-native to meta-oe we keep a
copy here to have a working build. The alternative would be to add two
extra layers to our build for just one recipe.

This file need to be removed once upstreamed into meta-oe.

The original source of this file is here:
https://git.yoctoproject.org/meta-arm/tree/meta-arm/recipes-devtools/gn/gn_git.bb

Signed-off-by: Stefan Schmidt <stefan.schmidt@huawei.com>
---
 .../recipes-devtools/gn/gn_git.bb             | 50 +++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 meta-oniro-staging/recipes-devtools/gn/gn_git.bb

diff --git a/meta-oniro-staging/recipes-devtools/gn/gn_git.bb b/meta-oniro-staging/recipes-devtools/gn/gn_git.bb
new file mode 100644
index 00000000..b7fa813c
--- /dev/null
+++ b/meta-oniro-staging/recipes-devtools/gn/gn_git.bb
@@ -0,0 +1,50 @@
+SUMMARY = "GN is a meta-build system that generates build files for Ninja"
+DEPENDS += "ninja-native"
+
+LICENSE = "BSD-3-Clause"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=0fca02217a5d49a14dfe2d11837bb34d"
+
+SRC_URI = "git://gn.googlesource.com/gn;protocol=https;branch=main"
+SRCREV = "69ec4fca1fa69ddadae13f9e6b7507efa0675263"
+PV = "0+git${SRCPV}"
+
+S = "${WORKDIR}/git"
+B = "${WORKDIR}/build"
+
+# Currently fails to build with clang, eg:
+# https://errors.yoctoproject.org/Errors/Details/610602/
+# https://errors.yoctoproject.org/Errors/Details/610486/
+TOOLCHAIN = "gcc"
+
+# Map from our _OS strings to the GN's platform values.
+def gn_platform(variable, d):
+    os = d.getVar(variable)
+    if "linux" in os:
+        return "linux"
+    elif "mingw" in os:
+        return "mingw"
+    else:
+        return os
+
+do_configure[cleandirs] += "${B}"
+do_configure() {
+    python3 ${S}/build/gen.py \
+        --platform=${@gn_platform("TARGET_OS", d)} \
+        --out-path=${B} \
+        --no-static-libstdc++ \
+        --no-strip
+}
+
+do_compile() {
+    ninja -C ${B} --verbose
+}
+
+do_install() {
+    install -d ${D}${bindir}
+    install ${B}/gn ${D}${bindir}
+}
+
+BBCLASSEXTEND = "native"
+
+COMPATIBLE_HOST = "^(?!riscv32).*"
+
-- 
GitLab