summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2014-11-01 08:11:46 +0000
committerMike Frysinger <vapier@gentoo.org>2014-11-01 08:11:46 +0000
commit8b5eaa69ffdf68b5ebe96ba60f0768fa0fe8570c (patch)
treec434584a5ea9531186192346805daff9eeed02bc /dev-util/ccache
parentVersion bump #527480 by Markus. (diff)
downloadgentoo-2-8b5eaa69ffdf68b5ebe96ba60f0768fa0fe8570c.tar.gz
gentoo-2-8b5eaa69ffdf68b5ebe96ba60f0768fa0fe8570c.tar.bz2
gentoo-2-8b5eaa69ffdf68b5ebe96ba60f0768fa0fe8570c.zip
Fix temp file usage to not rely on pids (fixes running in pid namespaces). Fix disk usage checks #456178 by Richard Yao. Always use /usr/lib/ccache/bin/ #509956 by Michał Górny.
(Portage version: 2.2.14/cvs/Linux x86_64, signed Manifest commit with key D2E96200)
Diffstat (limited to 'dev-util/ccache')
-rw-r--r--dev-util/ccache/ChangeLog11
-rw-r--r--dev-util/ccache/ccache-3.1.10-r1.ebuild69
-rw-r--r--dev-util/ccache/files/ccache-3.1.10-real-temp-files.patch185
-rw-r--r--dev-util/ccache/files/ccache-3.1.10-size-on-disk.patch21
4 files changed, 285 insertions, 1 deletions
diff --git a/dev-util/ccache/ChangeLog b/dev-util/ccache/ChangeLog
index fc474ce90e52..9d872d8c6406 100644
--- a/dev-util/ccache/ChangeLog
+++ b/dev-util/ccache/ChangeLog
@@ -1,6 +1,15 @@
# ChangeLog for dev-util/ccache
# Copyright 1999-2014 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/dev-util/ccache/ChangeLog,v 1.140 2014/11/01 07:54:34 vapier Exp $
+# $Header: /var/cvsroot/gentoo-x86/dev-util/ccache/ChangeLog,v 1.141 2014/11/01 08:11:46 vapier Exp $
+
+*ccache-3.1.10-r1 (01 Nov 2014)
+
+ 01 Nov 2014; Mike Frysinger <vapier@gentoo.org> +ccache-3.1.10-r1.ebuild,
+ +files/ccache-3.1.10-real-temp-files.patch,
+ +files/ccache-3.1.10-size-on-disk.patch:
+ Fix temp file usage to not rely on pids (fixes running in pid namespaces).
+ Fix disk usage checks #456178 by Richard Yao. Always use /usr/lib/ccache/bin/
+ #509956 by Michał Górny.
01 Nov 2014; Mike Frysinger <vapier@gentoo.org> files/ccache-config:
Trim empty ccache dirs automatically #517242 by Arfrever Frehtes Taifersar
diff --git a/dev-util/ccache/ccache-3.1.10-r1.ebuild b/dev-util/ccache/ccache-3.1.10-r1.ebuild
new file mode 100644
index 000000000000..0ec234981ef1
--- /dev/null
+++ b/dev-util/ccache/ccache-3.1.10-r1.ebuild
@@ -0,0 +1,69 @@
+# Copyright 1999-2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-util/ccache/ccache-3.1.10-r1.ebuild,v 1.1 2014/11/01 08:11:46 vapier Exp $
+
+EAPI="4"
+
+inherit eutils readme.gentoo
+
+DESCRIPTION="fast compiler cache"
+HOMEPAGE="http://ccache.samba.org/"
+SRC_URI="http://samba.org/ftp/ccache/${P}.tar.xz"
+
+LICENSE="GPL-3"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~x86-fbsd ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~x64-solaris ~x86-solaris"
+IUSE=""
+
+RDEPEND="sys-libs/zlib"
+DEPEND="${RDEPEND}
+ app-arch/xz-utils"
+
+src_prepare() {
+ # make sure we always use system zlib
+ rm -rf zlib
+ epatch "${FILESDIR}"/${PN}-3.1.7-no-perl.patch #421609
+ epatch "${FILESDIR}"/${PN}-3.1.10-size-on-disk.patch #456178
+ epatch "${FILESDIR}"/${PN}-3.1.10-real-temp-files.patch
+ sed \
+ -e "/^EPREFIX=/s:'':'${EPREFIX}':" \
+ "${FILESDIR}"/ccache-config-2 > ccache-config || die
+}
+
+src_install() {
+ default
+ dodoc AUTHORS.txt MANUAL.txt NEWS.txt README.txt
+
+ dobin ccache-config
+
+ DOC_CONTENTS="
+To use ccache with **non-Portage** C compiling, add
+${EPREFIX}/usr/lib/ccache/bin to the beginning of your path, before ${EPREFIX}usr/bin.
+Portage 2.0.46-r11+ will automatically take advantage of ccache with
+no additional steps. If this is your first install of ccache, type
+something like this to set a maximum cache size of 2GB:\\n
+# ccache -M 2G\\n
+If you are upgrading from an older version than 3.x you should clear all of your caches like so:\\n
+# CCACHE_DIR='${CCACHE_DIR:-${PORTAGE_TMPDIR}/ccache}' ccache -C\\n
+ccache now supports sys-devel/clang and dev-lang/icc, too!"
+
+ readme.gentoo_create_doc
+}
+
+pkg_prerm() {
+ if [[ -z ${REPLACED_BY_VERSION} ]] ; then
+ "${EROOT}"/usr/bin/ccache-config --remove-links
+ "${EROOT}"/usr/bin/ccache-config --remove-links ${CHOST}
+ fi
+}
+
+pkg_postinst() {
+ "${EROOT}"/usr/bin/ccache-config --install-links
+ "${EROOT}"/usr/bin/ccache-config --install-links ${CHOST}
+
+ # nuke broken symlinks from previous versions that shouldn't exist
+ rm -f "${EROOT}"/usr/lib/ccache/bin/${CHOST}-cc
+ rm -rf "${EROOT}"/usr/lib/ccache.backup
+
+ readme.gentoo_print_elog
+}
diff --git a/dev-util/ccache/files/ccache-3.1.10-real-temp-files.patch b/dev-util/ccache/files/ccache-3.1.10-real-temp-files.patch
new file mode 100644
index 000000000000..45e654105170
--- /dev/null
+++ b/dev-util/ccache/files/ccache-3.1.10-real-temp-files.patch
@@ -0,0 +1,185 @@
+https://lists.samba.org/archive/ccache/2014q4/001246.html
+
+From 5d0f507a4162ac89e05ca633dbc8056454b798f5 Mon Sep 17 00:00:00 2001
+From: Mike Frysinger <vapier@gentoo.org>
+Date: Mon, 15 Sep 2014 18:15:02 -0400
+Subject: [PATCH] do not rely on pids being unique
+
+Linux supports creating pid namespaces cheaply and running processes
+inside of them. When you try to share a single cache among multiple
+such runs, the fact that the code relies on pid numbers as globally
+unique values quickly fails. Instead, switch to standard mkstemp to
+generate temp files for us.
+
+Signed-off-by: Mike Frysinger <vapier@gentoo.org>
+---
+ ccache.c | 12 ++++++------
+ ccache.h | 2 +-
+ manifest.c | 2 +-
+ stats.c | 10 +++++++++-
+ util.c | 13 ++++++++-----
+ 5 files changed, 25 insertions(+), 14 deletions(-)
+
+diff --git a/ccache.c b/ccache.c
+index 02dbdfa..1dc0a06 100644
+--- a/ccache.c
++++ b/ccache.c
+@@ -526,8 +526,11 @@ to_cache(struct args *args)
+ unsigned added_files = 0;
+
+ tmp_stdout = format("%s.tmp.stdout.%s", cached_obj, tmp_string());
++ create_empty_file(tmp_stdout);
+ tmp_stderr = format("%s.tmp.stderr.%s", cached_obj, tmp_string());
++ create_empty_file(tmp_stderr);
+ tmp_obj = format("%s.tmp.%s", cached_obj, tmp_string());
++ create_empty_file(tmp_obj);
+
+ args_add(args, "-o");
+ args_add(args, tmp_obj);
+@@ -579,7 +582,7 @@ to_cache(struct args *args)
+ int fd_result;
+ char *tmp_stderr2;
+
+- tmp_stderr2 = format("%s.tmp.stderr2.%s", cached_obj, tmp_string());
++ tmp_stderr2 = format("%s.2", tmp_stderr);
+ if (x_rename(tmp_stderr, tmp_stderr2)) {
+ cc_log("Failed to rename %s to %s: %s", tmp_stderr, tmp_stderr2,
+ strerror(errno));
+@@ -808,6 +808,7 @@ get_object_name_from_cpp(struct args *args, struct mdfour *hash)
+ }
+
+ path_stderr = format("%s/tmp.cpp_stderr.%s", temp_dir, tmp_string());
++ create_empty_file(path_stderr);
+ add_pending_tmp_file(path_stderr);
+
+ time_of_compilation = time(NULL);
+@@ -815,6 +816,7 @@ get_object_name_from_cpp(struct args *args, struct mdfour *hash)
+ if (!direct_i_file) {
+ path_stdout = format("%s/%s.tmp.%s.%s",
+ temp_dir, input_base, tmp_string(), i_extension);
++ create_empty_file(path_stdout);
+ add_pending_tmp_file(path_stdout);
+
+ /* run cpp on the input file to obtain the .i */
+@@ -838,11 +843,6 @@ get_object_name_from_cpp(struct args *args, struct mdfour *hash)
+ can skip the cpp stage and directly form the
+ correct i_tmpfile */
+ path_stdout = input_file;
+- if (create_empty_file(path_stderr) != 0) {
+- cc_log("Failed to create %s: %s", path_stderr, strerror(errno));
+- stats_update(STATS_ERROR);
+- failed();
+- }
+ status = 0;
+ }
+
+diff --git a/ccache.h b/ccache.h
+index 2bc7c87..43ef98d 100644
+--- a/ccache.h
++++ b/ccache.h
+@@ -130,7 +130,7 @@ size_t file_size(struct stat *st);
+ int safe_open(const char *fname);
+ char *x_realpath(const char *path);
+ char *gnu_getcwd(void);
+-int create_empty_file(const char *fname);
++int create_empty_file(char *fname);
+ const char *get_home_directory(void);
+ char *get_cwd();
+ bool same_executable_name(const char *s1, const char *s2);
+diff --git a/manifest.c b/manifest.c
+index 7f02ede..47566d5 100644
+--- a/manifest.c
++++ b/manifest.c
+@@ -633,7 +633,7 @@ manifest_put(const char *manifest_path, struct file_hash *object_hash,
+ }
+
+ tmp_file = format("%s.tmp.%s", manifest_path, tmp_string());
+- fd2 = safe_open(tmp_file);
++ fd2 = mkstemp(tmp_file);
+ if (fd2 == -1) {
+ cc_log("Failed to open %s", tmp_file);
+ goto out;
+diff --git a/stats.c b/stats.c
+index 2111b65..4ed39c2 100644
+--- a/stats.c
++++ b/stats.c
+@@ -126,11 +126,18 @@ stats_write(const char *path, struct counters *counters)
+ size_t i;
+ char *tmp_file;
+ FILE *f;
++ int fd;
+
+ tmp_file = format("%s.tmp.%s", path, tmp_string());
+- f = fopen(tmp_file, "wb");
++ fd = mkstemp(tmp_file);
++ if (fd == -1) {
++ cc_log("Failed to open %s", tmp_file);
++ goto end;
++ }
++ f = fdopen(fd, "wb");
+ if (!f) {
+ cc_log("Failed to open %s", tmp_file);
++ close(fd);
+ goto end;
+ }
+ for (i = 0; i < counters->size; i++) {
+@@ -138,6 +145,7 @@ stats_write(const char *path, struct counters *counters)
+ fatal("Failed to write to %s", tmp_file);
+ }
+ }
++ /* This also implicitly closes the fd. */
+ fclose(f);
+ x_rename(tmp_file, path);
+
+diff --git a/util.c b/util.c
+index 3b472de..cc630a6 100644
+--- a/util.c
++++ b/util.c
+@@ -195,7 +195,7 @@ copy_file(const char *src, const char *dest, int compress_dest)
+ struct stat st;
+ int errnum;
+
+- tmp_name = format("%s.%s.XXXXXX", dest, tmp_string());
++ tmp_name = format("%s.%s", dest, tmp_string());
+ cc_log("Copying %s to %s via %s (%s)",
+ src, dest, tmp_name, compress_dest ? "compressed": "uncompressed");
+
+@@ -427,7 +427,7 @@ tmp_string(void)
+ static char *ret;
+
+ if (!ret) {
+- ret = format("%s.%u", get_hostname(), (unsigned)getpid());
++ ret = format("%s.%u.XXXXXX", get_hostname(), (unsigned)getpid());
+ }
+
+ return ret;
+@@ -884,12 +884,13 @@ gnu_getcwd(void)
+
+ /* create an empty file */
+ int
+-create_empty_file(const char *fname)
++create_empty_file(char *fname)
+ {
+ int fd;
+
+- fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 0666);
++ fd = mkstemp(fname);
+ if (fd == -1) {
++ cc_log("Failed to create %s: %s", fname, strerror(errno));
+ return -1;
+ }
+ close(fd);
+@@ -1134,7 +1135,9 @@ x_unlink(const char *path)
+ goto out;
+ }
+ if (unlink(tmp_name) == -1) {
+- result = -1;
++ /* If it was released in a race, that's OK. */
++ if (errno != ENOENT)
++ result = -1;
+ }
+ out:
+ free(tmp_name);
+--
+2.1.2
+
diff --git a/dev-util/ccache/files/ccache-3.1.10-size-on-disk.patch b/dev-util/ccache/files/ccache-3.1.10-size-on-disk.patch
new file mode 100644
index 000000000000..5e502912bfa2
--- /dev/null
+++ b/dev-util/ccache/files/ccache-3.1.10-size-on-disk.patch
@@ -0,0 +1,21 @@
+https://bugs.gentoo.org/56178
+
+stick to the size of files on disk rather than their byte size.
+this func is only used for stats management, so this should be safe.
+
+--- a/util.c
++++ b/util.c
+@@ -845,12 +845,7 @@ file_size(struct stat *st)
+ #ifdef _WIN32
+ return (st->st_size + 1023) & ~1023;
+ #else
+- size_t size = st->st_blocks * 512;
+- if ((size_t)st->st_size > size) {
+- /* probably a broken stat() call ... */
+- size = (st->st_size + 1023) & ~1023;
+- }
+- return size;
++ return st->st_blocks * 512;
+ #endif
+ }
+