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

add format target to cmake #2671

Merged
merged 35 commits into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4dd769b
add format target to cmake
strega-nil Apr 26, 2022
507e12b
remove parallelize
strega-nil Apr 26, 2022
dd1ea10
remember to call vsdevcmd; add ERROR_ON_CLANG_FORMAT_NOT_FOUND
strega-nil Apr 26, 2022
bb4fa64
add a format.diff output; should correct errors
strega-nil Apr 26, 2022
6a2a992
errrgh
strega-nil Apr 26, 2022
f552cba
aaaaaugh
strega-nil Apr 26, 2022
abf9330
fix build error, change how format is done
strega-nil Apr 27, 2022
791e5ba
moar fixin'
strega-nil Apr 27, 2022
4212816
forgot cmr :'(
strega-nil Apr 27, 2022
8863e7a
forgot to skip .diff files -.-
strega-nil Apr 27, 2022
1a27369
okay fix builds hopefully
strega-nil Apr 27, 2022
8dc715d
Merge remote-tracking branch 'upstream/main' into strega-nil/add-form…
strega-nil Apr 27, 2022
cf2f367
remove hiddenf iles
strega-nil Apr 27, 2022
de2988d
remove format.diff file
strega-nil Apr 27, 2022
fd5abee
single-quotes -> double-quotes
strega-nil Apr 27, 2022
070076d
(* cries *)
strega-nil Apr 27, 2022
955beb6
(* cries more *)
strega-nil Apr 27, 2022
ae2f1e6
clean UP
strega-nil Apr 27, 2022
ffbff5b
fix people's problems
strega-nil Apr 28, 2022
abe3bd0
[TEST] try clang-format
strega-nil Apr 28, 2022
0f57832
oops, need to fail the pipeline
strega-nil Apr 28, 2022
cce432e
NEAT
strega-nil Apr 28, 2022
bb3222b
vso[error] -> [error]
strega-nil Apr 28, 2022
a2d6aa4
how does that look?
strega-nil Apr 28, 2022
d32cc67
does that result in failures
strega-nil Apr 28, 2022
53e0527
do tests
strega-nil Apr 28, 2022
93d2186
does logissue work?
strega-nil Apr 28, 2022
e9ff5c4
figured it out!
strega-nil Apr 28, 2022
0f539a8
clang-format
strega-nil Apr 28, 2022
2688dce
[TEST] validate (tabs)
strega-nil Apr 28, 2022
19d0f42
validate prettifying
strega-nil Apr 28, 2022
9f899e4
more prettifying
strega-nil Apr 28, 2022
b8566a9
final format
strega-nil Apr 28, 2022
bf41006
Code review feedback, fixing missed path failures.
StephanTLavavej Apr 29, 2022
d4fe38f
add instructions for downloading
strega-nil Apr 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,9 @@ if(BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()

add_subdirectory(tools/format EXCLUDE_FROM_ALL)
if(TARGET clang-format-all)
add_custom_target(format)
add_dependencies(format clang-format-all)
endif()
28 changes: 28 additions & 0 deletions azure-devops/create-prdiff.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

[CmdletBinding(PositionalBinding = $False)]
Param(
[Parameter(Mandatory = $True)]
[String]$DiffFile
)

Start-Process -FilePath 'git' -ArgumentList 'diff' `
-NoNewWindow -Wait `
-RedirectStandardOutput $DiffFile
if (0 -ne (Get-Item -LiteralPath $DiffFile).Length) {
$message = @(
'##vso[task.logissue type=error]The formatting of the files in the repo was not what we expected.'
'Please access the diff from format.diff in the build artifacts,'
'and apply it with `git apply`.'
'Alternatively, you can run the `format` CMake target:'
' cmake --build <builddir> --target format'
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
''
'##[group]Expected formatting - click to expand diff'
Get-Content -LiteralPath $DiffFile -Raw
'##[endgroup]'
"##vso[artifact.upload artifactname=format.diff]$DiffFile"
'##vso[task.complete result=Failed]DONE'
)
Write-Host ($message -join "`n")
}
14 changes: 0 additions & 14 deletions azure-devops/enforce-clang-format.cmd

This file was deleted.

4 changes: 0 additions & 4 deletions azure-devops/validate-files.cmd

This file was deleted.

45 changes: 22 additions & 23 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ stages:
timeoutInMinutes: 90
displayName: 'Validation'
variables:
buildOutputLocation: 'D:\tools'
- name: DiffFile
value: '$(Build.ArtifactStagingDirectory)/format.diff'
steps:
- script: |
if exist "$(tmpDir)" (
Expand All @@ -29,34 +30,32 @@ stages:
clean: true
submodules: false
- script: |
if exist "$(buildOutputLocation)" (
rmdir /S /Q "$(buildOutputLocation)"
)
call "%ProgramFiles%\Microsoft Visual Studio\2022\Preview\Common7\Tools\VsDevCmd.bat" ^
-host_arch=amd64 -arch=amd64 -no_logo
cmake -G Ninja -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=Release ^
-S $(Build.SourcesDirectory)\tools -B $(buildOutputLocation)
cmake --build $(buildOutputLocation)
displayName: 'Build Support Tools'
env: { TMP: $(tmpDir), TEMP: $(tmpDir) }
- task: BatchScript@1
displayName: 'Enforce clang-format'
timeoutInMinutes: 60
-host_arch=amd64 -arch=amd64 -no_logo
strega-nil-ms marked this conversation as resolved.
Show resolved Hide resolved
cmake -G Ninja -S $(Build.SourcesDirectory)/tools/format -B $(tmpDir)/format-build
cmake --build $(tmpDir)/format-build
displayName: 'clang-format'
timeoutInMinutes: 5
condition: succeededOrFailed()
inputs:
filename: 'azure-devops/enforce-clang-format.cmd'
failOnStandardError: true
arguments: '$(buildOutputLocation)/parallelize/parallelize.exe'
env: { TMP: $(tmpDir), TEMP: $(tmpDir) }
- task: BatchScript@1
- script: |
call "%ProgramFiles%\Microsoft Visual Studio\2022\Preview\Common7\Tools\VsDevCmd.bat" ^
-host_arch=amd64 -arch=amd64 -no_logo
cmake -G Ninja -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=Release ^
-S $(Build.SourcesDirectory)/tools/validate -B $(tmpDir)/validate-build
cmake --build $(tmpDir)/validate-build
"$(tmpDir)\validate-build\validate.exe"
displayName: 'Validate Files'
timeoutInMinutes: 2
timeoutInMinutes: 5
condition: succeededOrFailed()
inputs:
filename: 'azure-devops/validate-files.cmd'
failOnStandardError: true
arguments: '$(buildOutputLocation)/validate/validate.exe'
env: { TMP: $(tmpDir), TEMP: $(tmpDir) }
- task: Powershell@2
displayName: 'Create Diff'
inputs:
filePath: azure-devops/create-prdiff.ps1
arguments: '-DiffFile $(DiffFile)'
pwsh: false
condition: succeededOrFailed()

- stage: Build_And_Test_x64
dependsOn: Code_Format
Expand Down
2 changes: 1 addition & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ add_compile_options(/W4 /WX $<$<NOT:$<CONFIG:Debug>>:/Zi> /permissive-)

include_directories(inc)

add_subdirectory(format)
add_subdirectory(jobify)
add_subdirectory(parallelize)
add_subdirectory(validate)
71 changes: 71 additions & 0 deletions tools/format/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

cmake_minimum_required(VERSION 3.22)
project(msvc_standard_libraries_format NONE)

set(did_search OFF)
if(NOT DEFINED CLANG_FORMAT)
message(STATUS "Searching for VS clang-format")
set(did_search ON)
endif()

if(PROJECT_IS_TOP_LEVEL)
set(message_level FATAL_ERROR)
else()
set(message_level WARNING)
endif()

find_program(CLANG_FORMAT
NAMES clang-format
PATHS "C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/Llvm/bin"
DOC "The clang-format program to use"
NO_DEFAULT_PATH
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH
)
if(CLANG_FORMAT)
if(did_search)
message(STATUS "Searching for VS clang-format - found")
endif()
strega-nil-ms marked this conversation as resolved.
Show resolved Hide resolved

file(GLOB_RECURSE maybe_clang_format_files
"../../stl/inc/*"
"../../stl/src/*"
"../../tests/*"
"../../tools/*"
)
set(clang_format_files "")
foreach(maybe_file IN LISTS maybe_clang_format_files)
cmake_path(GET maybe_file FILENAME filename)
cmake_path(GET maybe_file EXTENSION LAST_ONLY extension)
if(extension MATCHES [[^(|\.cpp|\.h|\.hpp)$]] AND NOT filename MATCHES [[^\.]])
list(APPEND clang_format_files "${maybe_file}")
endif()
endforeach()

if(NOT clang_format_files)
message("${message_level}" "Could not find any files to clang-format!")
endif()

add_custom_target(clang-format-all ALL)
foreach(file IN LISTS clang_format_files)
cmake_path(RELATIVE_PATH file
BASE_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../.."
OUTPUT_VARIABLE relative-file
)
string(REPLACE "/" "_" relative-file "${relative-file}")
set(target_name "clang-format.${relative-file}")
add_custom_target("${target_name}"
COMMAND "${CLANG_FORMAT}" -style=file -i "${file}"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
)
add_dependencies(clang-format-all "${target_name}")
endforeach()
else()
if(did_search)
message("${message_level}" "Searching for VS clang-format - not found.")
endif()
endif()
5 changes: 0 additions & 5 deletions tools/parallelize/CMakeLists.txt

This file was deleted.

Loading