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]>
  • Loading branch information
rogpeppe committed Oct 18, 2024
1 parent 0b6d0da commit 4642d77
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 @@ -266,9 +266,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 4642d77

Please sign in to comment.