Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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'
''
'##[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
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
1 change: 1 addition & 0 deletions contains space/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file's path contains a space!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file's relative path is too long!
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()

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