-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Tons of include file notices when building with Chinese version of Visual Studio 2010 #613
Comments
On an English install "Note: including file:%s%s\n" appears as resource in the string table in VC\bin\1033\clui.dll. 1033 is the locale identifier for "English (United States)". I'm not aware of any command line option to force cl into 1033 locale unfortunately. I assume if multiple locales are installed it uses system settings to determine which to use. So, I guess we'd have to have add various languages to the prefix search in the /showIncludes parser. :/ |
I think cmcldeps (the CMake parser of this output) uses a regex, something like "[^:]+: [^:]+: (.*)", to grab all output lines that look like showincludes output. I haven't looked at the code too hard because I'd eventually like to implement something like that and I don't want to violate any copyrights. :) The tricky part is not confusing showincludes output with warnings. sfcheng, could you paste the Chinese output of Visual Studio cl.exe when showing a warning or error message? |
It looks like that : is not ascii 58, so that might add a wrinkle. Maybe the line number "(\d+)" that will be in errors could be useful signal. |
There is no (clean) way to do this, unfortunately. Foreign language versions of VS would have other locale resources in different number(e.g. 1041 for JA). But fortunately, "error Cnnnn" and "warning Cnnnn" never get localized. So we can use them as key. But as @sgraham said, line numbers looks like more promising because it would also allow filtering out 'note:' output. I'm not sure whether or not : are not ascii 58. In Japanese version, these are certainly ascii 58. FWIW, Japanese output would look like this:
|
Related art: https://bugzilla.mozilla.org/show_bug.cgi?id=587372 (approach there: read prefix from an env var, have an autoconf check to verify /showIncludes parsing works. Not great.) |
Idea similar to the mozilla bug: There could be a toplevel var |
While CMake configurures, the include prefix is read from one dummy build, I assume ninja also needs to accept an additional (global) argument. CMake also uses cmcldeps to generate dependencies for .rc files by first "compiling" the .rc file with cl which generates the dependency file, and then processes it with the rc tool. |
Does this work with non-Ascii prefixes? |
#665 is merged. We might have to iterate on encoding issues a bit still though, so leaving this open until this is verified working. |
With a french local, ninja 1.8.2 and CMake 3.10.2, this still happens... |
#665 added msvc_deps_prefix. Does cmake set that? @syntheticpp @mathstuf |
@nico I see code in CMake which references it. |
Still happening on Visual Studio Community 15.9.7... |
For the record, this is still happening to me with the following configuration: EDIT: Better workaround: set Old workaround: This unfortunately causes CMake to generate |
Setting |
This comment was marked as abuse.
This comment was marked as abuse.
I'll give it a shot this week! |
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
This comment was marked as abuse.
Ha! I was actually going to look in there tomorrow. Seems like you caught it before I had a chance to. I just shut my computer down for the night. I'll get back to you tomorrow! |
It's worth noting, though, I suspect the logic just after it might be the actual culprit. But as I said, I'll do a proper investigation/debugging session tomorrow. |
The encodings don't match. I think that CL itself is outputting CP437, but the CMake-generated rules.ninja is in Latin-1. I'm guessing that some conversion occured on the CMake side, but that'll require more digging. EDIT: It seems like CL will output in whatever the console's codepage is. (Source 1, Source 2). I'm not sure how we can force it to be something else. Perhaps we can bring the two together by converting them both to a common encoding such as UTF-8 (or whatever Ninja prefers to use), e.g. by calling |
Thinking back on this... this might be CMake's fault. On Windows, the I tried changing So the question I'm having now is... should ninja's |
@bradking Thoughts on the encoding and prefix detection here? |
Historically ninja has been encoding agnostic (as long as the encoding used the same byte as ASCII for '/'). However, Windows might make that difficult. |
Ninja's IIRC, MSVC's output encoding can be affected by environment variables and/or flags. That means we may end up with the compiler output in a different encoding than the codepage in which Ninja is operating and using to interpret strings in |
I couldn't find any environment variable affecting the codepage used by CL. I think it just uses the codepage associated with the process (which is based on the system's regional settings, or by the console settings if the process is running in one). However, there is an environment variable that sets the language used by CL, |
Just to restate my above comment in different words: Ninja treats its input files as (encodingless) bytes, and does encoding-ignorant byte comparisons of strings, to attempt to evade these issues. You need the bytes that appear in the build.ninja file to match the bytes that ninja reads from the process stdout, but ninja doesn't care about encodings. |
Similar issue on last Visual Studio Preview 2022 17.2 with ninja 1.10.2 in CLion 2021.3. Tons of "Note including file: foo.h" even without /showIncludes option set. So annoying |
Hey all! Came across this while writing some Bazel tooling. After some experimenting, we ended up matching all the languages rather than using VSLANG=1033, because the latter doesn't work if the user doesn't have the English language pack installed. (Seems to work otherwise, though.) |
A solution not very good: such "Note include" output by MSVC tool chain,just change it. 用了clang就不能用.nativs了。。。。。。 |
Hit this issue as well, so we just switched to msbuild from ninja and the issue was gone. Unexpectedly found that msbuild has been far faster than before :D |
I guess the bug is in cmake. CMake can detect the prefix correctly, and stores it in its variable 'CMAKE_CL_SHOWINCLUDES_PREFIX' (or CMAKE_CXX_CL_SHOWINCLUDES_PREFIX). Note that this prefix is not utf-8 encoding. For example, in my locale it is encoded in 'GB18030'. During build, msvc_deps_prefix (utf-8 encoding) cannot match MSVC's output (gb18030 enconding, et al), so Ninja reports lots of include files. I switched to cmake-3.20, which doesn't convert the prefix to utf-8, and everything works well. |
So this can be closed then? |
A relevant change in CMake is MR 5089, first included in CMake 3.19. It switched to writing the The best path forward for Ninja upstream is #1812/#2200, which add support for using |
No as it still exists in CMake 3.24. I checked MR 5089, looks like the issue was introduced again in MR 5860 . When Ninja version is larger than 1.11, CMake assumes Ninja supports UTF-8; so it writes rules.ninja with UTF-8. |
@kangjianbin thanks. Please open a CMake upstream issue for that. Include details about the actual encoding of the byte sequence that you're observing. |
Created issue https://gitlab.kitware.com/cmake/cmake/-/issues/24068 |
Please try CMake 3.25. |
CMake 3.25 works for me. Thanks. |
When I update cmake to 3.25 this issue doesn't seem to be resolved.
Whether you run Enable I suggest that cmake/ninja should proactively avoid annoying problems caused by MSVC's multilingual mechanism if it wants to read this information from the standard output of 'cl.exe'. |
Did cmake detect the prefix correctly? |
We can run and we need also change build.ninja encoding (utf8) to function probe_include_note_from_cl()
local key = "cldeps.parse_include.note"
local note = detectcache:get(key)
if not note then
local cl = find_tool("cl")
if cl then
local projectdir = os.tmpfile() .. ".cldeps"
local sourcefile = path.join(projectdir, "main.c")
local headerfile = path.join(projectdir, "foo.h")
local objectfile = sourcefile .. ".obj"
local outdata = try { function()
local runenvs = toolchain.load("msvc"):runenvs()
local argv = {"-nologo", "-showIncludes", "-c", "-Fo" .. objectfile, sourcefile}
io.writefile(headerfile, "\n")
io.writefile(sourcefile, [[
#include "foo.h"
int main (int argc, char** argv) {
return 0;
}
]])
return vstool.iorunv(cl.program, argv, {envs = runenvs, curdir = projectdir})
end}
if outdata then
for _, line in ipairs(outdata:split('\n', {plain = true})) do
note = line:match("^(.-:.-: )")
if note then
break
end
end
end
os.tryrm(projectdir)
end
detectcache:set(key, note)
detectcache:save()
end
return note
end function _add_rules_for_compiler(ninjafile)
ninjafile:print("# rules for compiler")
if is_plat("windows") then
-- @see https://github.com/ninja-build/ninja/issues/613
local note_include = parse_include.probe_include_note_from_cl()
if not note_include then
note_include = "Note: including file:"
end
ninjafile:print("msvc_deps_prefix = %s", note_include:trim())
end BTW, if |
If useful: I think that the last time I checked out /sourceDependencies (and friends) they were only for module dependencies, rather than the normal header inclusion you'd need for this. Creating a test to extract the include note is very clever :) |
Early revisions of the P1689 format included this information but it was excluded in order to keep the initial revisions focused and less cluttered. |
I'm using Visual Studio 2019 with Chinese locale, and solved this issue simply by upgrading my cmake version to 3.26. 将 cmake 版本升级到 3.26 即可 |
Certainly, meson does this as well: https://github.com/mesonbuild/meson/blob/ef5da765af7c5687228ed6e77a19d20bc474c4a4/mesonbuild/backend/ninjabackend.py#L526-L573 So does cmake: https://gitlab.kitware.com/cmake/cmake/-/blob/1ec4c6579117634ddb20962cdb63313dbf79887e/Modules/CMakeDetermineCompilerId.cmake#L1131 Both use regexes a lot more complicated than yours, by the way -- I don't know whether that's necessary but it's plausible that you will sometimes fail to find the right info. |
If I understand it correctly ninja generator call MSVC compiler with /showIncludes (/showIncludes) si IMO it's ninja to offer an option to hide it. |
Ninja does since about five years ago, it's not clear why the ticket is still open.
Probably the Make backend doesn't support showIncludes at all, so you don't get reliable builds. Meanwhile, Visual Studio "cheats" since it's responsible for emitting the translated messages and can always tell exactly what part it is. Unfortunately everyone other than Microsoft needs to work around Microsoft's non-interoperable design of translating machine-readable messages into the user's prose language. |
I see that cmake detects it automatically, but I use cmake 3.24.2 and it still doesn't work. Is there any special configuration I need to do to turn it on? |
CMake 3.26 works for me. OS: Windows 11 22H2 |
Seems to be fixed. Please reopen if it still applies. |
QtCreator comes with CMake 3.27.7 and it's reproducible there. |
Can you please report back to CMake's issue tracker there with more details? |
When building chromium with ninja with Chinese version of Visual Studio 2010, the console window outputs tons of include file notices and thus greatly slows down the building process. The notice is like:
注意: 包含文件:include file path
The English equivalent is:
Note: including file: .....
Perhaps ninja is stripping the include notices based on the English words only.
The text was updated successfully, but these errors were encountered: