-
Notifications
You must be signed in to change notification settings - Fork 169
Add Windows/MSVC support #71
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
Conversation
FWIW here is a blueprint for compiling this with Craft:
I will setup a repository for this at some point, but now I'm tired and excited to get some feedback ;-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good. Thanks for the work.
Please have a look at inline comments.
generator/filesystem.cpp
Outdated
@@ -32,6 +32,11 @@ | |||
|
|||
#include <iostream> | |||
|
|||
// ATTENTION: Keep in sync with ECMAScript function of the same name in common.js | |||
void replace_invalid_filename_chars(std::string &str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Annotator::getReferenceAndTitle, we already escape '<' and '>'. We could also escape ':'
The problem if we do the way you did, is that refs generated with older version of the code browser will not be compatible with the new javascript.
But the problem if we escape it in getReferenceAndTitle, is that URL containing #foo::bar will stop working. And we also do not want that.
So I guess the way you did it is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking about it, this means that struct Foo__Bar
and srutct Foo { struct Bar; };
will have the same filename. Maybe that's not so common that it's not going to clash. (i think double underscore in a identifier is undefined behavior anyway). But could we use a symbol not allowed in a identifier? like .
or @
or %
or something else. maybe i'd go with .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable
generator/filesystem.cpp
Outdated
@@ -42,14 +52,24 @@ std::error_code canonicalize(const llvm::Twine &path, llvm::SmallVectorImpl<char | |||
std::string p = path.str(); | |||
#ifdef PATH_MAX | |||
int path_max = PATH_MAX; | |||
#elif defined(MAX_PATH) | |||
unsigned int path_max = MAX_PATH; | |||
#else | |||
int path_max = pathconf(p.c_str(), _PC_PATH_MAX); | |||
if (path_max <= 0) | |||
path_max = 4096; | |||
#endif | |||
result.resize(path_max); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, no need to resize to MAX_PATH when you know the size of the canonical string a bit later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to resize the buffer or get the MAX_PATH when using llvm::sys::fs::real_path
71e5ce9
to
5bcaaad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider also checking the demangleFunctionName in the js code.
generator/filesystem.cpp
Outdated
@@ -42,14 +52,24 @@ std::error_code canonicalize(const llvm::Twine &path, llvm::SmallVectorImpl<char | |||
std::string p = path.str(); | |||
#ifdef PATH_MAX | |||
int path_max = PATH_MAX; | |||
#elif defined(MAX_PATH) | |||
unsigned int path_max = MAX_PATH; | |||
#else | |||
int path_max = pathconf(p.c_str(), _PC_PATH_MAX); | |||
if (path_max <= 0) | |||
path_max = 4096; | |||
#endif | |||
result.resize(path_max); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to resize the buffer or get the MAX_PATH when using llvm::sys::fs::real_path
generator/filesystem.cpp
Outdated
@@ -32,6 +32,11 @@ | |||
|
|||
#include <iostream> | |||
|
|||
// ATTENTION: Keep in sync with ECMAScript function of the same name in common.js | |||
void replace_invalid_filename_chars(std::string &str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thinking about it, this means that struct Foo__Bar
and srutct Foo { struct Bar; };
will have the same filename. Maybe that's not so common that it's not going to clash. (i think double underscore in a identifier is undefined behavior anyway). But could we use a symbol not allowed in a identifier? like .
or @
or %
or something else. maybe i'd go with .
data/common.js
Outdated
// ATTENTION: Keep in sync with C++ function of the same name in filesystem.cpp and `Generator::escapeAttrForFilename` | ||
function replace_invalid_filename_chars(str) { | ||
return str.replace(new RegExp(':', 'g'), '_'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice if older generated file would still work with the newer javascript.
older generated files do not include this common.js. So maybe we need a fallback for when the function does not exist.
Note: I've been trying to keep only one .js included. this is why symbol.html has some duplicated code.
I've been wanting to use a build system to concatenate and minify files, but never got around to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see ... but then references with ::
(or now .
) still won't work while a lot of other refs still work.
We could possibly set a global var in the html files (:shudder:) that activates the filename sanitizing... old html files won't have it and so we would know not to replace ::.
I hate code duplication with a passion - but for this supershort function, I don't want to invest the time to setup a js build system. Pretty much out of scope for this PR.
Will remove common.js and implement a backwards compatible solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, a global var would work. Maybe with a version number or so.
Will maybe be a problem in symbol.html, but that's fine if tooltip there works less.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, because that is not generated but shared in the data folder. 🤷
…s again and use . instead of _ as replacement
I tried to be very conservative about changing any logic or performance on other platforms than Windows, that's why I ifdef'ed some code that should be working cross-platform. Moreover I did not want to raise the required C++ version to 2017 for std::filesystem on all platforms. Let me know if you would prefer it that way.