Skip to content

Commit

Permalink
sanityCheckNuget.fsx: respect dir for external sln
Browse files Browse the repository at this point in the history
Co-authored-by: Afshin Arani <afshin@arani.dev>
  • Loading branch information
Mersho and aarani committed Oct 31, 2023
1 parent 84d54d3 commit cd863aa
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions scripts/sanityCheckNuget.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ open Fsdk.Process

#r "nuget: Microsoft.Build, Version=16.11.0"
open Microsoft.Build.Construction
let ScriptsDir = __SOURCE_DIRECTORY__ |> DirectoryInfo
let RootDir = Path.Combine(ScriptsDir.FullName, "..") |> DirectoryInfo

let NugetSolutionPackagesDir =
Path.Combine(RootDir.FullName, "packages") |> DirectoryInfo
let GetNugetSolutionPackagesDir(solutionDir: DirectoryInfo) =
Path.Combine(solutionDir.FullName, "packages") |> DirectoryInfo

let args = Misc.FsxOnlyArguments()

Expand Down Expand Up @@ -102,8 +100,8 @@ type private ComparableFileInfo =

let SanityCheckNugetPackages() =

let notPackagesFolder(dir: DirectoryInfo) : bool =
dir.FullName <> NugetSolutionPackagesDir.FullName
let notPackagesFolder (solutionDir: DirectoryInfo) (dir: DirectoryInfo) : bool =
dir.FullName <> (GetNugetSolutionPackagesDir solutionDir).FullName

let notSubmodule(dir: DirectoryInfo) : bool =
let getSubmoduleDirsForThisRepo() : seq<DirectoryInfo> =
Expand Down Expand Up @@ -169,7 +167,7 @@ let SanityCheckNugetPackages() =
dir
.EnumerateDirectories()
.Where(notSubmodule)
.Where(notPackagesFolder) do
.Where(notPackagesFolder sol.Directory) do
for file in findNuspecFiles subdir do
yield file
}
Expand Down Expand Up @@ -324,23 +322,25 @@ let SanityCheckNugetPackages() =
: Map<string, seq<DependencyHolder>> =
solDir.Refresh()

if not NugetSolutionPackagesDir.Exists then
let packagesDir = GetNugetSolutionPackagesDir solDir

if not packagesDir.Exists then
failwithf
"'%s' subdir under solution dir %s doesn't exist, run `make` first"
NugetSolutionPackagesDir.Name
NugetSolutionPackagesDir.FullName
packagesDir.Name
packagesDir.FullName

let packageDirsAbsolutePaths =
NugetSolutionPackagesDir
packagesDir
.EnumerateDirectories()
.Select(fun dir -> dir.FullName)

if not(packageDirsAbsolutePaths.Any()) then
Console.Error.WriteLine(
sprintf
"'%s' subdir under solution dir %s doesn't contain any packages"
NugetSolutionPackagesDir.Name
NugetSolutionPackagesDir.FullName
packagesDir.Name
packagesDir.FullName
)

Console.Error.WriteLine
Expand All @@ -353,7 +353,7 @@ let SanityCheckNugetPackages() =
idealPackageDirs do
let pkgDirToLookFor =
Path.Combine(
NugetSolutionPackagesDir.FullName,
packagesDir.FullName,
packageDirNameThatShouldExist
)
|> DirectoryInfo
Expand All @@ -369,24 +369,26 @@ let SanityCheckNugetPackages() =
: seq<string> =
solDir.Refresh()

if not(NugetSolutionPackagesDir.Exists) then
let packagesDir = GetNugetSolutionPackagesDir solDir

if not(packagesDir.Exists) then
failwithf
"'%s' subdir under solution dir %s doesn't exist, run `make` first"
NugetSolutionPackagesDir.Name
NugetSolutionPackagesDir.FullName
packagesDir.Name
packagesDir.FullName
// "src" is a directory for source codes and build scripts,
// not for packages, so we need to exclude it from here
let packageDirNames =
NugetSolutionPackagesDir
packagesDir
.EnumerateDirectories()
.Select(fun dir -> dir.Name)
.Except([ "src" ])

if not(packageDirNames.Any()) then
failwithf
"'%s' subdir under solution dir %s doesn't contain any packages"
NugetSolutionPackagesDir.Name
NugetSolutionPackagesDir.FullName
packagesDir.Name
packagesDir.FullName

let packageDirsThatShouldExist =
MapHelper.GetKeysOfMap idealPackageDirs
Expand Down

0 comments on commit cd863aa

Please sign in to comment.