Skip to content

Commit

Permalink
(GH-631) Remove Get-BinRoot, Add Get-ToolsLocation
Browse files Browse the repository at this point in the history
Get-ToolsLocation is the successor to Get-BinRoot. It sets an alias to
the old method and provides the deprecation message when this method is
called with the older alias.

Get-ToolsLocation is a much more aptly named value, and the environment
variable surrounding it makes sense upon sight.  If either of the older
environment variables are found, they are used to update this value and
then those older environment variables are removed.

This also resolves GH-628, the tools location can be the root of the
drive again.
  • Loading branch information
ferventcoder committed Feb 12, 2016
1 parent 968f130 commit c014357
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 62 deletions.
4 changes: 3 additions & 1 deletion src/chocolatey.resources/chocolatey.resources.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
<ItemGroup>
<EmbeddedResource Include="helpers\chocolateyInstaller.psm1" />
<EmbeddedResource Include="helpers\functions\Format-FileSize.ps1" />
<EmbeddedResource Include="helpers\functions\Get-BinRoot.ps1" />
<EmbeddedResource Include="helpers\functions\Get-CheckSumValid.ps1" />
<EmbeddedResource Include="helpers\functions\Get-ChocolateyUnzip.ps1" />
<EmbeddedResource Include="helpers\functions\Get-ChocolateyWebFile.ps1" />
Expand Down Expand Up @@ -126,6 +125,9 @@
<ItemGroup>
<EmbeddedResource Include="helpers\functions\Get-FileName.ps1" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="helpers\functions\Get-ToolsLocation.ps1" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
61 changes: 0 additions & 61 deletions src/chocolatey.resources/helpers/functions/Get-BinRoot.ps1

This file was deleted.

55 changes: 55 additions & 0 deletions src/chocolatey.resources/helpers/functions/Get-ToolsLocation.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2011 - Present RealDimensions Software, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function Get-ToolsLocation {
Write-Debug "Running 'Get-ToolsLocation'";
$invocation = $MyInvocation
if ($invocation -ne $null -and $invocation.InvocationName -ne $null -and $invocation.InvocationName.ToLower() -eq 'Get-BinRoot') {
Write-Host "Get-BinRoot is going to be deprecated in v1 and removed in v2. It is being replaced with Get-ToolsLocation, however many packages no longer require a special separate directory since package folders no longer have versions on them. Some do though and should continue to use Get-ToolsLocation."
}

$toolsLocation = $env:ChocolateyToolsLocation

if ($toolsLocation -eq $null) {
$binRoot = $env:ChocolateyBinRoot
$olderRoot = $env:chocolatey_bin_root

if ($binRoot -eq $null -and $olderRoot -eq $null) {
$toolsLocation = Join-Path $env:systemdrive 'tools'
} else {
if ($olderRoot -ne $null) {
if ($binRoot -eq $null) {
$binRoot = $olderRoot
}
Set-EnvironmentVariable -Name "chocolatey_bin_root" -Value '' -Scope User
}

$toolsLocation = $binRoot
Set-EnvironmentVariable -Name "ChocolateyBinRoot" -Value '' -Scope User
}
}

# Add a drive letter if one doesn't exist
if (-not($toolsLocation -imatch "^\w:")) {
$toolsLocation = join-path $env:systemdrive $toolsLocation
}

if (-not($env:ChocolateyToolsLocation -eq $toolsLocation)) {
Set-EnvironmentVariable -Name "ChocolateyToolsLocation" -Value $toolsLocation -Scope User
}

return $toolsLocation
}

Set-Alias Get-BinRoot Get-ToolsLocation -Force -Scope Global -Option AllScope

0 comments on commit c014357

Please sign in to comment.