-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_project.ps1
More file actions
180 lines (149 loc) · 5.55 KB
/
Copy pathbuild_project.ps1
File metadata and controls
180 lines (149 loc) · 5.55 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
param(
[string]$MainRepoProject,
[string]$RedPitayaRepo,
[switch]$MirrorLocalProject
)
function Convert-WindowsPathToWsl {
param(
[Parameter(Mandatory = $true)]
[string]$WindowsPath
)
$normalized = $WindowsPath -replace "\\", "/"
if ($normalized -match "^([A-Za-z]):/(.*)$") {
$drive = $matches[1].ToLowerInvariant()
$rest = $matches[2]
return "/mnt/$drive/$rest"
}
throw "Unable to convert Windows path to a WSL path: $WindowsPath"
}
function Add-DirectoryToProcessPath {
param(
[Parameter(Mandatory = $true)]
[string]$Directory
)
$pathEntries = $env:Path -split ";"
if ($pathEntries -contains $Directory) {
return
}
$env:Path = "$Directory;$env:Path"
}
function Resolve-VivadoBinDirectory {
$vivadoCommand = Get-Command vivado -ErrorAction SilentlyContinue
if ($vivadoCommand) {
return Split-Path $vivadoCommand.Source -Parent
}
$candidateVivadoPaths = @(
"D:\Xilinx\Vivado\2020.1\bin\vivado.bat",
"D:\Xilinx\Vivado\2020.1\bin\vivado.exe",
"C:\Xilinx\Vivado\2020.1\bin\vivado.bat",
"C:\Xilinx\Vivado\2020.1\bin\vivado.exe"
)
foreach ($candidateVivadoPath in $candidateVivadoPaths) {
if (Test-Path $candidateVivadoPath) {
return Split-Path $candidateVivadoPath -Parent
}
}
return $null
}
function Invoke-RedPitayaMake {
param(
[Parameter(Mandatory = $true)]
[string]$WorkingDirectory,
[Parameter(Mandatory = $true)]
[string[]]$MakeArguments
)
$makeCommand = Get-Command make -ErrorAction SilentlyContinue
if ($makeCommand) {
Push-Location $WorkingDirectory
try {
& $makeCommand.Source @MakeArguments
}
finally {
Pop-Location
}
return
}
$mingwMakeCommand = Get-Command mingw32-make -ErrorAction SilentlyContinue
if ($mingwMakeCommand) {
Push-Location $WorkingDirectory
try {
& $mingwMakeCommand.Source @MakeArguments
}
finally {
Pop-Location
}
return
}
$knownMakePaths = @(
"C:\Program Files (x86)\GnuWin32\bin\make.exe",
"C:\Program Files\GnuWin32\bin\make.exe",
"$env:ProgramData\chocolatey\bin\make.exe",
"$env:USERPROFILE\scoop\apps\make\current\bin\make.exe",
"$env:USERPROFILE\scoop\shims\make.exe"
)
foreach ($knownMakePath in $knownMakePaths) {
if (Test-Path $knownMakePath) {
Push-Location $WorkingDirectory
try {
& $knownMakePath @MakeArguments
}
finally {
Pop-Location
}
return
}
}
$wslCommand = Get-Command wsl.exe -ErrorAction SilentlyContinue
if ($wslCommand) {
$wslDistros = & $wslCommand.Source -l -q 2>$null
if ($LASTEXITCODE -eq 0 -and $wslDistros) {
$wslWorkingDirectory = Convert-WindowsPathToWsl -WindowsPath $WorkingDirectory
$quotedArgs = ($MakeArguments | ForEach-Object { "'$_'" }) -join " "
& $wslCommand.Source bash -lc "cd '$wslWorkingDirectory' && make $quotedArgs"
return
}
}
throw "GNU make was not found. Install make on Windows, or configure WSL with a Linux distro and make installed, then rerun this script."
}
$RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).Path
$WorkspaceRoot = Split-Path $RepoRoot -Parent
if (-not $MainRepoProject) {
$MainRepoProject = Join-Path $RepoRoot "fpga\redpitaya_projects\daotweezer_v1"
}
if (-not $RedPitayaRepo) {
$RedPitayaRepo = Join-Path $WorkspaceRoot "RedPitaya-FPGA"
}
$ExternalProjectDir = Join-Path $RedPitayaRepo "prj\daotweezer_v1\project"
$RequiredProjectIpTcl = Join-Path $RedPitayaRepo "prj\daotweezer_v1\ip\systemZ10.tcl"
$RequiredProjectPsWrapper = Join-Path $RedPitayaRepo "prj\daotweezer_v1\rtl\red_pitaya_ps.sv"
$LocalMirrorDir = Join-Path $MainRepoProject "_generated_project"
if (-not (Test-Path $RedPitayaRepo)) {
throw "RedPitaya-FPGA repository was not found at $RedPitayaRepo"
}
if (-not (Test-Path $MainRepoProject)) {
throw "Main project source tree was not found at $MainRepoProject"
}
if (-not (Test-Path $RequiredProjectIpTcl)) {
throw "Required project IP TCL was not found at $RequiredProjectIpTcl. Run scripts\redpitaya\sync_to_redpitaya_build.ps1 before building."
}
if (-not (Test-Path $RequiredProjectPsWrapper)) {
throw "Required project RTL wrapper was not found at $RequiredProjectPsWrapper. Run scripts\redpitaya\sync_to_redpitaya_build.ps1 before building."
}
$vivadoBinDirectory = Resolve-VivadoBinDirectory
if (-not $vivadoBinDirectory) {
throw "Vivado was not found. Install Xilinx Vivado 2020.1 or add vivado.bat to PATH, then rerun this script."
}
Add-DirectoryToProcessPath -Directory $vivadoBinDirectory
Invoke-RedPitayaMake -WorkingDirectory $RedPitayaRepo -MakeArguments @("project", "PRJ=daotweezer_v1", "MODEL=Z10")
if (-not (Test-Path $ExternalProjectDir)) {
throw "Vivado project was not created at $ExternalProjectDir"
}
Write-Host "Vivado project is available at $ExternalProjectDir\redpitaya.xpr"
if ($MirrorLocalProject) {
if (Test-Path $LocalMirrorDir) {
Remove-Item -LiteralPath $LocalMirrorDir -Recurse -Force
}
New-Item -ItemType Directory -Path $LocalMirrorDir -Force | Out-Null
Get-ChildItem -Path $ExternalProjectDir -Force | Copy-Item -Destination $LocalMirrorDir -Recurse -Force
Write-Host "Mirrored generated Vivado project to $LocalMirrorDir"
}