Add Java output#605
Conversation
|
Hi! Thank you for your contribution! This all seems fine, but it's been a while since many of us have done anything with Java. We'll try to find a Java-savvy reviewer, but it might take a bit, so please be patient. Thanks again! |
|
Thanks for adding Java output here. I smoke-tested the generated One Java packaging issue stood out: package org.khronos.spv;but the generated file is currently written to: That means normal Java source discovery does not work, because I think the best fix is to generate/check in the file at: and keep That would also require:
The alternative would be to remove the package declaration, but I think keeping the package and moving the generated file under the matching directory is more useful for Java consumers. |
|
My one concern with putting the file at I do agree that moving the file is a better solution than removing the package declaration entirely, and I'll try to make the changes in the next couple of days. |
(just to preface that it's been over 25 years since I've really done Java development - so my knowledge might be a bit out of date, but) I think that that's probably what Java developers would expect based on the package name, and there are breadcrumbs to that package name in the other headers that do end up in directly in the unified/ folder. |
I don't usually write C++ so I may just be missing something obvious, but I (somewhat embarrassingly) can't figure out the best way create a directory. It seems like Instead I made the |
|
Thanks for moving the Java file. I retested this shape locally, and the Java sourcepath issue is fixed now: treating On the directory creation question: I agree and exits successfully without generating the Java file. A small localized C++11 helper seems reasonable here, even though it needs the usual #include <cerrno>
#ifdef _WIN32
#include <direct.h>
#else
#include <sys/stat.h>
#include <sys/types.h>
#endif
bool makeDirectory(const std::string& path) {
#ifdef _WIN32
const int result = _mkdir(path.c_str());
#else
const int result = mkdir(path.c_str(), 0755);
#endif
return result == 0 || errno == EEXIST;
}
bool ensureParentDirectories(const std::string& filename) {
std::string::size_type pos = 0;
while ((pos = filename.find(/, pos)) != std::string::npos) {
const std::string path = filename.substr(0, pos);
++pos;
if (!path.empty() && !makeDirectory(path))
return false;
}
return true;
}Then call I tested this approach locally on macOS: direct |
I don't know if there's any interest in including this, but I needed it for a project and figured there's no harm in opening a PR.
The output is
Spv.javarather thanspirv.javabecause Java requires public classes be declared in files that match their name.