TheLartians / Format.cmake

💅 Stylize your code! Automatic clang-format and cmake-format targets for CMake.
Apache License 2.0
159 stars 25 forks source link

add CI workflow for windows #6

Closed TheLartians closed 4 years ago

TheLartians commented 4 years ago

So that didn't work :( Still have to learn more about the platform before I can set up a CI workflow it seems. I'll come back another time.

DeveloperPaul123 commented 4 years ago

@TheLartians You probably need to refresh the env to use the updated path.

Chocolatey spits this out after install LLVM

Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
TheLartians commented 4 years ago

Oooh I see let's try that

TheLartians commented 4 years ago

nope, that wasn't it

DeveloperPaul123 commented 4 years ago

Hmm I'm not sure then, that's odd. Is there any way to tell the script where clang-format is for the purpose of the CI? It'll be in C:\Program Files\LLVM\bin\clang-format.exe.

TheLartians commented 4 years ago

Theoretically yes, you could pass the --binary path/to/clang/format flag to the python script. But we'd have to tunnel that through Cmake somehow. I just wonder why it's not finding clang-format automatically though.

DeveloperPaul123 commented 4 years ago

Couldn't you do a find_program call in cmake and pass that into the script that way?

Something like:

find_program(CLANG_FORMAT_PROGRAM clang-format${CMAKE_EXECUTABLE_SUFFIX})
if(NOT EXISTS ${CLANG_FORMAT_PROGRAM})
    message(FATAL_ERROR "Clang format is required!")
endif()

// pass ${CLANG_FORMAT_PROGRAM} to the python script...
TheLartians commented 4 years ago

let's find out

TheLartians commented 4 years ago
cmake --build build --target format
MSBUILD : error MSB1009: Project file does not exist.
Switch: format.vcxproj

Hm is that not how you invoke CMake targets in Windows?

TheLartians commented 4 years ago

Ah it still didn't find clang-format: clang-format not found: not adding Format.cmake targets (I didn't want it to error by default as it could break otherwise perfectly fine projects)

DeveloperPaul123 commented 4 years ago

Yeah, I just tried this as well locally using Windows Sandbox and I'm actually able to reproduce it not being able to find clang format automatically. I'll see if I can figure out a fix.

TheLartians commented 4 years ago

Thanks! Testing locally is much more fun than waiting 3 minutes on the CI for every change 😅

TheLartians commented 4 years ago

So I copied this stackoverflow answer to convert the exit codes to booleans and it worked for the simple case of -not. However the combination with -and still throws it off. This is a nightmare.

TheLartians commented 4 years ago

Holy s*** that worked

TheLartians commented 4 years ago

So apparently windows has a bash shell. Hell just froze over.

DeveloperPaul123 commented 4 years ago

I wonder if it's git bash or similar, glad it worked!

Edit:

Actually Windows now has built in support for Linux subsystems as well so it could be one of those 🤷

TheLartians commented 4 years ago

Thanks for the help :)