Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add argument to specify output directory #6

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ gcc <regular arguments> -fplugin=externis -fplugin-arg-externis-trace=SOME_PATH/
# Otherwise:
gcc <regular arguments> -fplugin=/PATH/TO/build/externis.so -fplugin-arg-externis-trace=SOME_PATH/trace.json
```
If a trace output path is not given, a temporary file with the name
Alternatively, you can specify a directory to write the files to:
```bash
gcc <regular arguments> -fplugin=/PATH/TO/build/externis.so -fplugin-arg-externis-trace-dir=SOME_PATH/
```
In which case the output will be written to SOME_PATH/trace_XXXXXX.json
If a trace output path or directory is not given, a temporary file with the name
`/tmp/trace_XXXXXX.json` will be used instead.

## License & Copyright
Expand Down
22 changes: 13 additions & 9 deletions externis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ static const char *PLUGIN_NAME = "externis";

bool setup_output(int argc, plugin_argument *argv) {
const char *flag_name = "trace";
const char *dir_flag_name = "trace-dir";
// TODO: Maybe make the default filename related to the source filename.
// TODO: Validate we only compile one TU at a time.
FILE *trace_file = nullptr;
Expand All @@ -113,22 +114,25 @@ bool setup_output(int argc, plugin_argument *argv) {
return false;
}
trace_file = fdopen(fd, "w");
} else if (argc == 1) {
if (strcmp(argv[0].key, flag_name)) {
fprintf(stderr,
"Externis Error! Arguments must be -fplugin-arg-%s-%s=FILENAME",
PLUGIN_NAME, flag_name);
return false;
}
} else if (argc == 1 && !strcmp(argv[0].key, flag_name)) {
trace_file = fopen(argv[0].value, "w");
if (!trace_file) {
fprintf(stderr, "Externis Error! Couldn't open %s for writing\n",
argv[0].value);
}
} else if (argc == 1 && !strcmp(argv[0].key, dir_flag_name)) {
std::string file_template{argv[0].value};
file_template += "/trace_XXXXXX.json";
int fd = mkstemps(file_template.data(), 5);
if (fd == -1) {
perror("Externis mkstemps error: ");
return false;
}
trace_file = fdopen(fd, "w");
} else {
fprintf(stderr,
"Externis Error! Arguments must be -fplugin-arg-%s-%s=FILENAME\n",
PLUGIN_NAME, flag_name);
"Externis Error! Arguments must be -fplugin-arg-%s-%s=FILENAME or -fplugin-arg-%s-%s=DIRECTORY\n",
PLUGIN_NAME, flag_name, PLUGIN_NAME, dir_flag_name);
return false;
}
if (trace_file) {
Expand Down