Add Makefiles for Go (#732)

* Add Makefiles for Go

* Makefile edits for Windows

* More how-to for CI debug
This commit is contained in:
John Kerl 2021-11-04 11:27:44 -04:00 committed by GitHub
parent a738c4b0c3
commit c684a7ff2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 93 additions and 11 deletions

View file

@ -23,13 +23,10 @@ jobs:
go-version: 1.15
- name: Build
run: cd go && go build -v mlr.go
run: make build
- name: Test
# In the event of needing to debug failures you can modify `./mlr regtest` verbosity
# using `-v`, `-vv`, or `-vvv`. Commit changes to this file and re-push to GitHub
# and let the GitHub Actions re-run.
run: cd go && go test -v mlr/src/... && ./mlr regtest -s 5
run: make check
- name: PrepareArtifactNonWindows
if: matrix.os != 'windows-latest'

12
Makefile Normal file
View file

@ -0,0 +1,12 @@
build:
make -C go build
check:
make -C go check
install:
make -C go install
make -C man install
# Go does its own dependency management, outside of make.
.PHONY: build

22
go/Makefile Normal file
View file

@ -0,0 +1,22 @@
# TODO: take from ../configure
INSTALLDIR=/usr/local/bin
build:
go build
check:
# Unit tests (small number)
go test -v mlr/src/...
# Regression tests (large number)
#
# See ./regression_test.go for information on how to get more details
# for debugging. TL;DR is for CI jobs, we have 'go test -v'; for
# interactive use, instead of 'go test -v' simply use 'mlr regtest
# -vvv' or 'mlr regtest -s 20'. See also src/auxents/regtest.
go test -v
install: build
cp mlr $(INSTALLDIR)
# Go does its own dependency management, outside of make.
.PHONY: build

View file

@ -1,6 +1,8 @@
package main
import (
"fmt"
"os"
"testing"
"mlr/src/auxents/regtest"
@ -11,12 +13,52 @@ import (
// is a standard location so people can get at them via 'go test'. Please see
// (as of this writing) src/auxents/regtest for the Miller regtest package.
func TestRegression(t *testing.T) {
// How much detail to show? There are thousands of cases, organized into a
// few hundred top-level directories under ./regtest/cases.
//
// Default behavior is to show PASS/FAIL for those top-level directories.
// If (for whatever reason) lots of tests are systematically failing then
// verbosityLevel = 3 for all cases is probably too much output to be
// useful.
//
// Also note our regtest framework supports four verbosity levels, 'mlr
// regtest' (0) through 'mlr regtest -vvv' (3), while 'go test' has only
// 'go test' and 'go test -v'. Our regtest framework also has 'mlr regtest
// -s 20' which means *re-run* up to 20 failing tests (after having failed
// once with verbosityLevel = 0) as if those had been invoked with
// verbosityLevel = 3.
//
// What we do is:
// * go test: like 'mlr regtest'
// * go test -v: like 'mlr regtest -s 20'
//
// This is (I hope) sufficient flexibility for use in GitHub Actions
// continuous-integration jobs. If more detail is needed then one may:
//
// * For CI debugging: simply edit the below parameters verbosityLevel
// and firstNFailsToShow and re-push to GitHub.
// * For interactive debug: run 'mlr regtest -v', 'mlr regtest -vv', 'mlr
// regtest -vvv' instead of going through 'go test'.
firstNFailsToShow := 0
if testing.Verbose() {
firstNFailsToShow = 20
}
// Let the tests find ./mlr
cwd, err := os.Getwd()
if err != nil {
fmt.Fprintln(os.Stderr, "mlr: could not find current working directory.")
os.Exit(1)
}
path := os.Getenv("PATH")
os.Setenv("PATH", cwd + ":" + path)
regtester := regtest.NewRegTester(
"mlr", // exeName
false, // doPopulate
0, // verbosityLevel
false, // plainMode
0, // firstNFailsToShow
firstNFailsToShow,
)
paths := []string{} // use default

View file

@ -2,6 +2,9 @@
PUNCHDOWN LIST
* ./configure equivalent
o make:
- windoc note 'choco install make'
- (works in GH CI due to their toolchain)
? twi-dm re all-contribs: all-contributors.org
* nikos materials -> fold in

View file

@ -5,24 +5,30 @@
INSTALLDIR=/usr/local/share/man/man1
INSTALLHOME=$(HOME)/man/man1
top: .always
# This is normally done only on a development host. Through CI and
# package-installer, mlr.1 should be treated as an already-built artifact,
# needing only to be copied to its install dir.
build: .always
echo mkman start
./mkman.rb > mlr.1
./mkman.rb | groff -man -Tascii | col -b | expand -8 > manpage.txt
cp manpage.txt ../docs/src/
echo mkman end
# These targets are only for local dev work.
install: top
install:
mkdir -p $(INSTALLDIR)
cp mlr.1 $(INSTALLDIR)/mlr.1
installhome: top
# ----------------------------------------------------------------
# These targets are only for local dev work.
installhome: build
mkdir -p $(INSTALLHOME)
cp mlr.1 $(INSTALLHOME)/mlr.1
# This is an out-of-tree operation so do it only if the user is using out-of-tree manpage setup
# (e.g. their $MANPATH as $HOME/man as a component).
maybeinstallhome: top
maybeinstallhome: build
if [ -d $(INSTALLHOME) ]; then cp mlr.1 $(INSTALLHOME)/mlr.1; else echo No $(INSTALLHOME) -- skipping ; fi
# ----------------------------------------------------------------
.always:
true