tup icon indicating copy to clipboard operation
tup copied to clipboard

Problem expanding %o in lua generated rule

Open edwinzrodriguez opened this issue 1 year ago • 2 comments

I'm having a problem getting a lua file to generate a rule which outputs to a different directory. I've simplified the example to highlight the issue.

TEST_SAMPLE_SRC = sample.txt TEST_SAMPLE_DST = $(DIR_LIBS)/sample.txt

The lua copies from source to dest and I want the destination to be build-dbg/root/lib/sample.txt but it winds up at 'build-dbg/src/utils/root/lib/sample.txt'

` [rodried@ln80-ryzen-build0-lazyk-local:60]~/git/tup_test3/sw(master)> rm -rf build-*/ .tup && tup-v0.7.11-120-g8739d024 init && tup-v0.7.11-120-g8739d024 variant build_tools/variants/dbg.config .tup repository initialized: .tup/db tup: Added variant 'build-dbg' using config file 'build_tools/variants/dbg.config' [rodried@ln80-ryzen-build0-lazyk-local:61]~/git/tup_test3/sw(master)> tup-v0.7.11-120-g8739d024 --verbose [ tup ] [0.007s] Scanning filesystem... [ tup ] [0.026s] Reading in new configuration/environment variables... 0) new variant: [build-dbg] tup.config [ ] 100% [ tup ] [0.045s] Parsing Tupfiles... 6) [0.002s] [build-dbg] build_tools/variants 5) [0.001s] [build-dbg] build_tools 4) [0.006s] [build-dbg] src/utils/test src_name=sample.txt dst_name=%18t/root/lib/sample.txt VARIANTDIR=%18t VARIANT_OUTPUTDIR=../../../build-dbg/src/utils/test tup.getcwd()=../../../build_tools tup.getdirectory()=build_tools tup.getvariantdir()=../../../build-dbg/build_tools elements[1]="%18t/root/lib/sample.txt" result=../../../build-dbg/build_tools/../root/lib/sample.txt fix_dst_name=../../../build-dbg/build_tools/../root/lib/sample.txt cp_cmd=^ BIN %o^ cp -v %f %o cp_rule=../root/lib/sample.txt 3) [0.001s] [build-dbg] src/utils 2) [0.001s] [build-dbg] src/include

  1. [0.001s] [build-dbg] src
  2. [0.001s] [build-dbg] . [ ] 100% [ tup ] [0.061s] No files to delete. [ tup ] [0.061s] Generating .gitignore files... [ tup ] [0.067s] Executing Commands...
  3. [0.029s] [build-dbg] src/utils/test: cp -v sample.txt ../../../build-dbg/src/utils/test/../root/lib/sample.txt 'sample.txt' -> '../../../build-dbg/src/utils/test/../root/lib/sample.txt' [ ] 100% [ tup ] [0.104s] Updated. If I try to add a rule to copy from where the result should be: $(DIR_LIBS)/sample.txt |> !cp |> $(DIR_TEST)/%bproduces an error:tup error: Failed to find directory ID for dir '../../../root/lib/sample.txt' relative to '[build-dbg] src/utils/test' tup error: Error parsing Tupfile line 16 Line was: ': $(DIR_LIBS)/sample.txt |> !cp |> $(DIR_TEST)/%b' [ ] 100%`

But if I change the DST to $(TUP_VARIANTDIR)/sample.txt and the copy rule to : $(TUP_VARIANTDIR)/sample.txt |> !cp |> $(DIR_LIBS)/%b

I finally get the file where I want it build-dbg/root/nimble/lib/sample.txt

tup_test3.tgz

edwinzrodriguez avatar Oct 03 '23 21:10 edwinzrodriguez

Let me clean this up a bit. I create VARIANT_ROOT = $(TUP_VARIANTDIR) in the topmost Tuprules.tup to use to define DIR_TEST = $(VARIANT_ROOT)/root/test The attached example has a lua which generates a cp command to copy a file to a destination. If the destination is specified as $(DIR_TEST)/sample.txt from src/utils/test the result winds up in build-dbg/src/utils/src/utils/test/root/test/sample.txt rather than build-dbg/root/test/sample.txt as intended.

If I add a rule to the Tupfile to copy the result from $(DIR_TEST)/sample.txt to $(DIR_BIN)/%b produces the error: ` tup error: Failed to find directory ID for dir '../../../root/test/sample.txt' relative to '[build-dbg] src/utils/test' tup error: Error parsing Tupfile line 17

Line was: ': $(DIR_TEST)/sample.txt |> !cp |> $(DIR_BIN)/%b' [ ETA~=<1s ] 60% ` tup_test3.tgz

edwinzrodriguez avatar Oct 09 '23 18:10 edwinzrodriguez

I'm not sure if I fully understood your test tarball in terms of what was expected to work and what was debug or a work in progress, but I do see how there was a problem with tup.getvariantdir() in Lua. I believe that is fixed with commit 41d130231, but I'm not sure if that fixes your problem here or not. Can you give the latest a try and see if things are working as you expect? If not, can you try to distill it down to a simpler test case? Thanks!

gittup avatar Jan 25 '24 03:01 gittup