This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathgenerateRepos.ps1
84 lines (71 loc) · 2.77 KB
/
generateRepos.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
[CmdletBinding()]
param(
$badParam,
[Parameter(Mandatory=$True)][string]$Distro,
[Parameter(Mandatory=$True)][string]$Version,
[Parameter(Mandatory=$True)][string[]]$Packages
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
# Powershell2-compatible way of forcing named-parameters
if ($badParam)
{
throw "Only named parameters are allowed"
}
try
{
function Remove-BomFromFile($OldPath, $NewPath)
{
$Content = Get-Content $OldPath -Raw
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines($NewPath, $Content, $Utf8NoBomEncoding)
}
# $scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
$rosdistroDir = Join-Path $Env:Temp $(New-Guid)
Set-Alias python (get-command 'python.exe').Path -Scope Script
Set-Alias git (get-command 'git.exe').Path -Scope Script
Set-Alias rosinstall_generator (get-command 'rosinstall_generator.exe').Path -Scope Script
# ensure the temp folder doesn't exist.
Remove-Item $rosdistroDir -Force -Recurse -ErrorAction SilentlyContinue
if (Test-Path $rosdistroDir -PathType Container) {
throw "Cannot remove $rosdistroDir"
}
git clone https://github.com/ros/rosdistro "$rosdistroDir"
git "--git-dir=${rosdistroDir}\.git" "--work-tree=${rosdistroDir}" checkout "$Version"
python (get-command 'rosdistro_build_cache').Path --ignore-local --debug "file://localhost/$rosdistroDir\index-v4.yaml" "$Distro"
$cacheFilePath = (Join-Path (Get-Location).Path "$Distro-cache.yaml.gz")
if (-Not (Test-Path $cacheFilePath -PathType Leaf)) {
throw "Cannot find $cacheFilePath"
}
$indexYaml = @"
%YAML 1.1
# ROS index file
# see REP 153: http://ros.org/reps/rep-0153.html
---
distributions:
${Distro}:
distribution: [${Distro}/distribution.yaml]
distribution_cache: file://localhost/${cacheFilePath}
distribution_status: active
distribution_type: ros1
python_version: 3
type: index
version: 4
"@
$indexYamlFile = (Join-Path $rosdistroDir "index-snapshot.yaml")
Out-File -filepath $indexYamlFile -inputobject $indexYaml -Encoding "utf8"
$Env:ROSDISTRO_INDEX_URL = "file://localhost/$indexYamlFile"
$generatedRepos = (Join-Path (Get-Location).Path "${Distro}.repos")
rosinstall_generator $Packages --rosdistro $Distro --upstream --deps --format repos | Out-File $generatedRepos -Encoding "utf8"
# ensure the temp folder to be cleaned up.
Remove-Item $rosdistroDir -Force -Recurse -ErrorAction SilentlyContinue
if (Test-Path $rosdistroDir -PathType Container) {
throw "Cannot remove $rosdistroDir"
}
Remove-BomFromFile -OldPath $generatedRepos -NewPath $generatedRepos
}
catch
{
Write-Warning "Failed to generate repos."
throw
}