diff --git a/internal/constants/constants.gen.go b/internal/constants/constants.gen.go index 5e5a631..1c28ce2 100644 --- a/internal/constants/constants.gen.go +++ b/internal/constants/constants.gen.go @@ -3,6 +3,7 @@ * * To regenerate, run 'go generate' in internal/lvgen. */ + package constants // libvirt procedure identifiers and other enums diff --git a/internal/lvgen/constants.tmpl b/internal/lvgen/constants.tmpl new file mode 100644 index 0000000..06a7240 --- /dev/null +++ b/internal/lvgen/constants.tmpl @@ -0,0 +1,28 @@ +/* + * This file generated by internal/lvgen/generate.go. DO NOT EDIT BY HAND! + * + * To regenerate, run 'go generate' in internal/lvgen. + */ + +package constants + +// libvirt procedure identifiers and other enums +// +// These are libvirt procedure numbers which correspond to each respective +// API call between remote_internal driver and libvirtd. Each procedure is +// identified by a unique number which *may change in any future libvirt +// update*. +// +// Examples: +// REMOTE_PROC_CONNECT_OPEN = 1 +// REMOTE_PROC_DOMAIN_DEFINE_XML = 11 +// REMOTE_PROC_DOMAIN_MIGRATE_SET_MAX_SPEED = 207, +const ( + // From enums: + {{range .Enums}}{{.Name}} = {{.Val}} + {{end}} + + // From consts: + {{range .Consts}}{{.Name}} = {{.Val}} + {{end}} +) diff --git a/internal/lvgen/generate.go b/internal/lvgen/generate.go index 7f6ff4a..193d5ec 100644 --- a/internal/lvgen/generate.go +++ b/internal/lvgen/generate.go @@ -112,35 +112,6 @@ func Generate(proto io.Reader) error { } func genGo(wr io.Writer) error { - // TODO: Move this someplace nice. - const consttempl = `/* - * This file generated by internal/lvgen/generate.go. DO NOT EDIT BY HAND! - * - * To regenerate, run 'go generate' in internal/lvgen. - */ -package constants - -// libvirt procedure identifiers and other enums -// -// These are libvirt procedure numbers which correspond to each respective -// API call between remote_internal driver and libvirtd. Each procedure is -// identified by a unique number which *may change in any future libvirt -// update*. -// -// Examples: -// REMOTE_PROC_CONNECT_OPEN = 1 -// REMOTE_PROC_DOMAIN_DEFINE_XML = 11 -// REMOTE_PROC_DOMAIN_MIGRATE_SET_MAX_SPEED = 207, -const ( - // From enums: - {{range .Enums}}{{.Name}} = {{.Val}} - {{end}} - - // From consts: - {{range .Consts}}{{.Name}} = {{.Val}} - {{end}} -) -` // Enums and consts from the protocol definition both become go consts in // the generated code. We'll remove "REMOTE_" and then camel-case the // name before making each one a go constant. @@ -151,7 +122,10 @@ const ( Gen.Consts[ix].Name = constNameTransform(en.Name) } - t := template.Must(template.New("consts").Parse(consttempl)) + t, err := template.ParseFiles("constants.tmpl") + if err != nil { + return err + } if err := t.Execute(wr, Gen); err != nil { return err }