cheshirekow / cmake_format

Source code formatter for cmake listfiles.
GNU General Public License v3.0
958 stars 105 forks source link

How to apply customized config file #155

Closed SE-June closed 4 years ago

SE-June commented 4 years ago

Hi!

When my customized file was applied to vscode, I got the following error:

" Command failed: cmake-format --config-file d:\totalcmd\util\VSCode-win32-x64-1.38.1 - Traceback (most recent call last): File "C:\Python27\Scripts\cmake-format-script.py", line 11, in load_entry_point('cmake-format==0.6.4', 'console_scripts', 'cmake-format')() File "c:\python27\lib\site-packages\cmake_format__main__.py", line 472, in main "You cannot mix stdin as an input with other input files" AssertionError: You cannot mix stdin as an input with other input files"

my settings.json "cmakeFormat.args": [ "--config-file d:\totalcmd\util\VSCode-win32-x64-1.38.1" ],

my setting.json is attached.

Merry Christmas!

settings.json.txt

cheshirekow commented 4 years ago

I think the problem is that you need to separate the two command line arguments, like this:

"cmakeFormat.args": [
   "--config-file", "d:\totalcmd\util\VSCode-win32-x64-1.38.1"
]

Otherwise it is interpreted all as a single argument string. Give that a try and let me know how it goes.

SE-June commented 4 years ago

I have captured how "cmake-format.exe" was called using "Procmon.exe" of "SysinternalsSuite"

1) The following config(which is suggested), "cmakeFormat.args": [ "--config-file", "d:\totalcmd\util\VSCode-win32-x64-1.38.1" ] made a call to "cmake-format.exe" as followings: cmake-format --config-file "d: otalcmdtilSCode-win32-x64-1.38.1" - I thouht backslash,"\" is used to escape a following character but not used for path delimiter.

2) So I changed "\" to '/' as followings "cmakeFormat.args": [ "--config-file", "d:/totalcmd/util/VSCode-win32-x64-1.38.1" ]

and then I got the two followings sequences : cmake-format --config-file d:/totalcmd/util/VSCode-win32-x64-1.38.1 - c:\python27\python.exe "C:\Python27\Scripts\cmake-format-script.py" "--config-file" "d:/totalcmd/util/VSCode-win32-x64-1.38.1" "-"

3) Also I changed "\" to "\\" like the followings: "cmakeFormat.args": [ "--config-file", "d:\\totalcmd\\util\\\VSCode-win32-x64-1.38.1" ]

in that case, I got the two following sequences. cmake-format --config-file d:\totalcmd\util\VSCode-win32-x64-1.38.1 - c:\python27\python.exe "C:\Python27\Scripts\cmake-format-script.py" "--config-file" "d:\totalcmd\util\VSCode-win32-x64-1.38.1" "-"

But All the cases didn't work.

After doing formatting in every cases, my cmake files was empty( All was deleted )

cheshirekow commented 4 years ago

Oh I see. Thank you for digging in further and providing the additional information. It looks like vscode itself is interpreting these backslashes as escape sequences. This is news to me. I wont have access to a windows machine for the next couple of days to reproduce this issue, but I will try myself when I can.

In the meantime, I suggest trying to escape the backslash itself by using double backslash:

"cmakeFormat.args": [ "--config-file", "d:\\totalcmd\\util\\VSCode-win32-x64-1.38.1" ]
SE-June commented 4 years ago

Also I changed "\" to "\\" like the followings: "cmakeFormat.args": [ "--config-file", "d:\\totalcmd\\util\\\VSCode-win32-x64-1.38.1" ]

in that case, I got the two following sequences which was executed internally. (I also captured it with "Procmon.exe")

1) cmake-format --config-file d:\totalcmd\util\VSCode-win32-x64-1.38.1 - 2) c:\python27\python.exe "C:\Python27\Scripts\cmake-format-script.py" "--config-file" "d:\totalcmd\util\VSCode-win32-x64-1.38.1" "-"

It also didn't work

My question: what is the last symbol, "-" for? why the symbol,"-" is appended automatically?

cheshirekow commented 4 years ago

Can you clarify what didn't work in this case? Did you see an error message? I'm not familiar with the cmake-format-script.py part but I suspect that is perhaps something that setuptools does on windows. On linux, it is different. If my suspicion is correct, then that command line looks right.

what is the last symbol, "-" for?

Positional arguments are the names of files to format. - means format stdin. It is automatically appended because the visual studio code extension pipes the file content to the cmake-format subprocess over stdin.

SE-June commented 4 years ago

After doing formatting, my cmake files was empty( All was deleted )

No error message. Just my cmake file got empty.

P.S. I didn't look at any config file used. I mean, If the config file was used or loaded, It should have been captured by "Procmon.exe".

cheshirekow commented 4 years ago

After doing formatting in every cases, my cmake files was empty

Hm... that's not good. Even if cmake-format itself is crashing the extension shouldn't replace the content of your listfiles. It looks like indeed the status of the subprocess command is not checked by the extension. I've filed this as bug #05489cf. That makes debugging more difficult, but is not the cause of your problem.

My hypothesis is that something in your configuration is causing cmake-format to error out. Can you share the content of your config file VSCode-win32-x64-1.38.1?

SE-June commented 4 years ago

"VSCode-win32-x64-1.38.1" is not file name but folder name which is including a config file.

Here are my two config file which I tried to use

The original name is "cmake-format.config" To upload it, I changed it to "cmake-format.config.txt" cmake-format.config.txt

The original name is ".cmake-format.py" To upload it, I changed it to ".cmake-format.py.txt" [.cmake-format.py.txt](https://github.com/cheshirekow/cmake_format/files/4001321/_.cmake-format.py.txt)

cheshirekow commented 4 years ago

Ah! If you wish to use the --config-file command line option, you should specify the full path to the file d:\\totalcmd\\util\\VSCode-win32-x64-1.38.1\\.cmake-format.py.

cmake-format doesn't understand ini style configuration files, just JSON, YAML, or python so I recommend using a .json, .yml or .py file extension to make it clear to cmake-format what style config file you are using. In other words I recommend something like cmake-format-config.json for the first file you tried.

If you specify the --config-file command line option, cmake-format will use that config file, and it can have any filename that you want (though please use the correct file extension, otherwise cmake-format will try to infer the correct style). You don't have to name it .cmake-format.py. You could name it my-cmake-format-config.py or similar.

That sounds like it is likely the problem. Sorry that the error is getting chomped and is not visible. Give that a try and let me know how it goes.

SE-June commented 4 years ago

I tried with the following setting. "cmakeFormat.args": [ "--config-file", "d:\totalcmd\util\VSCode-win32-x64-1.38.1\.cmake-format.py" ]

But It still didn't work.

All contents still was deleted

BTW, Happy new year

I am waiting for you to test it on a windows OS

Thanks in Advance!!!

cheshirekow commented 4 years ago

Can you try the same with the double backslash?

"cmakeFormat.args": [ "--config-file", "d:\\totalcmd\\util\\VSCode-win32-x64-1.38.1\\.cmake-format.py" ]

But if that doesn't work, I will report back after I can reproduce on my windows machine.

Happy near year also.

SE-June commented 4 years ago
"cmakeFormat.args": [
    "--config-file",
    "d:\\totalcmd\\util\\VSCode-win32-x64-1.38.1\\.cmake-format.py"
]

It still didn't work

All contents was deleted

cheshirekow commented 4 years ago

Try this:

"cmakeFormat.args": [
    "--config-file",
    "d:\\totalcmd\\util\\VSCode-win32-x64-1.38.1\\.cmake-format.py",
    "--"
]

I forgot that --config-file can take multiple arguments, so if it's the last argument on the command line it needs to be separated from positional arguments. This works for me on windows using your python style config file.

SE-June commented 4 years ago

Thank you so much. It also worked for me!!!!

Thanks again for making this great tool!!!

cheshirekow commented 4 years ago

I've created #4e6ca84 to "Insert -- after --config-file if needed" automatically in the extension to hopefully avoid this problem for other users, as well as #6551ce1 "exit with nonzero status if no input files" to make this failure case more discoverable.