On Fri, Jun 05, 2015 at 12:54:45AM -0400, Mike Frysinger wrote:
> On 04 Jun 2015 14:10, William Hubbs wrote:
> > # @ECLASS: go-live.eclass
> 
> since we're going to have a common go eclass, and i don't think we'll want to 
> call it "go.eclass", this too probably should not be go-xxx.  if we assume 
> the 
> base one will be "golang.eclass", then this should be golang-xxx.eclass.  i'd 
> prefer golang-vcs.eclass myself as that's the naming we've been moving 
> towards.
 
 I'm not convinced yet that we are going to have a base eclass for all
 go ebuilds, but I can rename this one easily enough to
 golang-vcs.eclass.

> > # @MAINTAINER:
> > # William Hubbs <willi...@gentoo.org>
> > # @BLURB: Eclass for fetching and unpacking go repositories.
> > # @DESCRIPTION:
> > # This eclass is written to ease the maintenance of live ebuilds
> > # of software written in the Go programming language.
> 
> this should note the ebuild is responsible for depending on the right vcs 
> packages.  e.g. if you use git, then you need to depend on git.

Since "go get" fetches $EGO_PN and its dependencies, there is no way an
ebuild author could get this right without reading all of the import
statements in the source for their package and all of its dependencies.
I don't really want to ask ebuild authors to keep up with all of that.

> although ...
> 
> > # @ECLASS-VARIABLE: EGO_PN
> > # @REQUIRED
> > # @DESCRIPTION:
> > # This is the import path for the go package. Please emerge dev-lang/go
> > # and read "go help importpath" for syntax.
> > #
> > # Example:
> > # @CODE
> > # EGO_PN="github.com/user/project"
> > # @CODE
> 
> can't we automate some of the common hosts ?  if it says github, we know it's 
> going to be using at least git.
 
I'm seeing two options. I can either let users emerge the vcs's they
need if something breaks or pull in all vcs's go supports.

Which way is best?

...

> >     if [[ ${EVCS_OFFLINE} ]]; then
> >             export GOPATH="${S}:${GOPATH}"
> 
> what if GOPATH isn't set ?  should this always be appending a colon ?

I thought it would always be set at this point because it was initially
set to ${EGO_STORE_DIR} in the env_setup function. What I can do, if it
makes things more clear, is to replace the value of GOPATH instead of
prepending it.

...

> >     go get -d -t -u -v -x "$EGO_PN"
> 
> needs braces around ${EGO_PN}, and shouldn't this be calling `die` ?
> 
> would also be useful to show the command you're running:
>       set -- go get -d -t -u -v -x "${EGO_PN}"
>       echo "$@"
>       "$@" || die
 
You are correct; we should be calling die here. However, I suspect an
upstream bug because the following returns an error:

$ cd /home/william/go
$ export GOPATH=/home/william/go
$ go get -d -t -u -v -x golang.org/x/tools

go downloads everything, then errors out with a message about "no
buildable source files in /home/william/go/src/golang.org/x/tools"

This isn't an error because you build the tools from the subdirectories
of the project.

...

> >     export GOPATH="${S}:${GOPATH}"
> 
> same questions here

See my comment above about GOPATH; the same thing applies here.

The eclass with your changes is attached.

William

# Copyright 1999-2015 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# @ECLASS: golang-vcs.eclass
# @MAINTAINER:
# William Hubbs <willi...@gentoo.org>
# @BLURB: Eclass for fetching and unpacking go repositories.
# @DESCRIPTION:
# This eclass is written to ease the maintenance of live ebuilds
# of software written in the Go programming language.

inherit eutils

case "${EAPI:-0}" in
        5)
                ;;
        *)
                die "${ECLASS}: Unsupported eapi (EAPI=${EAPI})"
                ;;
esac

EXPORT_FUNCTIONS src_unpack

if [[ -z ${_GOLANG_VCS} ]]; then

_GO_LIVE=1

DEPEND=">=dev-lang/go-1.4.2"

# @ECLASS-VARIABLE: EGO_PN
# @REQUIRED
# @DESCRIPTION:
# This is the import path for the go package. Please emerge dev-lang/go
# and read "go help importpath" for syntax.
#
# Example:
# @CODE
# EGO_PN="github.com/user/project"
# @CODE

# @ECLASS-VARIABLE: EGO_STORE_DIR
# @DESCRIPTION:
# Storage directory for Go sources.
#
# This is intended to be set by the user in make.conf. Ebuilds must not set
# it.
#
# EGO_STORE_DIR=${DISTDIR}/go-src

# @ECLASS-VARIABLE: EVCS_OFFLINE
# @DEFAULT_UNSET
# @DESCRIPTION:
# If non-empty, this variable prevents any online operations.

# @ECLASS-VARIABLE: EVCS_UMASK
# @DEFAULT_UNSET
# @DESCRIPTION:
# Set this variable to a custom umask. This is intended to be set by
# users. By setting this to something like 002, it can make life easier
# for people who do development as non-root (but are in the portage
# group) and use FEATURES=userpriv.

# @FUNCTION: _golang-vcs_env_setup
# @INTERNAL
# @DESCRIPTION:
# Create EGO_STORE_DIR if necessary and set GOPATH.
_golang-vcs_env_setup() {
        debug-print-function ${FUNCNAME} "$@"

        local distdir=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}
        : ${EGO_STORE_DIR:=${distdir}/go-src}

        [[ -n ${EVCS_UMASK} ]] && umask_push $EVCS_UMASK

        if [[ ! -d ${EGO_STORE_DIR} ]]; then
                (
                        addwrite /
                        mkdir -p "${EGO_STORE_DIR}"
                ) || die "${ECLASS}: unable to create ${EGO_STORE_DIR}"
        fi

        addwrite "${EGO_STORE_DIR}"
        export GOPATH="${EGO_STORE_DIR}"

        [[ -n ${EVCS_UMASK} ]] && umask_pop
        mkdir -p "${S}" ||
                die "${ECLASS}: unable to create ${S}"
}

# @FUNCTION: _golang-vcs_fetch
# @INTERNAL
# @DESCRIPTION:
# Retrieve the EGO_PN go package along with its dependencies.
_golang-vcs_fetch() {
        debug-print-function ${FUNCNAME} "$@"

        [[ -z ${EGO_PN} ]] &&
                die "${ECLASS}: EGO_PN is not set"

        if [[ -n ${EVCS_OFFLINE} ]]; then
                export GOPATH="${S}:${EGO_STORE_DIR}"
                return
        fi

        [[ -n ${EVCS_UMASK} ]] && umask_push ${EVCS_UMASK}

        set -- go get -d -t -u -v -x "${EGO_PN}"
        echo "$@"
        "$@"

        [[ ! -d "${EGO_STORE_DIR}/src/${EGO_PN}" ]] &&
                die "${ECLASS}: unable to retrieve ${EGO_PN} or a dependency"

        [[ -n ${EVCS_UMASK} ]] && umask_pop
        export GOPATH="${S}:${EGO_STORE_DIR}"
}

golang-vcs_src_fetch() {
        debug-print-function ${FUNCNAME} "$@"

        _golang-vcs_env_setup
        _golang-vcs_fetch
}

golang-vcs_src_unpack() {
        debug-print-function ${FUNCNAME} "$@"

        golang-vcs_src_fetch
}

fi

Attachment: signature.asc
Description: Digital signature

Reply via email to