Skip to content

Commit

Permalink
[localization 1/n] First minor changes, mostly additive (#218)
Browse files Browse the repository at this point in the history
* [localization 1/n] First minor changes, mostly additive

Additionally, convert vcpkg.cpp over to using messages.h

* oops, forgot to initialize the context

also, build on msvc & gcc 6

* add cgmanifest and NOTICE

* Add support for signing with fmt

* switch to MAXDWORD

* add localization file

* turn `find_package(fmt)` into a Findfmt script

* check sha

* Raise default locale initialization above filesystem access

* Avoid O(N^2) on happy path

* Address CR comment on formatter<vcpkg::StringLiteral>

Co-authored-by: Robert Schumacher <roschuma@microsoft.com>
  • Loading branch information
strega-nil and ras0219-msft authored Oct 26, 2021
1 parent 72deea4 commit 5b939c9
Show file tree
Hide file tree
Showing 37 changed files with 926 additions and 40 deletions.
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ project(vcpkg
LANGUAGES ${LANGUAGES}
)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(cmake/utilities.cmake)

# =============
Expand Down Expand Up @@ -120,6 +121,12 @@ endif()

include(GNUInstallDirs)

# ====================
# === Dependencies ===
# ====================

find_package(fmt REQUIRED)

# ===============
# === Targets ===
# ===============
Expand All @@ -142,7 +149,12 @@ target_compile_definitions(vcpkglib PUBLIC

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(vcpkglib PRIVATE Threads::Threads)
target_link_libraries(vcpkglib
PUBLIC
fmt::fmt
PRIVATE
Threads::Threads
)

if(MSVC)
get_target_property(_srcs vcpkglib SOURCES)
Expand Down
1 change: 1 addition & 0 deletions LocProject.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
18 changes: 18 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,21 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
=========================================
END OF Catch2 NOTICES, INFORMATION, AND LICENSE

2. fmt

%% fmt NOTICES, INFORMATION, AND LICENSE BEGIN HERE
=========================================
Copyright (c) 2012 - present, Victor Zverovich

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

--- Optional exception to the license ---

As an exception, if, as a result of your compiling your source code, portions of this Software are embedded into a machine-executable object form of such source code, you may redistribute such embedded portions in such object form without including the above copyright and permission notices.
=========================================
END OF fmt NOTICES, INFORMATION, AND LICENSE
88 changes: 84 additions & 4 deletions azure-pipelines/signing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,31 @@ jobs:
displayName: 'MacOS Build'
pool:
vmImage: macOS-10.15
variables:
- group: vcpkg-dependency-source-blobs
- name: FMT_TARBALL_URL
value: "$(fmt-tarball-url)"
- name: FMT_TARBALL_SHA
value: "$(fmt-tarball-sha)"
- name: FMT_TARBALL_DIRNAME
value: "$(fmt-tarball-dirname)"
steps:
- task: CmdLine@2
displayName: "Download fmt library"
inputs:
failOnStderr: true
workingDirectory: "$(Build.BinariesDirectory)"
script: |
curl -sSL "$FMT_TARBALL_URL" --output ./fmtlib.tar.gz
printf "$FMT_TARBALL_SHA *./fmtlib.tar.gz\n" >checksum
shasum -c ./checksum -a 512 || exit 1
tar -xf ./fmtlib.tar.gz
- task: CmdLine@2
displayName: "Build vcpkg with CMake"
inputs:
failOnStderr: true
script: |
cmake -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DVCPKG_DEVELOPMENT_WARNINGS=ON -DVCPKG_WARNINGS_AS_ERRORS=ON -DVCPKG_BUILD_FUZZING=OFF -DVCPKG_EMBED_GIT_SHA=ON -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -B "$(Build.BinariesDirectory)/build"
cmake -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DVCPKG_DEVELOPMENT_WARNINGS=ON -DVCPKG_WARNINGS_AS_ERRORS=ON -DVCPKG_BUILD_FUZZING=OFF -DVCPKG_EMBED_GIT_SHA=ON -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DFETCHCONTENT_FULLY_DISCONNECTED=ON "-DFETCHCONTENT_SOURCE_DIR_FMT=$(Build.BinariesDirectory)/$FMT_TARBALL_DIRNAME" -B "$(Build.BinariesDirectory)/build"
make -j 8 -C "$(Build.BinariesDirectory)/build"
zip -j "$(Build.ArtifactStagingDirectory)/vcpkg-macos.zip" "$(Build.BinariesDirectory)/build/vcpkg"
- task: PublishBuildArtifacts@1
Expand All @@ -47,13 +65,32 @@ jobs:
displayName: 'glibc (RHEL) Build'
pool:
name: 'vcpkg-rhel-7-5'
variables:
- group: vcpkg-dependency-source-blobs
- name: FMT_TARBALL_URL
value: "$(fmt-tarball-url)"
- name: FMT_TARBALL_SHA
value: "$(fmt-tarball-sha)"
- name: FMT_TARBALL_DIRNAME
value: "$(fmt-tarball-dirname)"
steps:
- task: CmdLine@2
displayName: "Download fmt library"
inputs:
failOnStderr: true
workingDirectory: "$(Build.BinariesDirectory)"
script: |
curl -sSL "$FMT_TARBALL_URL" --output "./fmtlib.tar.gz"
printf "$FMT_TARBALL_SHA *./fmtlib.tar.gz\n" >checksum
# shasum doesn't exist on rhel
sha512sum -c ./checksum || exit 1
tar -xf ./fmtlib.tar.gz
- task: CmdLine@2
displayName: "Build vcpkg with CMake"
inputs:
failOnStderr: true
script: |
scl enable devtoolset-9 'cmake3 -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DVCPKG_DEVELOPMENT_WARNINGS=ON -DVCPKG_WARNINGS_AS_ERRORS=ON -DVCPKG_BUILD_FUZZING=OFF -DVCPKG_EMBED_GIT_SHA=ON -DCMAKE_CXX_FLAGS="-static-libgcc -static-libstdc++" -B "$(Build.BinariesDirectory)/build"'
scl enable devtoolset-9 'cmake3 -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DVCPKG_DEVELOPMENT_WARNINGS=ON -DVCPKG_WARNINGS_AS_ERRORS=ON -DVCPKG_BUILD_FUZZING=OFF -DVCPKG_EMBED_GIT_SHA=ON -DCMAKE_CXX_FLAGS="-static-libgcc -static-libstdc++" -DFETCHCONTENT_FULLY_DISCONNECTED=ON "-DFETCHCONTENT_SOURCE_DIR_FMT=$(Build.BinariesDirectory)/$FMT_TARBALL_DIRNAME" -B "$(Build.BinariesDirectory)/build"'
make -j 4 -C "$(Build.BinariesDirectory)/build"
mv "$(Build.BinariesDirectory)/build/vcpkg" "$(Build.ArtifactStagingDirectory)/vcpkg-glibc"
- task: PublishBuildArtifacts@1
Expand All @@ -65,12 +102,31 @@ jobs:
displayName: 'muslc (Alpine) Build'
pool:
name: 'vcpkg-ubuntu-20-04-docker'
variables:
- group: vcpkg-dependency-source-blobs
- name: FMT_TARBALL_URL
value: "$(fmt-tarball-url)"
- name: FMT_TARBALL_SHA
value: "$(fmt-tarball-sha)"
- name: FMT_TARBALL_DIRNAME
value: "$(fmt-tarball-dirname)"
steps:
- task: CmdLine@2
displayName: "Download fmt library"
inputs:
failOnStderr: true
workingDirectory: "$(Build.BinariesDirectory)"
script: |
curl -sSL "$FMT_TARBALL_URL" --output "./fmtlib.tar.gz"
printf "$FMT_TARBALL_SHA *./fmtlib.tar.gz\n" >checksum
shasum -c ./checksum -a 512 || exit 1
tar -xf ./fmtlib.tar.gz
- task: CmdLine@2
displayName: "Build vcpkg in Alpine"
inputs:
failOnStderr: true
script: |
mv "$(Build.BinariesDirectory)/$FMT_TARBALL_DIRNAME" external-fmtlib
docker build -t vcpkg-muslc-image -f azure-pipelines/vcpkg-alpine/Dockerfile .
docker create -ti --name vcpkg-muslc-container vcpkg-muslc-image sh
docker cp vcpkg-muslc-container:/build/vcpkg "$(Build.ArtifactStagingDirectory)/vcpkg-muslc"
Expand All @@ -91,6 +147,14 @@ jobs:
name: 'VSEngSS-MicroBuild2019-1ES'
demands:
- CMAKE
variables:
- group: vcpkg-dependency-source-blobs
- name: FMT_TARBALL_URL
value: "$(fmt-tarball-url)"
- name: FMT_TARBALL_SHA
value: "$(fmt-tarball-sha)"
- name: FMT_TARBALL_DIRNAME
value: "$(fmt-tarball-dirname)"
steps:
- task: DownloadBuildArtifacts@0
displayName: 'Download Unsigned POSIX Binaries'
Expand All @@ -104,6 +168,22 @@ jobs:
mkdir "$(Build.BinariesDirectory)\build"
copy /Y "$(Build.ArtifactStagingDirectory)\staging\vcpkg-glibc" "$(Build.BinariesDirectory)\vcpkg-glibc"
copy /Y "$(Build.ArtifactStagingDirectory)\staging\vcpkg-muslc" "$(Build.BinariesDirectory)\vcpkg-muslc"
- task: PowerShell@2
displayName: "Download fmt library"
inputs:
targetType: 'inline'
pwsh: true
failOnStderr: true
workingDirectory: "$(Build.BinariesDirectory)"
script: |
curl.exe -sSL "$env:FMT_TARBALL_URL" --output ./fmtlib.tar.gz
$hash = (Get-FileHash -Algorithm SHA512 -Path ./fmtlib.tar.gz).Hash
if ($hash -ne "$env:FMT_TARBALL_SHA") {
throw "Unexpected hash for fmtlib download;
expected: $env:FMT_TARBALL_SHA
found : $hash"
}
tar.exe -xf ./fmtlib.tar.gz
- task: PoliCheck@1
inputs:
inputType: 'Basic'
Expand All @@ -116,15 +196,15 @@ jobs:
failOnStderr: true
script: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" -arch=x86 -host_arch=x86
cmake.exe -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DVCPKG_DEVELOPMENT_WARNINGS=ON -DVCPKG_WARNINGS_AS_ERRORS=ON -DVCPKG_BUILD_FUZZING=OFF -DVCPKG_BUILD_TLS12_DOWNLOADER=ON -DVCPKG_EMBED_GIT_SHA=ON -B "$(Build.BinariesDirectory)\x86"
cmake.exe -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DVCPKG_DEVELOPMENT_WARNINGS=ON -DVCPKG_WARNINGS_AS_ERRORS=ON -DVCPKG_BUILD_FUZZING=OFF -DVCPKG_BUILD_TLS12_DOWNLOADER=ON -DVCPKG_EMBED_GIT_SHA=ON -DFETCHCONTENT_FULLY_DISCONNECTED=ON "-DFETCHCONTENT_SOURCE_DIR_FMT=$(Build.BinariesDirectory)\%FMT_TARBALL_DIRNAME%" -B "$(Build.BinariesDirectory)\x86"
ninja.exe -C "$(Build.BinariesDirectory)\x86"
- task: CmdLine@2
displayName: "Build vcpkg arm64 with CMake"
inputs:
failOnStderr: true
script: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" -arch=arm64 -host_arch=x86
cmake.exe -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DVCPKG_DEVELOPMENT_WARNINGS=ON -DVCPKG_WARNINGS_AS_ERRORS=ON -DVCPKG_BUILD_FUZZING=OFF -DVCPKG_BUILD_TLS12_DOWNLOADER=ON -DVCPKG_EMBED_GIT_SHA=ON -DVCPKG_PDB_SUFFIX="-arm64" -B "$(Build.BinariesDirectory)\arm64"
cmake.exe -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DVCPKG_DEVELOPMENT_WARNINGS=ON -DVCPKG_WARNINGS_AS_ERRORS=ON -DVCPKG_BUILD_FUZZING=OFF -DVCPKG_BUILD_TLS12_DOWNLOADER=ON -DVCPKG_EMBED_GIT_SHA=ON -DVCPKG_PDB_SUFFIX="-arm64" -DFETCHCONTENT_FULLY_DISCONNECTED=ON "-DFETCHCONTENT_SOURCE_DIR_FMT=$(Build.BinariesDirectory)\%FMT_TARBALL_DIRNAME%" -B "$(Build.BinariesDirectory)\arm64"
ninja.exe -C "$(Build.BinariesDirectory)\arm64"
- task: MicroBuildSigningPlugin@2
inputs:
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines/vcpkg-alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ FROM alpine:3.11

RUN apk add alpine-sdk cmake ninja git curl tar gzip zip

ADD . /source
COPY . /source

RUN cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DVCPKG_DEVELOPMENT_WARNINGS=ON -DVCPKG_WARNINGS_AS_ERRORS=ON -DVCPKG_BUILD_FUZZING=OFF -DVCPKG_EMBED_GIT_SHA=OFF -DCMAKE_CXX_FLAGS="-static -s -static-libgcc -static-libstdc++" -S /source -B /build
RUN cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DVCPKG_DEVELOPMENT_WARNINGS=ON -DVCPKG_WARNINGS_AS_ERRORS=ON -DVCPKG_BUILD_FUZZING=OFF -DVCPKG_EMBED_GIT_SHA=OFF -DCMAKE_CXX_FLAGS="-static -s -static-libgcc -static-libstdc++" -DFETCHCONTENT_FULLY_DISCONNECTED=ON -DFETCHCONTENT_SOURCE_DIR_FMT=/source/external-fmtlib -S /source -B /build

RUN ninja -C build
26 changes: 26 additions & 0 deletions cgmanifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"Registrations": [
{
"Component": {
"Type": "git",
"git": {
"RepositoryUrl": "https://github.com/catchorg/Catch2",
"CommitHash": "2f631bb8087a0355d2b23a75a28d936ce237659d"
}
},
"DevelopmentDependency": true,
"DependencyRoots": []
},
{
"Component": {
"Type": "git",
"git": {
"RepositoryUrl": "https://github.com/fmtlib/fmt",
"CommitHash": "d141cdbeb0fb422a3fb7173b285fd38e0d1772dc"
}
},
"DevelopmentDependency": false,
"DependencyRoots": []
}
]
}
19 changes: 19 additions & 0 deletions cmake/Findfmt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
option(VCPKG_DEPENDENCY_EXTERNAL_FMT "Use an external version of the fmt library" OFF)

include(FetchContent)
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_TAG d141cdbeb0fb422a3fb7173b285fd38e0d1772dc # 8.0.1
)

if(NOT fmt_FIND_REQUIRED)
message(FATAL_ERROR "fmt must be REQUIRED")
endif()

if(VCPKG_DEPENDENCY_EXTERNAL_FMT)
find_package(fmt CONFIG REQUIRED)
else()
FetchContent_MakeAvailable(fmt)
endif()

1 change: 1 addition & 0 deletions include/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vcpkg/base/system_headers.h>

#include <vcpkg/base/files.h>
#include <vcpkg/base/format.h>
#include <vcpkg/base/pragmas.h>

#if defined(_WIN32)
Expand Down
4 changes: 2 additions & 2 deletions include/vcpkg/base/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <vcpkg/base/checks.h>
#include <vcpkg/base/lineinfo.h>
#include <vcpkg/base/messages.h>
#include <vcpkg/base/stringliteral.h>
#include <vcpkg/base/system.print.h>

#include <system_error>
#include <type_traits>
Expand Down Expand Up @@ -227,7 +227,7 @@ namespace vcpkg
{
if (m_s.has_error())
{
print2(Color::error, m_s.to_string(), "\n");
msg::write_unlocalized_text_to_stdout(Color::error, Strings::concat(m_s.to_string(), '\n'));
Checks::exit_fail(line_info);
}
}
Expand Down
18 changes: 18 additions & 0 deletions include/vcpkg/base/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,21 @@ namespace vcpkg
}
};
}

namespace fmt
{
template<>
struct formatter<vcpkg::Path>
{
constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin())
{
return vcpkg::basic_format_parse_impl(ctx);
}
template<class FormatContext>
auto format(const vcpkg::Path& path, FormatContext& ctx) -> decltype(ctx.out())
{
return format_to(ctx.out(), "{}", path.native());
}
};

}
47 changes: 47 additions & 0 deletions include/vcpkg/base/format.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include <vcpkg/base/lineinfo.h>
#include <vcpkg/base/pragmas.h>

VCPKG_MSVC_WARNING(push)
// notes:
// C6239 is not a useful warning for external code; it is
// (<non-zero constant> && <expression>) always evaluates to the result of <expression>.
// C6385 is a useful warning, but it's incorrect in this case; it thinks that (on line 1238),
// const char* top = data::digits[exp / 100];
// accesses outside the bounds of data::digits; however, `exp < 10000 => exp / 100 < 100`,
// and thus the access is safe.
VCPKG_MSVC_WARNING(disable : 6239 6385)
#include <fmt/format.h>
VCPKG_MSVC_WARNING(pop)

namespace vcpkg
{
constexpr auto basic_format_parse_impl(fmt::format_parse_context& ctx) -> decltype(ctx.begin())
{
if (ctx.begin() != ctx.end() && *ctx.begin() != '}')
{
throw fmt::format_error("invalid format - must be empty");
}

return ctx.begin();
}
}

namespace fmt
{
template<>
struct formatter<vcpkg::LineInfo>
{
constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin())
{
return vcpkg::basic_format_parse_impl(ctx);
}
template<class FormatContext>
auto format(const vcpkg::LineInfo& li, FormatContext& ctx) -> decltype(ctx.out())
{
return format_to(ctx.out(), "{}({})", li.file_name, li.line_number);
}
};

}
8 changes: 8 additions & 0 deletions include/vcpkg/base/fwd/files.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

namespace vcpkg
{
struct IgnoreErrors;
struct Filesystem;
struct Path;
}
Loading

0 comments on commit 5b939c9

Please sign in to comment.