dev-lang/go: rework bootstrap logic to use dev-lang/go-bootstrap
[gentoo.git] / dev-lang / go / go-9999.ebuild
index 8d4c7158d828dbc8198dd24d2efe7f15eaca35e9..635b905c4d9131cc9f34d2aea69dc84da9dda0cd 100644 (file)
@@ -1,52 +1,73 @@
-# Copyright 1999-2015 Gentoo Foundation
+# Copyright 1999-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
-# $Id$
 
-EAPI=5
+EAPI=7
 
 export CBUILD=${CBUILD:-${CHOST}}
 export CTARGET=${CTARGET:-${CHOST}}
 
-inherit eutils toolchain-funcs
+MY_PV=${PV/_/}
 
-if [[ ${PV} = 9999 ]]; then
-       EGIT_REPO_URI="git://github.com/golang/go.git"
+inherit toolchain-funcs
+
+case ${PV}  in
+*9999*)
+       EGIT_REPO_URI="https://github.com/golang/go.git"
        inherit git-r3
-else
-       SRC_URI="https://storage.googleapis.com/golang/go${PV}.src.tar.gz"
-       # go-bootstrap-1.4 only supports go on amd64, arm and x86 architectures.
-       # Allowing other bootstrap options would enable arm64 and ppc64 builds.
-       KEYWORDS="-* ~amd64 ~arm ~x86 ~amd64-fbsd ~x86-fbsd ~x64-macos ~x86-macos"
-fi
+       ;;
+*)
+       SRC_URI="https://storage.googleapis.com/golang/go${MY_PV}.src.tar.gz "
+       S="${WORKDIR}"/go
+       case ${PV} in
+       *_beta*|*_rc*) ;;
+       *)
+               KEYWORDS="-* ~amd64 ~arm ~arm64 ~ppc64 ~s390 ~x86 ~amd64-linux ~x86-linux ~x64-macos ~x64-solaris"
+               # The upstream tests fail under portage but pass if the build is
+               # run according to their documentation [1].
+               # I am restricting the tests on released versions until this is
+               # solved.
+               # [1] https://golang.org/issues/18442
+               RESTRICT="test"
+               ;;
+       esac
+esac
 
 DESCRIPTION="A concurrent garbage collected and typesafe programming language"
-HOMEPAGE="http://www.golang.org"
+HOMEPAGE="https://golang.org"
 
 LICENSE="BSD"
 SLOT="0/${PV}"
-IUSE=""
+IUSE="gccgo"
 
-DEPEND=">=dev-lang/go-bootstrap-1.4.1"
+BDEPEND="gccgo? ( >=sys-devel/gcc-5[go(-)] )
+       !gccgo? ( >=dev-lang/go-bootstrap-1.13.6 )"
 RDEPEND="!<dev-go/go-tools-0_pre20150902"
 
 # These test data objects have writable/executable stacks.
-QA_EXECSTACK="usr/lib/go/src/debug/elf/testdata/*.obj"
+QA_EXECSTACK="
+       usr/lib/go/src/debug/elf/testdata/*.obj
+       usr/lib/go/src/*.gox
+       "
+
+# Do not complain about CFLAGS, etc, since Go doesn't use them.
+QA_FLAGS_IGNORED='.*'
 
 REQUIRES_EXCLUDE="/usr/lib/go/src/debug/elf/testdata/*"
 
 # The tools in /usr/lib/go should not cause the multilib-strict check to fail.
 QA_MULTILIB_PATHS="usr/lib/go/pkg/tool/.*/.*"
 
-# The go language uses *.a files which are _NOT_ libraries and should not be
-# stripped. The test data objects should also be left alone and unstripped.
-STRIP_MASK="/usr/lib/go/pkg/*.a
-       /usr/lib/go/src/debug/elf/testdata/*
-       /usr/lib/go/src/debug/dwarf/testdata/*
-       /usr/lib/go/src/runtime/race/*.syso"
+# Do not strip this package. Stripping is unsupported upstream and may
+# fail.
+RESTRICT+=" strip"
 
-if [[ ${PV} != 9999 ]]; then
-       S="${WORKDIR}"/go
-fi
+DOCS=(
+AUTHORS
+CONTRIBUTING.md
+CONTRIBUTORS
+PATENTS
+README.md
+)
 
 go_arch()
 {
@@ -54,6 +75,9 @@ go_arch()
        local portage_arch=$(tc-arch $@)
        case "${portage_arch}" in
                x86)    echo 386;;
+               x64-*)  echo amd64;;
+               ppc64) [[ $(tc-endian $@) = big ]] && echo ppc64 || echo ppc64le ;;
+               s390) echo s390x ;;
                *)              echo "${portage_arch}";;
        esac
 }
@@ -98,26 +122,33 @@ go_cross_compile()
        [[ $(go_tuple ${CBUILD}) != $(go_tuple) ]]
 }
 
-pkg_pretend()
+src_unpack()
 {
-       # make.bash does not understand cross-compiling a cross-compiler
-       if [[ $(go_tuple) != $(go_tuple ${CTARGET}) ]]; then
-               die "CHOST CTARGET pair unsupported: CHOST=${CHOST} CTARGET=${CTARGET}"
+       if [[ ${PV} = 9999 ]]; then
+               git-r3_src_unpack
+       else
+               unpack "go${MY_PV}.src.tar.gz"
        fi
 }
 
-src_prepare()
+src_compile()
 {
-       if [[ ${PV} != 9999 ]]; then
-               sed -i -e 's/"-Werror",//g' src/cmd/dist/build.go ||
-                       die 'sed failed'
+       if use gccgo; then
+               export GOROOT_BOOTSTRAP="${WORKDIR}/go-bootstrap"
+               mkdir -p "${GOROOT_BOOTSTRAP}/bin" || die
+               local go_binary=$(gcc-config --get-bin-path)/go-$(gcc-major-version)
+               [[ -x ${go_binary} ]] || go_binary=$(
+                       find "${EPREFIX}"/usr/${CHOST}/gcc-bin/*/go-$(gcc-major-version) |
+                               sort -V | tail -n1)
+               [[ -x ${go_binary} ]] ||
+                       die "go-$(gcc-major-version): command not found"
+               ln -s "${go_binary}" "${GOROOT_BOOTSTRAP}/bin/go" || die
+       elif has_version -b dev-lang/go-bootstrap; then
+               export GOROOT_BOOTSTRAP="${BROOT}/usr/lib/go-bootstrap"
+       else
+               die "Should not be here, please report a bug"
        fi
-       epatch_user
-}
 
-src_compile()
-{
-       export GOROOT_BOOTSTRAP="${EPREFIX}"/usr/lib/go1.4
        export GOROOT_FINAL="${EPREFIX}"/usr/lib/go
        export GOROOT="$(pwd)"
        export GOBIN="${GOROOT}/bin"
@@ -145,66 +176,38 @@ src_test()
 
        cd src
        PATH="${GOBIN}:${PATH}" \
-               ./run.bash -no-rebuild || die "tests failed"
+       ./run.bash -no-rebuild || die "tests failed"
 }
 
 src_install()
 {
-       local bin_path="${GOBIN}"
-       if go_cross_compile; then
-               bin_path="${GOBIN}/$(go_tuple)"
-       fi
-       dobin "${bin_path}"/*
-       dodoc AUTHORS CONTRIBUTORS PATENTS README.md
+       local bin_path f x
 
-       dodir /usr/lib/go /usr/lib/go/pkg /usr/lib/go/pkg/tool
-       insinto /usr/lib/go
+       dodir /usr/lib/go
 
        # There is a known issue which requires the source tree to be installed [1].
        # Once this is fixed, we can consider using the doc use flag to control
        # installing the doc and src directories.
        # [1] https://golang.org/issue/2775
-       doins -r doc lib src
-
-       # Selectively install pkg directory to exclude the bootstrap build
-       insinto /usr/lib/go/pkg
-       doins -r pkg/include "pkg/$(go_tuple)"
-       insinto /usr/lib/go/pkg/tool
-       doins -r "pkg/tool/$(go_tuple)"
-       fperms -R +x /usr/lib/go/pkg/tool
-}
-
-pkg_preinst()
-{
-       has_version '<dev-lang/go-1.4' &&
-               export had_support_files=true ||
-               export had_support_files=false
-}
-
-pkg_postinst()
-{
-       # If the go tool sees a package file timestamped older than a dependancy it
-       # will rebuild that file.  So, in order to stop go from rebuilding lots of
-       # packages for every build we need to fix the timestamps.  The compiler and
-       # linker are also checked - so we need to fix them too.
-       ebegin "fixing timestamps to avoid unnecessary rebuilds"
-       tref="usr/lib/go/pkg/*/runtime.a"
-       find "${EROOT}"usr/lib/go -type f \
-               -exec touch -r "${EROOT}"${tref} {} \;
-       eend $?
-
-       if [[ ${PV} != 9999 && -n ${REPLACING_VERSIONS} &&
-               ${REPLACING_VERSIONS} != ${PV} ]]; then
-               elog "Release notes are located at http://golang.org/doc/go${PV}"
+       #
+       # deliberately use cp to retain permissions
+       cp -R api bin doc lib pkg misc src test "${ED}"/usr/lib/go
+       if go_cross_compile; then
+               bin_path="bin/$(go_tuple)"
+       else
+               bin_path=bin
        fi
-
-       if $had_support_files; then
-               ewarn
-               ewarn "All editor support, IDE support, shell completion"
-               ewarn "support, etc has been removed from the go package"
-               ewarn "upstream."
-               ewarn "For more information on which support is available, see"
-               ewarn "the following URL:"
-               ewarn "https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins"
+       for x in ${bin_path}/*; do
+               f=${x##*/}
+               dosym ../lib/go/${bin_path}/${f} /usr/bin/${f}
+       done
+       einstalldocs
+
+       if [[ ${CHOST} == *-darwin* ]] ; then
+               # fix install_name for test object (binutils_test) on Darwin, it
+               # is never used in real circumstances
+               local libmac64="${EPREFIX}"/usr/lib/go/src/cmd/vendor/github.com/
+                     libmac64+=google/pprof/internal/binutils/testdata/lib_mac_64
+               install_name_tool -id "${libmac64}" "${D}${libmac64}"
        fi
 }