mirror of
https://github.com/Microsoft/calculator.git
synced 2025-07-30 19:40:00 -07:00
Merge master into feature/GraphingCalculator branch (#585)
* Merge master into feature/GraphingCalculator branch
This commit is contained in:
parent
1475b49120
commit
a418777f02
447 changed files with 18056 additions and 19323 deletions
91
Tools/Scripts/clang-format/clang-format-all.ps1
Normal file
91
Tools/Scripts/clang-format/clang-format-all.ps1
Normal file
|
@ -0,0 +1,91 @@
|
|||
<#
|
||||
.DESCRIPTION
|
||||
Helper script to format all header and source files in the repository.
|
||||
|
||||
By default, the script will recursively search under the repo root for
|
||||
files to format. Users can give explicit parameters indicating how the
|
||||
search should include and exclude filetypes.
|
||||
|
||||
If users don't want the search functionality, they can instead provide
|
||||
an explicit list of files to format.
|
||||
|
||||
.PARAMETER RepoRoot
|
||||
Full path to the root of the repository which is the target of the search.
|
||||
Will default to the root of the current working directory.
|
||||
|
||||
.PARAMETER Include
|
||||
Array of filetype extensions to target for formatting.
|
||||
By default, targets standard extensions for header and source files.
|
||||
Follows the same rules as the -Include parameter for Get-ChildItem.
|
||||
|
||||
.PARAMETER Exclude
|
||||
Array of filetype extensions to exclude from formatting.
|
||||
By default, excludes generated XAML files.
|
||||
Follows the same rules as the -Exclude paramter for Get-ChildItem.
|
||||
|
||||
.PARAMETER Files
|
||||
Array of files to format. The script will exit if one of the provided
|
||||
filepaths does not exist.
|
||||
|
||||
.EXAMPLE
|
||||
.\clang-format-all.ps1
|
||||
|
||||
Formats all header and source files under the repository root.
|
||||
|
||||
.EXAMPLE
|
||||
.\clang-format-all.ps1 -RepoRoot 'S:\repos\calculator' -Include '*.h', '*.cpp' -Exclude '*.g.*'
|
||||
|
||||
Formats all *.h and *.cpp files under 'S:\repos\calculator', excluding files with an extension
|
||||
like *.g.*
|
||||
|
||||
.EXAMPLE
|
||||
.\clang-format-all.ps1 -File 'S:\repos\calculator\src\CalcViewModel\UnitConverterViewModel.h', 'S:\repos\calculator\src\CalcViewModel\MemoryItemViewModel.cpp'
|
||||
|
||||
Formats the specified files.
|
||||
#>
|
||||
[CmdletBinding( DefaultParameterSetName = 'Search' )]
|
||||
param(
|
||||
[Parameter( ParameterSetName = 'Search' )]
|
||||
[ValidateScript({ Test-Path -PathType Container -Path $_ })]
|
||||
[string] $RepoRoot = "$( git rev-parse --show-toplevel )",
|
||||
|
||||
[Parameter( ParameterSetName = 'Search' )]
|
||||
[string[]] $Include = ( '*.h', '*.hh', '*.hpp', '*.c', '*.cc', '*.cpp' ),
|
||||
|
||||
[Parameter( ParameterSetName = 'Search' )]
|
||||
[string[]] $Exclude = '*.g.*',
|
||||
|
||||
[Parameter(
|
||||
ParameterSetName = 'Explicit',
|
||||
Mandatory)]
|
||||
[ValidateScript({
|
||||
$_ | Where-Object { -not (Test-Path -PathType Leaf -Path $_) } |
|
||||
ForEach-Object { throw "Could not find file: [$_]" }
|
||||
|
||||
return $true
|
||||
})]
|
||||
[string[]] $Files
|
||||
)
|
||||
|
||||
if ($PSCmdlet.ParameterSetName -eq 'Explicit')
|
||||
{
|
||||
# Use the file paths we were given.
|
||||
$targetFiles = @($Files)
|
||||
}
|
||||
else
|
||||
{
|
||||
# Gather the files to be formatted.
|
||||
$targetFiles = @(
|
||||
Get-ChildItem -Recurse -Path $RepoRoot -Include $Include -Exclude $Exclude |
|
||||
Select-Object -ExpandProperty FullName
|
||||
)
|
||||
}
|
||||
|
||||
# Format the files.
|
||||
$formatParams = @(
|
||||
'-i' # In-place
|
||||
'-style=file' # Search for a .clang-format file in the parent directory of the source file.
|
||||
'-verbose'
|
||||
)
|
||||
|
||||
clang-format $formatParams $targetFiles
|
53
Tools/Scripts/clang-format/clang-format-all.sh
Normal file
53
Tools/Scripts/clang-format/clang-format-all.sh
Normal file
|
@ -0,0 +1,53 @@
|
|||
#!/bin/bash
|
||||
|
||||
function usage {
|
||||
echo "Usage: $0 DIR..."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Variable that will hold the name of the clang-format command
|
||||
FMT=""
|
||||
|
||||
# Some distros just call it clang-format. Others (e.g. Ubuntu) are insistent
|
||||
# that the version number be part of the command. We prefer clang-format if
|
||||
# that's present, otherwise we work backwards from highest version to lowest
|
||||
# version.
|
||||
for clangfmt in clang-format{,-{4,3}.{9,8,7,6,5,4,3,2,1,0}}; do
|
||||
if which "$clangfmt" &>/dev/null; then
|
||||
FMT="$clangfmt"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if we found a working clang-format
|
||||
if [ -z "$FMT" ]; then
|
||||
echo "failed to find clang-format"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SRC_PATH="$@"
|
||||
if [ -z "$SRC_PATH" ]; then
|
||||
SRC_PATH="../../../src"
|
||||
fi
|
||||
|
||||
# Check all of the arguments first to make sure they're all directories
|
||||
for dir in "$SRC_PATH"; do
|
||||
if [ ! -d "${dir}" ]; then
|
||||
echo "${dir} is not a directory"
|
||||
usage
|
||||
fi
|
||||
done
|
||||
|
||||
# Run clang-format -i on all of the things
|
||||
for dir in "$SRC_PATH"; do
|
||||
pushd "${dir}" &>/dev/null
|
||||
find . \
|
||||
\( -name '*.c' \
|
||||
-o -name '*.cc' \
|
||||
-o -name '*.cpp' \
|
||||
-o -name '*.h' \
|
||||
-o -name '*.hh' \
|
||||
-o -name '*.hpp' \) \
|
||||
-exec "${FMT}" -style=file -i '{}' \;
|
||||
popd &>/dev/null
|
||||
done
|
Loading…
Add table
Add a link
Reference in a new issue