Skip to content

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

Merged
merged 15 commits into from
Sep 18, 2018
Merged

Add Windows/MSVC support #71

merged 15 commits into from
Sep 18, 2018

Conversation

dschmidt
Copy link
Contributor

@dschmidt dschmidt commented Sep 10, 2018

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.

@dschmidt
Copy link
Contributor Author

FWIW here is a blueprint for compiling this with Craft:

import info

class subinfo(info.infoclass):
    def setTargets(self):
        for ver in ["msvc"]:
            self.svnTargets[ver] = f"[git]https://github.com/dschmidt/woboq_codebrowser|{ver}|"

        self.defaultTarget = 'msvc'
        self.description = "Woboq CodeBrowser"
        self.webpage = "http://woboq.com/codebrowser.html"

    def setDependencies(self):
        self.buildDependencies["dev-utils/cmake"] = "default"
        self.buildDependencies["libs/meta-llvm"] = "default"

from Package.CMakePackageBase import *

class Package(CMakePackageBase):
    def __init__(self):
        CMakePackageBase.__init__(self)

I will setup a repository for this at some point, but now I'm tired and excited to get some feedback ;-)

Copy link
Contributor

@ogoffart ogoffart left a 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.

@@ -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)
Copy link
Contributor

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.

Copy link
Contributor

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 .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable

@@ -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);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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

@CLAassistant
Copy link

CLAassistant commented Sep 10, 2018

CLA assistant check
All committers have signed the CLA.

@dschmidt dschmidt force-pushed the msvc branch 2 times, most recently from 71e5ce9 to 5bcaaad Compare September 10, 2018 09:51
Copy link
Contributor

@ogoffart ogoffart left a 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.

@@ -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);
Copy link
Contributor

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

@@ -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)
Copy link
Contributor

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'), '_');
}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@ogoffart ogoffart Sep 10, 2018

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.

Copy link
Contributor Author

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. 🤷

@ogoffart ogoffart merged commit 19f6181 into KDAB:master Sep 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants