mirror of
https://github.com/github/codeql.git
synced 2026-01-29 14:23:03 +01:00
Add support for go:build style constraints
This doesn't account for the new syntax, but there was no syntax parsing in the old version anyway, and the only user doesn't currently care about semantics
This commit is contained in:
@@ -189,7 +189,7 @@ private Comment getInitialComment(File f, int i) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A build constraint comment of the form `// +build ...`.
|
||||
* A build constraint comment of the form `// +build ...` or `//go:build ...`.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
@@ -203,17 +203,23 @@ class BuildConstraintComment extends LineComment {
|
||||
// a line comment preceding the package declaration, itself only preceded by
|
||||
// line comments
|
||||
exists(File f, int i |
|
||||
// correctness of the placement of the build constraint is not checked here;
|
||||
// this is more lax than the actual rules for build constraints
|
||||
this = getInitialComment(f, i) and
|
||||
not getInitialComment(f, [0 .. i - 1]) instanceof BlockComment
|
||||
) and
|
||||
// comment text starts with `+build`
|
||||
getText().regexpMatch("\\s*\\+build.*")
|
||||
(
|
||||
// comment text starts with `+build` or `go:build`
|
||||
this.getText().regexpMatch("\\s*\\+build.*")
|
||||
or
|
||||
this.getText().regexpMatch("\\s*go:build.*")
|
||||
)
|
||||
}
|
||||
|
||||
override string getAPrimaryQlClass() { result = "BuildConstraintComment" }
|
||||
|
||||
/** Gets the body of this build constraint. */
|
||||
string getConstraintBody() { result = getText().splitAt("+build ", 1) }
|
||||
string getConstraintBody() { result = getText().splitAt("build ", 1) }
|
||||
|
||||
/** Gets a disjunct of this build constraint. */
|
||||
string getADisjunct() { result = getConstraintBody().splitAt(" ") }
|
||||
|
||||
@@ -222,6 +222,8 @@ class ExtractedOrExternalFile extends Container, @file, Documentable, ExprParent
|
||||
exists(BuildConstraintComment bcc | this = bcc.getFile() |
|
||||
forex(string disjunct | disjunct = bcc.getADisjunct() |
|
||||
disjunct.splitAt(",").(Architecture).getBitSize() = bitSize
|
||||
or
|
||||
disjunct.splitAt("/").(Architecture).getBitSize() = bitSize
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user