From 4642d77a2d329fcf6ae1ab5e3e27f0ba5b63f897 Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Fri, 18 Oct 2024 13:25:34 +0100 Subject: [PATCH] cue/load: fix `@if` attributes in command line-specified files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: I6b6649aa0e53ed0184a2b3d0648f86bbd98561ed Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1202738 Reviewed-by: Daniel Martí TryBot-Result: CUEcueckoo Unity-Result: CUE porcuepine --- cmd/cue/cmd/testdata/script/issue3250.txtar | 6 +++--- cue/load/loader_common.go | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/cue/cmd/testdata/script/issue3250.txtar b/cmd/cue/cmd/testdata/script/issue3250.txtar index 55546225e89..f5fba6bdf53 100644 --- a/cmd/cue/cmd/testdata/script/issue3250.txtar +++ b/cmd/cue/cmd/testdata/script/issue3250.txtar @@ -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) diff --git a/cue/load/loader_common.go b/cue/load/loader_common.go index 703f2fbd218..677aed37b04 100644 --- a/cue/load/loader_common.go +++ b/cue/load/loader_common.go @@ -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 }