Skip to content

Commit 328f2bd

Browse files
rogpeppemvdan
authored andcommitted
cue/load: fix @if attributes in command line-specified files
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
1 parent 53f8c8d commit 328f2bd

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Diff for: cmd/cue/cmd/testdata/script/issue3250.txtar

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ exec cue mod init
1010
# passes - with module
1111
exec cue export -t foo .:foo
1212

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

1717
-- foo.cue --
1818
@if(foo)

Diff for: cue/load/loader_common.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,11 @@ func (fp *fileProcessor) add(root string, file *build.File, mode importMode) {
270270

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

0 commit comments

Comments
 (0)