unix: factor out mkmerge into a proper package
Factor mkmerge.go and mkmerge_test.go into package internal/mkmerge.
Due to ignore constraints, mkmerge_test.go wasn't run by the Go
builders and failing tests were unnoticed.
Factoring mkmerge into its own package and removing ignore constraints
makes the tests run automatically by the Go builders.
Fixes golang/go#49484
Change-Id: I56a0b7220e40d1d7e5193490cb547cad4202f9ac
Reviewed-on: https://go-review.googlesource.com/c/sys/+/363334
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
diff --git a/unix/README.md b/unix/README.md
index 474efad..7d3c060 100644
--- a/unix/README.md
+++ b/unix/README.md
@@ -149,7 +149,7 @@
Then, edit the regex (if necessary) to match the desired constant. Avoid making
the regex too broad to avoid matching unintended constants.
-### mkmerge.go
+### internal/mkmerge
This program is used to extract duplicate const, func, and type declarations
from the generated architecture-specific files listed below, and merge these
diff --git a/unix/mkmerge.go b/unix/internal/mkmerge/mkmerge.go
similarity index 95%
rename from unix/mkmerge.go
rename to unix/internal/mkmerge/mkmerge.go
index 9bfd150..efcdede 100644
--- a/unix/mkmerge.go
+++ b/unix/internal/mkmerge/mkmerge.go
@@ -2,25 +2,22 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build ignore
-// +build ignore
-
-// mkmerge.go parses generated source files and merges common
+// The mkmerge command parses generated source files and merges common
// consts, funcs, and types into a common source file, per GOOS.
//
// Usage:
-// $ go run mkmerge.go -out MERGED FILE [FILE ...]
+// $ mkmerge -out MERGED FILE [FILE ...]
//
// Example:
// # Remove all common consts, funcs, and types from zerrors_linux_*.go
// # and write the common code into zerrors_linux.go
-// $ go run mkmerge.go -out zerrors_linux.go zerrors_linux_*.go
+// $ mkmerge -out zerrors_linux.go zerrors_linux_*.go
//
-// mkmerge.go performs the merge in the following steps:
-// 1. Construct the set of common code that is idential in all
-// architecture-specific files.
-// 2. Write this common code to the merged file.
-// 3. Remove the common code from all architecture-specific files.
+// mkmerge performs the merge in the following steps:
+// 1. Construct the set of common code that is idential in all
+// architecture-specific files.
+// 2. Write this common code to the merged file.
+// 3. Remove the common code from all architecture-specific files.
package main
import (
@@ -464,7 +461,7 @@
}
buf := bufio.NewWriter(f)
- fmt.Fprintln(buf, "// Code generated by mkmerge.go; DO NOT EDIT.")
+ fmt.Fprintln(buf, "// Code generated by mkmerge; DO NOT EDIT.")
fmt.Fprintln(buf)
fmt.Fprintf(buf, "//go:build %s\n", goos)
fmt.Fprintf(buf, "// +build %s\n", goos)
diff --git a/unix/mkmerge_test.go b/unix/internal/mkmerge/mkmerge_test.go
similarity index 98%
rename from unix/mkmerge_test.go
rename to unix/internal/mkmerge/mkmerge_test.go
index a1463b9..3207244 100644
--- a/unix/mkmerge_test.go
+++ b/unix/internal/mkmerge/mkmerge_test.go
@@ -2,12 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build ignore
-// +build ignore
-
-// Test cases for mkmerge.go.
-// Usage:
-// $ go test mkmerge.go mkmerge_test.go
package main
import (
diff --git a/unix/linux/mkall.go b/unix/linux/mkall.go
index 70a58d3..7ea4de8 100644
--- a/unix/linux/mkall.go
+++ b/unix/linux/mkall.go
@@ -572,7 +572,7 @@
// Merge each of the four type of files
for _, ztyp := range []string{"zerrors", "zsyscall", "zsysnum", "ztypes"} {
- cmd := makeCommand("go", "run", "mkmerge.go", "-out", fmt.Sprintf("%s_%s.go", ztyp, GOOS), fmt.Sprintf("%s_%s_*.go", ztyp, GOOS))
+ cmd := makeCommand("go", "run", "./internal/mkmerge", "-out", fmt.Sprintf("%s_%s.go", ztyp, GOOS), fmt.Sprintf("%s_%s_*.go", ztyp, GOOS))
err := cmd.Run()
if err != nil {
return fmt.Errorf("could not merge %s files: %w", ztyp, err)
diff --git a/unix/zerrors_linux.go b/unix/zerrors_linux.go
index 3bbc527..4e4e7f8 100644
--- a/unix/zerrors_linux.go
+++ b/unix/zerrors_linux.go
@@ -1,4 +1,4 @@
-// Code generated by mkmerge.go; DO NOT EDIT.
+// Code generated by mkmerge; DO NOT EDIT.
//go:build linux
// +build linux
diff --git a/unix/zsyscall_linux.go b/unix/zsyscall_linux.go
index 4f5da1f..fe6c232 100644
--- a/unix/zsyscall_linux.go
+++ b/unix/zsyscall_linux.go
@@ -1,4 +1,4 @@
-// Code generated by mkmerge.go; DO NOT EDIT.
+// Code generated by mkmerge; DO NOT EDIT.
//go:build linux
// +build linux
diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go
index 620a670..d887d9b 100644
--- a/unix/ztypes_linux.go
+++ b/unix/ztypes_linux.go
@@ -1,4 +1,4 @@
-// Code generated by mkmerge.go; DO NOT EDIT.
+// Code generated by mkmerge; DO NOT EDIT.
//go:build linux
// +build linux