v icon indicating copy to clipboard operation
v copied to clipboard

pref: Give Warnings When Compiling Sources with Flags

Open JoeyShapiro opened this issue 1 year ago • 5 comments

Describe the Problem

Compiling a single code file with flags does not give a warning, and continues the compile. This will work on real or fake flags This does not look nice and could cause unknown usage.

$ ./v examples/hello_world.v -autofree
$ ./v examples/hello_world.v -garbage
$ echo $?
0

Show the Change

This change reports an error and exits as such. It will report the same error if the argument is valid or not, but it is clear what the problem is.

$ ./v examples/hello_world.v -autofree
Build flags must be before the source file.
$ ./v examples/hello_world.v -garbage
Build flags must be before the source file.
$ echo $?
1

JoeyShapiro avatar Apr 30 '24 23:04 JoeyShapiro

I agree that not reporting an error for ./v examples/hello_world.v -garbage is a problem. Note however that recognized options do work after the source file currently, and will not after your change, which is a breaking change:

#0 09:47:17 ᛋ master /v/oo❱./v examples/hello_world.v -gc none
#0 09:49:15 ᛋ master /v/oo❱ls -l examples/hello_world
-rwxrwxr-x 1 delian delian 502792 May  1 09:49 examples/hello_world
#0 09:49:20 ᛋ master /v/oo❱./v examples/hello_world.v
#0 09:49:23 ᛋ master /v/oo❱ls -l examples/hello_world
-rwxrwxr-x 1 delian delian 699344 May  1 09:49 examples/hello_world

spytheman avatar May 01 '24 06:05 spytheman

Testing on your branch, shows that it behaves differently than your demonstration:

#0 09:54:22 ᛋ master /v/oo❱
#0 09:54:22 ᛋ master /v/oo❱git switch -
Switched to branch 'v-file-flags'
#0 09:54:23 ᛋ v-file-flags /v/oo❱./v self
V self compiling ...
V built successfully as executable "v".
#0 09:54:27 ᛋ v-file-flags /v/oo❱./v examples/hello_world.v -autofree
#0 09:54:30 ᛋ v-file-flags /v/oo❱./v examples/hello_world.v -garbage
Build flags must be before the source file.
#1 09:54:34 ᛋ v-file-flags /v/oo❱echo $?
1
#0 09:54:38 ᛋ v-file-flags /v/oo❱

... which is nice.

spytheman avatar May 01 '24 06:05 spytheman

wow a response, and yeah, it is acting different, my bad. ok give me a bit to work on this, I might have to retitle this issue.

JoeyShapiro avatar May 01 '24 12:05 JoeyShapiro

Personally, I would like for it to warn about options after the filename. This is one way v build is different from v run. In v run, all options after the filename are passed to the target program after it is built. In v build, they're just treated as options to the build.

It can be a bit confusing to new users as to why it is ok to have v file.v -gc none but v run file.v -gc none doesn't work the same.

JalonSolov avatar May 01 '24 12:05 JalonSolov

yes I agree. that is why I want this worked out. I realized what I was doing. doing a double dash --skip-unused is not the same as -skip-unused. This is why in my testing it appeared like they were not working. So let me reformat my statement.

I want to make some statements, and we can discuss, before I start making any changes If an option is valid, on either side, it works as intended. however, an invalid option on the right side will not be caught. I think this examples rounds out all the problems

$ ./v -o hello-skip.c -skip-unused examples/hello_world.v
$ ./v -o hello-maybe-skip.c examples/hello_world.v -skip-unused
$ ./v -o hello-wont-skip.c examples/hello_world.v --skip-unused
$ ./v -o nothing.c --skip-unused examples/hello_world.v
Unknown argument `--skip-unused`

$ diff -q hello-skip.c hello-maybe-skip.c
$ diff -q hello-skip.c hello-wont-skip.c 
Files hello-skip.c and hello-wont-skip.c differ

JoeyShapiro avatar May 02 '24 00:05 JoeyShapiro

(rebased over master and resolved conflicts)

spytheman avatar May 18 '24 10:05 spytheman

(rebased again, since master had an unrelated error, that is now fixed)

spytheman avatar May 18 '24 12:05 spytheman

@spytheman The PR unfortunately comes with a regression. It might the reason for #21621

It's not possible to run some V commands with flags anymore. E.g. if there is directory with the name of the command, like having a fmt directory in the in the cwd and trying to run v fmt -diff file.v.

❯ v fmt -diff file.v
Unknown argument `-diff` for command `fmt`

ttytm avatar Jun 05 '24 10:06 ttytm