From 2a2c78aeeaa16e8847907a68d21992e083c47fb7 Mon Sep 17 00:00:00 2001 From: Nicholas Chin Date: Sun, 23 Jun 2024 10:15:47 -0600 Subject: util/autoport: Make printing of SPDX headers generic Previously, Add_gpl() was only used with C and ASL source code files, and was hard coded to use the C /* */ style comment, preventing it from being used with files with other comment styles. Convert this into a generic function for adding arbitrary SPDX license identifiers for arbitrary filetypes. This replaces the hard coded GPL-2.0-or-later string used in gma-mainboard.ads with a call to the new function. This is also used to add SPDX headers to Kconfig and Makefile sources; as previous commits added them to all such files in the tree. Tested against logs from a Latitude E6430 (Ivy Bridge) and Precision M6800 (Haswell) to check that license headers that were already being generated did not change. Change-Id: I24a1ccd0afb7045e878bf6eaae7a23f828a9240d Signed-off-by: Nicholas Chin Reviewed-on: https://review.coreboot.org/c/coreboot/+/83184 Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber Reviewed-by: Angel Pons --- util/autoport/main.go | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'util/autoport/main.go') diff --git a/util/autoport/main.go b/util/autoport/main.go index 3b085152c5..c4f884a985 100644 --- a/util/autoport/main.go +++ b/util/autoport/main.go @@ -99,6 +99,31 @@ type Context struct { SaneVendor string } +type Filetype int + +const ( + Ada Filetype = iota + ASL + C + Kconfig + Makefile +) + +var CommentFormatStrings map[Filetype]string = map[Filetype]string { + Ada: "-- %s\n", + ASL: "/* %s */\n", + C: "/* %s */\n", + Kconfig: "## %s\n", + Makefile: "## %s\n", +} + +type License string + +const ( + GPL2_only License = "GPL-2.0-only" + GPL2_or_later = "GPL-2.0-or-later" +) + var KconfigBool map[string]bool = map[string]bool{} var KconfigComment map[string]string = map[string]string{} var KconfigString map[string]string = map[string]string{} @@ -209,11 +234,15 @@ func Create(ctx Context, name string) *os.File { return mf } -func Add_gpl(f *os.File) { - fmt.Fprintln(f, "/* SPDX-License-Identifier: GPL-2.0-only */") +func Add_SPDX(f *os.File, filetype Filetype, license License) { + Add_Comment(f, filetype, "SPDX-License-Identifier: " + string(license)) fmt.Fprintln(f) } +func Add_Comment(f *os.File, filetype Filetype, comment string) { + fmt.Fprintf(f, CommentFormatStrings[filetype], comment) +} + func RestorePCI16Simple(f *os.File, pcidev PCIDevData, addr uint16) { fmt.Fprintf(f, " pci_write_config16(PCI_DEV(%d, 0x%02x, %d), 0x%02x, 0x%02x%02x);\n", pcidev.Bus, pcidev.Dev, pcidev.Func, addr, @@ -522,6 +551,7 @@ func (g GenericVGA) Scan(ctx Context, addr PCIDevData) { func makeKconfigName(ctx Context) { kn := Create(ctx, "Kconfig.name") defer kn.Close() + Add_SPDX(kn, Kconfig, GPL2_only) fmt.Fprintf(kn, "config %s\n\tbool \"%s\"\n", ctx.KconfigName, ctx.Model) } @@ -537,6 +567,7 @@ func makeComment(name string) string { func makeKconfig(ctx Context) { kc := Create(ctx, "Kconfig") defer kc.Close() + Add_SPDX(kc, Kconfig, GPL2_only) fmt.Fprintf(kc, "if %s\n\n", ctx.KconfigName) @@ -633,6 +664,7 @@ func makeVendor(ctx Context) { log.Fatal(err) } defer f.Close() + Add_SPDX(f, Kconfig, GPL2_only) f.WriteString(`if VENDOR_` + vendorUpper + ` choice @@ -657,6 +689,7 @@ endif # VENDOR_` + vendorUpper + "\n") log.Fatal(err) } defer f.Close() + Add_SPDX(f, Kconfig, GPL2_only) f.WriteString(`config VENDOR_` + vendorUpper + ` bool "` + vendor + `" `) @@ -734,6 +767,7 @@ func main() { if len(BootBlockFiles) > 0 || len(ROMStageFiles) > 0 || len(RAMStageFiles) > 0 || len(SMMFiles) > 0 { mf := Create(ctx, "Makefile.mk") defer mf.Close() + Add_SPDX(mf, Makefile, GPL2_only) writeMF(mf, BootBlockFiles, "bootblock") writeMF(mf, ROMStageFiles, "romstage") writeMF(mf, RAMStageFiles, "ramstage") @@ -749,7 +783,7 @@ func main() { if MainboardInit != "" || MainboardEnable != "" || MainboardIncludes != nil { mainboard := Create(ctx, "mainboard.c") defer mainboard.Close() - Add_gpl(mainboard) + Add_SPDX(mainboard, C, GPL2_only) mainboard.WriteString("#include \n") for _, include := range MainboardIncludes { mainboard.WriteString("#include <" + include + ">\n") @@ -820,7 +854,7 @@ func main() { dsdt := Create(ctx, "dsdt.asl") defer dsdt.Close() - Add_gpl(dsdt) + Add_SPDX(dsdt, ASL, GPL2_only) for _, define := range DSDTDefines { if define.Comment != "" { @@ -870,10 +904,9 @@ DefinitionBlock( if IGDEnabled { gma := Create(ctx, "gma-mainboard.ads") defer gma.Close() + Add_SPDX(gma, Ada, GPL2_or_later) - gma.WriteString(`-- SPDX-License-Identifier: GPL-2.0-or-later - -with HW.GFX.GMA; + gma.WriteString(`with HW.GFX.GMA; with HW.GFX.GMA.Display_Probing; use HW.GFX.GMA; -- cgit v1.2.3