diff options
| author | seanyen <seanyen@microsoft.com> | 2019-06-12 18:20:02 -0700 |
|---|---|---|
| committer | Sean Yen <seanyen@corp.microsoft.com> | 2019-06-19 16:36:48 -0700 |
| commit | c63af255e39c8303b07014456d97985a71ef3174 (patch) | |
| tree | 9d68bf3c82b135cfcebfa57090f3bf87b2cb9588 | |
| parent | 9a3999d8e29c535ed7fd304a1db5eb2805313416 (diff) | |
| download | vcpkg-c63af255e39c8303b07014456d97985a71ef3174.tar.gz vcpkg-c63af255e39c8303b07014456d97985a71ef3174.zip | |
add chocolatey install scripts.
| -rw-r--r-- | toolsrc/src/vcpkg/export.chocolatey.cpp | 86 |
1 files changed, 83 insertions, 3 deletions
diff --git a/toolsrc/src/vcpkg/export.chocolatey.cpp b/toolsrc/src/vcpkg/export.chocolatey.cpp index 3e6acd34e..b2bfffd41 100644 --- a/toolsrc/src/vcpkg/export.chocolatey.cpp +++ b/toolsrc/src/vcpkg/export.chocolatey.cpp @@ -44,6 +44,7 @@ namespace vcpkg::Export::Chocolatey </metadata>
<files>
<file src="@EXPORTED_ROOT_DIR@\installed\**" target="installed" />
+ <file src="@EXPORTED_ROOT_DIR@\tools\**" target="tools" />
</files>
</package>
)";
@@ -66,12 +67,81 @@ namespace vcpkg::Export::Chocolatey return nuspec_file_content;
}
+ static std::string create_chocolatey_install_contents()
+ {
+ static constexpr auto CONTENT_TEMPLATE = R"###(
+$ErrorActionPreference = 'Stop';
+
+$packageName= $env:ChocolateyPackageName
+$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
+$rootDir = "$(Split-Path -parent $toolsDir)"
+$installedDir = Join-Path $rootDir 'installed'
+
+$whereToInstall = (pwd).path
+$whereToInstallCache = Join-Path $rootDir 'install.txt'
+Set-Content -Path $whereToInstallCache -Value $whereToInstall
+Copy-Item $installedDir -destination $whereToInstall -recurse -force
+)###";
+ return CONTENT_TEMPLATE;
+ }
+
+ static std::string create_chocolatey_uninstall_contents(const BinaryParagraph& binary_paragraph)
+ {
+ static constexpr auto CONTENT_TEMPLATE = R"###(
+$ErrorActionPreference = 'Stop';
+
+$packageName= $env:ChocolateyPackageName
+$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
+$rootDir = "$(Split-Path -parent $toolsDir)"
+$listFile = Join-Path $rootDir 'installed\vcpkg\info\@PACKAGE_FULLSTEM@.list'
+
+$whereToInstall = $null
+$whereToInstallCache = Join-Path $rootDir 'install.txt'
+Get-Content $whereToInstallCache | Foreach-Object {
+ $whereToInstall = $_
+}
+
+$installedDir = Join-Path $whereToInstall 'installed'
+Get-Content $listFile | Foreach-Object {
+ $fileToRemove = Join-Path $installedDir $_
+ if (Test-Path $fileToRemove -PathType Leaf) {
+ Remove-Item $fileToRemove
+ }
+}
+
+Get-Content $listFile | Foreach-Object {
+ $fileToRemove = Join-Path $installedDir $_
+ if (Test-Path $fileToRemove -PathType Container) {
+ $folderToDelete = Join-Path $fileToRemove *
+ if (-Not (Test-Path $folderToDelete))
+ {
+ Remove-Item $fileToRemove
+ }
+ }
+}
+
+$listFileToRemove = Join-Path $whereToInstall 'installed\vcpkg\info\@PACKAGE_FULLSTEM@.list'
+Remove-Item $listFileToRemove
+
+if (Test-Path $installedDir)
+{
+ while (
+ $empties = Get-ChildItem $installedDir -recurse -Directory | Where-Object {
+ $_.GetFiles().Count -eq 0 -and $_.GetDirectories().Count -eq 0
+ }
+ ) { $empties | Remove-Item }
+}
+)###";
+ std::string chocolatey_uninstall_content = Strings::replace_all(CONTENT_TEMPLATE, "@PACKAGE_FULLSTEM@", binary_paragraph.fullstem());
+ return chocolatey_uninstall_content;
+ }
+
void do_export(const std::vector<ExportPlanAction>& export_plan,
const VcpkgPaths& paths)
{
Files::Filesystem& fs = paths.get_filesystem();
- const fs::path export_to_path = paths.root;
- const fs::path raw_exported_dir_path = export_to_path / "chocolatey";
+ const fs::path vcpkg_root_path = paths.root;
+ const fs::path raw_exported_dir_path = vcpkg_root_path / "chocolatey";
const fs::path& nuget_exe = paths.get_tool_exe(Tools::NUGET);
std::error_code ec;
@@ -105,9 +175,19 @@ namespace vcpkg::Export::Chocolatey const fs::path nuspec_file_path = per_package_dir_path / Strings::concat(binary_paragraph.spec.name(), ".nuspec");
fs.write_contents(nuspec_file_path, nuspec_file_content);
+ fs.create_directory(per_package_dir_path / "tools", ec);
+
+ const std::string chocolatey_install_content = create_chocolatey_install_contents();
+ const fs::path chocolatey_install_file_path = per_package_dir_path / "tools" / "chocolateyInstall.ps1";
+ fs.write_contents(chocolatey_install_file_path, chocolatey_install_content);
+
+ const std::string chocolatey_uninstall_content = create_chocolatey_uninstall_contents(binary_paragraph);
+ const fs::path chocolatey_uninstall_file_path = per_package_dir_path / "tools" / "chocolateyUninstall.ps1";
+ fs.write_contents(chocolatey_uninstall_file_path, chocolatey_uninstall_content);
+
const auto cmd_line = Strings::format(R"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes > nul)",
nuget_exe.u8string(),
- raw_exported_dir_path.u8string(),
+ vcpkg_root_path.u8string(),
nuspec_file_path.u8string());
const int exit_code = System::cmd_execute_clean(cmd_line);
|
