Skip to content

Commit

Permalink
[vcpkg manifests] fix some issues (microsoft#12227)
Browse files Browse the repository at this point in the history
  • Loading branch information
strega-nil authored Jul 9, 2020
1 parent cb8aa9c commit 3871d73
Show file tree
Hide file tree
Showing 17 changed files with 250 additions and 92 deletions.
20 changes: 13 additions & 7 deletions docs/maintainers/control-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ The first paragraph in a `CONTROL` file is the Source paragraph. It must have a
### Examples:
```no-highlight
Source: ace
Version: 6.5.5-1
Version: 6.5.5
Description: The ADAPTIVE Communication Environment
```

```no-highlight
Source: vtk
Version: 8.2.0-2
Version: 8.2.0
Port-Version: 2
Description: Software system for 3D computer graphics, image processing, and visualization
Build-Depends: zlib, libpng, tiff, libxml2, jsoncpp, glew, freetype, expat, hdf5, libjpeg-turbo, proj4, lz4, libtheora, atlmfc (windows), eigen3, double-conversion, pugixml, libharu, sqlite3, netcdf-c
```
Expand All @@ -39,15 +40,14 @@ Package collections to check for conflicts:
+ [Packages search](https://pkgs.org/)

#### Version
The port version.
The library version.

This field is an alphanumeric string that may also contain `.`, `_`, or `-`. No attempt at ordering versions is made; all versions are treated as bit strings and are only evaluated for equality.

For tagged-release ports, we follow the following convention:

1. If the port follows a scheme like `va.b.c`, we remove the leading `v`. In this case, it becomes `a.b.c`.
2. If the port includes its own name in the version like `curl-7_65_1`, we remove the leading name: `7_65_1`
3. If the port has been modified, we append a `-N` to distinguish the versions: `1.2.1-4`

For rolling-release ports, we use the date that the _commit was accessed by you_, formatted as `YYYY-MM-DD`. Stated another way: if someone had a time machine and went to that date, they would see this commit as the latest master.

Expand All @@ -56,11 +56,17 @@ For example, given:
2. The current version string is `2019-02-14-1`
3. Today's date is 2019-06-01.

Then if you update the source version today, you should give it version `2019-06-01`. If you need to make a change which doesn't adjust the source version, you should give it version `2019-02-14-2`.
Then if you update the source version today, you should give it version `2019-06-01`.

#### Port-Version
The version of the port.

This field is a non-negative integer. It allows one to version the port file separately from the version of the underlying library; if you make a change to a port, without changing the underlying version of the library, you should increment this field by one (starting at `0`, which is equivalent to no `Port-Version` field). When the version of the underlying library is upgraded, this field should be set back to `0` (i.e., delete the `Port-Version` field).

##### Examples:
```no-highlight
Version: 1.0.5-2
Version: 1.0.5
Port-Version: 2
```
```no-highlight
Version: 2019-03-21
Expand All @@ -77,7 +83,7 @@ Description: C++ header-only JSON library
```
```no-highlight
Description: Mosquitto is an open source message broker that implements the MQ Telemetry Transport protocol versions 3.1 and 3.1.1.
MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for "machine
MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for "machine
to machine" messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers like the Arduino.
````
Expand Down
4 changes: 4 additions & 0 deletions scripts/azure-pipelines/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ stages:
pool: $(windows-pool)
jobs:
- job:
workspace:
clean: resources
steps:
- task: Powershell@2
displayName: 'Check C++ Formatting'
Expand All @@ -23,6 +25,8 @@ stages:
dependsOn: []
jobs:
- job:
workspace:
clean: resources
steps:
- task: Powershell@2
displayName: 'Check port manifest Formatting'
Expand Down
68 changes: 46 additions & 22 deletions scripts/buildsystems/vcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ option(VCPKG_VERBOSE "Enables messages from the VCPKG toolchain for debugging pu
mark_as_advanced(VCPKG_VERBOSE)

function(_vcpkg_get_directory_name_of_file_above OUT DIRECTORY FILENAME)
if(DEFINED ${OUT})
return()
endif()

set(_vcpkg_get_dir_candidate ${DIRECTORY})
while(IS_DIRECTORY ${_vcpkg_get_dir_candidate} AND NOT DEFINED _vcpkg_get_dir_out)
if(EXISTS ${_vcpkg_get_dir_candidate}/${FILENAME})
Expand All @@ -28,22 +24,28 @@ function(_vcpkg_get_directory_name_of_file_above OUT DIRECTORY FILENAME)
endfunction()

_vcpkg_get_directory_name_of_file_above(_VCPKG_MANIFEST_DIR ${CMAKE_CURRENT_SOURCE_DIR} "vcpkg.json")
if(_VCPKG_MANIFEST_DIR)
set(_VCPKG_MANIFEST_MODE_DEFAULT ON)
else()
set(_VCPKG_MANIFEST_MODE_DEFAULT OFF)
endif()

option(VCPKG_MANIFEST_MODE "Set vcpkg to manifest mode" ${_VCPKG_MANIFEST_MODE_DEFAULT})

if(NOT _VCPKG_MANIFEST_DIR AND VCPKG_MANIFEST_MODE)
if(NOT DEFINED VCPKG_MANIFEST_MODE)
if(_VCPKG_MANIFEST_DIR)
set(VCPKG_MANIFEST_MODE ON)
else()
set(VCPKG_MANIFEST_MODE OFF)
endif()
elseif(VCPKG_MANIFEST_MODE AND NOT _VCPKG_MANIFEST_DIR)
message(FATAL_ERROR
"vcpkg manifest mode was enabled, but we couldn't find a manifest file (vcpkg.json) "
"in any directories above ${CMAKE_CURRENT_SOURCE_DIR}. Please add a manifest, or "
"disable manifests by turning off VCPKG_MANIFEST_MODE.")
endif()

option(VCPKG_MANIFEST_INSTALL "Install packages from the manifest" ON)
if(VCPKG_MANIFEST_MODE)
option(VCPKG_MANIFEST_INSTALL
[[
Install the dependencies listed in your manifest:
If this is off, you will have to manually install your dependencies.
See https://github.com/microsoft/vcpkg/tree/master/docs/specifications/manifests.md for more info.
]]
ON)
endif()

# Determine whether the toolchain is loaded during a try-compile configuration
get_property(_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE)
Expand Down Expand Up @@ -198,7 +200,7 @@ endif()

if (NOT DEFINED _VCPKG_INSTALLED_DIR)
if(_VCPKG_MANIFEST_DIR)
set(_VCPKG_INSTALLED_DIR ${_VCPKG_MANIFEST_DIR}/vcpkg_installed)
set(_VCPKG_INSTALLED_DIR ${CMAKE_BINARY_DIR}/vcpkg_installed)
else()
set(_VCPKG_INSTALLED_DIR ${_VCPKG_ROOT_DIR}/installed)
endif()
Expand Down Expand Up @@ -230,11 +232,11 @@ else() #Release build: Put Release paths before Debug paths. Debug Paths are req
)
endif()

# If one CMAKE_FIND_ROOT_PATH_MODE_* variables is set to ONLY, to make sure that ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}
# If one CMAKE_FIND_ROOT_PATH_MODE_* variables is set to ONLY, to make sure that ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}
# and ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug are searched, it is not sufficient to just add them to CMAKE_FIND_ROOT_PATH,
# as CMAKE_FIND_ROOT_PATH specify "one or more directories to be prepended to all other search directories", so to make sure that
# as CMAKE_FIND_ROOT_PATH specify "one or more directories to be prepended to all other search directories", so to make sure that
# the libraries are searched as they are, it is necessary to add "/" to the CMAKE_PREFIX_PATH
if(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE STREQUAL "ONLY" OR
if(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE STREQUAL "ONLY" OR
CMAKE_FIND_ROOT_PATH_MODE_LIBRARY STREQUAL "ONLY" OR
CMAKE_FIND_ROOT_PATH_MODE_PACKAGE STREQUAL "ONLY")
list(APPEND CMAKE_PREFIX_PATH "/")
Expand Down Expand Up @@ -280,23 +282,45 @@ endforeach()

# CMAKE_EXECUTABLE_SUFFIX is not yet defined
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(_VCPKG_EXECUTABLE_SUFFIX ".exe")
set(_VCPKG_EXECUTABLE "${_VCPKG_ROOT_DIR}/vcpkg.exe")
set(_VCPKG_BOOTSTRAP_SCRIPT "${_VCPKG_ROOT_DIR}/bootstrap-vcpkg.bat")
else()
set(_VCPKG_EXECUTABLE_SUFFIX "")
set(_VCPKG_EXECUTABLE "${_VCPKG_ROOT_DIR}/vcpkg")
set(_VCPKG_BOOTSTRAP_SCRIPT "${_VCPKG_ROOT_DIR}/bootstrap-vcpkg.sh")
endif()

if(VCPKG_MANIFEST_MODE AND VCPKG_MANIFEST_INSTALL AND NOT _CMAKE_IN_TRY_COMPILE)
if(NOT EXISTS "${_VCPKG_EXECUTABLE}")
message(STATUS "Bootstrapping vcpkg before install")

execute_process(
COMMAND "${_VCPKG_BOOTSTRAP_SCRIPT}"
RESULT_VARIABLE _VCPKG_BOOTSTRAP_RESULT)

if (NOT _VCPKG_BOOTSTRAP_RESULT EQUAL 0)
message(FATAL_ERROR "Bootstrapping vcpkg before install - failed")
endif()

message(STATUS "Bootstrapping vcpkg before install - done")
endif()

message(STATUS "Running vcpkg install")

execute_process(
COMMAND "${_VCPKG_ROOT_DIR}/vcpkg${_VCPKG_EXECUTABLE_SUFFIX}" install
COMMAND "${_VCPKG_EXECUTABLE}" install
--triplet ${VCPKG_TARGET_TRIPLET}
--vcpkg-root ${_VCPKG_ROOT_DIR}
--x-manifest-root=${_VCPKG_MANIFEST_DIR}
--x-install-root=${_VCPKG_INSTALLED_DIR}
--binarycaching
RESULT_VARIABLE _VCPKG_INSTALL_RESULT)

if (NOT _VCPKG_INSTALL_RESULT EQUAL 0)
message(FATAL_ERROR "vcpkg install failed")
message(FATAL_ERROR "Running vcpkg install - failed")
endif()

message(STATUS "Running vcpkg install - done")

set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
"${_VCPKG_MANIFEST_DIR}/vcpkg.json"
"${_VCPKG_INSTALLED_DIR}/vcpkg/status")
Expand Down
3 changes: 3 additions & 0 deletions toolsrc/include/vcpkg/base/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ namespace vcpkg::Files
virtual void current_path(const fs::path& path, std::error_code&) = 0;
void current_path(const fs::path& path, LineInfo li);

// waits forever for the file lock
virtual fs::SystemHandle take_exclusive_file_lock(const fs::path& path, std::error_code&) = 0;
// waits, at most, 1.5 seconds, for the file lock
virtual fs::SystemHandle try_take_exclusive_file_lock(const fs::path& path, std::error_code&) = 0;
virtual void unlock_file_lock(fs::SystemHandle handle, std::error_code&) = 0;

Expand Down
4 changes: 4 additions & 0 deletions toolsrc/include/vcpkg/vcpkgcmdarguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ namespace vcpkg
constexpr static StringLiteral PRINT_METRICS_SWITCH = "printmetrics";
Optional<bool> print_metrics = nullopt;

constexpr static StringLiteral WAIT_FOR_LOCK_SWITCH = "x-wait-for-lock";
Optional<bool> wait_for_lock = nullopt;

// feature flags
constexpr static StringLiteral FEATURE_FLAGS_ENV = "VCPKG_FEATURE_FLAGS";
constexpr static StringLiteral FEATURE_FLAGS_ARG = "feature-flags";
Expand All @@ -175,6 +178,7 @@ namespace vcpkg

void check_feature_flag_consistency() const;

void debug_print_feature_flags() const;
void track_feature_flag_metrics() const;

private:
Expand Down
13 changes: 7 additions & 6 deletions toolsrc/include/vcpkg/versiont.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ namespace vcpkg
struct VersionT
{
VersionT() noexcept;
VersionT(std::string&& value);
VersionT(const std::string& value);
VersionT(std::string&& value, int port_version);
VersionT(const std::string& value, int port_version);

const std::string& to_string() const;
std::string to_string() const;

friend bool operator==(const VersionT& left, const VersionT& right);
friend bool operator!=(const VersionT& left, const VersionT& right);

private:
std::string value;
int port_version;
};

bool operator==(const VersionT& left, const VersionT& right);
bool operator!=(const VersionT& left, const VersionT& right);

struct VersionDiff
{
VersionT left;
Expand Down
1 change: 1 addition & 0 deletions toolsrc/src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ int main(const int argc, const char* const* const argv)
"Warning: passed either --printmetrics or --no-printmetrics, but metrics are disabled.\n");
}

args.debug_print_feature_flags();
args.track_feature_flag_metrics();

if (Debug::g_debugging)
Expand Down
Loading

0 comments on commit 3871d73

Please sign in to comment.