88 [string []]$PackageNames ,
99 [Parameter (ParameterSetName = ' PackageInfo' )]
1010 [string ]$PackageInfoDirectory ,
11- [switch ]$NoVerify
11+ [switch ]$Release ,
12+ [switch ]$NoVerify ,
13+ [string ]$OutBuildOrderFile
1214)
1315
1416$ErrorActionPreference = ' Stop'
1517
1618. ([System.IO.Path ]::Combine($PSScriptRoot , ' ..' , ' common' , ' scripts' , ' common.ps1' ))
17- . ([System.IO.Path ]::Combine($PSScriptRoot , ' Pack-Common.ps1' ))
1819
1920Write-Host @"
2021Packing crates with
@@ -61,8 +62,8 @@ function Get-OutputPackageNames($workspacePackages) {
6162function Get-CargoPackages () {
6263 $metadata = Get-CargoMetadata
6364
64- # path based depdenencies are assumed to be unreleased package versions
65- # they must be included in this build and build before packages that depend on them
65+ # Path based dependencies are assumed to be unreleased package versions. In
66+ # non-release builds these should be packed as well.
6667 foreach ($package in $metadata.packages ) {
6768 $package.UnreleasedDependencies = @ ()
6869 foreach ($dependency in $package.dependencies ) {
@@ -80,9 +81,13 @@ function Get-PackagesToBuild() {
8081 $packages = Get-CargoPackages
8182 $outputPackageNames = Get-OutputPackageNames $packages
8283
83- # We start with output packages, then recursively add unreleased dependencies to the list of packages that need to be built
8484 [array ]$packagesToBuild = $packages | Where-Object { $outputPackageNames.Contains ($_.name ) }
8585
86+ if ($Release ) {
87+ return $packagesToBuild
88+ }
89+
90+ # If not releasing, expand dependencies into list of packages to build
8691 $toProcess = $packagesToBuild
8792 while ($toProcess.Length -gt 0 ) {
8893 $package = $toProcess [0 ]
@@ -96,111 +101,77 @@ function Get-PackagesToBuild() {
96101 }
97102 }
98103
99- $buildOrder = @ ()
100-
101- # Then we order the packages to that dependencies are built first
102- while ($packagesToBuild.Count -gt 0 ) {
103- # Pick any package with no unreleased dependencies, add it to the build order and remove it from the list of other packages' unreleased dependencies
104- $package = $packagesToBuild | Where-Object { $_.UnreleasedDependencies.Count -eq 0 } | Select-Object - First 1
105-
106- if (-not $package ) {
107- Write-Error " These packages cannot be built because they depend on unreleased dependencies that aren't being built." - ErrorAction Continue
108- foreach ($package in $packagesToBuild ) {
109- Write-Error " $ ( $package.name ) -> $ ( $package.UnreleasedDependencies -join ' , ' ) " - ErrorAction Continue
110- }
111- exit 1
112- }
113-
114- $package.OutputPackage = $outputPackageNames.Contains ($package.name )
115- $buildOrder += $package
116- $packagesToBuild = @ ($packagesToBuild -ne $package )
117-
118- foreach ($otherPackage in $packagesToBuild ) {
119- $otherPackage.UnreleasedDependencies = $otherPackage.UnreleasedDependencies -ne $package
120- }
121- }
122-
123- return $buildOrder
104+ return $packagesToBuild
124105}
125106
126- function Initialize-VendorDirectory () {
127- $path = " $RepoRoot /target/vendor"
128- Invoke-LoggedCommand " cargo vendor $path " - GroupOutput | Out-Host
129- return $path
107+ function Get-CargoMetadata () {
108+ cargo metadata -- no- deps -- format-version 1 -- manifest- path " $RepoRoot /Cargo.toml" | ConvertFrom-Json - Depth 100 - AsHashtable
130109}
131110
132- function Add-CrateToLocalRegistry ($LocalRegistryPath , $Package ) {
133- $packageName = $Package.name
134- $packageVersion = $Package.version
135-
136- # create an index entry for the package
137- $packagePath = " $RepoRoot /target/package/$packageName -$packageVersion "
111+ function Create-ApiViewFile ($package ) {
112+ $packageName = $package.name
113+ $command = " cargo run --manifest-path $RepoRoot /eng/tools/generate_api_report/Cargo.toml -- --package $packageName "
114+ Invoke-LoggedCommand $command - GroupOutput | Out-Host
138115
139- Write-Host " Copying package '$packageName ' to vendor directory '$LocalRegistryPath '"
140- Copy-Item - Path $packagePath - Destination $LocalRegistryPath - Recurse
116+ $packagePath = Split-Path - Path $package.manifest_path - Parent
141117
142- # write an empty checksum file
143- ' {"files":{}}' | Out-File - FilePath " $LocalRegistryPath /$packageName -$packageVersion /.cargo-checksum.json" - Encoding utf8
118+ " $packagePath /review/$packageName .rust.json"
144119}
145120
146- Push -Location $RepoRoot
121+ $originalLocation = Get -Location
147122try {
148- $localRegistryPath = Initialize-VendorDirectory
123+ Set-Location $RepoRoot
149124
150125 [array ]$packages = Get-PackagesToBuild
151-
152- Write-Host " Building packages in the following order:"
126+ $packageParams = @ ()
153127 foreach ($package in $packages ) {
154- $packageName = $package.name
155- $type = if ($package.OutputPackage ) { " output" } else { " dependency" }
156- Write-Host " $packageName ($type )"
128+ $packageParams += " --package" , $package.name
157129 }
158130
159- foreach ($package in $packages ) {
160- Write-Host " "
131+ if ($NoVerify ) {
132+ $packageParams += " --no-verify"
133+ }
161134
162- $packageName = $package.name
163- $packageVersion = $package.version
135+ Write-Host " > cargo publish --locked --dry-run --allow-dirty $ ( $packageParams -join ' ' ) "
136+ & cargo publish -- locked -- dry- run -- allow- dirty @packageParams 2>&1 | Tee-Object - Variable packResult
137+ if ($LASTEXITCODE ) {
138+ Write-Host " cargo publish failed with exit code $LASTEXITCODE "
139+ exit $LASTEXITCODE
140+ }
164141
165- $command = " cargo publish --locked --dry-run --package $packageName --registry crates-io --config `" source.crates-io.replace-with='local'`" --config `" source.local.directory='$localRegistryPath '`" --allow-dirty"
142+ if ($OutputPath -and $package.OutputPackage ) {
143+ $sourcePath = [System.IO.Path ]::Combine($RepoRoot , " target" , " package" , " $packageName -$packageVersion " )
144+ $targetPath = [System.IO.Path ]::Combine($OutputPath , $packageName )
145+ $targetContentsPath = [System.IO.Path ]::Combine($targetPath , " contents" )
146+ $targetApiReviewFile = [System.IO.Path ]::Combine($targetPath , " $packageName .rust.json" )
166147
167- if ($NoVerify ) {
168- $command += " --no-verify "
148+ if (Test-Path - Path $targetContentsPath ) {
149+ Remove-Item - Path $targetContentsPath - Recurse - Force
169150 }
170151
171- Invoke-LoggedCommand - Command $command - GroupOutput
152+ Write-Host " Copying package '$packageName ' to '$targetContentsPath '"
153+ New-Item - ItemType Directory - Path $targetContentsPath - Force | Out-Null
154+ Copy-Item - Path $sourcePath /* - Destination $targetContentsPath - Recurse - Exclude " Cargo.toml.orig"
172155
156+ Write-Host " Creating API review file"
157+ $apiReviewFile = Create- ApiViewFile $package
158+
159+ Write-Host " Copying API review file to '$targetApiReviewFile '"
160+ Copy-Item - Path $apiReviewFile - Destination $targetApiReviewFile - Force
161+ }
173162
174- # copy the package to the local registry
175- Add-CrateToLocalRegistry `
176- - LocalRegistryPath $localRegistryPath `
177- - Package $package
178-
179- if ($OutputPath -and $package.OutputPackage ) {
180- $sourcePath = " $RepoRoot /target/package/$packageName -$packageVersion "
181- $targetPath = " $OutputPath /$packageName "
182- $targetContentsPath = " $targetPath /contents"
183- $targetApiReviewFile = " $targetPath /$packageName .rust.json"
184-
185- if (Test-Path - Path $targetContentsPath ) {
186- Remove-Item - Path $targetContentsPath - Recurse - Force
163+ if ($OutBuildOrderFile ) {
164+ $buildOrder = @ ()
165+ foreach ($line in $packResult ) {
166+ if ($line -match ' ^\s*Packaging (\w*) ([\w\d\.-]*)' ) {
167+ $buildOrder += $matches [1 ]
187168 }
188-
189- Write-Host " Copying package '$packageName ' to '$targetContentsPath '"
190- New-Item - ItemType Directory - Path $targetContentsPath - Force | Out-Null
191- Copy-Item - Path $sourcePath /* - Destination $targetContentsPath - Recurse - Exclude " Cargo.toml.orig"
192-
193- Write-Host " Creating API review file"
194- $apiReviewFile = Create- ApiViewFile $package
195-
196- Write-Host " Copying API review file to '$targetApiReviewFile '"
197- Copy-Item - Path $apiReviewFile - Destination $targetApiReviewFile - Force
198169 }
199- }
200170
201- Write-Host " Removing local registry"
202- Remove-Item - Path $localRegistryPath - Recurse - Force | Out-Null
171+ Write-Host " Build Order: $ ( $buildOrder -join ' , ' ) "
172+ $buildOrder | ConvertTo-Json - Depth 100 | Set-Content $OutBuildOrderFile
173+ }
203174}
204175finally {
205- Pop -Location
176+ Set -Location $originalLocation
206177}
0 commit comments