Skip to contentSkip to conversation

ccache.bbclass: Refactor it to make it more reliable

PATCH Superseded Robert Yang 4 participants 20 messages Dec 10, 2018 – Dec 13, 2018

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover ccache.bbclass: Refactor it to make it more reliable

Hi RP and Ross,

With this refactor, I think that we can even enable ccache by default, it is useful for debugging recipes which require a lot of time to compile.

// Robert

The following changes since commit 8bc0d2f2197430723f8b2d0785169e48c883eedb:

mdadm: Drop redundant patches and fix build with clang (2018-12-09 11:08:07 +0000)

are available in the git repository at:

git://git.openembedded.org/openembedded-core-contrib rbt/ccache
http://cgit.openembedded.org/openembedded-core-contrib/log/?h=rbt/ccache

Robert Yang (4):
base.bbclass: Remove invalid ccache related code ccache.bbclass: Refactor it to make it more reliable apr/openssl10: Enable ccache for them cmake.bbclass/goarch.bbclass: Set CCACHE_DISABLE

 meta/classes/base.bbclass                          |  2 --
 meta/classes/ccache.bbclass                        | 25 +++++++++++++++++++---
 meta/classes/cmake.bbclass                         |  4 ++--
 meta/classes/goarch.bbclass                        |  4 ++++
 meta/conf/bitbake.conf                             | 21 +++++++++++++-----
 meta/conf/layer.conf                               |  1 -
 meta/lib/oe/utils.py                               |  3 +++
 .../openssl/openssl10_1.0.2q.bb                    |  3 ---
 meta/recipes-devtools/ccache/ccache.inc            |  2 ++
 meta/recipes-support/apr/apr_1.6.5.bb              |  1 -
 10 files changed, 49 insertions(+), 17 deletions(-)
Signature · 1 line
2.10.2
#1 lore raw

PATCH 1/4 base.bbclass: Remove invalid ccache related code

The code is in setup_hosttools_dir(), it searches ccache in PATH in reverse order, I can't figure out what it is used for, maybe it is aimed to use host's ccache rather than recipe-sysroot-native/usr/bin/ccache, but the later one isn't in original PATH, so remove the code.

---
 meta/classes/base.bbclass | 2 --
 1 file changed, 2 deletions(-)
meta/classes/base.bbclass +0 -2
index e715ffa..36b9c15 100644
@@ -122,8 +122,6 @@ def setup_hosttools_dir(dest, toolsvar, d, fatal=True):
         desttool = os.path.join(dest, tool)
         if not os.path.exists(desttool):
             srctool = bb.utils.which(path, tool, executable=True)
-            if "ccache" in srctool:
-                srctool = bb.utils.which(path, tool, executable=True, direction=1)
             if srctool:
                 os.symlink(srctool, desttool)
             else:
Signature · 1 line
2.10.2
#16 lore raw

PATCH 3/4 apr/openssl10: Enable ccache for them

In reply to Robert Yang

The work well now.

---
 meta/recipes-connectivity/openssl/openssl10_1.0.2q.bb | 3 ---
 meta/recipes-support/apr/apr_1.6.5.bb                 | 1 -
 2 files changed, 4 deletions(-)
meta/recipes-connectivity/openssl/openssl10_1.0.2q.bb +0 -3
index 6518dac..1986cf2 100644
@@ -76,9 +76,6 @@ EXTRA_OEMAKE = "${@bb.utils.contains('PACKAGECONFIG', 'manpages', '', 'OE_DISABL
 
 export OE_LDFLAGS = "${LDFLAGS}"
 
-# openssl fails with ccache: https://bugzilla.yoctoproject.org/show_bug.cgi?id=12810
-CCACHE = ""
-
 TERMIO ?= "-DTERMIO"
 TERMIO_libc-musl = "-DTERMIOS"
 
meta/recipes-support/apr/apr_1.6.5.bb +0 -1
index c2f5900..ed93a7e 100644
@@ -40,7 +40,6 @@ CACHED_CONFIGUREVARS += "ac_cv_file__dev_zero=yes"
 # Otherwise libtool fails to compile apr-utils
 # x86_64-linux-libtool: compile: unable to infer tagged configuration
 # x86_64-linux-libtool:   error: specify a tag with '--tag'
-CCACHE = ""
 
 PACKAGECONFIG ??= "${@bb.utils.filter('DISTRO_FEATURES', 'ipv6', d)}"
 PACKAGECONFIG[ipv6] = "--enable-ipv6,--disable-ipv6,"
Signature · 1 line
2.10.2
#19 lore raw

PATCH 4/4 cmake.bbclass/goarch.bbclass: Set CCACHE_DISABLE

In reply to Robert Yang

They can't be built with ccache.

---
 meta/classes/cmake.bbclass  | 4 ++--
 meta/classes/goarch.bbclass | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)
meta/classes/cmake.bbclass +2 -2
index b364d2b..12fc452 100644
@@ -4,8 +4,8 @@ OECMAKE_SOURCEPATH ??= "${S}"
 DEPENDS_prepend = "cmake-native "
 B = "${WORKDIR}/build"
 
-# We need to unset CCACHE otherwise cmake gets too confused
-CCACHE = ""
+# We need to disable CCACHE otherwise cmake gets too confused
+CCACHE_DISABLE = "1"
 
 # What CMake generator to use.
 # The supported options are "Unix Makefiles" or "Ninja".
meta/classes/goarch.bbclass +4 -0
index b2c94fa..1390f31 100644
@@ -42,6 +42,10 @@ TUNE_CCARGS_remove = "-march=mips32r2"
 SECURITY_CFLAGS_mipsarch = "${SECURITY_NOPIE_CFLAGS}"
 SECURITY_NOPIE_CFLAGS ??= ""
 
+# go can't be built with ccache:
+# gcc: fatal error: no input files
+CCACHE_DISABLE = "1"
+
 def go_map_arch(a, d):
     import re
     if re.match('i.86', a):
Signature · 1 line
2.10.2
#10 lore raw

PATCH 2/4 ccache.bbclass: Refactor it to make it more reliable

In reply to Robert Yang

The previous ccache.bbclass has the following problems:
- It uses host's ccache for native recipes, but this may not work on some hosts, for example, it nerver works on my Ubuntu 14.04.4, there are always build failures (m4-native failed at do_configure, and others will also be failed if I disable CCACHE for m4-native)

- native/nativesdk/cross/crosssdk recipes use host's ccahe, but target uses ccache-native, this may confuse user.

- The target recipes may use both host's ccache and ccache-native, this may cause unexpected problems and hard to debug. This is because ccache-native is in SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS, so ccache-native may not be present when rebuild target recipes, and then it would use hosttools/ccache, but the previous ccache files were generated by ccache-native.

- Target recipes can't use ccache when no ccahe is installed on the host:
CCACHE = "${@bb.utils.which(d.getVar('PATH'), 'ccache') and 'ccache '}"

After refactored:
All types recipes (native, target and others) will use ccache-native except ccache-native's dependencies, host's cache won't be used any more. It is more reliable now, which will work everywhere when ccache-native can be built.

And now we need use "CCACHE_DISABLE = '1'" to disable ccahe for the recipe rather than "CCACHE = ''" since we set CCACHE in anonymous function, and d.getVar('CCACHE') works after "CCACHE ??=" which is set in bitbake.conf, so we can't check whether CCACHE is set or not in anonymous function since it is always set. Use CCACHE_DISABLE to disable it would be more clear.

---
 meta/classes/ccache.bbclass             | 25 ++++++++++++++++++++++---
 meta/conf/bitbake.conf                  | 21 ++++++++++++++++-----
 meta/conf/layer.conf                    |  1 -
 meta/lib/oe/utils.py                    |  3 +++
 meta/recipes-devtools/ccache/ccache.inc |  2 ++
 5 files changed, 43 insertions(+), 9 deletions(-)
meta/classes/ccache.bbclass +22 -3
index 9609020..f4eefce 100644
@@ -1,4 +1,14 @@
-CCACHE = "${@bb.utils.which(d.getVar('PATH'), 'ccache') and 'ccache '}"
+#
+# Usage:
+# - Enable ccache
+#   Add the following line to a conffile such as conf/local.conf:
+#   INHERIT += "ccache"
+#
+# - Disable ccache for a recipe
+#   Add the following line to the recipe if it can't be built with ccache:
+#   CCACHE_DISABLE = '1'
+#
+
 export CCACHE_DIR ?= "${TMPDIR}/ccache/${MULTIMACH_TARGET_SYS}/${PN}"
 
 # We need to stop ccache considering the current directory or the
@@ -7,5 +17,14 @@ export CCACHE_DIR ?= "${TMPDIR}/ccache/${MULTIMACH_TARGET_SYS}/${PN}"
 # ${PV} or ${PR} change.
 export CCACHE_NOHASHDIR ?= "1"
 
-DEPENDS_append_class-target = " ccache-native"
-DEPENDS[vardepvalueexclude] = " ccache-native"
+python() {
+    """
+    Enable ccache for the recipe if is not a dependency of ccache-native
+    """
+    ccache_native_deps = d.getVar('CCACHE_NATIVE_DEPENDS') or ''
+    ccache_native_deps += 'ccache-native'
+    if not (d.getVar('PN') in ccache_native_deps.split() or \
+            bb.utils.to_boolean(d.getVar('CCACHE_DISABLE'))):
+        d.appendVar('DEPENDS', ' ccache-native')
+        d.setVar('CCACHE', 'ccache ')
+}
meta/conf/bitbake.conf +16 -5
index 6480062..cb1dba8 100644
@@ -492,7 +492,7 @@ HOSTTOOLS += " \
 HOSTTOOLS += "${@'ip ping ps scp ssh stty' if (bb.utils.contains_any('IMAGE_CLASSES', 'testimage testsdk', True, False, d) or any(x in (d.getVar("BBINCLUDED") or "") for x in ["testimage.bbclass", "testsdk.bbclass"])) else ''}"
 
 # Link to these if present
-HOSTTOOLS_NONFATAL += "aws ccache gcc-ar gpg ld.bfd ld.gold nc pigz sftp socat ssh sudo"
+HOSTTOOLS_NONFATAL += "aws gcc-ar gpg ld.bfd ld.gold nc pigz sftp socat ssh sudo"
 
 # Temporary add few more detected in bitbake world
 HOSTTOOLS_NONFATAL += "join nl size yes zcat"
@@ -503,11 +503,22 @@ HOSTTOOLS_NONFATAL += "bzr"
 # Used by ssh fetcher
 HOSTTOOLS_NONFATAL += "scp"
 
+# This is used by both ccache.bbclass and ccahe-native recipe, these
+# recipes can't use ccache since ccache-native depends on them,
+# otherwise, there would be loop dependencies.
+CCACHE_NATIVE_DEPENDS ?= " \
+    gnu-config-native \
+    autoconf-native \
+    quilt-native \
+    zlib-native \
+    gettext-minimal-native \
+    texinfo-dummy-native \
+    m4-native \
+    libtool-native \
+    automake-native \
+    xz-native \
+"
 CCACHE ??= ""
-# ccache < 3.1.10 will create CCACHE_DIR on startup even if disabled, and
-# autogen sets HOME=/dev/null so in certain situations builds can fail.
-# Explicitly export CCACHE_DIR until we can assume ccache >3.1.10 on the host.
-export CCACHE_DIR ??= "${@os.getenv('HOME')}/.ccache"
 
 TOOLCHAIN_OPTIONS = " --sysroot=${STAGING_DIR_TARGET}"
 
meta/conf/layer.conf +0 -1
index c67dec4..4141d6c 100644
@@ -49,7 +49,6 @@ SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS += " \
   *->quilt-native \
   *->subversion-native \
   *->git-native \
-  *->ccache-native \
   *->icecc-create-env-native \
   gcc-cross-${TARGET_ARCH}->virtual/${TARGET_PREFIX}libc-for-gcc \
   gcc-cross-${TARGET_ARCH}->linux-libc-headers \
meta/lib/oe/utils.py +3 -0
index 8a584d6..9c41705 100644
@@ -363,6 +363,9 @@ def host_gcc_version(d, taskcontextonly=False):
         return
 
     compiler = d.getVar("BUILD_CC")
+    # Get rid of ccache since it is not present when parsing.
+    if compiler.startswith('ccache '):
+        compiler = compiler[7:]
     try:
         env = os.environ.copy()
         env["PATH"] = d.getVar("PATH")
meta/recipes-devtools/ccache/ccache.inc +2 -0
index 6566328..259c196 100644
@@ -9,6 +9,8 @@ LICENSE = "GPLv3+"
 
 DEPENDS = "zlib"
 
+DEPENDS_class-native = "${CCACHE_NATIVE_DEPENDS}"
+
 SRC_URI = "https://download.samba.org/pub/${BPN}/${BP}.tar.xz"
 
 inherit autotools
Signature · 1 line
2.10.2
#17 lore raw

Re: [PATCH 3/4] apr/openssl10: Enable ccache for them

In reply to Robert Yang
Quoted 27 lines · Robert Yang

The work well now.

---
 meta/recipes-connectivity/openssl/openssl10_1.0.2q.bb | 3 ---
 meta/recipes-support/apr/apr_1.6.5.bb                 | 1 -
 2 files changed, 4 deletions(-)
meta/recipes-connectivity/openssl/openssl10_1.0.2q.bb +0 -3
index 6518dac..1986cf2 100644
@@ -76,9 +76,6 @@ EXTRA_OEMAKE = "${@bb.utils.contains('PACKAGECONFIG', 'manpages', '', 'OE_DISABL
 
 export OE_LDFLAGS = "${LDFLAGS}"
 
-# openssl fails with ccache: https://bugzilla.yoctoproject.org/show_bug.cgi?id=12810
-CCACHE = ""
-
 TERMIO ?= "-DTERMIO"
 TERMIO_libc-musl = "-DTERMIOS"
 
meta/recipes-support/apr/apr_1.6.5.bb +0 -0
index c2f5900..ed93a7e 100644

meta/recipes-support/apr/apr_1.6.5.bb CACHED_CONFIGUREVARS += "ac_cv_file__dev_zero=yes" · line 43

Quoted 4 lines
meta/recipes-support/apr/apr_1.6.5.bb +0 -1
@@ -40,7 +40,6 @@ CACHED_CONFIGUREVARS += "ac_cv_file__dev_zero=yes"
 # Otherwise libtool fails to compile apr-utils
 # x86_64-linux-libtool: compile: unable to infer tagged configuration
 # x86_64-linux-libtool:   error: specify a tag with '--tag'
-CCACHE = ""

Remove the comment as well.

Quoted 10 lines
meta/recipes-support/apr/apr_1.6.5.bb +0 -0
 PACKAGECONFIG ??= "${@bb.utils.filter('DISTRO_FEATURES', 'ipv6', d)}"
 PACKAGECONFIG[ipv6] = "--enable-ipv6,--disable-ipv6,"
Signature · 7 lines
2.10.2

-- 
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Signature · 1 line
Martin 'JaMa' Jansa     jabber: [email protected]
#11 lore raw
In reply to Robert Yang

Hi Robert,

Just a small nit-pick below..

Quoted 38 lines · Robert Yang

The previous ccache.bbclass has the following problems:
- It uses host's ccache for native recipes, but this may not work on some hosts, for example, it nerver works on my Ubuntu 14.04.4, there are always build failures (m4-native failed at do_configure, and others will also be failed if I disable CCACHE for m4-native)

- native/nativesdk/cross/crosssdk recipes use host's ccahe, but target uses ccache-native, this may confuse user.

- The target recipes may use both host's ccache and ccache-native, this may cause unexpected problems and hard to debug. This is because ccache-native is in SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS, so ccache-native may not be present when rebuild target recipes, and then it would use hosttools/ccache, but the previous ccache files were generated by ccache-native.

- Target recipes can't use ccache when no ccahe is installed on the host:

   CCACHE = "${@bb.utils.which(d.getVar('PATH'), 'ccache') and 'ccache '}"

After refactored:
All types recipes (native, target and others) will use ccache-native except ccache-native's dependencies, host's cache won't be used any more. It is more reliable now, which will work everywhere when ccache-native can be built.

And now we need use "CCACHE_DISABLE = '1'" to disable ccahe for the recipe rather than "CCACHE = ''" since we set CCACHE in anonymous function, and d.getVar('CCACHE') works after "CCACHE ??=" which is set in bitbake.conf, so we can't check whether CCACHE is set or not in anonymous function since it is always set. Use CCACHE_DISABLE to disable it would be more clear.

---
  meta/classes/ccache.bbclass             | 25 ++++++++++++++++++++++---
  meta/conf/bitbake.conf                  | 21 ++++++++++++++++-----
  meta/conf/layer.conf                    |  1 -
  meta/lib/oe/utils.py                    |  3 +++
  meta/recipes-devtools/ccache/ccache.inc |  2 ++
  5 files changed, 43 insertions(+), 9 deletions(-)

<snip>

meta/lib/oe/utils.py def host_gcc_version(d, taskcontextonly=False): · line 368

Quoted 11 lines
meta/lib/oe/utils.py +3 -0
index 8a584d6..9c41705 100644
@@ -363,6 +363,9 @@ def host_gcc_version(d, taskcontextonly=False):
          return
 
      compiler = d.getVar("BUILD_CC")
+    # Get rid of ccache since it is not present when parsing.
+    if compiler.startswith('ccache '):
+        compiler = compiler[7:]

You can avoid the if-condition and hard-coded 7-value by doing:

# Get rid of ccache since it is no present when parsing. compiler = d.getVar("BUILD_CC").lstrip("ccache-")

// Martin

Quoted 17 lines
meta/lib/oe/utils.py +0 -0
      try:
          env = os.environ.copy()
          env["PATH"] = d.getVar("PATH")
meta/recipes-devtools/ccache/ccache.inc +2 -0
index 6566328..259c196 100644
@@ -9,6 +9,8 @@ LICENSE = "GPLv3+"
 
  DEPENDS = "zlib"
 
+DEPENDS_class-native = "${CCACHE_NATIVE_DEPENDS}"
+
  SRC_URI = "https://download.samba.org/pub/${BPN}/${BP}.tar.xz"
 
  inherit autotools
Signature · 10 lines
Kind regards,
Martin Hundebøll
Embedded Linux Consultant

+45 61 65 54 61
[email protected]

Geanix IVS
https://geanix.com
DK39600706
#2 lore raw

Re: [PATCH 1/4] base.bbclass: Remove invalid ccache related code

In reply to Robert Yang
Quoted 10 lines · Robert Yang

The code is in setup_hosttools_dir(), it searches ccache in PATH in reverse order, I can't figure out what it is used for, maybe it is aimed to use host's ccache rather than recipe-sysroot- native/usr/bin/ccache, but the later one isn't in original PATH, so remove the code.

---
 meta/classes/base.bbclass | 2 --
 1 file changed, 2 deletions(-)

We should document it and I think its still needed.

Some distros have a "gcc" which automatically wraps ccache behind the scenes. This code lets us find the real gcc and bypass ccache.

There would be oe-selftest failures on such a distro if we didn't do that.

Cheers,

Richard

#14 lore raw
In reply to Robert Yang
Quoted 102 lines · Robert Yang

The previous ccache.bbclass has the following problems:
- It uses host's ccache for native recipes, but this may not work on some hosts, for example, it nerver works on my Ubuntu 14.04.4, there are always build failures (m4-native failed at do_configure, and others will also be failed if I disable CCACHE for m4-native)

- native/nativesdk/cross/crosssdk recipes use host's ccahe, but target uses ccache-native, this may confuse user.

- The target recipes may use both host's ccache and ccache-native, this may cause unexpected problems and hard to debug. This is because ccache-native is in SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS, so ccache-native may not be present when rebuild target recipes, and then it would use hosttools/ccache, but the previous ccache files were generated by ccache-native.

- Target recipes can't use ccache when no ccahe is installed on the host:
CCACHE = "${@bb.utils.which(d.getVar('PATH'), 'ccache') and 'ccache '}"

After refactored:
All types recipes (native, target and others) will use ccache-native except ccache-native's dependencies, host's cache won't be used any more. It is more reliable now, which will work everywhere when ccache-native can be built.

And now we need use "CCACHE_DISABLE = '1'" to disable ccahe for the recipe rather than "CCACHE = ''" since we set CCACHE in anonymous function, and d.getVar('CCACHE') works after "CCACHE ??=" which is set in bitbake.conf, so we can't check whether CCACHE is set or not in anonymous function since it is always set. Use CCACHE_DISABLE to disable it would be more clear.

---
 meta/classes/ccache.bbclass             | 25 ++++++++++++++++++++++---
 meta/conf/bitbake.conf                  | 21 ++++++++++++++++-----
 meta/conf/layer.conf                    |  1 -
 meta/lib/oe/utils.py                    |  3 +++
 meta/recipes-devtools/ccache/ccache.inc |  2 ++
 5 files changed, 43 insertions(+), 9 deletions(-)
meta/classes/ccache.bbclass +22 -3
index 9609020..f4eefce 100644
@@ -1,4 +1,14 @@
-CCACHE = "${@bb.utils.which(d.getVar('PATH'), 'ccache') and 'ccache '}"
+#
+# Usage:
+# - Enable ccache
+#   Add the following line to a conffile such as conf/local.conf:
+#   INHERIT += "ccache"
+#
+# - Disable ccache for a recipe
+#   Add the following line to the recipe if it can't be built with ccache:
+#   CCACHE_DISABLE = '1'
+#
+
 export CCACHE_DIR ?= "${TMPDIR}/ccache/${MULTIMACH_TARGET_SYS}/${PN}"
 
 # We need to stop ccache considering the current directory or the
@@ -7,5 +17,14 @@ export CCACHE_DIR ?= "${TMPDIR}/ccache/${MULTIMACH_TARGET_SYS}/${PN}"
 # ${PV} or ${PR} change.
 export CCACHE_NOHASHDIR ?= "1"
 
-DEPENDS_append_class-target = " ccache-native"
-DEPENDS[vardepvalueexclude] = " ccache-native"
+python() {
+    """
+    Enable ccache for the recipe if is not a dependency of ccache-native
+    """
+    ccache_native_deps = d.getVar('CCACHE_NATIVE_DEPENDS') or ''
+    ccache_native_deps += 'ccache-native'
+    if not (d.getVar('PN') in ccache_native_deps.split() or \
+            bb.utils.to_boolean(d.getVar('CCACHE_DISABLE'))):
+        d.appendVar('DEPENDS', ' ccache-native')
+        d.setVar('CCACHE', 'ccache ')
+}
meta/conf/bitbake.conf +11 -1
index 6480062..cb1dba8 100644
@@ -492,7 +492,7 @@ HOSTTOOLS += " \
 HOSTTOOLS += "${@'ip ping ps scp ssh stty' if (bb.utils.contains_any('IMAGE_CLASSES', 'testimage testsdk', True, False, d) or any(x in (d.getVar("BBINCLUDED") or "") for x in ["testimage.bbclass", "testsdk.bbclass"])) else ''}"
 
 # Link to these if present
-HOSTTOOLS_NONFATAL += "aws ccache gcc-ar gpg ld.bfd ld.gold nc pigz sftp socat ssh sudo"
+HOSTTOOLS_NONFATAL += "aws gcc-ar gpg ld.bfd ld.gold nc pigz sftp socat ssh sudo"
 
 # Temporary add few more detected in bitbake world
 HOSTTOOLS_NONFATAL += "join nl size yes zcat"
@@ -503,11 +503,22 @@ HOSTTOOLS_NONFATAL += "bzr"
 # Used by ssh fetcher
 HOSTTOOLS_NONFATAL += "scp"
 
+# This is used by both ccache.bbclass and ccahe-native recipe, these
+# recipes can't use ccache since ccache-native depends on them,
+# otherwise, there would be loop dependencies.
+CCACHE_NATIVE_DEPENDS ?= " \
+    gnu-config-native \
+    autoconf-native \
+    quilt-native \
+    zlib-native \
+    gettext-minimal-native \
+    texinfo-dummy-native \

meta/conf/bitbake.conf HOSTTOOLS_NONFATAL += "bzr" · line 510

Quoted 10 lines
meta/conf/bitbake.conf +5 -4
+    m4-native \
+    libtool-native \
+    automake-native \
+    xz-native \
+"
 CCACHE ??= ""
-# ccache < 3.1.10 will create CCACHE_DIR on startup even if disabled, and
-# autogen sets HOME=/dev/null so in certain situations builds can fail.
-# Explicitly export CCACHE_DIR until we can assume ccache >3.1.10 on the host.
-export CCACHE_DIR ??= "${@os.getenv('HOME')}/.ccache"

Hardcoding a list of ccache-native dependencies is horrible and I do not want to do that.

Also, I want to stop the build up of unneeded 'stuff' in bitbake.conf. We should start making better use of inc files.

Please also ensure that the oe-selftest ccache tests continue to work after these changes. I haven't checked specifically here but we've had a lot of trouble with that before.

Cheers,

Richard

#18 lore raw

Re: [PATCH 3/4] apr/openssl10: Enable ccache for them

In reply to Martin Jansa
Quoted 23 lines · Martin Jansa
Quoted 22 lines · Robert Yang

The work well now.

---
  meta/recipes-connectivity/openssl/openssl10_1.0.2q.bb | 3 ---
  meta/recipes-support/apr/apr_1.6.5.bb                 | 1 -
  2 files changed, 4 deletions(-)
meta/recipes-connectivity/openssl/openssl10_1.0.2q.bb +0 -3
index 6518dac..1986cf2 100644
@@ -76,9 +76,6 @@ EXTRA_OEMAKE = "${@bb.utils.contains('PACKAGECONFIG', 'manpages', '', 'OE_DISABL
 
  export OE_LDFLAGS = "${LDFLAGS}"
 
-# openssl fails with ccache: https://bugzilla.yoctoproject.org/show_bug.cgi?id=12810
-CCACHE = ""
-
  TERMIO ?= "-DTERMIO"
  TERMIO_libc-musl = "-DTERMIOS"
 
Quoted 11 lines

meta/recipes-support/apr/apr_1.6.5.bb CACHED_CONFIGUREVARS += "ac_cv_file__dev_zero=yes" · line 43

Quoted 9 lines
meta/recipes-support/apr/apr_1.6.5.bb +0 -1
index c2f5900..ed93a7e 100644
@@ -40,7 +40,6 @@ CACHED_CONFIGUREVARS += "ac_cv_file__dev_zero=yes"
  # Otherwise libtool fails to compile apr-utils
  # x86_64-linux-libtool: compile: unable to infer tagged configuration
  # x86_64-linux-libtool:   error: specify a tag with '--tag'
-CCACHE = ""

Remove the comment as well.

Thanks, will fix it in V2.

// Robert

Quoted 12 lines
Quoted 11 lines
meta/recipes-support/apr/apr_1.6.5.bb +0 -0
  PACKAGECONFIG ??= "${@bb.utils.filter('DISTRO_FEATURES', 'ipv6', d)}"
  PACKAGECONFIG[ipv6] = "--enable-ipv6,--disable-ipv6,"
Signature · 7 lines
2.10.2

-- 
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core
#12 lore raw
In reply to Martin Hundebøll
Quoted 59 lines · Martin Hundebøll

Hi Robert,

Just a small nit-pick below..

Quoted 38 lines · Robert Yang

The previous ccache.bbclass has the following problems:
- It uses host's ccache for native recipes, but this may not work on some hosts, for example, it nerver works on my Ubuntu 14.04.4, there are always build failures (m4-native failed at do_configure, and others will also be failed if I disable CCACHE for m4-native)

- native/nativesdk/cross/crosssdk recipes use host's ccahe, but target uses ccache-native, this may confuse user.

- The target recipes may use both host's ccache and ccache-native, this may cause unexpected problems and hard to debug. This is because ccache-native is in SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS, so ccache-native may not be present when rebuild target recipes, and then it would use hosttools/ccache, but the previous ccache files were generated by ccache-native.

- Target recipes can't use ccache when no ccahe is installed on the host:
   CCACHE = "${@bb.utils.which(d.getVar('PATH'), 'ccache') and 'ccache '}"

After refactored:
All types recipes (native, target and others) will use ccache-native except ccache-native's dependencies, host's cache won't be used any more. It is more reliable now, which will work everywhere when ccache-native can be built.

And now we need use "CCACHE_DISABLE = '1'" to disable ccahe for the recipe rather than "CCACHE = ''" since we set CCACHE in anonymous function, and d.getVar('CCACHE') works after "CCACHE ??=" which is set in bitbake.conf, so we can't check whether CCACHE is set or not in anonymous function since it is always set. Use CCACHE_DISABLE to disable it would be more clear.

---
  meta/classes/ccache.bbclass             | 25 ++++++++++++++++++++++--- meta/conf/bitbake.conf                  | 21 ++++++++++++++++----- meta/conf/layer.conf                    |  1 - meta/lib/oe/utils.py                    |  3 +++ meta/recipes-devtools/ccache/ccache.inc |  2 ++

  5 files changed, 43 insertions(+), 9 deletions(-)

<snip>

Quoted 10 lines
meta/lib/oe/utils.py +0 -0
index 8a584d6..9c41705 100644
@@ -363,6 +363,9 @@ def host_gcc_version(d, taskcontextonly=False):

          return
      compiler = d.getVar("BUILD_CC")
+    # Get rid of ccache since it is not present when parsing. +    if compiler.startswith('ccache '):
+        compiler = compiler[7:]

You can avoid the if-condition and hard-coded 7-value by doing:

Quoted 2 lines

  # Get rid of ccache since it is no present when parsing. compiler = d.getVar("BUILD_CC").lstrip("ccache-")

Thanks, will fix it in V2.

// Robert

Quoted 18 lines

// Martin

Quoted 14 lines

      try:
          env = os.environ.copy()
          env["PATH"] = d.getVar("PATH")

meta/recipes-devtools/ccache/ccache.inc +0 -0
index 6566328..259c196 100644
@@ -9,6 +9,8 @@ LICENSE = "GPLv3+"

  DEPENDS = "zlib"

meta/recipes-devtools/ccache/ccache.inc +2 -0
+DEPENDS_class-native = "${CCACHE_NATIVE_DEPENDS}"
+

  SRC_URI = "https://download.samba.org/pub/${BPN}/${BP}.tar.xz" inherit autotools

#3 lore raw

Re: [PATCH 1/4] base.bbclass: Remove invalid ccache related code

In reply to Richard Purdie
Quoted 12 lines · Richard Purdie
Quoted 10 lines · Robert Yang

The code is in setup_hosttools_dir(), it searches ccache in PATH in reverse order, I can't figure out what it is used for, maybe it is aimed to use host's ccache rather than recipe-sysroot- native/usr/bin/ccache, but the later one isn't in original PATH, so remove the code.

---
  meta/classes/base.bbclass | 2 --
  1 file changed, 2 deletions(-)
Quoted 4 lines

We should document it and I think its still needed.

Some distros have a "gcc" which automatically wraps ccache behind the scenes. This code lets us find the real gcc and bypass ccache.

Ah, thanks for the explanations, I got it now. I think that we don't need the code any more since we don't use host's ccache, and I have removed ccache from HOSTTOOLS.

I will update commit message and send a V2.

// Robert

Quoted 9 lines

There would be oe-selftest failures on such a distro if we didn't do that.

Cheers,

Richard

#15 lore raw
In reply to Richard Purdie
Quoted 108 lines · Richard Purdie
Quoted 107 lines · Robert Yang

The previous ccache.bbclass has the following problems:
- It uses host's ccache for native recipes, but this may not work on some hosts, for example, it nerver works on my Ubuntu 14.04.4, there are always build failures (m4-native failed at do_configure, and others will also be failed if I disable CCACHE for m4-native)

- native/nativesdk/cross/crosssdk recipes use host's ccahe, but target uses ccache-native, this may confuse user.

- The target recipes may use both host's ccache and ccache-native, this may cause unexpected problems and hard to debug. This is because ccache-native is in SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS, so ccache-native may not be present when rebuild target recipes, and then it would use hosttools/ccache, but the previous ccache files were generated by ccache-native.

- Target recipes can't use ccache when no ccahe is installed on the host:

   CCACHE = "${@bb.utils.which(d.getVar('PATH'), 'ccache') and 'ccache '}"

After refactored:
All types recipes (native, target and others) will use ccache-native except ccache-native's dependencies, host's cache won't be used any more. It is more reliable now, which will work everywhere when ccache-native can be built.

And now we need use "CCACHE_DISABLE = '1'" to disable ccahe for the recipe rather than "CCACHE = ''" since we set CCACHE in anonymous function, and d.getVar('CCACHE') works after "CCACHE ??=" which is set in bitbake.conf, so we can't check whether CCACHE is set or not in anonymous function since it is always set. Use CCACHE_DISABLE to disable it would be more clear.

---
  meta/classes/ccache.bbclass             | 25 ++++++++++++++++++++++---
  meta/conf/bitbake.conf                  | 21 ++++++++++++++++-----
  meta/conf/layer.conf                    |  1 -
  meta/lib/oe/utils.py                    |  3 +++
  meta/recipes-devtools/ccache/ccache.inc |  2 ++
  5 files changed, 43 insertions(+), 9 deletions(-)
meta/classes/ccache.bbclass +22 -3
index 9609020..f4eefce 100644
@@ -1,4 +1,14 @@
-CCACHE = "${@bb.utils.which(d.getVar('PATH'), 'ccache') and 'ccache '}"
+#
+# Usage:
+# - Enable ccache
+#   Add the following line to a conffile such as conf/local.conf:
+#   INHERIT += "ccache"
+#
+# - Disable ccache for a recipe
+#   Add the following line to the recipe if it can't be built with ccache:
+#   CCACHE_DISABLE = '1'
+#
+
  export CCACHE_DIR ?= "${TMPDIR}/ccache/${MULTIMACH_TARGET_SYS}/${PN}"
 
  # We need to stop ccache considering the current directory or the
@@ -7,5 +17,14 @@ export CCACHE_DIR ?= "${TMPDIR}/ccache/${MULTIMACH_TARGET_SYS}/${PN}"
  # ${PV} or ${PR} change.
  export CCACHE_NOHASHDIR ?= "1"
 
-DEPENDS_append_class-target = " ccache-native"
-DEPENDS[vardepvalueexclude] = " ccache-native"
+python() {
+    """
+    Enable ccache for the recipe if is not a dependency of ccache-native
+    """
+    ccache_native_deps = d.getVar('CCACHE_NATIVE_DEPENDS') or ''
+    ccache_native_deps += 'ccache-native'
+    if not (d.getVar('PN') in ccache_native_deps.split() or \
+            bb.utils.to_boolean(d.getVar('CCACHE_DISABLE'))):
+        d.appendVar('DEPENDS', ' ccache-native')
+        d.setVar('CCACHE', 'ccache ')
+}
meta/conf/bitbake.conf +16 -1
index 6480062..cb1dba8 100644
@@ -492,7 +492,7 @@ HOSTTOOLS += " \
  HOSTTOOLS += "${@'ip ping ps scp ssh stty' if (bb.utils.contains_any('IMAGE_CLASSES', 'testimage testsdk', True, False, d) or any(x in (d.getVar("BBINCLUDED") or "") for x in ["testimage.bbclass", "testsdk.bbclass"])) else ''}"
 
  # Link to these if present
-HOSTTOOLS_NONFATAL += "aws ccache gcc-ar gpg ld.bfd ld.gold nc pigz sftp socat ssh sudo"
+HOSTTOOLS_NONFATAL += "aws gcc-ar gpg ld.bfd ld.gold nc pigz sftp socat ssh sudo"
 
  # Temporary add few more detected in bitbake world
  HOSTTOOLS_NONFATAL += "join nl size yes zcat"
@@ -503,11 +503,22 @@ HOSTTOOLS_NONFATAL += "bzr"
  # Used by ssh fetcher
  HOSTTOOLS_NONFATAL += "scp"
 
+# This is used by both ccache.bbclass and ccahe-native recipe, these
+# recipes can't use ccache since ccache-native depends on them,
+# otherwise, there would be loop dependencies.
+CCACHE_NATIVE_DEPENDS ?= " \
+    gnu-config-native \
+    autoconf-native \
+    quilt-native \
+    zlib-native \
+    gettext-minimal-native \
+    texinfo-dummy-native \
+    m4-native \
+    libtool-native \
+    automake-native \
+    xz-native \
+"
Quoted 8 lines

meta/conf/bitbake.conf HOSTTOOLS_NONFATAL += "bzr" · line 510

Quoted 5 lines
meta/conf/bitbake.conf +0 -4
  CCACHE ??= ""
-# ccache < 3.1.10 will create CCACHE_DIR on startup even if disabled, and
-# autogen sets HOME=/dev/null so in certain situations builds can fail.
-# Explicitly export CCACHE_DIR until we can assume ccache >3.1.10 on the host.
-export CCACHE_DIR ??= "${@os.getenv('HOME')}/.ccache"

Hardcoding a list of ccache-native dependencies is horrible and I do not want to do that.

Yes, I don't like this either:-). I've fixed it as:

* Remove all ccache-native's dependencies.
ccache-native has two dependencies: zlib-native and autotools-native, we can use --with-bundled-zlib do get rid of zlib-native. And use INHIBIT_AUTOTOOLS_DEPS to get rid of autotools-native, and add a simple do_configure function:

do_configure_class-native() {
oe_runconf
}

So that ccache-native can be depended by any recipe except quilt-native:

So now the code in ccache.bbclass is very simple:

python() {
    """
    Enable ccache for the recipe
    """
    pn = d.getVar('PN')
    if not pn in ('quilt-native', 'ccache-native'):
            d.appendVar('DEPENDS', ' ccache-native')
            d.setVar('CCACHE', 'ccache ')
}

We can also set PATCHTOOL = "patch" in ccache to make quilt-native can use ccache too, but I don't think that we have too.

I will send a V2 after more testing.

// Robert

Quoted 14 lines

Also, I want to stop the build up of unneeded 'stuff' in bitbake.conf. We should start making better use of inc files.

Please also ensure that the oe-selftest ccache tests continue to work after these changes. I haven't checked specifically here but we've had a lot of trouble with that before.

Cheers,

Richard

#4 lore raw

Re: [PATCH 1/4] base.bbclass: Remove invalid ccache related code

In reply to Robert Yang
Quoted 23 lines · Robert Yang
Quoted 15 lines · Richard Purdie
Quoted 9 lines · Robert Yang

The code is in setup_hosttools_dir(), it searches ccache in PATH in
reverse order, I can't figure out what it is used for, maybe it is
aimed to use host's ccache rather than recipe-sysroot- native/usr/bin/ccache, but the later one isn't in original PATH, so
remove the code.

Quoted 4 lines
---
  meta/classes/base.bbclass | 2 --
  1 file changed, 2 deletions(-)
Quoted 5 lines

We should document it and I think its still needed.

Some distros have a "gcc" which automatically wraps ccache behind the
scenes. This code lets us find the real gcc and bypass ccache.

Quoted 7 lines

Ah, thanks for the explanations, I got it now. I think that we don't need the
code any more since we don't use host's ccache, and I have removed ccache from
HOSTTOOLS.

I will update commit message and send a V2.

No, that isn't correct :(

The problem is that "gcc" can be linked directly to ccache by the host distro. This means you end up using the host ccache just by calling "gcc". This code is still needed if we want to control ccache and be able to disable it and use ccache-native for determinism.

Cheers,

Richard

#5 lore raw

Re: [PATCH 1/4] base.bbclass: Remove invalid ccache related code

Hi RP,

Quoted 30 lines · On 12/11/18 5:44 PM, [email protected] wrote:
Quoted 29 lines · Robert Yang
Quoted 15 lines · Richard Purdie
Quoted 9 lines · Robert Yang

The code is in setup_hosttools_dir(), it searches ccache in PATH in
reverse order, I can't figure out what it is used for, maybe it is
aimed to use host's ccache rather than recipe-sysroot- native/usr/bin/ccache, but the later one isn't in original PATH, so
remove the code.

Quoted 4 lines
---
   meta/classes/base.bbclass | 2 --
   1 file changed, 2 deletions(-)
Quoted 5 lines

We should document it and I think its still needed.

Some distros have a "gcc" which automatically wraps ccache behind the
scenes. This code lets us find the real gcc and bypass ccache.

Ah, thanks for the explanations, I got it now. I think that we don't need the
code any more since we don't use host's ccache, and I have removed ccache from
HOSTTOOLS.

Quoted 8 lines
Quoted 1 line

I will update commit message and send a V2.

No, that isn't correct :(

The problem is that "gcc" can be linked directly to ccache by the host distro. This means you end up using the host ccache just by calling "gcc". This code is still needed if we want to control ccache and be able to disable it and use ccache-native for determinism.

I did a test:

$ ln -s /usr/bin/ccache /folk/lyang1/bin/gcc
I got errors with/without the code:
$ bitbake -p
bb.BBHandledException
ERROR: Error running gcc  --version:
$ ls -l tmp/hosttools/gcc
tmp/hosttools/gcc -> /folk/lyang1/bin/gcc
$ ls -l /folk/lyang1/bin/gcc
/folk/lyang1/bin/gcc -> /usr/bin/ccache

It worked well if I run gcc --version manually:

$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
$ echo $?
0

There must be something wrong in such a case. I will fix this later.

Let's get back to he code:

srctool = bb.utils.which(path, tool, executable=True)
if "ccache" in srctool:
srctool = bb.utils.which(path, tool, executable=True, direction=1)
if srctool:
os.symlink(srctool, desttool)

* If tool == "gcc", then srctool would be gcc, too.
* If tool == "ccache", then srctool would be ccache, too.

So I think that the code doesn't help when gcc links to ccache ?

// Robert

Quoted 8 lines

Cheers,

Richard

#6 lore raw

Re: [PATCH 1/4] base.bbclass: Remove invalid ccache related code

Quoted 46 lines · Robert Yang
Quoted 10 lines · On 12/11/18 5:44 PM, [email protected] wrote:
Quoted 1 line · Robert Yang

On 12/10/18 6:29 PM, Richard Purdie wrote:

No, that isn't correct :(

The problem is that "gcc" can be linked directly to ccache by the host
distro. This means you end up using the host ccache just by calling "gcc". This code is still needed if we want to control ccache and be
able to disable it and use ccache-native for determinism.

I did a test:

$ ln -s /usr/bin/ccache /folk/lyang1/bin/gcc
I got errors with/without the code:
$ bitbake -p
bb.BBHandledException
ERROR: Error running gcc  --version:
$ ls -l tmp/hosttools/gcc
tmp/hosttools/gcc -> /folk/lyang1/bin/gcc
$ ls -l /folk/lyang1/bin/gcc
/folk/lyang1/bin/gcc -> /usr/bin/ccache

It worked well if I run gcc --version manually:

$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
$ echo $?
0

There must be something wrong in such a case. I will fix this later.

Let's get back to he code:

srctool = bb.utils.which(path, tool, executable=True) if "ccache" in srctool:
srctool = bb.utils.which(path, tool,
executable=True, direction=1)
if srctool:
os.symlink(srctool, desttool)

Quoted 4 lines

* If tool == "gcc", then srctool would be gcc, too.
* If tool == "ccache", then srctool would be ccache, too.

So I think that the code doesn't help when gcc links to ccache ?

https://www.unix.com/man-page/suse/1/ccache/

When the distros we tested on did this they placed it in something like bin/ccache/ so the code detects the "ccache" element of the path returned by which() (something like /usr/bin/ccache/gcc but I don't remember exactly).

Try using /folk/lyang1/ccache/ or /folk/lyang1/bin/ccache/ in your example.

Cheers,

Richard

#7 lore raw

Re: [PATCH 1/4] base.bbclass: Remove invalid ccache related code

Sent from mobile phone

Quoted 56 lines · 在 2018年12月11日,18:43,"[email protected]"…
Quoted 48 lines · Robert Yang
Quoted 11 lines · On 12/11/18 5:44 PM, [email protected] wrote:
Quoted 2 lines · Robert Yang

On 12/10/18 6:29 PM, Richard Purdie wrote:

No, that isn't correct :(

The problem is that "gcc" can be linked directly to ccache by the host
distro. This means you end up using the host ccache just by calling "gcc". This code is still needed if we want to control ccache and be
able to disable it and use ccache-native for determinism.

I did a test:

$ ln -s /usr/bin/ccache /folk/lyang1/bin/gcc
I got errors with/without the code:
$ bitbake -p
bb.BBHandledException
ERROR: Error running gcc  --version:
$ ls -l tmp/hosttools/gcc
tmp/hosttools/gcc -> /folk/lyang1/bin/gcc
$ ls -l /folk/lyang1/bin/gcc
/folk/lyang1/bin/gcc -> /usr/bin/ccache

It worked well if I run gcc --version manually:

$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
$ echo $?
0

There must be something wrong in such a case. I will fix this later.

Let's get back to he code:

srctool = bb.utils.which(path, tool, executable=True) if "ccache" in srctool:
srctool = bb.utils.which(path, tool,
executable=True, direction=1)
if srctool:
os.symlink(srctool, desttool)

Quoted 4 lines

* If tool == "gcc", then srctool would be gcc, too.
* If tool == "ccache", then srctool would be ccache, too.

So I think that the code doesn't help when gcc links to ccache ?

https://www.unix.com/man-page/suse/1/ccache/

Quoted 7 lines

When the distros we tested on did this they placed it in something like bin/ccache/ so the code detects the "ccache" element of the path returned by which() (something like /usr/bin/ccache/gcc but I don't remember exactly).

Try using /folk/lyang1/ccache/ or /folk/lyang1/bin/ccache/ in your example.

Thanks, I will try it tomorrow.

// Robert

Quoted 8 lines

Cheers,

Richard

#8 lore raw

Re: [PATCH 1/4] base.bbclass: Remove invalid ccache related code

In reply to [email protected]
Quoted 54 lines · On 12/11/18 6:42 PM, [email protected] wrote:
Quoted 46 lines · Robert Yang
Quoted 10 lines · On 12/11/18 5:44 PM, [email protected] wrote:
Quoted 1 line · Robert Yang

On 12/10/18 6:29 PM, Richard Purdie wrote:

No, that isn't correct :(

The problem is that "gcc" can be linked directly to ccache by the host
distro. This means you end up using the host ccache just by calling "gcc". This code is still needed if we want to control ccache and be
able to disable it and use ccache-native for determinism.

I did a test:

$ ln -s /usr/bin/ccache /folk/lyang1/bin/gcc
I got errors with/without the code:
$ bitbake -p
bb.BBHandledException
ERROR: Error running gcc  --version:
$ ls -l tmp/hosttools/gcc
tmp/hosttools/gcc -> /folk/lyang1/bin/gcc
$ ls -l /folk/lyang1/bin/gcc
/folk/lyang1/bin/gcc -> /usr/bin/ccache

It worked well if I run gcc --version manually:

$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
$ echo $?
0

There must be something wrong in such a case. I will fix this later.

Let's get back to he code:

srctool = bb.utils.which(path, tool, executable=True) if "ccache" in srctool:
srctool = bb.utils.which(path, tool,
executable=True, direction=1)
if srctool:
os.symlink(srctool, desttool)

Quoted 4 lines

* If tool == "gcc", then srctool would be gcc, too.
* If tool == "ccache", then srctool would be ccache, too.

So I think that the code doesn't help when gcc links to ccache ?

https://www.unix.com/man-page/suse/1/ccache/

Quoted 7 lines

When the distros we tested on did this they placed it in something like bin/ccache/ so the code detects the "ccache" element of the path returned by which() (something like /usr/bin/ccache/gcc but I don't remember exactly).

Try using /folk/lyang1/ccache/ or /folk/lyang1/bin/ccache/ in your example.

Ah, sorry, I mixed 'ccache in srctool' with 'ccache == srctool', yes, we do need it. I will keep the original code, and add comments for it.

// Robert

Quoted 9 lines

Cheers,

Richard

#13 lore raw
In reply to Martin Hundebøll

Hi Martin

Quoted 59 lines · Martin Hundebøll

Hi Robert,

Just a small nit-pick below..

Quoted 38 lines · Robert Yang

The previous ccache.bbclass has the following problems:
- It uses host's ccache for native recipes, but this may not work on some hosts, for example, it nerver works on my Ubuntu 14.04.4, there are always build failures (m4-native failed at do_configure, and others will also be failed if I disable CCACHE for m4-native)

- native/nativesdk/cross/crosssdk recipes use host's ccahe, but target uses ccache-native, this may confuse user.

- The target recipes may use both host's ccache and ccache-native, this may cause unexpected problems and hard to debug. This is because ccache-native is in SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS, so ccache-native may not be present when rebuild target recipes, and then it would use hosttools/ccache, but the previous ccache files were generated by ccache-native.

- Target recipes can't use ccache when no ccahe is installed on the host:
   CCACHE = "${@bb.utils.which(d.getVar('PATH'), 'ccache') and 'ccache '}"

After refactored:
All types recipes (native, target and others) will use ccache-native except ccache-native's dependencies, host's cache won't be used any more. It is more reliable now, which will work everywhere when ccache-native can be built.

And now we need use "CCACHE_DISABLE = '1'" to disable ccahe for the recipe rather than "CCACHE = ''" since we set CCACHE in anonymous function, and d.getVar('CCACHE') works after "CCACHE ??=" which is set in bitbake.conf, so we can't check whether CCACHE is set or not in anonymous function since it is always set. Use CCACHE_DISABLE to disable it would be more clear.

---
  meta/classes/ccache.bbclass             | 25 ++++++++++++++++++++++--- meta/conf/bitbake.conf                  | 21 ++++++++++++++++----- meta/conf/layer.conf                    |  1 - meta/lib/oe/utils.py                    |  3 +++ meta/recipes-devtools/ccache/ccache.inc |  2 ++

  5 files changed, 43 insertions(+), 9 deletions(-)

<snip>

Quoted 10 lines
meta/lib/oe/utils.py +0 -0
index 8a584d6..9c41705 100644
@@ -363,6 +363,9 @@ def host_gcc_version(d, taskcontextonly=False):

          return
      compiler = d.getVar("BUILD_CC")
+    # Get rid of ccache since it is not present when parsing. +    if compiler.startswith('ccache '):
+        compiler = compiler[7:]

You can avoid the if-condition and hard-coded 7-value by doing:

Quoted 2 lines

  # Get rid of ccache since it is no present when parsing. compiler = d.getVar("BUILD_CC").lstrip("ccache-")

I'm afraid that this may not work, lstrip("ccache-") strips any characters of 'ccache-' (c, a, h e -), which seems dangerous, and not what we want. I've will revert it in V2's PULL.

// Robert

Quoted 18 lines

// Martin

Quoted 14 lines

      try:
          env = os.environ.copy()
          env["PATH"] = d.getVar("PATH")

meta/recipes-devtools/ccache/ccache.inc +0 -0
index 6566328..259c196 100644
@@ -9,6 +9,8 @@ LICENSE = "GPLv3+"

  DEPENDS = "zlib"

meta/recipes-devtools/ccache/ccache.inc +2 -0
+DEPENDS_class-native = "${CCACHE_NATIVE_DEPENDS}"
+

  SRC_URI = "https://download.samba.org/pub/${BPN}/${BP}.tar.xz" inherit autotools

#9 lore raw

Re: [PATCH 1/4] base.bbclass: Remove invalid ccache related code

In reply to Robert Yang
Quoted 4 lines · Robert Yang

Hi RP,

Quoted 1 line · On 12/11/18 5:44 PM, [email protected] wrote:

On Tue, 2018-12-11 at 17:24 +0800, Robert Yang wrote:

[snip]

Quoted 8 lines

I did a test:

$ ln -s /usr/bin/ccache /folk/lyang1/bin/gcc
I got errors with/without the code:
$ bitbake -p
bb.BBHandledException
ERROR: Error running gcc  --version:

I've sent a patch to fix/explain this problem:

[OE-core] [PATCH 0/1] lib/oe/utils: Set stderr for host_gcc_version()

// Robert

Quoted 40 lines
$ ls -l tmp/hosttools/gcc
tmp/hosttools/gcc -> /folk/lyang1/bin/gcc
$ ls -l /folk/lyang1/bin/gcc
/folk/lyang1/bin/gcc -> /usr/bin/ccache

It worked well if I run gcc --version manually:

$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
$ echo $?
0

There must be something wrong in such a case. I will fix this later.

Let's get back to he code:

            srctool = bb.utils.which(path, tool, executable=True)
            if "ccache" in srctool:
                srctool = bb.utils.which(path, tool, executable=True, direction=1) if srctool:
                os.symlink(srctool, desttool)

* If tool == "gcc", then srctool would be gcc, too.
* If tool == "ccache", then srctool would be ccache, too.

So I think that the code doesn't help when gcc links to ccache ?

// Robert

Quoted 8 lines

Cheers,

Richard