Skip to content

Commit

Permalink
[vcpkg] Add initial versioning documentation (microsoft#15565)
Browse files Browse the repository at this point in the history
* [vcpkg] Improve efficiency and tests of versioning

* [vcpkg] Add initial versioning documentation and rename x-default-baseline to builtin-baseline

* [vcpkg] Enable metrics for builtin-baseline & overrides

* [vcpkg] Address PR comments

* [vcpkg] Add support for  syntax in version>=

* [vcpkg] Remove port-version from dependency syntax

* [vcpkg] Address CR comment

* [vcpkg] Minor docs fixup
  • Loading branch information
ras0219 authored Jan 15, 2021
1 parent f107c61 commit 710a2ac
Show file tree
Hide file tree
Showing 17 changed files with 468 additions and 257 deletions.
9 changes: 4 additions & 5 deletions include/vcpkg/base/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,10 @@ namespace vcpkg
void exit_if_error(const LineInfo& line_info) const
{
// This is used for quick value_or_exit() calls, so always put line_info in the error message.
Checks::check_exit(line_info,
!m_s.has_error(),
"Failed at [%s] with message:\n%s",
line_info.to_string(),
m_s.to_string());
if (m_s.has_error())
{
Checks::exit_with_message(line_info, "Failed at [%s] with message:\n%s", line_info, m_s.to_string());
}
}

ErrorHolder<S> m_s;
Expand Down
33 changes: 11 additions & 22 deletions include/vcpkg/base/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,45 +282,34 @@ namespace vcpkg::Files
};

ExclusiveFileLock() = default;
ExclusiveFileLock(ExclusiveFileLock&& other)
: fs_(other.fs_), handle_(std::exchange(handle_, fs::SystemHandle{}))
{
}
ExclusiveFileLock& operator=(ExclusiveFileLock&& other)
{
if (this == &other) return *this;

clear();
fs_ = other.fs_;
handle_ = std::exchange(other.handle_, fs::SystemHandle{});
return *this;
}
ExclusiveFileLock(ExclusiveFileLock&&) = delete;
ExclusiveFileLock& operator=(ExclusiveFileLock&&) = delete;

ExclusiveFileLock(Wait wait, Filesystem& fs, const fs::path& path_, std::error_code& ec) : fs_(&fs)
ExclusiveFileLock(Wait wait, Filesystem& fs, const fs::path& path_, std::error_code& ec) : m_fs(&fs)
{
switch (wait)
{
case Wait::Yes: handle_ = fs_->take_exclusive_file_lock(path_, ec); break;
case Wait::No: handle_ = fs_->try_take_exclusive_file_lock(path_, ec); break;
case Wait::Yes: m_handle = m_fs->take_exclusive_file_lock(path_, ec); break;
case Wait::No: m_handle = m_fs->try_take_exclusive_file_lock(path_, ec); break;
}
}
~ExclusiveFileLock() { clear(); }

explicit operator bool() const { return handle_.is_valid(); }
bool has_lock() const { return handle_.is_valid(); }
explicit operator bool() const { return m_handle.is_valid(); }
bool has_lock() const { return m_handle.is_valid(); }

void clear()
{
if (fs_ && handle_.is_valid())
if (m_fs && m_handle.is_valid())
{
std::error_code ignore;
fs_->unlock_file_lock(std::exchange(handle_, fs::SystemHandle{}), ignore);
m_fs->unlock_file_lock(std::exchange(m_handle, fs::SystemHandle{}), ignore);
}
}

private:
fs::SystemHandle handle_;
Filesystem* fs_;
Filesystem* m_fs;
fs::SystemHandle m_handle;
};

}
4 changes: 3 additions & 1 deletion include/vcpkg/base/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ namespace vcpkg::Json
ExpectedT<std::pair<Value, JsonStyle>, std::unique_ptr<Parse::IParseError>> parse_file(
const Files::Filesystem&, const fs::path&, std::error_code& ec) noexcept;
ExpectedT<std::pair<Value, JsonStyle>, std::unique_ptr<Parse::IParseError>> parse(
StringView text, const fs::path& filepath = {}) noexcept;
StringView text, const fs::path& filepath) noexcept;
ExpectedT<std::pair<Value, JsonStyle>, std::unique_ptr<Parse::IParseError>> parse(StringView text,
StringView origin = {}) noexcept;
std::pair<Value, JsonStyle> parse_file(vcpkg::LineInfo linfo, const Files::Filesystem&, const fs::path&) noexcept;

std::string stringify(const Value&, JsonStyle style);
Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/base/jsonreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ namespace vcpkg::Json

struct NaturalNumberDeserializer final : IDeserializer<int>
{
virtual StringView type_name() const override { return "a natural number"; }
virtual StringView type_name() const override { return "a nonnegative integer"; }

virtual Optional<int> visit_integer(Reader&, int64_t value) override
{
Expand Down
1 change: 1 addition & 0 deletions include/vcpkg/sourceparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace vcpkg
std::vector<DependencyOverride> overrides;
std::vector<std::string> default_features;
std::string license; // SPDX license expression
Optional<std::string> builtin_baseline;

Type type;
PlatformExpression::Expr supports_expression;
Expand Down
15 changes: 6 additions & 9 deletions include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ namespace vcpkg
const std::string& get_tool_version(const std::string& tool) const;

// Git manipulation in the vcpkg directory
fs::path git_checkout_baseline(Files::Filesystem& filesystem, StringView commit_sha) const;
fs::path git_checkout_port(Files::Filesystem& filesystem, StringView port_name, StringView git_tree) const;
ExpectedS<std::string> get_current_git_sha() const;
std::string get_current_git_sha_message() const;
ExpectedS<fs::path> git_checkout_baseline(StringView commit_sha) const;
ExpectedS<fs::path> git_checkout_port(StringView port_name,
StringView git_tree,
const fs::path& dot_git_dir) const;
ExpectedS<std::string> git_show(const std::string& treeish, const fs::path& dot_git_dir) const;

ExpectedS<std::map<std::string, std::string, std::less<>>> git_get_local_port_treeish_map() const;
Expand Down Expand Up @@ -168,12 +172,5 @@ namespace vcpkg
const fs::path& destination,
const fs::path& dot_git_dir,
const fs::path& work_tree);

static void git_checkout_object(const VcpkgPaths& paths,
StringView git_object,
const fs::path& local_repo,
const fs::path& destination,
const fs::path& dot_git_dir,
const fs::path& work_tree);
};
}
3 changes: 1 addition & 2 deletions include/vcpkg/versions.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ namespace vcpkg::Versions
enum class Type
{
None,
Minimum,
Exact
Minimum
};
};
}
27 changes: 14 additions & 13 deletions src/vcpkg-test/dependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ struct MockOverlayProvider : PortFileProvider::IOverlayProvider, Util::ResourceB

static const MockOverlayProvider s_empty_mock_overlay;

ExpectedS<Dependencies::ActionPlan> create_versioned_install_plan(
static ExpectedS<Dependencies::ActionPlan> create_versioned_install_plan(
const PortFileProvider::IVersionedPortfileProvider& provider,
const PortFileProvider::IBaselineProvider& bprovider,
const CMakeVars::CMakeVarProvider& var_provider,
Expand Down Expand Up @@ -335,7 +335,7 @@ TEST_CASE ("basic version install scheme baseline missing success", "[versionpla
bp,
var_provider,
{
Dependency{"a", {}, {}, {Constraint::Type::Exact, "2"}},
Dependency{"a", {}, {}, {Constraint::Type::Minimum, "2"}},
},
{},
toplevel_spec()));
Expand Down Expand Up @@ -375,7 +375,7 @@ TEST_CASE ("version string baseline agree", "[versionplan]")
MockCMakeVarProvider var_provider;

auto install_plan = create_versioned_install_plan(
vp, bp, var_provider, {Dependency{"a", {}, {}, {Constraint::Type::Exact, "2"}}}, {}, toplevel_spec());
vp, bp, var_provider, {Dependency{"a", {}, {}, {Constraint::Type::Minimum, "2"}}}, {}, toplevel_spec());

REQUIRE(install_plan.has_value());
}
Expand All @@ -396,7 +396,7 @@ TEST_CASE ("version install scheme baseline conflict", "[versionplan]")
bp,
var_provider,
{
Dependency{"a", {}, {}, {Constraint::Type::Exact, "3"}},
Dependency{"a", {}, {}, {Constraint::Type::Minimum, "3"}},
},
{},
toplevel_spec());
Expand All @@ -421,7 +421,7 @@ TEST_CASE ("version install string port version", "[versionplan]")
bp,
var_provider,
{
Dependency{"a", {}, {}, {Constraint::Type::Exact, "2", 1}},
Dependency{"a", {}, {}, {Constraint::Type::Minimum, "2", 1}},
},
{},
toplevel_spec()));
Expand All @@ -447,7 +447,7 @@ TEST_CASE ("version install string port version 2", "[versionplan]")
bp,
var_provider,
{
Dependency{"a", {}, {}, {Constraint::Type::Exact, "2", 0}},
Dependency{"a", {}, {}, {Constraint::Type::Minimum, "2", 0}},
},
{},
toplevel_spec()));
Expand All @@ -463,10 +463,10 @@ TEST_CASE ("version install transitive string", "[versionplan]")

MockVersionedPortfileProvider vp;
vp.emplace("a", {"2", 0}).source_control_file->core_paragraph->dependencies = {
Dependency{"b", {}, {}, DependencyConstraint{Constraint::Type::Exact, "1"}},
Dependency{"b", {}, {}, DependencyConstraint{Constraint::Type::Minimum, "1"}},
};
vp.emplace("a", {"2", 1}).source_control_file->core_paragraph->dependencies = {
Dependency{"b", {}, {}, DependencyConstraint{Constraint::Type::Exact, "2"}},
Dependency{"b", {}, {}, DependencyConstraint{Constraint::Type::Minimum, "2"}},
};
vp.emplace("b", {"1", 0});
vp.emplace("b", {"2", 0});
Expand All @@ -478,7 +478,7 @@ TEST_CASE ("version install transitive string", "[versionplan]")
bp,
var_provider,
{
Dependency{"a", {}, {}, {Constraint::Type::Exact, "2", 1}},
Dependency{"a", {}, {}, {Constraint::Type::Minimum, "2", 1}},
},
{},
toplevel_spec()));
Expand Down Expand Up @@ -1006,7 +1006,7 @@ TEST_CASE ("version install scheme change in port version", "[versionplan]")
{
MockVersionedPortfileProvider vp;
vp.emplace("a", {"2", 0}).source_control_file->core_paragraph->dependencies = {
Dependency{"b", {}, {}, DependencyConstraint{Constraint::Type::Exact, "1"}},
Dependency{"b", {}, {}, DependencyConstraint{Constraint::Type::Minimum, "1"}},
};
vp.emplace("a", {"2", 1}).source_control_file->core_paragraph->dependencies = {
Dependency{"b", {}, {}, DependencyConstraint{Constraint::Type::Minimum, "1", 1}},
Expand All @@ -1026,7 +1026,7 @@ TEST_CASE ("version install scheme change in port version", "[versionplan]")
bp,
var_provider,
{
Dependency{"a", {}, {}, {Constraint::Type::Exact, "2", 1}},
Dependency{"a", {}, {}, {Constraint::Type::Minimum, "2", 1}},
},
{},
toplevel_spec()));
Expand All @@ -1045,7 +1045,7 @@ TEST_CASE ("version install scheme change in port version", "[versionplan]")
bp,
var_provider,
{
Dependency{"a", {}, {}, {Constraint::Type::Exact, "2", 0}},
Dependency{"a", {}, {}, {Constraint::Type::Minimum, "2", 0}},
},
{},
toplevel_spec()));
Expand Down Expand Up @@ -1305,7 +1305,8 @@ TEST_CASE ("version install transitive overrides", "[versionplan]")
MockVersionedPortfileProvider vp;

vp.emplace("b", {"1", 0}, Scheme::Relaxed)
.source_control_file->core_paragraph->dependencies.push_back({"c", {}, {}, {Constraint::Type::Exact, "2", 1}});
.source_control_file->core_paragraph->dependencies.push_back(
{"c", {}, {}, {Constraint::Type::Minimum, "2", 1}});
vp.emplace("b", {"2", 0}, Scheme::Relaxed);
vp.emplace("c", {"1", 0}, Scheme::String);
vp.emplace("c", {"2", 1}, Scheme::String);
Expand Down
Loading

0 comments on commit 710a2ac

Please sign in to comment.