1212$ErrorActionPreference = ' Stop'
1313
1414. (Join-Path $PSScriptRoot ' ..' ' common' ' scripts' ' common.ps1' )
15- . (Join-Path $EngCommonScriptsDir ' Helpers' ' CommandInvocation-Helpers.ps1' )
1615
1716if ($OutputPath ) {
1817 $OutputPath = New-Item - ItemType Directory - Path $OutputPath - Force | Select-Object - ExpandProperty FullName
@@ -168,61 +167,6 @@ function Add-PathVersions($packages) {
168167 }
169168}
170169
171- function Get-ApiMetadata ($package ) {
172- $packagePath = Split-Path - Path $package.manifest_path - Parent
173- $readmePath = Join-Path - Path $packagePath - ChildPath $package.readme
174- $jsonBody = [ordered ]@ {
175- ' name' = $package.name
176- ' vers' = $package.version
177- ' deps' = @ ()
178- ' features' = $package.features
179- ' authors' = $package.authors
180- ' description' = $package.description
181- ' documentation' = $package.documentation
182- ' homepage' = $package.homepage
183- ' readme' = if ($package.readme -and (Test-Path - Path $readmePath )) {
184- Get-Content - Path $readmePath - Raw
185- }
186- else {
187- $null
188- }
189- ' readme_file' = $package.readme
190- ' keywords' = $package.keywords
191- ' categories' = $package.categories
192- ' license' = $package.license
193- ' license_file' = $package.license_file
194- ' repository' = $package.repository
195- ' links' = $package.links
196- ' rust_version' = $package.rust_version
197- }
198-
199- foreach ($dependency in $package.dependencies ) {
200- $jsonBody.deps += @ {
201- ' name' = $dependency.name
202- ' version_req' = $dependency.req
203- ' features' = $dependency.features
204- ' optional' = $dependency.optional
205- ' default_features' = $dependency.default_features
206- ' target' = $dependency.target
207- ' kind' = $dependency.kind
208- ' explicit_name_in_toml' = $dependency.rename
209- }
210- }
211-
212- return $jsonBody
213- }
214-
215- function New-ApiPutFile ($crateMetadata , $CrateFilePath ) {
216- $metadataBytes = [Text.Encoding ]::Utf8.GetBytes($crateMetadata )
217- $metadataLengthBytes = [BitConverter ]::GetBytes([UInt32 ]$metadataBytes.Length )
218- $crateBytes = [IO.File ]::ReadAllBytes($CrateFilePath )
219- $crateLengthBytes = [BitConverter ]::GetBytes([UInt32 ]$crateBytes.Length )
220-
221- $bytes += $metadataLengthBytes + $metadataBytes + $crateLengthBytes + $crateBytes
222-
223- return $bytes
224- }
225-
226170Push-Location $RepoRoot
227171try {
228172 $localRegistryPath = Initialize-VendorDirectory
@@ -245,14 +189,7 @@ try {
245189
246190 Invoke-LoggedCommand `
247191 - GroupOutput `
248- - Command " cargo package --package $packageName --config `" source.crates-io.replace-with='local'`" --config `" source.local.directory='$localRegistryPath '`" --allow-dirty"
249-
250- $crateFile = " $RepoRoot /target/package/$packageName -$packageVersion .crate"
251-
252- if (-not (Test-Path - Path $crateFile )) {
253- Write-Error " Building the package '$packageName ' didn't produce a crate file in the expected location: '$crateFile '"
254- exit 1
255- }
192+ - Command " cargo publish --dry-run --package $packageName --registry crates-io --config `" source.crates-io.replace-with='local'`" --config `" source.local.directory='$localRegistryPath '`" --allow-dirty"
256193
257194 # copy the package to the local registry
258195 Add-CrateToLocalRegistry `
@@ -261,31 +198,15 @@ try {
261198
262199 if ($OutputPath -and $package.OutputPackage ) {
263200 $packageOutputPath = " $OutputPath /$packageName "
201+ $targetPackagePath = " $RepoRoot /target/package/$packageName -$packageVersion "
202+
264203 if (Test-Path - Path $packageOutputPath ) {
265204 Remove-Item - Path $packageOutputPath - Recurse - Force
266205 }
267206
268207 Write-Host " Copying package '$packageName ' to '$packageOutputPath '"
269-
270208 New-Item - ItemType Directory - Path $packageOutputPath - Force | Out-Null
271- Copy-Item - Path $crateFile - Destination $packageOutputPath
272- # Copy package's Cargo.toml to the output directory
273- Copy-Item - Path " $RepoRoot /target/package/$packageName -$packageVersion /Cargo.toml" - Destination $packageOutputPath
274- # Write package metadata to the output directory
275-
276- $metadataFile = " $packageOutputPath /cargo-metadata.json"
277- $uploadFile = " $packageOutputPath /cargo-put.bin"
278-
279- $crateMetadata = Get-ApiMetadata $package | ConvertTo-Json - Depth 10
280-
281- Write-Host " Writing crates.io request metadata to '$metadataFile '"
282- $crateMetadata | Out-File - FilePath " $metadataFile " - Encoding utf8
283-
284- $uploadBytes = New-ApiPutFile $crateMetadata $crateFile
285- Write-Host " Writing crates.io request bundle to '$uploadFile '"
286- [IO.File ]::WriteAllBytes($uploadFile , $uploadBytes )
287-
288- Get-ApiMetadata $package | ConvertTo-Json - Depth 100 | Out-File - FilePath " $packageOutputPath /cargo-metadata.json" - Encoding utf8
209+ Copy-Item - Path $targetPackagePath - Destination $packageOutputPath - Recurse - Exclude " Cargo.toml.orig"
289210 }
290211 }
291212
0 commit comments