From 3c4a6f2fdacbc7a4387f00dc829fced3072237ce Mon Sep 17 00:00:00 2001
From: Esben Haabendal <esben.haabendal@huawei.com>
Date: Wed, 29 Jun 2022 11:42:47 +0200
Subject: [PATCH] openharmony-standard: Fix another host OS flex dependency

OpenHarmony 3.1 introduced another script which copies directly from
/usr/include/FlexLexer.h path, so we need to fix that as well in order
to not depend on host OS flex package.

Signed-off-by: Esben Haabendal <esben.haabendal@huawei.com>
---
 ...ndation_graphic_standard-flexlexer-h.patch | 52 +++++++++++++++++++
 .../openharmony/openharmony-standard_3.1.bb   |  2 +
 2 files changed, 54 insertions(+)
 create mode 100644 recipes-openharmony/openharmony/openharmony-standard-3.1/foundation_graphic_standard-flexlexer-h.patch

diff --git a/recipes-openharmony/openharmony/openharmony-standard-3.1/foundation_graphic_standard-flexlexer-h.patch b/recipes-openharmony/openharmony/openharmony-standard-3.1/foundation_graphic_standard-flexlexer-h.patch
new file mode 100644
index 00000000..0bc8a388
--- /dev/null
+++ b/recipes-openharmony/openharmony/openharmony-standard-3.1/foundation_graphic_standard-flexlexer-h.patch
@@ -0,0 +1,52 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+Fix host OS dependency on flex package by copying the FlexLexer.h file from recipe-sysroot-native.
+
+Apply to foundation/graphic/standard repository.
+
+Signed-off-by: Esben Haabendal <esben.haabendal@huawei.com>
+Upstream-Status: Pending
+
+diff --git a/utils/lex_yacc/gen_flexlexer_header.py b/utils/lex_yacc/gen_flexlexer_header.py
+index cde71464bfe8..f32c7e68184d 100755
+--- a/utils/lex_yacc/gen_flexlexer_header.py
++++ b/utils/lex_yacc/gen_flexlexer_header.py
+@@ -22,10 +22,11 @@ import sys
+ def parse_args(args):
+     parser = optparse.OptionParser()
+     parser.add_option("--output")
++    parser.add_option("--includedir", default="/usr/include")
+     opts, _ = parser.parse_args(args)
+     return opts
+ 
+ if __name__ == '__main__':
+     options = parse_args(sys.argv[1:])
+     parse_scripts = subprocess.check_call(
+-        ["cp", "-f", "/usr/include/FlexLexer.h", options.output])
++        ["cp", "-f", "%s/FlexLexer.h"%(options.includedir,), options.output])
+diff --git a/utils/lex_yacc/lex_yacc.gni b/utils/lex_yacc/lex_yacc.gni
+index 5c27743c507e..905252a93cf7 100644
+--- a/utils/lex_yacc/lex_yacc.gni
++++ b/utils/lex_yacc/lex_yacc.gni
+@@ -15,6 +15,10 @@ import("//build/ohos.gni")
+ 
+ gni_filepath = "//foundation/graphic/standard/utils/lex_yacc"
+ 
++declare_args() {
++  flex_includedir = "/usr/include"
++}
++
+ template("lex_yacc") {
+   lex_name = invoker.lex
+   yacc_name = invoker.yacc
+@@ -33,6 +37,8 @@ template("lex_yacc") {
+     args = [
+       "--output",
+       flexlexer_pathname,
++      "--includedir",
++      rebase_path(flex_includedir)
+     ]
+   }
+ 
diff --git a/recipes-openharmony/openharmony/openharmony-standard_3.1.bb b/recipes-openharmony/openharmony/openharmony-standard_3.1.bb
index 40014b52..60d06e91 100644
--- a/recipes-openharmony/openharmony/openharmony-standard_3.1.bb
+++ b/recipes-openharmony/openharmony/openharmony-standard_3.1.bb
@@ -66,6 +66,7 @@ SRC_URI += "file://developtools_hdc_standard-gcc.patch;patchdir=${S}/developtool
 SRC_URI += "file://foundation_graphic_standard-hdi-display-layer.patch;patchdir=${S}/foundation/graphic/standard"
 SRC_URI += "file://third_party_weston-hdi-display-layer.patch;patchdir=${S}/third_party/weston"
 SRC_URI += "file://third_party_selinux-flex-bison-path.patch;patchdir=${S}/third_party/selinux"
+SRC_URI += "file://foundation_graphic_standard-flexlexer-h.patch;patchdir=${S}/foundation/graphic/standard"
 SRC_URI += "file://features.json;subdir=${OHOS_BUILD_CONFIGS_DIR}"
 
 # Patch to allow /system/profile and /system/usr to be symlinks to /usr/lib/openharmony
@@ -114,6 +115,7 @@ GN_ARGS += 'host_toolchain="//oniro:clang_x64"'
 GN_ARGS += 'install_oniro_third_party=false'
 GN_ARGS += 'flex_path="${RECIPE_SYSROOT_NATIVE}/usr/bin/flex"'
 GN_ARGS += 'bison_path="${RECIPE_SYSROOT_NATIVE}/usr/bin/bison"'
+GN_ARGS += 'flex_includedir="${RECIPE_SYSROOT_NATIVE}/usr/include"'
 
 # OpenHarmony unit tests are statically linked and therefore not stripped
 # binaries sum up to almost 80GB which makes it difficult to build OpenHarmony
-- 
GitLab