-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Achille Roussel <[email protected]>
- Loading branch information
1 parent
3f2e3c1
commit 13847ce
Showing
10 changed files
with
196 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package compiler | ||
|
||
import ( | ||
"go/build/constraint" | ||
"reflect" | ||
) | ||
|
||
func containsExpr(expr, contains constraint.Expr) bool { | ||
switch x := expr.(type) { | ||
case *constraint.AndExpr: | ||
return containsExpr(x.X, contains) || containsExpr(x.Y, contains) | ||
default: | ||
return reflect.DeepEqual(expr, contains) | ||
} | ||
} | ||
|
||
func withBuildTag(expr constraint.Expr, buildTag *constraint.TagExpr) constraint.Expr { | ||
if buildTag == nil || containsExpr(expr, buildTag) { | ||
return expr | ||
} else if expr == nil { | ||
return buildTag | ||
} else { | ||
return &constraint.AndExpr{X: expr, Y: buildTag} | ||
} | ||
} | ||
|
||
func withoutBuildTag(expr constraint.Expr, buildTag *constraint.TagExpr) constraint.Expr { | ||
notBuildTag := &constraint.NotExpr{X: buildTag} | ||
if buildTag == nil || containsExpr(expr, notBuildTag) { | ||
return expr | ||
} else if expr == nil { | ||
return notBuildTag | ||
} else { | ||
return &constraint.AndExpr{X: expr, Y: notBuildTag} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.