mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fix various issues related to enabling go-marshal.
- Add missing build tags to files in the abi package. - Add the marshal package as a sentry dependency, allowed by deps_test. - Fix an issue with our top-level go_library BUILD rule, which incorrectly shadows the variable containing the input set of source files. This caused the expansion for the go_marshal clause to silently omit input files. - Fix formatting when copying build tags to gomarshal-generated files. - Fix a bug with import statement collision detection in go-marshal. PiperOrigin-RevId: 295112284
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build amd64
|
||||
|
||||
package linux
|
||||
|
||||
// Constants for open(2).
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build arm64
|
||||
|
||||
package linux
|
||||
|
||||
// Constants for open(2).
|
||||
|
||||
+6
-6
@@ -117,10 +117,10 @@ def go_library(name, srcs, deps = [], imports = [], stateify = True, marshal = F
|
||||
# First, we need to segregate the input files via the special suffixes,
|
||||
# and calculate the final output set.
|
||||
state_sets = calculate_sets(srcs)
|
||||
for (suffix, srcs) in state_sets.items():
|
||||
for (suffix, src_subset) in state_sets.items():
|
||||
go_stateify(
|
||||
name = name + suffix + "_state_autogen_with_imports",
|
||||
srcs = srcs,
|
||||
srcs = src_subset,
|
||||
imports = imports,
|
||||
package = full_pkg,
|
||||
out = name + suffix + "_state_autogen_with_imports.go",
|
||||
@@ -140,10 +140,10 @@ def go_library(name, srcs, deps = [], imports = [], stateify = True, marshal = F
|
||||
if marshal:
|
||||
# See above.
|
||||
marshal_sets = calculate_sets(srcs)
|
||||
for (suffix, srcs) in marshal_sets.items():
|
||||
for (suffix, src_subset) in marshal_sets.items():
|
||||
go_marshal(
|
||||
name = name + suffix + "_abi_autogen",
|
||||
srcs = srcs,
|
||||
srcs = src_subset,
|
||||
debug = False,
|
||||
imports = imports,
|
||||
package = name,
|
||||
@@ -172,11 +172,11 @@ def go_library(name, srcs, deps = [], imports = [], stateify = True, marshal = F
|
||||
|
||||
# See above.
|
||||
marshal_sets = calculate_sets(srcs)
|
||||
for (suffix, srcs) in marshal_sets.items():
|
||||
for (suffix, _) in marshal_sets.items():
|
||||
_go_test(
|
||||
name = name + suffix + "_abi_autogen_test",
|
||||
srcs = [name + suffix + "_abi_autogen_test.go"],
|
||||
library = ":" + name + suffix,
|
||||
library = ":" + name,
|
||||
deps = marshal_test_deps,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
@@ -123,7 +123,7 @@ func (g *Generator) writeHeader() error {
|
||||
// Emit build tags.
|
||||
if t := tags.Aggregate(g.inputs); len(t) > 0 {
|
||||
b.emit(strings.Join(t.Lines(), "\n"))
|
||||
b.emit("\n")
|
||||
b.emit("\n\n")
|
||||
}
|
||||
|
||||
// Package header.
|
||||
|
||||
@@ -310,7 +310,7 @@ func (i *importStmt) markUsed() {
|
||||
}
|
||||
|
||||
func (i *importStmt) equivalent(other *importStmt) bool {
|
||||
return i == other
|
||||
return i.name == other.name && i.path == other.path && i.aliased == other.aliased
|
||||
}
|
||||
|
||||
// importTable represents a collection of importStmts.
|
||||
@@ -329,7 +329,7 @@ func newImportTable() *importTable {
|
||||
// result in a panic.
|
||||
func (i *importTable) merge(other *importTable) {
|
||||
for name, im := range other.is {
|
||||
if dup, ok := i.is[name]; ok && dup.equivalent(im) {
|
||||
if dup, ok := i.is[name]; ok && !dup.equivalent(im) {
|
||||
panic(fmt.Sprintf("Found colliding import statements: ours: %+v, other's: %+v", dup, im))
|
||||
}
|
||||
|
||||
@@ -337,16 +337,27 @@ func (i *importTable) merge(other *importTable) {
|
||||
}
|
||||
}
|
||||
|
||||
func (i *importTable) addStmt(s *importStmt) *importStmt {
|
||||
if old, ok := i.is[s.name]; ok && !old.equivalent(s) {
|
||||
// A collision should always be between an import inserted by the
|
||||
// go-marshal tool and an import from the original source file (assuming
|
||||
// the original source file was valid). We could theoretically handle
|
||||
// the collision by assigning a local name to our import. However, this
|
||||
// would need to be plumbed throughout the generator. Given that
|
||||
// collisions should be rare, simply panic on collision.
|
||||
panic(fmt.Sprintf("Import collision: old: %s as %v; new: %v as %v", old.path, old.name, s.path, s.name))
|
||||
}
|
||||
i.is[s.name] = s
|
||||
return s
|
||||
}
|
||||
|
||||
func (i *importTable) add(s string) *importStmt {
|
||||
n := newImport(s)
|
||||
i.is[n.name] = n
|
||||
return n
|
||||
return i.addStmt(n)
|
||||
}
|
||||
|
||||
func (i *importTable) addFromSpec(spec *ast.ImportSpec, f *token.FileSet) *importStmt {
|
||||
n := newImportFromSpec(spec, f)
|
||||
i.is[n.name] = n
|
||||
return n
|
||||
return i.addStmt(newImportFromSpec(spec, f))
|
||||
}
|
||||
|
||||
// Marks the import named n as used. If no such import is in the table, returns
|
||||
|
||||
Reference in New Issue
Block a user