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

.cpp files are not recompiled by xmake when a header changes on Windows #1072

Closed
SirLynix opened this issue Nov 25, 2020 · 24 comments
Closed
Milestone

Comments

@SirLynix
Copy link
Member

SirLynix commented Nov 25, 2020

Describe the bug

I tried to switch to xmake yesterday when I got this bug, it seems .cpp are not recompiled when a .hpp changes on Windows.

I reproduced the problem using a very small project, here are the files:

src/headerA.hpp:

constexpr int ValueA = 254;

src/headerB.hpp:

#include "headerA.hpp"

constexpr int ValueB = 42;

src/headerC.hpp:

#include "headerB.hpp"

constexpr int ValueC = 124;

src/main.cpp:

#include "headerC.hpp"
#include <iostream>

int main(int argc, char** argv)
{
    std::cout << "A: " << ValueA << std::endl;
    std::cout << "B: " << ValueB << std::endl;
    std::cout << "C: " << ValueC << std::endl;
}

xmake.lua:

add_rules("mode.debug", "mode.release")

target("test_recompilation")
    set_kind("binary")
    add_headerfiles("src/*.hpp")
    add_files("src/*.cpp")

When I change any value in the header, the main.cpp is not recompiled and outputs the old values.

This bug doesn't occurs on Linux.

Expected behavior

That when changing any header file, all .cpp including it (even not directly) are compiled.

Error output

lynix@SirLynixVanDesktop:/mnt/c/Projets/Tests/xmake-build/test_recompilation$ cat src/headerB.hpp
#pragma once

#include "headerA.hpp"

constexpr int ValueB = 43;
lynix@SirLynixVanDesktop:/mnt/c/Projets/Tests/xmake-build/test_recompilation$ xmake.exe
[100%]: build ok!
lynix@SirLynixVanDesktop:/mnt/c/Projets/Tests/xmake-build/test_recompilation$ xmake.exe run
A: 255
B: 42
C: 123

Note the B value is the previous one.

(Please note also I'm on WSL so I have access to Linux cat command but I'm using the Windows xmake version)

Related Environment

Please provide compiling and running environment information:

  • xmake version: v2.3.9+202011250023
  • os: Windows 10 2004
  • target platform: Windows
@waruqi
Copy link
Member

waruqi commented Nov 25, 2020

I think it may be related to the lowercase header file path list output by cl.exe + /sourceDependencies. But there is no time to confirm it further.

I will check this issue in detail tomorrow.

@waruqi waruqi added this to the v2.5.1 milestone Nov 25, 2020
@waruqi
Copy link
Member

waruqi commented Nov 26, 2020

I tested it completely using the test example you provided. It works fine for me. But I don’t have a wsl environment, I did the test on cmd/msvc.

Can you let me see your the content of build/.deps/test_recompilation/windows/x64/release/src/main.cpp.obj.d?

In addition, I found a small problem in detecting /sourceDependencies flags. When incrementally compiling, it will automatically switch back to /showIncludes flags. And I have fixed it now on dev branch.

I am not sure if it is related to the problem you encountered, of course you can try to update to the dev version and continue to test it.

@SirLynix
Copy link
Member Author

SirLynix commented Nov 26, 2020

I don't think it's related to WSL as I reproduced the problem using a vsxmake2019 project.

Here's main.cpp.obj.d content, it's kinda weird (beware: french, maybe that's causing the issue?):

{
    values = {
        [[C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bin\HostX64\x64\cl.exe]],
        {
            "/EHsc",
            "-nologo",
            "-Ox",
            "-fp:fast"
        }
    },
    files = {
        [[src\main.cpp]]
    },
    depfiles_cl = "main.cpp\
Remarque : inclusion du fichier :  C:\\Projets\\Tests\\xmake-build\\test_recompilation\\src\\headerc.hpp\
Remarque : inclusion du fichier :   C:\\Projets\\Tests\\xmake-build\\test_recompilation\\src\\headerb.hpp\
Remarque : inclusion du fichier :    C:\\Projets\\Tests\\xmake-build\\test_recompilation\\src\\headera.hpp\
Remarque : inclusion du fichier :  C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\iostream\
Remarque : inclusion du fichier :   C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\yvals_core.h\
Remarque : inclusion du fichier :    C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\vcruntime.h\
Remarque : inclusion du fichier :     C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\sal.h\
Remarque : inclusion du fichier :      C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\concurrencysal.h\
Remarque : inclusion du fichier :     C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\vadefs.h\
Remarque : inclusion du fichier :    C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xkeycheck.h\
Remarque : inclusion du fichier :   C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\istream\
Remarque : inclusion du fichier :    C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\ostream\
Remarque : inclusion du fichier :     C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\ios\
Remarque : inclusion du fichier :      C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xlocnum\
Remarque : inclusion du fichier :       C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\climits\
Remarque : inclusion du fichier :        C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\limits.h\
Remarque : inclusion du fichier :       C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\cmath\
Remarque : inclusion du fichier :        C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\yvals.h\
Remarque : inclusion du fichier :         C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\crtdbg.h\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt.h\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\vcruntime_new_debug.h\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\vcruntime_new.h\
Remarque : inclusion du fichier :         C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\crtdefs.h\
Remarque : inclusion du fichier :         C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\use_ansi.h\
Remarque : inclusion du fichier :        C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\cstdlib\
Remarque : inclusion du fichier :         C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\math.h\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_math.h\
Remarque : inclusion du fichier :         C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\stdlib.h\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_malloc.h\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_search.h\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\stddef.h\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_wstdlib.h\
Remarque : inclusion du fichier :        C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xtr1common\
Remarque : inclusion du fichier :       C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\cstdio\
Remarque : inclusion du fichier :        C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\stdio.h\
Remarque : inclusion du fichier :         C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_wstdio.h\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_stdio_config.h\
Remarque : inclusion du fichier :       C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\iterator\
Remarque : inclusion du fichier :        C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\iosfwd\
Remarque : inclusion du fichier :         C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\cstring\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\string.h\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_memory.h\
Remarque : inclusion du fichier :            C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_memcpy_s.h\
Remarque : inclusion du fichier :             C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\errno.h\
Remarque : inclusion du fichier :             C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\vcruntime_string.h\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_wstring.h\
Remarque : inclusion du fichier :         C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\cwchar\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\wchar.h\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_wconio.h\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_wctype.h\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_wdirect.h\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_wio.h\
Remarque : inclusion du fichier :            C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_share.h\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_wprocess.h\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_wtime.h\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\sys/stat.h\
Remarque : inclusion du fichier :            C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\sys/types.h\
Remarque : inclusion du fichier :         C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xstddef\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\cstddef\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\initializer_list\
Remarque : inclusion du fichier :        C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xutility\
Remarque : inclusion du fichier :         C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\utility\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\type_traits\
Remarque : inclusion du fichier :       C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\streambuf\
Remarque : inclusion du fichier :        C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xiosbase\
Remarque : inclusion du fichier :         C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\share.h\
Remarque : inclusion du fichier :         C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\system_error\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\__msvc_system_error_abi.hpp\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\cerrno\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\stdexcept\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\exception\
Remarque : inclusion du fichier :            C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\malloc.h\
Remarque : inclusion du fichier :            C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\vcruntime_exception.h\
Remarque : inclusion du fichier :             C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\eh.h\
Remarque : inclusion du fichier :              C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\corecrt_terminate.h\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xstring\
Remarque : inclusion du fichier :            C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xmemory\
Remarque : inclusion du fichier :             C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\cstdint\
Remarque : inclusion du fichier :              C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\stdint.h\
Remarque : inclusion du fichier :             C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\limits\
Remarque : inclusion du fichier :              C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\cfloat\
Remarque : inclusion du fichier :               C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\float.h\
Remarque : inclusion du fichier :              C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\intrin0.h\
Remarque : inclusion du fichier :              C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\isa_availability.h\
Remarque : inclusion du fichier :             C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\new\
Remarque : inclusion du fichier :             C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xatomic.h\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xcall_once.h\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xerrc.h\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\atomic\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xthreads.h\
Remarque : inclusion du fichier :            C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xtimec.h\
Remarque : inclusion du fichier :             C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\time.h\
Remarque : inclusion du fichier :         C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xlocale\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\memory\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\typeinfo\
Remarque : inclusion du fichier :            C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\vcruntime_typeinfo.h\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xfacet\
Remarque : inclusion du fichier :          C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xlocinfo\
Remarque : inclusion du fichier :           C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\include\\xlocinfo.h\
Remarque : inclusion du fichier :            C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\ctype.h\
Remarque : inclusion du fichier :            C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\ucrt\\locale.h\
"
}

I'll update to the dev version and test it again

@SirLynix
Copy link
Member Author

Okay, as far as I understand it's due to the french output, as https://github.com/xmake-io/xmake/blob/master/xmake/modules/private/tools/cl/parse_include.lua#L35 only handle two languages and doesn't understand french outputs. I'll try to fill that array if you want

@waruqi
Copy link
Member

waruqi commented Nov 26, 2020

I probably know the reason, because xmake is not compatible with all the prefix strings generated by /showIncludes.

_g.notes = _g.notes or
{
"Note: including file: "
, "注意: 包含文件: "
}

Currently xmake only supports parsing Chinese and English string prefixes and does not support Remarque : inclusion du fichier : yet.

If xmake uses /sourceDependencies correctly, this problem should not exist, so if you update to the dev version, it should work normally.

In addition, I found a small problem in detecting /sourceDependencies flags. When incrementally compiling, it will automatically switch back to /showIncludes flags. And I have fixed it now on dev branch.

@waruqi
Copy link
Member

waruqi commented Nov 26, 2020

Okay, as far as I understand it's due to the french output, as https://github.com/xmake-io/xmake/blob/master/xmake/modules/private/tools/cl/parse_include.lua#L35 only handle two languages and doesn't understand french outputs. I'll try to fill that array if you want

If it is a high version vs, this problem should not be encountered, of course, I am also happy that you can help to improve this list.

@SirLynix
Copy link
Member Author

SirLynix commented Nov 26, 2020

My MSVC version is 19.28.29334, the latest I'm aware of.

Updating to the dev branch didn't fix the issue unfortunately. And adding the french prefix didn't seem to work either (I edited xmake files to test, it's still not recompiling files).

Is there anything I can do to better understand what xmake does internally?

@waruqi
Copy link
Member

waruqi commented Nov 26, 2020

Can you try cleaning cache first? rm -rf .xmake; xmake f -c; xmake and let me see the content of main.cpp.obj.d again.

@waruqi
Copy link
Member

waruqi commented Nov 26, 2020

Is there anything I can do to better understand what xmake does internally?

if _has_source_dependencies(self) then
depfile = os.tmpfile()
compflags = table.join(flags, "/sourceDependencies", depfile)
else
compflags = table.join(flags, "-showIncludes")
end

-- generate the dependent includes
if dependinfo then
if depfile and os.isfile(depfile) then
dependinfo.depfiles_cl_json = io.readfile(depfile)
os.rm(depfile)
elseif outdata then
dependinfo.depfiles_cl = outdata
end
end
end

elseif dependinfo.depfiles_cl_json then
_load_depfiles(parse_deps_cl_json, dependinfo, dependinfo.depfiles_cl_json)
dependinfo.depfiles_cl_json = nil
elseif dependinfo.depfiles_cl then
_load_depfiles(parse_deps_cl, dependinfo, dependinfo.depfiles_cl)
dependinfo.depfiles_cl = nil
elseif dependinfo.depfiles_rc then

/showIncludes

https://github.com/xmake-io/xmake/blob/master/xmake/modules/private/tools/cl/parse_deps.lua

/sourceDependencies

https://github.com/xmake-io/xmake/blob/master/xmake/modules/private/tools/cl/parse_deps_json.lua

@SirLynix
Copy link
Member Author

SirLynix commented Nov 26, 2020

Okay so I did clean the cache and removed the build folder, it seems to work now. I added a print in parse_include.lua which shows that xmake now parses the french output.

I also ran a -vD build to show what xmake was doing with flags

checking for architecture ... x64
checking for Microsoft Visual Studio (x64) version ... 2019
checking for the c++ compiler (cxx) ... cl.exe
checking for C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bin\HostX64\x64\cl.exe ... ok
checking for flags (-Ox -fp:fast) ... ok
> cl.exe "-Ox" "-fp:fast" "/EHsc"
checking for ccache ... no
[ 50%]: compiling.release src\main.cpp
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\bin\\HostX64\\x64\\cl.exe" -c /EHsc -nologo -Ox -fp:fast -Fobuild\.objs\test_recompilation\windows\x64\release\src\main.cpp.obj src\main.cpp
checking for flags (cl_sourceDependencies) ... ok
> cl.exe "/sourceDependencies" "C:\Users\Lynix\AppData\Local\Temp\.xmake\201126\_C9FF029B8AE7492083D9816CB6F56240.json" "/EHsc"
checking for link.exe ... C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bin\HostX64\x64\link.exe
checking for the linker (ld) ... link.exe
[ 75%]: linking.release test_recompilation.exe
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\bin\\HostX64\\x64\\link.exe" -nologo -dynamicbase -nxcompat -machine:x64 /opt:ref /opt:icf /ltcg -out:build\windows\x64\release\test_recompilation.exe
build\.objs\test_recompilation\windows\x64\release\src\main.cpp.obj
[100%]: build ok!

But I'm wondering now, you said this issue shouldn't be encountered with a high VS version (which is my case as far as I know) because it will use /sourceDependencies, which it seems to be doing, but it's still using /showIncludes lines.

@waruqi
Copy link
Member

waruqi commented Nov 26, 2020

checking for flags (cl_sourceDependencies) ... ok

I see that he is already using /sourceDependencies.

If you have updated to the dev version, then it should not continue to use /showIncludes. Becase I improved it on dev. see 6426a1e

Can you let me see the content of main.cpp.obj.d again?

@SirLynix
Copy link
Member Author

SirLynix commented Nov 26, 2020

Okay I found something weird.

On the very first xmake run, it does use sourceDependencies and main.cpp.obj.d looks like this:
https://hastebin.com/ayetoduyud.properties

If I change a header file, the .cpp is recompiled as it should be, but the main.cpp.obj.d content changes to this:
https://hastebin.com/bamadohene.properties

So I tried to do this using verbose output.

First time:

lynix@SirLynixVanDesktop:/mnt/c/Projets/Tests/xmake-build/test_recompilation$ xmake.exe -vD
checking for architecture ... x64
checking for Microsoft Visual Studio (x64) version ... 2019
checking for the c++ compiler (cxx) ... cl.exe
checking for C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bin\HostX64\x64\cl.exe ... ok
checking for flags (-Ox -fp:fast) ... ok
> cl.exe "-Ox" "-fp:fast" "/EHsc"
checking for ccache ... no
[ 50%]: compiling.release src\main.cpp
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\bin\\HostX64\\x64\\cl.exe" -c /EHsc -nologo -Ox -fp:fast -Fobuild\.objs\test_recompilation\windows\x64\release\sr
c\main.cpp.obj src\main.cpp
checking for flags (cl_sourceDependencies) ... ok
> cl.exe "/sourceDependencies" "C:\Users\Lynix\AppData\Local\Temp\.xmake\201126\_F6B54EAE436F4F5081A18AB40EB4D280.json" "/EHsc"
checking for link.exe ... C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bin\HostX64\x64\link.exe
checking for the linker (ld) ... link.exe
[ 75%]: linking.release test_recompilation.exe
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\bin\\HostX64\\x64\\link.exe" -nologo -dynamicbase -nxcompat -machine:x64 /opt:ref /opt:icf /ltcg -out:build\windo
ws\x64\release\test_recompilation.exe build\.objs\test_recompilation\windows\x64\release\src\main.cpp.obj
[100%]: build ok!

After changing a header file:

lynix@SirLynixVanDesktop:/mnt/c/Projets/Tests/xmake-build/test_recompilation$ xmake.exe -vD
[ 50%]: compiling.release src\main.cpp
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\bin\\HostX64\\x64\\cl.exe" -c /EHsc -nologo -Ox -fp:fast -Fobuild\.objs\test_recompilation\windows\x64\release\sr
c\main.cpp.obj src\main.cpp
[ 75%]: linking.release test_recompilation.exe
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29333\\bin\\HostX64\\x64\\link.exe" -nologo -dynamicbase -nxcompat -machine:x64 /opt:ref /opt:icf /ltcg -out:build\windo
ws\x64\release\test_recompilation.exe build\.objs\test_recompilation\windows\x64\release\src\main.cpp.obj
[100%]: build ok!

At this point the main.cpp.obj.d now uses showIncludes

And from there, it relies on the french output parsing to continues to work.

Edit: I did try after using xmake.exe update -s dev again, just in case, same behavior.

@waruqi
Copy link
Member

waruqi commented Nov 26, 2020

On the very first xmake run, it does use sourceDependencies and main.cpp.obj.d looks like this:
https://hastebin.com/ayetoduyud.properties

If I change a header file, the .cpp is recompiled as it should be, but the main.cpp.obj.d content changes to this:
https://hastebin.com/bamadohene.properties

This is the small problem I said at the beginning. It should have been fixed on dev, unless you have not fully updated to the latest commit of the dev branch. see this patch: 6426a1e

In addition, I found a small problem in detecting /sourceDependencies flags. When incrementally compiling, it will automatically switch back to /showIncludes flags. And I have fixed it now on dev branch.

see #1072 (comment)

@SirLynix
Copy link
Member Author

SirLynix commented Nov 26, 2020

It's weird, I ran xmake.exe update -s dev three times already but I can confirm the modules/core/tools/cl.lua file on my computer doesn't have the same content as the dev branch. Even xmake.exe update dev didn't work.

Edit: Ok it seems to be related to WSL, running xmake update -s dev in powershell did work.

@waruqi
Copy link
Member

waruqi commented Nov 26, 2020

please run xmake update -s dev in ps/cmd.

@SirLynix
Copy link
Member Author

I can confirm your fix for /sourceDependencies works! Thanks.

I will make a PR to add the french prefix to parse_includes.lua, and maybe more if I find other languages prefixes.

I know xmake 2.3.9 just released, but considering the severity of this issue could a small bugfix release be considered? I wanted to use xmake for some projects I'm teaching next week to my C++ students, but as they're french xmake 2.3.9 won't work.
If you prefer not to, I would understand and give them an installer from AppVeyor.

@waruqi
Copy link
Member

waruqi commented Nov 26, 2020

I know xmake 2.3.9 just released, but considering the severity of this issue could a small bugfix release be considered? I wanted to use xmake for some projects I'm teaching next week to my C++ students, but as they're french xmake 2.3.9 won't work.

This will cause sha256 errors in existing installation packages, affecting the installation of other package managers, such as winget.

But I can upload an additional patch version on github/release/assets. For example: xmake-v2.3.9-1.win64.exe

@SirLynix
Copy link
Member Author

That would be perfect, thanks a lot.

About showIncludes, I've been looking at what CMake does, it seems to be wrapping cl.exe and receive the file prefix (folder I guess) as a parameter.

I suppose listing every language prefix isn't the best way to handle this, wouldn't it be better to try to parse a file path from the end of each line?

@waruqi
Copy link
Member

waruqi commented Nov 26, 2020

That would be perfect, thanks a lot.

About showIncludes, I've been looking at what CMake does, it seems to be wrapping cl.exe and receive the file prefix (folder I guess) as a parameter.

I suppose listing every language prefix isn't the best way to handle this, wouldn't it be better to try to parse a file path from the end of each line?

However, the output of cl.exe will also mix compilation warning output and error messages to interfere with the analysis.
And there may also be a header file path string in the warning message.

like this:

warnings: ..... in /xxx/xxxx.h
.....

note includes: .. xxxx.h
note includes: ..

warnings: ... in /xxxx/xxx.h
....

error: ...
....

@SirLynix
Copy link
Member Author

Oh yeah, didn't think of that.

From reading ninja-build/ninja#613 :
It seems VSLANG=1033 forces cl.exe to output english messages.

It seems CMake detects the prefix by running cl.exe on a dummy file, I think this is the best solution, albeit a bit complicated.

I will make you a PR with french and Japanese prefixes, couldn't find more for now.

@waruqi
Copy link
Member

waruqi commented Nov 26, 2020

It seems CMake detects the prefix by running cl.exe on a dummy file, I think this is the best solution, albeit a bit complicated.

This seems to be a good solution, I will consider it later.

@waruqi
Copy link
Member

waruqi commented Nov 26, 2020

It seems CMake detects the prefix by running cl.exe on a dummy file, I think this is the best solution, albeit a bit complicated.

This seems to be a good solution, I will consider it later.

I have improved and supported it.

function _probe_include_note_from_cl()
local key = "note_include"
local cacheinfo = cache.load("cldeps.parse_include")
local note = cacheinfo[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
cacheinfo[key] = note
cache.save("cldeps.parse_include", cacheinfo)
end
return note
end
-- get include notes prefix, e.g. "Note: including file: "
--
-- @note we cannot get better solution to distinguish between `includes` and `error infos`
--
function _get_include_notes()
local notes = _g.notes
if not notes then
notes = {}
local note = _probe_include_note_from_cl()
if note then
table.insert(notes, note)
end
table.join2(notes, {

@waruqi
Copy link
Member

waruqi commented Nov 26, 2020

@SirLynix
Copy link
Member Author

Dude you're a machine! Thank you for being so reactive 😄

@waruqi waruqi closed this as completed Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants