`go fmt` doesn't seem to respect `-mod=vendor`
https://github.com/golang/go/issues/27841
Instead try using `gofmt` which doesn't trigger downloading dependencies
in the first place. However, `gofmt` affects files under `vendor/`, so
we reset that before checking for changes.
When go autodetects that it is being run as a go mod, and that there is
a vendor directory, it will still try to redownload all sources over the
network, unless you use -mod=vendor to tell it to use that. Additionally,
when using -mod=vendor the compiler will nicely avoid messing with
$GOPATH at all, since it can operate in a completely self-contained
manner.
Take advantage of this, when the detected go version is at least 1.11
(when the -mod flag was introduced).
golang does not natively respect LDFLAGS, but you can pass them on the
command line using -ldflags=-extldflags=...
This is important for distributions, in order to provide common
functionality such as hardening flags.
Also strip the prefixed root source directory from the embedded source
file paths. This is not important information for the debugger, which
should only care about paths relative to $GOPATH, and results in less
build environment metadata leaking into the final binary. (This also
aids in reproducible builds when using different build directories, see
e.g. https://github.com/golang/go/issues/16860)
When packaging for distributions (particularly RPM), it is common
for the packaging tool to install all of the files into a chroot-
style directory structure as a non-privileged user. This is done
to avoid requiring root privileges for packaging (particularly to
avoid issues where the attempt to package causes changes to be
made to the packaging host.
The standard variable used for this (from autotools) is DESTDIR.
This patch adds DESTDIR before the prefix in install.sh to ensure
that when `make install` is run, it will direct output to the
proper location.
Signed-off-by: Stephen Gallagher <sgallagh@redhat.com>
This was from the time when we tried to have hub build even if it wasn't
checkout out within a local GOPATH. This change assumes a working Go
environment.
Go has code coverage tooling for test mode, which temporarily rewrites
the source code to insert annotations which will activate during the
test run and track progress of executed code. Then, upon process
completion, that information is dumped into a coverage report.
We can't use this approach for hub, at least not without substantial
changes. First of all, hub's test coverage is mostly "from the outside",
utilizing Cucumber to invoke the binary with different arguments and
inspect the outputs and result. There are some tests in go, but they are
minimal compared to the cukes.
Second, hub frequently aborts the process on errors via `os.Exit(1)`,
and those scenarios need to be tested too. However, if the process exits
prematurely, the code coverage report will never be generated.
To work around this, I first used the go tool that annotates the source:
go tool cover -mode=set -var=LiveCoverage myfile.go
This injects `LiveCoverage.Count[pos] = 1` lines at appropriate places
all over the source code, and generates a mapping of line/column
positions in the original source.
Then I rewrite those lines to become a method invocation:
coverage.Record(LiveCoverage, pos)
The new `Record` method will immediately append the information to a
code coverage report file as soon as it's invoked. This ensures that
there is coverage information even if the process gets aborted.
This approach works the same for go tests as well as for cukes. They all
append to the same file. Finally, the rest of Go tooling is used to
generate an HTML report of code coverage:
go tool cover -html=cover.out
The only thing that has substansively changed is that Go 1.8 handles
redirect logic more safely than previous versions. This means we can
drop our special handling to avoid following redirects to other
domains. We were only doing that to protect against the possibility
of leaking auth headers. With Go 1.8, the auth headers are not
forwarded when following a redirect to another domain, so we don't
need our special handling any more.
As long as people are attempting to build with the Makefile, the new
check_go_version script should cause the build to stop if our
collaborators aren't using at least version 1.8 of go.
This is helpful for when TMPDIR already has a trailing slash. We can't
be sure that it will on all operating systems, but this will remove it
if it is there.
on each man hub* commands in the shell, the shell reports
warning: ignore bogus filename for the respective .txt present
in the man path.
copying only the man file to the man path solves this issue.