diff --git a/Makefile b/Makefile index 5b8cf0abd..f92eace65 100644 --- a/Makefile +++ b/Makefile @@ -125,6 +125,7 @@ generate: install-gen-deps ## Generate dynamically generated code @find post-processor common helper template builder provisioner -type f | xargs grep -l '^// Code generated' | xargs rm go generate ./... go fmt common/bootcommand/boot_command.go + go run ./cmd/generate-fixer-deprecations generate-check: generate ## Check go code generation is on par @echo "==> Checking that auto-generated code is not changed..." diff --git a/cmd/generate-fixer-deprecations/main.go b/cmd/generate-fixer-deprecations/main.go new file mode 100644 index 000000000..846926a4a --- /dev/null +++ b/cmd/generate-fixer-deprecations/main.go @@ -0,0 +1,74 @@ +package main + +import ( + "flag" + "fmt" + "os" + "path/filepath" + "strings" + "text/template" + + "github.com/hashicorp/packer/fix" +) + +var deprecatedOptsTemplate = template.Must(template.New("deprecatedOptsTemplate"). + Parse(`// + +package config + +var DeprecatedOptions = []string{ +{{- range .DeprecatedOpts}} + "{{.}}", +{{- end}} +}`)) + +type executeOpts struct { + DeprecatedOpts []string +} + +func main() { + // Figure out location in directory structure + args := flag.Args() + if len(args) == 0 { + // Default: process the file + args = []string{os.Getenv("GOFILE")} + } + fname := args[0] + + absFilePath, err := filepath.Abs(fname) + if err != nil { + panic(err) + } + paths := strings.SplitAfter(absFilePath, "packer"+string(os.PathSeparator)) + packerDir := paths[0] + + // Load all deprecated options from all active fixers + allDeprecatedOpts := []string{} + for _, name := range fix.FixerOrder { + fixer, ok := fix.Fixers[name] + if !ok { + panic("fixer not found: " + name) + } + + deprecated := fixer.DeprecatedOptions() + for _, dep := range deprecated { + allDeprecatedOpts = append(allDeprecatedOpts, dep) + } + } + + deprecated_path := filepath.Join(packerDir, "helper", "config", + "deprecated_options.go") + + outputFile, err := os.Create(deprecated_path) + if err != nil { + panic(err) + } + defer outputFile.Close() + + deprecated := &executeOpts{DeprecatedOpts: allDeprecatedOpts} + err = deprecatedOptsTemplate.Execute(outputFile, deprecated) + if err != nil { + fmt.Printf("%v", err) + os.Exit(1) + } +} diff --git a/helper/config/deprecated_options.go b/helper/config/deprecated_options.go new file mode 100644 index 000000000..0ee1b038b --- /dev/null +++ b/helper/config/deprecated_options.go @@ -0,0 +1,37 @@ +// + +package config + +var DeprecatedOptions = []string{ + "iso_md5", + "guest_additions_attach", + "headless", + "parallels_tools_host_path", + "guest_os_distribution", + "ssh_key_path", + "ssh_disable_agent", + "access_key", + "filename", + "shutdown_behaviour", + "enhanced_networking", + "ssh_private_ip", + "login_email", + "tag", + "vhd_temp_path", + "clone_from_vmxc_path", + "cpu", + "ram_size", + "clean_image_name", + "clean_ami_name", + "spot_price_auto_product", + "galaxycommand", + "ssh_host_port_min", + "ssh_host_port_max", + "ssh_skip_nat_mapping", + "ssh_wait_timeout", + "network_card", + "network", + "networkCard", + "iso_checksum_url", + "iso_checksum_type", +} \ No newline at end of file