*: reflow comments to 80 characters
This reformats the entire Metropolis codebase to have comments no longer
than 80 characters, implementing CR/66.
This has been done half manually, as we don't have a good integration
between commentwrap/Bazel, but that can be implemented if we decide to
go for this tool/limit.
Change-Id: If1fff0b093ef806f5dc00551c11506e8290379d0
diff --git a/build/bazel_cc_fix/main.go b/build/bazel_cc_fix/main.go
index 244e849..1be47f7 100644
--- a/build/bazel_cc_fix/main.go
+++ b/build/bazel_cc_fix/main.go
@@ -14,17 +14,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-// bazel_cc_fix rewrites include directives in C and C++ code. It rewrites all includes in the target workspace to be
-// workspace-relative and additionally supports rewriting includes via a prototxt-based spec file to for example
+// bazel_cc_fix rewrites include directives in C and C++ code. It rewrites all
+// includes in the target workspace to be workspace-relative and additionally
+// supports rewriting includes via a prototxt-based spec file to for example
// fix up includes for external libraries.
-// The rewritten code can then be used in Bazel intra- and inter-workspace without dealing with any copts or include-
-// related attributes.
-// To know where an include would resolve to it expects a compilation database (see
-// https://clang.llvm.org/docs/JSONCompilationDatabase.html) as an input. It looks at all files in that database and
-// their transitive dependencies and rewrites all of them according to the include paths specified in the compilation
-// command from the database.
-// The compilation database itself is either generated by the original build system or by using intercept-build, which
-// intercepts calls to the compiler and records them into a compilation database.
+// The rewritten code can then be used in Bazel intra- and inter-workspace
+// without dealing with any copts or include- related attributes.
+// To know where an include would resolve to it expects a compilation database
+// (see https://clang.llvm.org/docs/JSONCompilationDatabase.html) as an input.
+// It looks at all files in that database and their transitive dependencies and
+// rewrites all of them according to the include paths specified in the
+// compilation command from the database.
+// The compilation database itself is either generated by the original build
+// system or by using intercept-build, which intercepts calls to the compiler
+// and records them into a compilation database.
package main
import (
@@ -44,8 +47,9 @@
"source.monogon.dev/build/bazel_cc_fix/ccfixspec"
)
-// compilationDBEntry is a single entry from the compilation database which represents a single compiler invocation on
-// a C/C++ source file. It contains the compiler working directory, arguments and input file path.
+// compilationDBEntry is a single entry from the compilation database which
+// represents a single compiler invocation on a C/C++ source file. It contains
+// the compiler working directory, arguments and input file path.
type compilationDBEntry struct {
Directory string `json:"directory"`
Command string `json:"command"`
@@ -54,15 +58,18 @@
Output string `json:"output"`
}
-// compilationDB is a collection of compilationDBEntries usually stored in a big JSON-serialized document.
+// compilationDB is a collection of compilationDBEntries usually stored in a
+// big JSON-serialized document.
// https://clang.llvm.org/docs/JSONCompilationDatabase.html
type compilationDB []compilationDBEntry
-// rewrites represents a list of include rewrites with the key being the original include statement
-// (like "#include <xyz.h>", with whitespace trimmed on both sides) and the value being another
+// rewrites represents a list of include rewrites with the key being the
+// original include statement (like "#include <xyz.h>", with whitespace trimmed
+// on both sides) and the value being another
type rewrites map[string]string
-// replacer returns a strings.Replacer which efficiently performs all replacements in a single pass
+// replacer returns a strings.Replacer which efficiently performs all
+// replacements in a single pass
func (r rewrites) replacer() *strings.Replacer {
var replacerArgs []string
for from, to := range r {
@@ -107,9 +114,10 @@
reIncludeDirective = regexp.MustCompile(`(?m:^\s*#\s*include\s*([<"])(.*)([>"]))`)
)
-// applyReplaceDirectives applies all directives of the given replaceType in directives to originalPath and returns the
-// resulting string. If returnUnmodified is unset, it returns an empty string when no replacements were performed,
-// otherwise it returns the unmodified originalPath.
+// applyReplaceDirectives applies all directives of the given replaceType in
+// directives to originalPath and returns the resulting string. If
+// returnUnmodified is unset, it returns an empty string when no replacements
+// were performed, otherwise it returns the unmodified originalPath.
// The first rewrite wins, it does not do any recursive processing.
func applyReplaceDirectives(directives []*ccfixspec.Replace, replaceType ccfixspec.Replace_Type, originalPath string, returnUnmodified bool) string {
for _, d := range directives {
@@ -128,9 +136,11 @@
return ""
}
-// findFileInWorkspace takes a path from a C include directive and uses the given search path to find its absolute
-// path. If that absolute path is outside the workspace, it returns an empty string, otherwise it returns the path
-// of the file relative to the workspace. It pretends that all files in isGeneratedFile exist on the filesystem.
+// findFileInWorkspace takes a path from a C include directive and uses the
+// given search path to find its absolute path. If that absolute path is
+// outside the workspace, it returns an empty string, otherwise it returns the
+// path of the file relative to the workspace. It pretends that all files in
+// isGeneratedFile exist on the filesystem.
func findFileInWorkspace(searchPath []string, inclFile string, isGeneratedFile map[string]bool) string {
var inclPath string
for _, path := range searchPath {
@@ -145,12 +155,13 @@
}
}
if inclPath == "" {
- // We haven't found the included file. This can happen for system includes (<stdio.h>) or includes from
- // other operating systems.
+ // We haven't found the included file. This can happen for system
+ // includes (<stdio.h>) or includes from other operating systems.
return ""
}
- // Ignore all include directives that don't resolve into our workspace after processing
+ // Ignore all include directives that don't resolve into our workspace
+ // after processing
if !filepath.HasPrefix(inclPath, *workspacePath) {
return ""
}
@@ -162,8 +173,9 @@
return workspaceRelativeFilePath
}
-// fixIncludesAndGetRefs opens a file, looks at all its includes, records rewriting data into rewriteMetadata and
-// returns all files included by the file for further analysis.
+// fixIncludesAndGetRefs opens a file, looks at all its includes, records
+// rewriting data into rewriteMetadata and returns all files included by the
+// file for further analysis.
func (m rewriteMetadata) fixIncludesAndGetRefs(filePath string, quoteIncludes, systemIncludes []string, spec *ccfixspec.CCFixSpec, isGeneratedFile map[string]bool) []string {
meta, ok := m[filePath]
if !ok {
@@ -206,21 +218,24 @@
includeFiles = append(includeFiles, filepath.Join(*workspacePath, workspaceRelativeFilePath))
}
- // Pretend that a generated file exists at the given path when stripping the BuildDir prefix. This is
- // generally true for all out-of-tree build systems and saves the user from needing to manually specify
- // lots of GeneratedFiles.
+ // Pretend that a generated file exists at the given path when
+ // stripping the BuildDir prefix. This is generally true for all
+ // out-of-tree build systems and saves the user from needing to
+ // manually specify lots of GeneratedFiles.
if spec.BuildDir != "" && filepath.HasPrefix(workspaceRelativeFilePath, spec.BuildDir+"/") {
workspaceRelativeFilePath = filepath.Clean(strings.TrimPrefix(workspaceRelativeFilePath, spec.BuildDir+"/"))
foundGenerated = true
}
- // Shorten include paths when both files are in the same directory except when a generated file is involved
- // as these end up in physically different locations and need to be referenced using a full workspace-
- // relative path
+ // Shorten include paths when both files are in the same directory
+ // except when a generated file is involved as these end up in
+ // physically different locations and need to be referenced using a
+ // full workspace- relative path
if !foundGenerated && filepath.Dir(filePath) == filepath.Dir(filepath.Join(*workspacePath, workspaceRelativeFilePath)) {
workspaceRelativeFilePath = filepath.Base(workspaceRelativeFilePath)
}
- // Don't perform rewrites when both include directives are semantically equivalent
+ // Don't perform rewrites when both include directives are semantically
+ // equivalent
if workspaceRelativeFilePath == inclFile && inclType == "\"" {
continue
}
@@ -229,7 +244,8 @@
return includeFiles
}
-// getIncludeDirs takes a compilation database entry and returns the search paths for both system and quote includes
+// getIncludeDirs takes a compilation database entry and returns the search
+// paths for both system and quote includes
func getIncludeDirs(entry compilationDBEntry) (quoteIncludes []string, systemIncludes []string, err error) {
// Normalize arguments
if len(entry.Arguments) == 0 {
@@ -325,7 +341,8 @@
rewriteMetadata := make(rewriteMetadata)
- // Iterate over all source files in the compilation database and analyze them one-by-one
+ // Iterate over all source files in the compilation database and analyze
+ // them one-by-one
for _, entry := range compilationDB {
quoteIncludes, systemIncludes, err := getIncludeDirs(entry)
if err != nil {