Modify struct-markdown generator code to work from different projct roots

Modify makefile to call generate code properly, setting project root.
'make generate' now avoids deleting website code generated in the packer plugin sdk.
For now it will be maintainers' responsibility to regenerate this docs code from the
packer plugin sdk every release, and commit it to these folders manually.
remove boot command generator code
This commit is contained in:
Megan Marsh 2020-12-10 14:07:08 -08:00
parent e89db37717
commit f179f01314
3 changed files with 15 additions and 21 deletions

View File

@ -56,7 +56,6 @@ install-gen-deps: ## Install dependencies for code generation
# out code dependencies; so a go mod tidy will remove them again. `go
# install` seems to install the last tagged version and we want to install
# master.
@(cd $(TEMPDIR) && GO111MODULE=on go get github.com/mna/pigeon@master)
@(cd $(TEMPDIR) && GO111MODULE=on go get github.com/alvaroloes/enumer@master)
@go install ./cmd/struct-markdown
@go install ./cmd/mapstructure-to-hcl2
@ -66,16 +65,6 @@ install-lint-deps: ## Install linter dependencies
@echo "==> Updating linter dependencies..."
@curl -sSfL -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.23.8
dev: ## Build and install a development build
@grep 'const VersionPrerelease = ""' version/version.go > /dev/null ; if [ $$? -eq 0 ]; then \
echo "ERROR: You must add prerelease tags to version/version.go prior to making a dev build."; \
exit 1; \
fi
@mkdir -p pkg/$(GOOS)_$(GOARCH)
@mkdir -p bin
@go install -ldflags '$(GOLDFLAGS)'
@cp $(GOPATH)/bin/packer bin/packer
@cp $(GOPATH)/bin/packer pkg/$(GOOS)_$(GOARCH)
lint: install-lint-deps ## Lint Go code
@if [ ! -z $(PKG_NAME) ]; then \
@ -120,13 +109,11 @@ fmt-examples:
# generate runs `go generate` to build the dynamically generated
# source files.
generate: install-gen-deps ## Generate dynamically generated code
@echo "==> removing autogenerated markdown..."
@find website/pages/ -type f | xargs grep -l '^<!-- Code generated' | xargs rm -f
@echo "==> removing autogenerated markdown..." # but don't remove partials generated in the SDK and copied over.
@find website/pages -path website/pages/partials/packer-plugin-sdk -prune -o -type f | xargs grep -l '^<!-- Code generated' | xargs rm -f
@echo "==> removing autogenerated code..."
@find post-processor packer-plugin-sdk helper builder provisioner -type f | xargs grep -l '^// Code generated' | xargs rm -f
go generate ./...
go fmt packer-plugin-sdk/bootcommand/boot_command.go
go run ./cmd/generate-fixer-deprecations
@find post-processor helper builder provisioner -type f | xargs grep -l '^// Code generated' | xargs rm -f
PROJECT_ROOT="$(pwd)" go generate ./...
generate-check: generate ## Check go code generation is on par
@echo "==> Checking that auto-generated code is not changed..."

View File

@ -27,8 +27,16 @@ func main() {
if err != nil {
panic(err)
}
paths := strings.SplitAfter(absFilePath, "packer"+string(os.PathSeparator))
packerDir := paths[0]
projectRoot := os.Getenv("PROJECT_ROOT")
var paths []string
if projectRoot == "" {
// fall back to the packer root.
paths = strings.SplitAfter(absFilePath, "packer"+string(os.PathSeparator))
projectRoot = paths[0]
} else {
paths = strings.SplitAfter(absFilePath, projectRoot+string(os.PathSeparator))
}
builderName, _ := filepath.Split(paths[1])
builderName = strings.Trim(builderName, string(os.PathSeparator))
@ -144,7 +152,7 @@ func main() {
}
}
dir := filepath.Join(packerDir, "website", "pages", "partials", builderName)
dir := filepath.Join(projectRoot, "website", "pages", "partials", builderName)
os.MkdirAll(dir, 0755)
for _, str := range []Struct{header, required, notRequired} {

View File

@ -1,7 +1,6 @@
// This is the main package for the `packer` application.
//go:generate go run ./scripts/generate-plugins.go
//go:generate go generate ./packer-plugin-sdk/bootcommand/...
package main
import (