diff --git a/Makefile b/Makefile index d83c4f3..13d3a03 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ else endif GOBIN ?= $(shell go env GOPATH)/bin -GOMAKE ?= github.com/tkrop/go-make@v0.0.23 +GOMAKE ?= github.com/tkrop/go-make@v0.0.24 TARGETS := $(shell command -v go-make >/dev/null || \ go install $(GOMAKE) && go-make targets) diff --git a/Makefile.base b/Makefile.base index 5d26982..d5ef3ca 100644 --- a/Makefile.base +++ b/Makefile.base @@ -64,13 +64,13 @@ TOOLS_GO := $(TOOLS_GO) \ github.com/icholy/gomajor \ github.com/golang/mock/mockgen \ github.com/tkrop/go-testing/cmd/mock \ - github.com/tkrop/go-make + github.com/tkrop/go-make@v0.0.24 TOOLS_SH := $(TOOLS_SH) \ github.com/anchore/syft \ github.com/anchore/grype -# function for correct gol-package handling. -go-pkg = $(shell awk -v mode="$(1)" -v filter="$(3)" -v not="$(4)" ' \ +# function for correct go-package handling. +go-pkg = $(shell awk -v mode="$(2)" -v filter="$(3)" -v not="$(4)" ' \ BEGIN { FS = "[/@]"; RS = "[ \n\r]" } { \ field = NF; \ if (version = index($$0, "@")) { field-- } \ @@ -98,8 +98,15 @@ go-pkg = $(shell awk -v mode="$(1)" -v filter="$(3)" -v not="$(4)" ' \ if (version) { \ return substr($$0, 1, index($$0, "@") - 1) \ } else { return $$0 } \ - }' <<<"$(2)") - + }' <<<"$(1)") +git-pkg = $(shell awk -v mode="$(2)" ' \ + BEGIN { RS = "[ \n\r]" } { \ + if (mode == "repo") { \ + print "git@" gensub("/",":",1,substr($$0, 1, index($$0, "@") - 1)) ".git" \ + } else if (mode == "tag") { \ + print substr($$0, index($$0, "@") + 1) \ + } \ + }' <<<"$(1)") BROWSER ?= xdg-open VERSION ?= snapshot @@ -220,8 +227,8 @@ COMMANDS := $(shell $(FIND) -name "main.go" | xargs -r readlink -f | \ COMMANDS_PKG := $(shell $(FIND) -name "main.go" | xargs -r readlink -f | \ sed -E "s/^(.*\/([^/]*))\/main.go$$/\2=\1/; s|$(CURDIR)|.|") COMMANDS_REGEX := $(shell echo "^$(COMMANDS)$$" | tr ' ' '|' ) -COMMANDS_GO := $(call go-pkg,cmd,$(TOOLS_GO),$(COMMANDS_REGEX),not) -COMMANDS_SH := $(call go-pkg,cmd,$(TOOLS_SH),$(COMMANDS_REGEX),not) +COMMANDS_GO := $(call go-pkg,$(TOOLS_GO),cmd,$(COMMANDS_REGEX),not) +COMMANDS_SH := $(call go-pkg,$(TOOLS_SH),cmd,$(COMMANDS_REGEX),not) # Setup optimized golang mock setup environment. @@ -368,15 +375,21 @@ targets:: else cat -; fi || true; #@ create a clone of the base repository to update from. -BASE ?= git@github.com:tkrop/go-make.git -setup/base:: # TODO: support cloning of a distinct revision. +GOMAKE ?= $(call go-pkg,$(TOOLS_GO),install,^go-make$$) +setup/base:: @$(eval BASEDIR = $(shell mktemp -d)) ( \ trap "rm -rf $${DIR}" INT TERM EXIT; \ while pgrep $(MAKE) > /dev/null; do sleep 1; done; \ rm -rf $${DIR} \ ) & \ + REPO="$(call git-pkg,$(GOMAKE),repo)"; TAG="$(call git-pkg,$(GOMAKE),tag)"; \ git clone --no-checkout --depth 2 --single-branch \ - --branch main $(BASE) $(BASEDIR) 2> /dev/null; \ + --branch main $${REPO} $(BASEDIR) 2> /dev/null || \ + ( echo "error: cloning repo $${REPO} [$${TAG}]" >"/dev/stderr"; exit 1 ) && \ + if [ "$${TAG}" != "latest" ]; then \ + cd $(BASEDIR) && git checkout tags/$${TAG} 2> /dev/null || \ + ( echo "error: finding tag $${REPO} [$${TAG}]" >"/dev/stderr"; exit 1 ) \ + fi; ## Git-Support: targets for standard git commands (experimental). @@ -397,7 +410,7 @@ git-graph:: --pretty=format:"%Cred%h %Cgreen%ad%Creset | %s $${SUFFIX}"; #@ cleans up all local branches except the default and current branch. git-clean:: - @BRANCH="$$(git branch --show-current)"; \ + @git fetch; BRANCH="$$(git branch --show-current)"; \ MAIN="$$(git remote show origin | grep "HEAD branch:" | cut -d ' ' -f 5)"; \ BRANCHES=($$(git branch | cut -c 3- | grep -vw "$${MAIN}\|$${BRANCH}")); \ for BRANCH in $"$${BRANCHES[@]}"; do \ @@ -405,15 +418,15 @@ git-clean:: done; #@ checks out default branch and cleans up all local branches except the default. git-reset:: - @BRANCH="$$(git branch --show-current)"; \ + @git fetch; BRANCH="$$(git branch --show-current)"; \ MAIN="$$(git remote show origin | grep "HEAD branch:" | cut -d ' ' -f 5)"; \ if [ "$${BRANCH}" != "$${MAIN}" ]; then git checkout "$${MAIN}" || exit 1; fi; \ for BRANCH in $$(git branch | cut -c 3- | grep -vw "$${MAIN}"); do \ git branch --delete "$${BRANCH}"; \ done; - #@ # creates a branch with the current change set using next issue. git-create:: git-create-feature +# TODO: check whether I'm on the default branch and on remote HEAD. git-create-fix git-create-chore git-create-feature:: git-create-%: @BRANCH="$(firstword $(RUNARGS))"; \ MESSAGE="$(wordlist 2,$(words $(RUNARGS)),$(RUNARGS))"; \ @@ -555,7 +568,7 @@ test-go = \ fi; \ echo -e "\t$${GOCHANGE} your local go version to $${VERSION} or "; \ echo -e "\trun 'make update-go $${VERSION}' to adjust the project!"; \ - exit -1; \ + exit 1; \ fi; \ done; @@ -1011,7 +1024,7 @@ install-all:: $(TARGETS_INSTALL_ALL) # install go tools used by the project. $(TARGETS_INSTALL_GO):: install-%: $(GOBIN)/% $(addprefix $(GOBIN)/,$(COMMANDS_GO)): $(GOBIN)/%: - go install $(call go-pkg,install,$(TOOLS_GO),^$*$$); + go install $(call go-pkg,$(TOOLS_GO),install,^$*$$); # install go tools providing an install.sh script. $(TARGETS_INSTALL_SH):: install-%: $(GOBIN)/% $(addprefix $(GOBIN)/,$(COMMANDS_SH)): $(GOBIN)/%: @@ -1041,7 +1054,7 @@ uninstall-all:: $(TARGETS_UNINSTALL_ALL) # uninstall go tools used by the project. $(TARGETS_UNINSTALL_GO):: uninstall-%: - @#PACKAGE=$(call go-pkg,strip,$(TOOLS_GO),^$*$$); \ + @#PACKAGE=$(call go-pkg,$(TOOLS_GO),strip,^$*$$); \ rm -rf $(wildcard $(GOBIN)/$* $(GOBIN)/$*.config); # uninstall npm based tools used by the project. $(TARGETS_UNINSTALL_NPM):: uninstall-%: @@ -1359,7 +1372,7 @@ update-tools:: $(TARGETS_UPDATE_GO) $(TARGETS_INSTALL_SH) $(TARGETS_INSTALL_NPM) # update go tools used by the project. $(TARGETS_UPDATE_GO):: update-%: - go install $(call go-pkg,update,$(TOOLS_GO),^$*$$); + go install $(call go-pkg,$(TOOLS_GO),update,^$*$$); ## Custom: custom extension targets. diff --git a/Makefile.ext b/Makefile.ext index bee084e..02fa97d 100644 --- a/Makefile.ext +++ b/Makefile.ext @@ -3,7 +3,8 @@ clean:: bump:: @VERSION="$$(cat VERSION)"; \ - sed -i -e "s#\(github.com/tkrop/go-make@v\)[^ ]*#\1$${VERSION}#" Makefile; + sed -i -e "s#\(github.com[/:]tkrop/go-make@v\)[^ ]*#\1$${VERSION}#" \ + Makefile Makefile.base; \ cp Makefile Makefile.base config; commit:: diff --git a/VERSION b/VERSION index df5db66..b056f41 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.23 +0.0.24 diff --git a/config/Makefile b/config/Makefile index d83c4f3..13d3a03 100644 --- a/config/Makefile +++ b/config/Makefile @@ -8,7 +8,7 @@ else endif GOBIN ?= $(shell go env GOPATH)/bin -GOMAKE ?= github.com/tkrop/go-make@v0.0.23 +GOMAKE ?= github.com/tkrop/go-make@v0.0.24 TARGETS := $(shell command -v go-make >/dev/null || \ go install $(GOMAKE) && go-make targets) diff --git a/config/Makefile.base b/config/Makefile.base index 5d26982..d5ef3ca 100644 --- a/config/Makefile.base +++ b/config/Makefile.base @@ -64,13 +64,13 @@ TOOLS_GO := $(TOOLS_GO) \ github.com/icholy/gomajor \ github.com/golang/mock/mockgen \ github.com/tkrop/go-testing/cmd/mock \ - github.com/tkrop/go-make + github.com/tkrop/go-make@v0.0.24 TOOLS_SH := $(TOOLS_SH) \ github.com/anchore/syft \ github.com/anchore/grype -# function for correct gol-package handling. -go-pkg = $(shell awk -v mode="$(1)" -v filter="$(3)" -v not="$(4)" ' \ +# function for correct go-package handling. +go-pkg = $(shell awk -v mode="$(2)" -v filter="$(3)" -v not="$(4)" ' \ BEGIN { FS = "[/@]"; RS = "[ \n\r]" } { \ field = NF; \ if (version = index($$0, "@")) { field-- } \ @@ -98,8 +98,15 @@ go-pkg = $(shell awk -v mode="$(1)" -v filter="$(3)" -v not="$(4)" ' \ if (version) { \ return substr($$0, 1, index($$0, "@") - 1) \ } else { return $$0 } \ - }' <<<"$(2)") - + }' <<<"$(1)") +git-pkg = $(shell awk -v mode="$(2)" ' \ + BEGIN { RS = "[ \n\r]" } { \ + if (mode == "repo") { \ + print "git@" gensub("/",":",1,substr($$0, 1, index($$0, "@") - 1)) ".git" \ + } else if (mode == "tag") { \ + print substr($$0, index($$0, "@") + 1) \ + } \ + }' <<<"$(1)") BROWSER ?= xdg-open VERSION ?= snapshot @@ -220,8 +227,8 @@ COMMANDS := $(shell $(FIND) -name "main.go" | xargs -r readlink -f | \ COMMANDS_PKG := $(shell $(FIND) -name "main.go" | xargs -r readlink -f | \ sed -E "s/^(.*\/([^/]*))\/main.go$$/\2=\1/; s|$(CURDIR)|.|") COMMANDS_REGEX := $(shell echo "^$(COMMANDS)$$" | tr ' ' '|' ) -COMMANDS_GO := $(call go-pkg,cmd,$(TOOLS_GO),$(COMMANDS_REGEX),not) -COMMANDS_SH := $(call go-pkg,cmd,$(TOOLS_SH),$(COMMANDS_REGEX),not) +COMMANDS_GO := $(call go-pkg,$(TOOLS_GO),cmd,$(COMMANDS_REGEX),not) +COMMANDS_SH := $(call go-pkg,$(TOOLS_SH),cmd,$(COMMANDS_REGEX),not) # Setup optimized golang mock setup environment. @@ -368,15 +375,21 @@ targets:: else cat -; fi || true; #@ create a clone of the base repository to update from. -BASE ?= git@github.com:tkrop/go-make.git -setup/base:: # TODO: support cloning of a distinct revision. +GOMAKE ?= $(call go-pkg,$(TOOLS_GO),install,^go-make$$) +setup/base:: @$(eval BASEDIR = $(shell mktemp -d)) ( \ trap "rm -rf $${DIR}" INT TERM EXIT; \ while pgrep $(MAKE) > /dev/null; do sleep 1; done; \ rm -rf $${DIR} \ ) & \ + REPO="$(call git-pkg,$(GOMAKE),repo)"; TAG="$(call git-pkg,$(GOMAKE),tag)"; \ git clone --no-checkout --depth 2 --single-branch \ - --branch main $(BASE) $(BASEDIR) 2> /dev/null; \ + --branch main $${REPO} $(BASEDIR) 2> /dev/null || \ + ( echo "error: cloning repo $${REPO} [$${TAG}]" >"/dev/stderr"; exit 1 ) && \ + if [ "$${TAG}" != "latest" ]; then \ + cd $(BASEDIR) && git checkout tags/$${TAG} 2> /dev/null || \ + ( echo "error: finding tag $${REPO} [$${TAG}]" >"/dev/stderr"; exit 1 ) \ + fi; ## Git-Support: targets for standard git commands (experimental). @@ -397,7 +410,7 @@ git-graph:: --pretty=format:"%Cred%h %Cgreen%ad%Creset | %s $${SUFFIX}"; #@ cleans up all local branches except the default and current branch. git-clean:: - @BRANCH="$$(git branch --show-current)"; \ + @git fetch; BRANCH="$$(git branch --show-current)"; \ MAIN="$$(git remote show origin | grep "HEAD branch:" | cut -d ' ' -f 5)"; \ BRANCHES=($$(git branch | cut -c 3- | grep -vw "$${MAIN}\|$${BRANCH}")); \ for BRANCH in $"$${BRANCHES[@]}"; do \ @@ -405,15 +418,15 @@ git-clean:: done; #@ checks out default branch and cleans up all local branches except the default. git-reset:: - @BRANCH="$$(git branch --show-current)"; \ + @git fetch; BRANCH="$$(git branch --show-current)"; \ MAIN="$$(git remote show origin | grep "HEAD branch:" | cut -d ' ' -f 5)"; \ if [ "$${BRANCH}" != "$${MAIN}" ]; then git checkout "$${MAIN}" || exit 1; fi; \ for BRANCH in $$(git branch | cut -c 3- | grep -vw "$${MAIN}"); do \ git branch --delete "$${BRANCH}"; \ done; - #@ # creates a branch with the current change set using next issue. git-create:: git-create-feature +# TODO: check whether I'm on the default branch and on remote HEAD. git-create-fix git-create-chore git-create-feature:: git-create-%: @BRANCH="$(firstword $(RUNARGS))"; \ MESSAGE="$(wordlist 2,$(words $(RUNARGS)),$(RUNARGS))"; \ @@ -555,7 +568,7 @@ test-go = \ fi; \ echo -e "\t$${GOCHANGE} your local go version to $${VERSION} or "; \ echo -e "\trun 'make update-go $${VERSION}' to adjust the project!"; \ - exit -1; \ + exit 1; \ fi; \ done; @@ -1011,7 +1024,7 @@ install-all:: $(TARGETS_INSTALL_ALL) # install go tools used by the project. $(TARGETS_INSTALL_GO):: install-%: $(GOBIN)/% $(addprefix $(GOBIN)/,$(COMMANDS_GO)): $(GOBIN)/%: - go install $(call go-pkg,install,$(TOOLS_GO),^$*$$); + go install $(call go-pkg,$(TOOLS_GO),install,^$*$$); # install go tools providing an install.sh script. $(TARGETS_INSTALL_SH):: install-%: $(GOBIN)/% $(addprefix $(GOBIN)/,$(COMMANDS_SH)): $(GOBIN)/%: @@ -1041,7 +1054,7 @@ uninstall-all:: $(TARGETS_UNINSTALL_ALL) # uninstall go tools used by the project. $(TARGETS_UNINSTALL_GO):: uninstall-%: - @#PACKAGE=$(call go-pkg,strip,$(TOOLS_GO),^$*$$); \ + @#PACKAGE=$(call go-pkg,$(TOOLS_GO),strip,^$*$$); \ rm -rf $(wildcard $(GOBIN)/$* $(GOBIN)/$*.config); # uninstall npm based tools used by the project. $(TARGETS_UNINSTALL_NPM):: uninstall-%: @@ -1359,7 +1372,7 @@ update-tools:: $(TARGETS_UPDATE_GO) $(TARGETS_INSTALL_SH) $(TARGETS_INSTALL_NPM) # update go tools used by the project. $(TARGETS_UPDATE_GO):: update-%: - go install $(call go-pkg,update,$(TOOLS_GO),^$*$$); + go install $(call go-pkg,$(TOOLS_GO),update,^$*$$); ## Custom: custom extension targets. diff --git a/internal/make/fixtures/targets-trace.err b/internal/make/fixtures/targets-trace.err index dbf319d..514fd4f 100644 --- a/internal/make/fixtures/targets-trace.err +++ b/internal/make/fixtures/targets-trace.err @@ -1,5 +1,6 @@ call: targets --trace info: {"path":"github.com/tkrop/go-make","repo":"git@github.com:tkrop/go-make","build":"0001-01-01T00:00:00Z","commit":"0001-01-01T00:00:00Z","dirty":true,"go":"{{GOVERSION}}","platform":"{{PLATFORM}}","compiler":"{{COMPILER}}"} -exec: make --file Makefile.base targets --trace [go-make/internal/make] -Makefile.base:18: info: please customize variables in Makefile.vars -Makefile.base:211: info: please define custom functions in Makefile.defs +exec: git status --short [make.test.config] +exec: make --file make.test.config/Makefile.base targets --trace [go-make/internal/make] +make.test.config/Makefile.base:18: info: please customize variables in Makefile.vars +make.test.config/Makefile.base:218: info: please define custom functions in Makefile.defs diff --git a/internal/make/fixtures/targets-trace.out b/internal/make/fixtures/targets-trace.out index ca11336..d6f7ce1 100644 --- a/internal/make/fixtures/targets-trace.out +++ b/internal/make/fixtures/targets-trace.out @@ -1,6 +1,6 @@ -Makefile.base:362: target 'targets' does not exist +make.test.config/Makefile.base:369: target 'targets' does not exist make --no-builtin-rules --no-builtin-variables --print-data-base \ - --question --makefile=Makefile.base 2>/dev/null | \ + --question --makefile=make.test.config/Makefile.base 2>/dev/null | \ if [ "" != "raw" ]; then awk -v RS= -F: ' \ /(^|\n)# Files(\n|$)/,/(^|\n)# Finished Make data base/ { \ if ($1 !~ "^[#.]") { print $1 } \ diff --git a/internal/make/fixtures/targets.err b/internal/make/fixtures/targets.err index 50784ee..2bc2be6 100644 --- a/internal/make/fixtures/targets.err +++ b/internal/make/fixtures/targets.err @@ -1,2 +1,2 @@ -Makefile.base:18: info: please customize variables in Makefile.vars -Makefile.base:211: info: please define custom functions in Makefile.defs +make.test.config/Makefile.base:18: info: please customize variables in Makefile.vars +make.test.config/Makefile.base:218: info: please define custom functions in Makefile.defs diff --git a/internal/make/make.go b/internal/make/make.go index c7d0072..b765108 100644 --- a/internal/make/make.go +++ b/internal/make/make.go @@ -86,6 +86,8 @@ var ( cmdGitClone = []string{"git", "clone", "--depth=1"} // Base command array for `git fetch` arguments. cmdGitFetch = []string{"git", "fetch"} + // Base command array for `git status`` arguments. + cmdGitStatus = []string{"git", "status", "--short"} // Base command array for `git reset --hard` arguments. cmdGitHashReset = []string{"git", "reset", "--hard"} // Base command array for `git rev-list --max-count=1` arguments. @@ -102,6 +104,11 @@ func CmdGitClone(repo, dir string) []string { return append(cmdGitClone, repo, dir) } +// CmdGitStatus creates the argument array of a `git status` command. +func CmdGitStatus() []string { + return cmdGitStatus +} + // CmdGitFetch creates the argument array of a `git fetch` command using the // given source repository. func CmdGitFetch(repo string) []string { @@ -189,7 +196,9 @@ func (gm *GoMake) updateGoMakeRepo() error { } // Do never update on dirty revisions. - if gm.Info.Dirty { + if ok, err := gm.repoIsDirty(); err != nil { + return err + } else if ok { return nil } @@ -225,6 +234,16 @@ func (gm *GoMake) cloneGoMakeExec(repo string) error { CmdGitClone(repo, gm.MakeDir)...) } +// repoIsDirty returns whether the go-make command repository is dirty. +func (gm *GoMake) repoIsDirty() (bool, error) { + builder := strings.Builder{} + if err := gm.exec(&builder, gm.Stderr, gm.MakeDir, + CmdGitStatus()...); err != nil { + return false, err + } + return strings.TrimSpace(builder.String()) != "", nil +} + // updateRevision updates the current revision of the go-make command // repository as required by the go-make command. If the update fails the // an error is returned. diff --git a/internal/make/make_test.go b/internal/make/make_test.go index c9f0322..c13d8f4 100644 --- a/internal/make/make_test.go +++ b/internal/make/make_test.go @@ -54,8 +54,8 @@ const ( ) var ( - // infoDirty without version and revision hash. - infoDirty = info.NewInfo(goMakePath, "", "", "", "", true) + // infoBase without version and revision hash. + infoBase = info.NewInfo(goMakePath, "", "", "", "", true) // infoTag with version and revision hash from git. infoTag = info.NewInfo(goMakePath, @@ -211,36 +211,55 @@ var testMakeParams = map[string]MakeParams{ }, "check go-make version": { mockSetup: mock.Chain( - LogInfo("stdout", infoDirty, true), + LogInfo("stdout", infoBase, true), ), - info: infoDirty, + info: infoBase, args: argsVersion, }, - "dirty go-make to run target": { + "go-make dirty target": { mockSetup: mock.Chain( + Exec("builder", "stderr", goMakeDirExist, + make.CmdGitStatus(), nil, "m Makefile.base", ""), Exec("stdout", "stderr", dirExec, make.CmdMakeTargets(make.Makefile, argsTarget...), nil, "", ""), ), - info: infoDirty, + info: infoBase, args: argsTarget, }, - "dirty go-make failed": { + "go-make dirty target failed": { mockSetup: mock.Chain( + Exec("builder", "stderr", goMakeDirExist, + make.CmdGitStatus(), nil, "m Makefile.base", ""), Exec("stdout", "stderr", dirExec, make.CmdMakeTargets(make.Makefile, argsTarget...), errAny, "", ""), LogCall("stderr", argsTarget), - LogInfo("stderr", infoDirty, false), + LogInfo("stderr", infoBase, false), LogError("stderr", "execute make", make.NewErrCallFailed( make.CmdMakeTargets(make.Makefile, argsTarget...), errAny)), ), - info: infoDirty, + info: infoBase, args: argsTarget, expectError: make.NewErrCallFailed( make.CmdMakeTargets(make.Makefile, argsTarget...), errAny), expectExit: 2, }, + "go-make dirty target status failed": { + mockSetup: mock.Chain( + Exec("builder", "stderr", goMakeDirExist, + make.CmdGitStatus(), errAny, "", ""), + LogCall("stderr", argsTarget), + LogInfo("stderr", infoBase, false), + LogError("stderr", "update config", make.NewErrCallFailed( + make.CmdGitStatus(), errAny)), + ), + info: infoBase, + args: argsTarget, + expectError: make.NewErrCallFailed(make.CmdGitStatus(), errAny), + expectExit: 1, + }, + "clone go-make clone failed": { mockSetup: mock.Chain( Exec("stderr", "stderr", dirExec, @@ -248,11 +267,11 @@ var testMakeParams = map[string]MakeParams{ Exec("stderr", "stderr", dirExec, make.CmdGitClone(goMakeHTTP, goMakeDirNew), errAny, "", ""), LogCall("stderr", argsTarget), - LogInfo("stderr", infoDirty, false), + LogInfo("stderr", infoBase, false), LogError("stderr", "update config", make.NewErrCallFailed( make.CmdGitClone(goMakeHTTP, goMakeDirNew), errAny)), ), - info: infoDirty, + info: infoBase, args: argsTarget, goMakeDir: goMakeDirNew, expectError: make.NewErrCallFailed( @@ -260,41 +279,47 @@ var testMakeParams = map[string]MakeParams{ expectExit: 1, }, - // dirty option targets with trace. + // option targets with trace. "check go-make completion bash traced": { mockSetup: mock.Chain( LogCall("stderr", argsTraceBash), - LogInfo("stderr", infoDirty, false), + LogInfo("stderr", infoBase, false), LogMessage("stdout", make.BashCompletion), ), - info: infoDirty, + info: infoBase, args: argsTraceBash, }, "check go-make version traced": { mockSetup: mock.Chain( LogCall("stderr", argsTraceVersion), - LogInfo("stderr", infoDirty, false), - LogInfo("stdout", infoDirty, true), + LogInfo("stderr", infoBase, false), + LogInfo("stdout", infoBase, true), ), - info: infoDirty, + info: infoBase, args: argsTraceVersion, }, - "dirty go-make to run target traced": { + "go-make dirty run target traced": { mockSetup: mock.Chain( LogCall("stderr", argsTraceTarget), - LogInfo("stderr", infoDirty, false), + LogInfo("stderr", infoBase, false), + LogExec("stderr", goMakeDirExist, make.CmdGitStatus()), + Exec("builder", "stderr", goMakeDirExist, + make.CmdGitStatus(), nil, "m Makefile.base", ""), LogExec("stderr", dirExec, make.CmdMakeTargets(make.Makefile, argsTraceTarget...)), Exec("stdout", "stderr", dirExec, make.CmdMakeTargets(make.Makefile, argsTraceTarget...), nil, "", ""), ), - info: infoDirty, + info: infoBase, args: argsTraceTarget, }, - "dirty go-make failed traced": { + "go-make dirty run target failed traced": { mockSetup: mock.Chain( LogCall("stderr", argsTraceTarget), - LogInfo("stderr", infoDirty, false), + LogInfo("stderr", infoBase, false), + LogExec("stderr", goMakeDirExist, make.CmdGitStatus()), + Exec("builder", "stderr", goMakeDirExist, + make.CmdGitStatus(), nil, "m Makefile.base", ""), LogExec("stderr", dirExec, make.CmdMakeTargets(make.Makefile, argsTraceTarget...)), Exec("stdout", "stderr", dirExec, @@ -302,7 +327,7 @@ var testMakeParams = map[string]MakeParams{ LogError("stderr", "execute make", make.NewErrCallFailed( make.CmdMakeTargets(make.Makefile, argsTraceTarget...), errAny)), ), - info: infoDirty, + info: infoBase, args: argsTraceTarget, expectError: make.NewErrCallFailed( make.CmdMakeTargets(make.Makefile, argsTraceTarget...), errAny), @@ -311,7 +336,7 @@ var testMakeParams = map[string]MakeParams{ "clone go-make failed traced": { mockSetup: mock.Chain( LogCall("stderr", argsTraceTarget), - LogInfo("stderr", infoDirty, false), + LogInfo("stderr", infoBase, false), LogExec("stderr", dirExec, make.CmdGitClone(goMakeGit, goMakeDirNew)), Exec("stderr", "stderr", dirExec, @@ -323,7 +348,7 @@ var testMakeParams = map[string]MakeParams{ LogError("stderr", "update config", make.NewErrCallFailed( make.CmdGitClone(goMakeHTTP, goMakeDirNew), errAny)), ), - info: infoDirty, + info: infoBase, args: argsTraceTarget, goMakeDir: goMakeDirNew, expectError: make.NewErrCallFailed( @@ -575,6 +600,7 @@ var testMakeParams = map[string]MakeParams{ // check targets without trace. "check go-make head hash failed": { mockSetup: mock.Chain( + Exec("builder", "stderr", goMakeDirExist, make.CmdGitStatus(), nil, "", ""), Exec("builder", "stderr", goMakeDirExist, make.CmdGitHashHead(), errAny, "", ""), LogCall("stderr", argsTarget), @@ -591,6 +617,7 @@ var testMakeParams = map[string]MakeParams{ "check go-make head now failed": { mockSetup: mock.Chain( + Exec("builder", "stderr", goMakeDirExist, make.CmdGitStatus(), nil, "", ""), Exec("builder", "stderr", goMakeDirExist, make.CmdGitHashHead(), nil, revisionHead, ""), Exec("builder", "stderr", goMakeDirExist, @@ -609,6 +636,7 @@ var testMakeParams = map[string]MakeParams{ "check go-make tag log failed": { mockSetup: mock.Chain( + Exec("builder", "stderr", goMakeDirExist, make.CmdGitStatus(), nil, "", ""), Exec("builder", "stderr", goMakeDirExist, make.CmdGitHashTag(infoTag.Revision), errAny, revisionDefault, ""), LogCall("stderr", argsTarget), @@ -626,6 +654,7 @@ var testMakeParams = map[string]MakeParams{ "check go-make tag fetch failed": { mockSetup: mock.Chain( + Exec("builder", "stderr", goMakeDirExist, make.CmdGitStatus(), nil, "", ""), Exec("builder", "stderr", goMakeDirExist, make.CmdGitHashTag(infoTag.Revision), nil, revisionDefault, ""), Exec("builder", "stderr", goMakeDirExist, @@ -649,6 +678,7 @@ var testMakeParams = map[string]MakeParams{ "check go-make head to run target": { mockSetup: mock.Chain( + Exec("builder", "stderr", goMakeDirExist, make.CmdGitStatus(), nil, "", ""), Exec("builder", "stderr", goMakeDirExist, make.CmdGitHashHead(), nil, revisionHead, ""), Exec("builder", "stderr", goMakeDirExist, @@ -664,6 +694,7 @@ var testMakeParams = map[string]MakeParams{ "check go-make hash to run target": { mockSetup: mock.Chain( + Exec("builder", "stderr", goMakeDirExist, make.CmdGitStatus(), nil, "", ""), Exec("builder", "stderr", goMakeDirExist, make.CmdGitHashNow(), nil, revisionHead, ""), Exec("stderr", "stderr", goMakeDirExist, @@ -679,6 +710,7 @@ var testMakeParams = map[string]MakeParams{ "check go-make tag to run target": { mockSetup: mock.Chain( + Exec("builder", "stderr", goMakeDirExist, make.CmdGitStatus(), nil, "", ""), Exec("builder", "stderr", goMakeDirExist, make.CmdGitHashTag(infoTag.Revision), nil, revisionDefault, ""), Exec("builder", "stderr", goMakeDirExist, @@ -696,6 +728,7 @@ var testMakeParams = map[string]MakeParams{ "check go-make tag fetch to run target": { mockSetup: mock.Chain( + Exec("builder", "stderr", goMakeDirExist, make.CmdGitStatus(), nil, "", ""), Exec("builder", "stderr", goMakeDirExist, make.CmdGitHashTag(infoTag.Revision), nil, revisionDefault, ""), Exec("builder", "stderr", goMakeDirExist, @@ -725,6 +758,8 @@ var testMakeParams = map[string]MakeParams{ mockSetup: mock.Chain( LogCall("stderr", argsTraceTarget), LogInfo("stderr", infoHead, false), + LogExec("stderr", goMakeDirExist, make.CmdGitStatus()), + Exec("builder", "stderr", goMakeDirExist, make.CmdGitStatus(), nil, "", ""), LogExec("stderr", goMakeDirExist, make.CmdGitHashHead()), Exec("builder", "stderr", goMakeDirExist, make.CmdGitHashHead(), nil, revisionHead, ""), @@ -746,6 +781,8 @@ var testMakeParams = map[string]MakeParams{ mockSetup: mock.Chain( LogCall("stderr", argsTraceTarget), LogInfo("stderr", infoHash, false), + LogExec("stderr", goMakeDirExist, make.CmdGitStatus()), + Exec("builder", "stderr", goMakeDirExist, make.CmdGitStatus(), nil, "", ""), LogExec("stderr", goMakeDirExist, make.CmdGitHashNow()), Exec("builder", "stderr", goMakeDirExist, make.CmdGitHashNow(), nil, revisionHead, ""), @@ -768,6 +805,8 @@ var testMakeParams = map[string]MakeParams{ mockSetup: mock.Chain( LogCall("stderr", argsTraceTarget), LogInfo("stderr", infoTag, false), + LogExec("stderr", goMakeDirExist, make.CmdGitStatus()), + Exec("builder", "stderr", goMakeDirExist, make.CmdGitStatus(), nil, "", ""), LogExec("stderr", goMakeDirExist, make.CmdGitHashTag(infoTag.Revision)), Exec("builder", "stderr", goMakeDirExist, @@ -838,7 +877,7 @@ var ( // regexMatchTestDir is the regular expression that is used to remove the // test execution path dependent parts. regexMatchTestDir = regexp.MustCompile( - "(?m)/tmp/go-build.*/make.test.config/") + "(?m)/tmp/go-build.*/(make.test.config/?)") // regexMatchBuildDir is the regular expression that is used to remove the // build path dependent parts. //lint:ignore S1007 // Escaping makes it less readable. @@ -859,7 +898,7 @@ var ( func FilterMakeOutput(str string) string { str = regexMatchMakeLog.ReplaceAllString(str, "") - str = regexMatchTestDir.ReplaceAllString(str, "") + str = regexMatchTestDir.ReplaceAllString(str, "$1") str = regexMatchSourceDir.ReplaceAllString(str, "$1$3$4") return str } @@ -878,31 +917,31 @@ type MakeExecParams struct { var testMakeExecParams = map[string]MakeExecParams{ "go-make version": { - info: infoDirty, + info: infoBase, args: []string{"go-make", "--version"}, expectStdout: ReadFile(fixtures, "fixtures/version.out"), }, "go-make version trace": { - info: infoDirty, + info: infoBase, args: []string{"go-make", "--trace", "--version"}, expectStdout: ReadFile(fixtures, "fixtures/version.out"), expectStderr: ReadFile(fixtures, "fixtures/version-trace.err"), }, "go-make bash": { - info: infoDirty, + info: infoBase, args: []string{"go-make", "--completion=bash"}, expectStdout: ReadFile(fixtures, "fixtures/bash.out"), }, "go-make bash trace": { - info: infoDirty, + info: infoBase, args: []string{"go-make", "--trace", "--completion=bash"}, expectStdout: ReadFile(fixtures, "fixtures/bash.out"), expectStderr: ReadFile(fixtures, "fixtures/bash-trace.err"), }, "go-make targets": { - info: infoDirty, + info: infoBase, args: []string{"go-make", "targets"}, expectStdout: ReadFile(fixtures, "fixtures/targets.out"), expectStderr: ReadFile(fixtures, "fixtures/targets.err"), @@ -923,7 +962,7 @@ func TestMakeExec(t *testing.T) { test.Map(t, testMakeExecParams). Run(func(t test.Test, param MakeExecParams) { // Given - info := infoDirty + info := infoBase stdout := &strings.Builder{} stderr := &strings.Builder{}