[meta-tensorflow,21/25] add classes/bazel-base.bbclass and imporve classes/bazel-base.bbclass

Submitted by Hongxu Jia on Dec. 16, 2020, 1:08 p.m. | Patch ID: 178926

Details

Message ID 20201216130822.28476-22-hongxu.jia@windriver.com
State New
Headers show

Commit Message

Hongxu Jia Dec. 16, 2020, 1:08 p.m.
- Move common config settings to bazel-base.bbclass

- Improve bazel_get_flags to make each flag per line with comments

- Use BAZEL_MEM rather than hardcoded for option --local_ram_resources

- Explicitly remove dir ${BAZEL_DIR} before do_clean

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 classes/bazel-base.bbclass                   | 11 +++++
 classes/bazel.bbclass                        | 47 ++++++++++++--------
 recipes-devtools/bazel/bazel-native_3.7.1.bb |  6 +--
 3 files changed, 41 insertions(+), 23 deletions(-)
 create mode 100644 classes/bazel-base.bbclass

Patch hide | download patch | download mbox

diff --git a/classes/bazel-base.bbclass b/classes/bazel-base.bbclass
new file mode 100644
index 0000000..a067733
--- /dev/null
+++ b/classes/bazel-base.bbclass
@@ -0,0 +1,11 @@ 
+export JAVA_HOME="${STAGING_LIBDIR_NATIVE}/jvm/openjdk-8-native"
+
+BAZEL_JOBS ??= "4"
+
+# Memory 4GB
+BAZEL_MEM ??= "4096"
+
+TS_DL_DIR ??= "${DL_DIR}"
+
+CCACHE_DISABLE = "1"
+
diff --git a/classes/bazel.bbclass b/classes/bazel.bbclass
index 3ace2ba..8a3dadf 100644
--- a/classes/bazel.bbclass
+++ b/classes/bazel.bbclass
@@ -3,6 +3,8 @@  DEPENDS += "bazel-native \
           "
 DEPENDS_append_class-target = " python3"
 
+inherit bazel-base
+
 BAZEL_DIR ?= "${WORKDIR}/bazel"
 BAZEL_OUTPUTBASE_DIR ?= "${BAZEL_DIR}/output_base"
 export BAZEL_ARGS="--output_user_root=${BAZEL_DIR}/user_root \
@@ -11,8 +13,6 @@  export BAZEL_ARGS="--output_user_root=${BAZEL_DIR}/user_root \
                    --batch  \
                   "
 
-export JAVA_HOME="${STAGING_LIBDIR_NATIVE}/jvm/openjdk-8-native"
-
 BAZEL ?= "${BAZEL_DIR}/bazel"
 
 do_prepare_recipe_sysroot[postfuncs] += "do_install_bazel"
@@ -26,56 +26,64 @@  do_install_bazel() {
 def bazel_get_flags(d):
     flags = ""
     for i in d.getVar("CC").split()[1:]:
-        flags += "--conlyopt=%s --cxxopt=%s --linkopt=%s " % (i, i, i)
+        flags += "# From CC\n"
+        flags += "build --conlyopt=%s --cxxopt=%s --linkopt=%s\n" % (i, i, i)
 
     for i in d.getVar("CFLAGS").split():
         if i == "-g":
             continue
-        flags += "--conlyopt=%s " % i
+        flags += "# From CFLAGS\n"
+        flags += "build --conlyopt=%s\n" % i
 
     for i in d.getVar("BUILD_CFLAGS").split():
-        flags += "--host_conlyopt=%s " % i
+        flags += "# From BUILD_CFLAGS\n"
+        flags += "build --host_conlyopt=%s\n" % i
 
     for i in d.getVar("CXXFLAGS").split():
         if i == "-g":
             continue
-        flags += "--cxxopt=%s " % i
+        flags += "# From CXXFLAGS\n"
+        flags += "build --cxxopt=%s\n" % i
 
     for i in d.getVar("BUILD_CXXFLAGS").split():
-        flags += "--host_cxxopt=%s " % i
+        flags += "# From BUILD_CXXFLAGS\n"
+        flags += "build --host_cxxopt=%s\n" % i
 
     for i in d.getVar("CPPFLAGS").split():
         if i == "-g":
             continue
-        flags += "--conlyopt=%s --cxxopt=%s " % (i, i)
+        flags += "# From CPPFLAGS\n"
+        flags += "build --conlyopt=%s --cxxopt=%s\n" % (i, i)
 
     for i in d.getVar("BUILD_CPPFLAGS").split():
-        flags += "--host_conlyopt=%s --host_cxxopt=%s " % (i, i)
+        flags += "# From BUILD_CPPFLAGS\n"
+        flags += "build --host_conlyopt=%s --host_cxxopt=%s\n" % (i, i)
 
     for i in d.getVar("LDFLAGS").split():
         if i == "-Wl,--as-needed":
             continue
-        flags += "--linkopt=%s " % i
+        flags += "# From LDFLAGS\n"
+        flags += "build --linkopt=%s\n" % i
 
     for i in d.getVar("BUILD_LDFLAGS").split():
         if i == "-Wl,--as-needed":
             continue
-        flags += "--host_linkopt=%s " % i
+        flags += "# From BUILD_LDFLAGS\n"
+        flags += "build --host_linkopt=%s\n" % i
 
     for i in d.getVar("TOOLCHAIN_OPTIONS").split():
         if i == "-Wl,--as-needed":
             continue
-        flags += "--linkopt=%s " % i
+        flags += "# From TOOLCHAIN_OPTIONS\n"
+        flags += "build --linkopt=%s\n" % i
 
     return flags
 
-TS_DL_DIR ??= "${DL_DIR}"
-BAZEL_JOBS ??= "4"
 bazel_do_configure () {
     cat > "${S}/bazelrc" <<-EOF
 build --verbose_failures
 build --spawn_strategy=standalone --genrule_strategy=standalone
-#build --jobs=${BAZEL_JOBS} --local_ram_resources=4096 --local_cpu_resources=${BAZEL_JOBS}
+build --jobs=${BAZEL_JOBS} --local_ram_resources=${BAZEL_MEM} --local_cpu_resources=${BAZEL_JOBS}
 test --verbose_failures --verbose_test_summary
 test --spawn_strategy=standalone --genrule_strategy=standalone
 
@@ -98,8 +106,10 @@  EOF
 
 bazel_do_configure_append_class-target () {
     cat >> "${S}/bazelrc" <<-EOF
-# FLAGS
-build ${@bazel_get_flags(d)}
+# FLAGS begin
+${@bazel_get_flags(d)}
+# FLAGS end
+
 build --linkopt=-Wl,-latomic
 
 EOF
@@ -109,8 +119,6 @@  EOF
 
 EXPORT_FUNCTIONS do_configure
 
-CCACHE_DISABLE = "1"
-
 PSEUDO_IGNORE_PATHS .= ",${WORKDIR}/bazel"
 
 inherit unsupportarch
@@ -125,4 +133,5 @@  clean_bazel() {
             ${BAZEL} clean
         fi
     fi
+    rm ${BAZEL_DIR} -rf
 }
diff --git a/recipes-devtools/bazel/bazel-native_3.7.1.bb b/recipes-devtools/bazel/bazel-native_3.7.1.bb
index a1575d6..03cff37 100644
--- a/recipes-devtools/bazel/bazel-native_3.7.1.bb
+++ b/recipes-devtools/bazel/bazel-native_3.7.1.bb
@@ -25,19 +25,17 @@  DEPENDS = "coreutils-native \
 
 S="${WORKDIR}"
 
-TS_DL_DIR ??= "${DL_DIR}"
+inherit bazel-base
 
-BAZEL_JOBS ??= "4"
 EXTRA_BAZEL_ARGS = " \
     --host_javabase=@local_jdk//:jdk \
     --python_path=python3 \
     --jobs=${BAZEL_JOBS} \
-    --local_ram_resources=4096 \
+    --local_ram_resources=${BAZEL_MEM} \
     --local_cpu_resources=${BAZEL_JOBS} \
 "
 
 do_compile () {
-    export JAVA_HOME="${STAGING_LIBDIR_NATIVE}/jvm/openjdk-8-native"
     TMPDIR="${TOPDIR}/bazel" \
     VERBOSE=yes \
     EXTRA_BAZEL_ARGS="${EXTRA_BAZEL_ARGS}" \