Skip to content

Commit

Permalink
cue/load: fix @if attributes in command line-specified files
Browse files Browse the repository at this point in the history
We were treating files directly specified on the command
line as outside of the module when actually they should not be.

Fixed #3250

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: I6b6649aa0e53ed0184a2b3d0648f86bbd98561ed
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202738
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202873
  • Loading branch information
rogpeppe authored and mvdan committed Oct 22, 2024
1 parent 53f8c8d commit 328f2bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cmd/cue/cmd/testdata/script/issue3250.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ exec cue mod init
# passes - with module
exec cue export -t foo .:foo

# fails - with module
# TODO fix this case
! exec cue export -t foo foo.cue
# passes - with module
# (failed previously due to #3250).
exec cue export -t foo foo.cue

-- foo.cue --
@if(foo)
Expand Down
6 changes: 4 additions & 2 deletions cue/load/loader_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,11 @@ func (fp *fileProcessor) add(root string, file *build.File, mode importMode) {

if !fp.c.AllCUEFiles {
tagIsSet := fp.tagger.tagIsSet
if p.Module != fp.c.Module {
if p.Module != "" && p.Module != fp.c.Module {
// The file is outside the main module so treat all build tag keys as unset.
// TODO also consider packages explicitly specified on the command line.
// Note that if there's no module, we don't consider it to be outside
// the main module, because otherwise @if tags in non-package files
// explicitly specified on the command line will not work.
tagIsSet = func(string) bool {
return false
}
Expand Down

0 comments on commit 328f2bd

Please sign in to comment.