Skip to content

Commit 7946c6d

Browse files
committed
Deprecate positional file arguments to vdb_ax. Added -i for file reads. Added --copy-file-metadata but removed this behaviour by default
Signed-off-by: Nick Avramoussis <[email protected]>
1 parent 60d0f4d commit 7946c6d

22 files changed

+455
-107
lines changed

openvdb_ax/openvdb_ax/cmd/openvdb_ax.cc

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct ProgOptions
6767
std::unique_ptr<std::string> mInputCode = nullptr;
6868
std::vector<std::string> mInputVDBFiles = {};
6969
std::string mOutputVDBFile = "";
70+
bool mCopyFileMeta = false;
7071
bool mVerbose = false;
7172
openvdb::ax::CompilerOptions::OptLevel mOptLevel =
7273
openvdb::ax::CompilerOptions::OptLevel::O3;
@@ -154,13 +155,14 @@ auto usage_execute(const bool verbose)
154155
"\n";
155156
}
156157
os <<
157-
" [a.vdb, b.vdb ... ] list of input files\n"
158-
" -s [code], -f [file] input code to execute as a string or from a file.\n" <<
159-
" -o [file.vdb] write the result to a given vdb file\n" <<
160-
" --opt [level] optimization level [NONE, O0, O1, O2, Os, Oz, O3 (default)]\n" <<
161-
" --werror warnings as errors\n" <<
162-
" --max-errors [n] maximum error messages, 0 (default) allows all error messages\n" <<
163-
" --threads [n] number of threads to use, 0 (default) uses all available.\n";
158+
" -i [file.vdb] append an input vdb file to be read\n"
159+
" -s [code], -f [file] input code to execute as a string or from a file.\n" <<
160+
" -o [file.vdb] write the result to a given vdb file\n" <<
161+
" --opt [level] optimization level [NONE, O0, O1, O2, Os, Oz, O3 (default)]\n" <<
162+
" --werror warnings as errors\n" <<
163+
" --max-errors [n] maximum error messages, 0 (default) allows all error messages\n" <<
164+
" --threads [n] number of threads to use, 0 (default) uses all available.\n" <<
165+
" --copy-file-metadata copy the file level metadata of the first input to the output.\n";
164166
if (verbose) {
165167
os << '\n' <<
166168
"Notes:\n" <<
@@ -415,6 +417,7 @@ main(int argc, char *argv[])
415417
#define axtime() getTime()
416418

417419
bool multiSnippet = false;
420+
bool dashInputHasBeenUsed = false, positionalInputHasBeenUsed = false;
418421
for (int i = 1; i < argc; ++i) {
419422
std::string arg = argv[i];
420423
if (arg[0] == '-') {
@@ -427,11 +430,22 @@ main(int argc, char *argv[])
427430
multiSnippet |= static_cast<bool>(opts.mInputCode);
428431
opts.mInputCode.reset(new std::string());
429432
loadSnippetFile(argv[i], *opts.mInputCode);
433+
} else if (parser.check(i, "-i")) {
434+
if (positionalInputHasBeenUsed) {
435+
fatal("unrecognized positional argument: \"" + opts.mInputVDBFiles.back() + "\". use -i and -o for vdb files");
436+
}
437+
dashInputHasBeenUsed = true;
438+
opts.mInputVDBFiles.emplace_back(argv[++i]);
430439
} else if (parser.check(i, "-v", 0)) {
431440
opts.mVerbose = true;
432441
} else if (parser.check(i, "--threads")) {
433442
opts.threads = atoi(argv[++i]);
443+
} else if (parser.check(i, "--copy-file-metadata", 0)) {
444+
opts.mCopyFileMeta = true;
434445
} else if (parser.check(i, "-o")) {
446+
if (positionalInputHasBeenUsed) {
447+
fatal("unrecognized positional argument: \"" + opts.mInputVDBFiles.back() + "\". use -i and -o for vdb files");
448+
}
435449
opts.mOutputVDBFile = argv[++i];
436450
} else if (parser.check(i, "--max-errors")) {
437451
opts.mMaxErrors = atoi(argv[++i]);
@@ -469,28 +483,34 @@ main(int argc, char *argv[])
469483
fatal("\"" + arg + "\" is not a valid option");
470484
}
471485
} else if (!arg.empty()) {
486+
if (dashInputHasBeenUsed) {
487+
fatal("unrecognized positional argument: \"" + arg + "\". use -i and -o for vdb files");
488+
}
472489

473-
bool addToFileList = true;
474490
if (opts.mMode == ProgOptions::Mode::Default) {
491+
bool skip = true;
475492
if (arg == "analyze") opts.mMode = ProgOptions::Analyze;
476493
else if (arg == "functions") opts.mMode = ProgOptions::Functions;
477-
else if (arg == "execute") {
494+
else if (arg == "execute") opts.mMode = ProgOptions::Execute;
495+
else {
496+
skip = false;
478497
opts.mMode = ProgOptions::Execute;
479-
addToFileList = false;
480-
}
481-
else opts.mMode = ProgOptions::Execute;
482-
}
483-
else {
484-
// if mode has already been set, no more positional arguments are expected
485-
// (except for execute which takes in and out)
486-
if (opts.mMode != ProgOptions::Mode::Execute) {
487-
fatal("unrecognized positional argument: \"" + arg + "\"");
488498
}
499+
if (skip) continue;
489500
}
490501

491-
if (addToFileList) {
502+
// @todo remove positional vdb in/out file arg support
503+
if (opts.mInputVDBFiles.empty()) {
504+
positionalInputHasBeenUsed = true;
505+
OPENVDB_LOG_WARN("position arguments [input.vdb <output.vdb>] are deprecated. use -i and -o");
492506
opts.mInputVDBFiles.emplace_back(arg);
493507
}
508+
else if (opts.mOutputVDBFile.empty()) {
509+
opts.mOutputVDBFile = arg;
510+
}
511+
else {
512+
fatal("unrecognized positional argument: \"" + arg + "\"");
513+
}
494514
} else {
495515
usage();
496516
}
@@ -503,9 +523,12 @@ main(int argc, char *argv[])
503523
if (opts.mMode == ProgOptions::Mode::Execute) {
504524
opts.mInitCompile = true;
505525
if (opts.mInputVDBFiles.empty()) {
506-
fatal("no vdb files have been provided.");
526+
fatal("no vdb files have been provided");
507527
}
508528
}
529+
else if (!opts.mInputVDBFiles.empty()) {
530+
fatal(modeString(opts.mMode) + " does not take input vdb files");
531+
}
509532

510533
if (opts.mVerbose) {
511534
axlog("OpenVDB AX " << openvdb::getLibraryVersionString() << '\n');
@@ -599,7 +622,7 @@ main(int argc, char *argv[])
599622
auto in = file.getGrids();
600623
grids.insert(grids.end(), in->begin(), in->end());
601624
// choose the first files metadata
602-
if (!meta) meta = file.getMetadata();
625+
if (opts.mCopyFileMeta && !meta) meta = file.getMetadata();
603626
file.close();
604627
axlog(": " << axtime() << '\n');
605628
} catch (openvdb::Exception& e) {
@@ -624,8 +647,11 @@ main(int argc, char *argv[])
624647
printFunctions(opts.mFunctionNamesOnly,
625648
opts.mFunctionSearch,
626649
std::cout);
650+
return EXIT_SUCCESS;
651+
}
652+
else {
653+
fatal("vdb_ax functions requires a valid option");
627654
}
628-
return EXIT_SUCCESS;
629655
}
630656

631657
// set up logger

openvdb_ax/openvdb_ax/test/TestAXCmd.cmake

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ if(EXISTS ${SPHERE_VDB} AND EXISTS ${TORUS_VDB})
5151
endif()
5252

5353
set(OUTPUT_DIR ${CMAKE_BINARY_DIR})
54-
if(UPDATE_BASELINE)
54+
if(UPDATE_BASELINES)
5555
set(OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR}/cmd)
5656
endif()
5757

@@ -179,6 +179,7 @@ run_test(PASS GENERATES_OUTPUT ARGS analyze -f ${CMAKE_CURRENT_LIST_DIR}/snippet
179179
run_test(PASS GENERATES_OUTPUT ARGS analyze -f ${CMAKE_CURRENT_LIST_DIR}/snippets/loop/forLoop --try-compile)
180180
run_test(PASS GENERATES_OUTPUT ARGS analyze -f ${CMAKE_CURRENT_LIST_DIR}/snippets/loop/forLoop --try-compile points)
181181
run_test(PASS GENERATES_OUTPUT ARGS analyze -f ${CMAKE_CURRENT_LIST_DIR}/snippets/loop/forLoop --try-compile volumes)
182+
run_test(PASS GENERATES_OUTPUT ARGS functions -h)
182183
run_test(PASS GENERATES_OUTPUT ARGS functions --list log)
183184
run_test(PASS GENERATES_OUTPUT ARGS functions --list-names)
184185

@@ -215,14 +216,6 @@ run_test(PASS ARGS analyze --try-compile points AX "@a+=@b;")
215216
run_test(PASS ARGS analyze --try-compile volumes AX "@a+=@b;")
216217
run_test(PASS ARGS functions --list non-existant-function)
217218

218-
if(HAS_DOWNLOAD_VDBS)
219-
# @todo diff these once we have attribute bindings (can't diff the files)
220-
# due to UUID changing
221-
run_test(PASS ARGS ${SPHERE_VDB} -o ${CMAKE_BINARY_DIR}/tmp.vdb AX "@ls_sphere += 1;")
222-
run_test(PASS ARGS ${SPHERE_VDB} ${CMAKE_BINARY_DIR}/tmp.vdb -o ${CMAKE_BINARY_DIR}/tmp.vdb AX "@ls_sphere -= 1;")
223-
run_test(PASS COMMAND ${CMAKE_COMMAND} ARGS -E remove -f ${CMAKE_BINARY_DIR}/tmp.vdb)
224-
endif()
225-
226219
# These tests should fail and the output should be checked
227220

228221
run_test(FAIL GENERATES_OUTPUT)
@@ -235,6 +228,25 @@ run_test(FAIL GENERATES_OUTPUT ARGS analyze --werror --try-compile --max-errors
235228
run_test(FAIL GENERATES_OUTPUT ARGS analyze --werror --try-compile --max-errors 2 AX "int a = 1.0; int a = 1.0;")
236229
run_test(FAIL GENERATES_OUTPUT ARGS analyze AX "invalid code")
237230
run_test(FAIL GENERATES_OUTPUT ARGS analyze --try-compile volumes AX "string str; bool a = ingroup(str);")
231+
run_test(FAIL GENERATES_OUTPUT ARGS analyze analyze AX "@a+=@b;")
232+
run_test(FAIL GENERATES_OUTPUT ARGS -i file.vdb execute AX "@a+=@b;")
233+
run_test(FAIL GENERATES_OUTPUT ARGS execute -i file.vdb execute AX "@a+=@b;")
234+
run_test(FAIL GENERATES_OUTPUT ARGS analyze -i file.vdb AX "@a+=@b;")
235+
run_test(FAIL GENERATES_OUTPUT ARGS functions)
236+
run_test(FAIL GENERATES_OUTPUT ARGS functions -i file.vdb)
237+
run_test(FAIL GENERATES_OUTPUT ARGS file.vdb -o tmp.vdb AX "@ls_sphere += 1;")
238+
run_test(FAIL GENERATES_OUTPUT ARGS execute file.vdb -o tmp.vdb AX "@ls_sphere += 1;")
239+
240+
# These should come last so that, when enabled, any that GENERATES_OUTPUT don't impact order
241+
242+
if(HAS_DOWNLOAD_VDBS)
243+
# @todo diff these once we have attribute bindings (can't diff the files)
244+
# due to UUID changing
245+
run_test(PASS ARGS -i ${SPHERE_VDB} -o ${CMAKE_BINARY_DIR}/tmp.vdb AX "@ls_sphere += 1;")
246+
run_test(PASS ARGS -i ${SPHERE_VDB} -i ${CMAKE_BINARY_DIR}/tmp.vdb -o ${CMAKE_BINARY_DIR}/tmp.vdb AX "@ls_sphere -= 1;")
247+
run_test(PASS GENERATES_OUTPUT ARGS ${SPHERE_VDB} ${CMAKE_BINARY_DIR}/tmp.vdb AX "@ls_sphere -= 1;")
248+
run_test(PASS COMMAND ${CMAKE_COMMAND} ARGS -E remove -f ${CMAKE_BINARY_DIR}/tmp.vdb)
249+
endif()
238250

239251
# These test fail and output is not checked
240252
# @todo tests here should be documented as to why the output is not being

openvdb_ax/openvdb_ax/test/cmd/vdb_ax_test_fail_1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ CLI utility for processing OpenVDB data using AX. Various commands are supported
55
-v verbose (print timing and diagnostics)
66

77
[execute] read/process/write VDB file/streams (default command):
8-
[a.vdb, b.vdb ... ] list of input files
9-
-s [code], -f [file] input code to execute as a string or from a file.
10-
-o [file.vdb] write the result to a given vdb file
11-
--opt [level] optimization level [NONE, O0, O1, O2, Os, Oz, O3 (default)]
12-
--werror warnings as errors
13-
--max-errors [n] maximum error messages, 0 (default) allows all error messages
14-
--threads [n] number of threads to use, 0 (default) uses all available.
8+
-i [file.vdb] append an input vdb file to be read
9+
-s [code], -f [file] input code to execute as a string or from a file.
10+
-o [file.vdb] write the result to a given vdb file
11+
--opt [level] optimization level [NONE, O0, O1, O2, Os, Oz, O3 (default)]
12+
--werror warnings as errors
13+
--max-errors [n] maximum error messages, 0 (default) allows all error messages
14+
--threads [n] number of threads to use, 0 (default) uses all available.
15+
--copy-file-metadata copy the file level metadata of the first input to the output.
1516

1617
[analyze] parse the provided code and run analysis:
1718
-s [code], -f [file] input code as a string or from a file.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
WARNING: position arguments [input.vdb <output.vdb>] are deprecated. use -i and -o
2+
FATAL: analyze does not take input vdb files. See 'vdb_ax --help'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FATAL: unrecognized positional argument: "execute". use -i and -o for vdb files. See 'vdb_ax --help'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FATAL: unrecognized positional argument: "execute". use -i and -o for vdb files. See 'vdb_ax --help'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FATAL: analyze does not take input vdb files. See 'vdb_ax --help'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FATAL: vdb_ax functions requires a valid option. See 'vdb_ax --help'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FATAL: functions does not take input vdb files. See 'vdb_ax --help'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
WARNING: position arguments [input.vdb <output.vdb>] are deprecated. use -i and -o
2+
FATAL: unrecognized positional argument: "file.vdb". use -i and -o for vdb files. See 'vdb_ax --help'

0 commit comments

Comments
 (0)