p4lang / p4c

P4_16 reference compiler
https://p4.org/
Apache License 2.0
679 stars 443 forks source link

It's not obvious how to specify a target for the p4c driver #502

Closed sethfowler closed 7 years ago

sethfowler commented 7 years ago
○ > ./p4c --help
usage: p4c [-h] [-V] [-v] [-###] [-Xpreprocessor <arg>] [-Xp4c <arg>]
           [-Xassembler <arg>] [-Xlinker <arg>] [-b BACKEND] [-E] [-e] [-S]
           [-c] [-x {p4-14,p4-16}] [-I SEARCH_PATH] [-o PATH] [--target-help]
           [source_file]

positional arguments:
  source_file           Files to compile

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show version and exit
  -v                    verbose
  -###                  print (but do not run) the commands
  -Xpreprocessor <arg>  Pass <arg> to the preprocessor
  -Xp4c <arg>           Pass <arg> to the compiler
  -Xassembler <arg>     Pass <arg> to the assembler
  -Xlinker <arg>        Pass <arg> to the linker
  -b BACKEND            specify target backend
  -E                    Only run the preprocessor
  -e                    Skip the preprocessor
  -S                    Only run the preprocess and compilation steps
  -c                    Only run preprocess, compile, and assemble steps
  -x {p4-14,p4-16}      Treat subsequent input files as having type language.
  -I SEARCH_PATH        Add directory to include search path
  -o PATH               Write output to the provided path
  --target-help         Display target specific command line options.

Hmm, OK.

○ > ./p4c -b bmv2 ../testdata/p4_16_samples/issue210.p4-o foo.bmv2.json
Invalid target-arch-vendor triplet.

Hmm. Maybe --target-help?

○ > ./p4c --target-help
usage: p4c [-h] [-V] [-v] [-###] [-Xpreprocessor <arg>] [-Xp4c <arg>]
           [-Xassembler <arg>] [-Xlinker <arg>] [-b BACKEND] [-E] [-e] [-S]
           [-c] [-x {p4-14,p4-16}] [-I SEARCH_PATH] [-o PATH] [--target-help]
           [source_file]
p4c: error: No input specified.

:(

○ > ./p4c --target-help bmv2
Supported backends in "target-arch-vendor" triplet:
bmv2-*-p4org
ebpf-*-p4org
tofino-*-barefoot

Oh, OK.

○ > ./p4c -b bmv2-*-p4org ../testdata/p4_16_samples/issue210.p4 -o out.bmv2.json
No matches for wildcard 'bmv2-*-p4org'.  (Tip: empty matches are allowed in 'set', 'count', 'for'.)
fish: ./p4c -b bmv2-*-p4org ../testdata/p4_16_samples/issue210.p4 -o out.bmv2.json
               ^

Doh! (In fairness, fish is harsher about this than bash.)

○ > ./p4c -b bmv2-v1model-p4org ../testdata/p4_16_samples/issue210.p4 -o out.bmv2.json

There we go. Whew.

sethfowler commented 7 years ago

This issue is about the driver's error handling and help messages. I don't think this has been fixed, has it? I don't see a fix in those commits, but please reclose if I'm wrong.

hanw commented 7 years ago

The handling for --target-help is fixed. The commit did not change how triplets are represented, so the issue with fish remains. But who uses fish? =P

sethfowler commented 7 years ago

=P

The same problem would occur with bash/zsh if there were a file in the current directory that matched that wildcard, though. It'd be better not to use a shell wildcard in the triple names.

hanw commented 7 years ago

I believe this is fixed.

sethfowler commented 7 years ago

The issue with the triplets including shell wildcards has not been fixed. I'll file a separate issue.