From 3eab83a635af6ece7554c8a3a4fab1ba63a748e2 Mon Sep 17 00:00:00 2001 From: Chidozie Ononiwu <31145988+chidozieononiwu@users.noreply.github.com> Date: Wed, 3 Mar 2021 16:35:24 -0800 Subject: [PATCH] Add alternate code path for Get-cpp-PackageInfoFromRepo (#1762) * Add alternate code path for Get-cpp-PackageInfoFromRepo * Use Join-Path rather than slashes * Remove quotes from Join-Path arguments --- eng/scripts/Get-PkgVersion.ps1 | 20 +++++++++++++++----- eng/scripts/Language-Settings.ps1 | 15 +++++++++++++-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/eng/scripts/Get-PkgVersion.ps1 b/eng/scripts/Get-PkgVersion.ps1 index af7c13591..9aeadb10b 100644 --- a/eng/scripts/Get-PkgVersion.ps1 +++ b/eng/scripts/Get-PkgVersion.ps1 @@ -7,26 +7,36 @@ param ( [string] $PackageName ) -. ${PSScriptRoot}/SdkVersion-Common.ps1 +$repoRoot = Resolve-Path "$PSScriptRoot/../.."; +. (Join-Path ${repoRoot} eng common scripts logging.ps1) +. (Join-Path ${repoRoot} eng scripts SdkVersion-Common.ps1) $versionFileLocation = Get-VersionHppLocaiton ` -ServiceDirectory $ServiceDirectory ` -PackageName $PackageName if (!$versionFileLocation) { - $fallback = Get-Content $RepoRoot/sdk/$ServiceDirectory/$PackageName/version.txt + $fallbackpath = Join-Path $RepoRoot sdk $ServiceDirectory $PackageName version.txt + if (!(Test-Path $fallbackpath)) + { + LogWarning "Failed to retrieve package version. No version file found." + return $null + } + + $fallback = Get-Content $fallbackpath if ($fallback) { return $fallback } else { - Write-Error "Cannot locate package version" - exit 1 + LogWarning "Cannot locate package version" + return $null } } $versionFileContents = Get-Content $versionFileLocation -Raw if (!($versionFileContents -match $VersionRegex)) { - Write-Error "does not match version information schema" + LogWarning "does not match version information schema" + return $null } $VersionString = if ($Matches.prerelease) { diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index ee54b3d20..574b1e90f 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -12,12 +12,23 @@ function Get-cpp-PackageInfoFromRepo($pkgPath, $serviceDirectory, $pkgName) # Test if the package path ends with the package name (e.g. sdk/storage/azure-storage-common) # This function runs in a loop where $pkgPath might be the path to the package and must return # $null in cases where $pkgPath is not the path to the package specified by $pkgName - if ($pkgName -ne (Split-Path -Leaf $pkgPath)) { + if ($pkgName -and ($pkgName -ne (Split-Path -Leaf $pkgPath))) { return $null } + if (!$pkgName) + { + $pkgName = Split-Path -Leaf $pkgPath + } + $packageVersion = & $PSScriptRoot/Get-PkgVersion.ps1 -ServiceDirectory $serviceDirectory -PackageName $pkgName - return [PackageProps]::new($pkgName, $packageVersion, $pkgPath, $serviceDirectory) + if ($null -ne $packageVersion) + { + $packageProps = [PackageProps]::new($pkgName, $packageVersion, $pkgPath, $serviceDirectory) + $packageProps.ArtifactName = $pkgName + return $packageProps + } + return $null } # Parse out package publishing information from a package-info.json file.