Skip to content

Commit

Permalink
[vcpkg] Allow to use Nuget's cache for Nuget binary caching sources (fix
Browse files Browse the repository at this point in the history
 microsoft#15169) (microsoft#15512)

* Fix warning on clang version 10.0.0-4ubuntu1

The warning was

```shell
../src/vcpkg/commands.porthistory.cpp:55:14: error: unused function 'is_date' [-Werror,-Wunused-function]
```

* Add environment variable VCPKG_USE_NUGET_CACHE

As the name suggests, this environment variable allow tu use Nuget
cache for Nuget binary caching sources.

* Document NuGet's Cache environment variable
  • Loading branch information
klalumiere authored Jan 25, 2021
1 parent b5e8e48 commit f60b947
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/users/binarycaching.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ or
```
if the appropriate environment variables are defined and non-empty. This is specifically used to associate packages in GitHub Packages with the _building_ project and not intended to associate with the original package sources.

#### NuGet's cache

NuGet's cache is not used by default. To use it for every nuget-based source, set the [environment variable](config-environment.md) `VCPKG_USE_NUGET_CACHE` to `true` (case-insensitive) or `1`.

## Implementation Notes (internal details subject to change without notice)

Binary caching relies on hashing everything that contributes to a particular package build. This includes:
Expand Down
4 changes: 4 additions & 0 deletions docs/users/config-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ This environment variable adds or removes binary sources. See [Binary Caching](b
#### VCPKG_NUGET_REPOSITORY

This environment variable changes the metadata of produced NuGet packages. See [Binary Caching](binarycaching.md#Configuration) for more details.

#### VCPKG_USE_NUGET_CACHE

This environment variable allows using NuGet's cache for every nuget-based binary source. See [Binary Caching](binarycaching.md#NuGets-cache) for more details.
21 changes: 17 additions & 4 deletions toolsrc/src/vcpkg/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <vcpkg/base/downloads.h>
#include <vcpkg/base/files.h>
#include <vcpkg/base/parse.h>
#include <vcpkg/base/strings.h>
#include <vcpkg/base/system.debug.h>
#include <vcpkg/base/system.print.h>
#include <vcpkg/base/system.process.h>
Expand Down Expand Up @@ -415,7 +416,11 @@ namespace
, m_read_configs(std::move(read_configs))
, m_write_configs(std::move(write_configs))
, m_interactive(interactive)
, m_use_nuget_cache(false)
{
const std::string use_nuget_cache = System::get_environment_variable("VCPKG_USE_NUGET_CACHE").value_or("");
m_use_nuget_cache = Strings::case_insensitive_ascii_equals(use_nuget_cache, "true") ||
Strings::case_insensitive_ascii_equals(use_nuget_cache, "1");
}

int run_nuget_commandline(const System::Command& cmdline)
Expand Down Expand Up @@ -531,9 +536,7 @@ namespace
.string_arg("-Source")
.string_arg(Strings::join(";", m_read_sources))
.string_arg("-ExcludeVersion")
.string_arg("-NoCache")
.string_arg("-PreRelease")
.string_arg("-DirectDownload")
.string_arg("-PackageSaveMode")
.string_arg("nupkg")
.string_arg("-Verbosity")
Expand All @@ -543,6 +546,10 @@ namespace
{
cmdline.string_arg("-NonInteractive");
}
if (!m_use_nuget_cache)
{
cmdline.string_arg("-DirectDownload").string_arg("-NoCache");
}

cmdlines.push_back(std::move(cmdline));
}
Expand All @@ -561,9 +568,7 @@ namespace
.string_arg("-ConfigFile")
.path_arg(cfg)
.string_arg("-ExcludeVersion")
.string_arg("-NoCache")
.string_arg("-PreRelease")
.string_arg("-DirectDownload")
.string_arg("-PackageSaveMode")
.string_arg("nupkg")
.string_arg("-Verbosity")
Expand All @@ -573,6 +578,10 @@ namespace
{
cmdline.string_arg("-NonInteractive");
}
if (!m_use_nuget_cache)
{
cmdline.string_arg("-DirectDownload").string_arg("-NoCache");
}

cmdlines.push_back(std::move(cmdline));
}
Expand Down Expand Up @@ -735,6 +744,7 @@ namespace

std::set<PackageSpec> m_restored;
bool m_interactive;
bool m_use_nuget_cache;
};
}

Expand Down Expand Up @@ -1429,6 +1439,9 @@ void vcpkg::help_topic_binary_caching(const VcpkgPaths&)
"\n"
"if the appropriate environment variables are defined and non-empty.\n");
tbl.blank();
tbl.text("NuGet's cache is not used by default. To use it for every nuget-based source, set the environment "
"variable `VCPKG_USE_NUGET_CACHE` to `true` (case-insensitive) or `1`.\n");
tbl.blank();
System::print2(tbl.m_str);
const auto& maybe_cachepath = default_cache_path();
if (auto p = maybe_cachepath.get())
Expand Down

0 comments on commit f60b947

Please sign in to comment.