Skip to content

Commit 09dd375

Browse files
committed
fix: Fixed documentation resolving for PDF or HTML
1 parent a32a8fd commit 09dd375

File tree

2 files changed

+109
-43
lines changed

2 files changed

+109
-43
lines changed

Build-Installer.ps1

Lines changed: 104 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,45 @@ function GetConstraintFile() {
7272
return "espidf.constraints.v${ShortVersion}.txt"
7373
}
7474

75+
# Extract major and minor version from a version string and return as [System.Version] object
76+
# For example, "v5.0.1" returns [System.Version]"5.0", "v4.4.2-rc" returns [System.Version]"4.4"
77+
# Handles patch versions correctly by extracting only major.minor parts
78+
function GetVersionObject() {
79+
param (
80+
[Parameter(Mandatory)]
81+
[String]
82+
$VersionString
83+
)
84+
85+
# Remove 'v' prefix and any suffix after '-'
86+
$CleanVersion = $VersionString -replace "^v" -replace "-.*$"
87+
$SplitVersion = $CleanVersion -split "\."
88+
89+
# Get major and minor parts, default to 0 if missing
90+
$Major = if ($SplitVersion.Length -gt 0 -and $SplitVersion[0] -match '^\d+$') { [int]$SplitVersion[0] } else { 0 }
91+
$Minor = if ($SplitVersion.Length -gt 1 -and $SplitVersion[1] -match '^\d+$') { [int]$SplitVersion[1] } else { 0 }
92+
93+
return [System.Version]"${Major}.${Minor}"
94+
}
95+
96+
# Compare two version strings properly
97+
# Returns $true if Version1 >= Version2, $false otherwise
98+
function CompareVersions() {
99+
param (
100+
[Parameter(Mandatory)]
101+
[String]
102+
$Version1,
103+
[Parameter(Mandatory)]
104+
[String]
105+
$Version2
106+
)
107+
108+
$Ver1 = GetVersionObject -VersionString $Version1
109+
$Ver2 = GetVersionObject -VersionString $Version2
110+
111+
return $Ver1 -ge $Ver2
112+
}
113+
75114
function PrepareConstraints {
76115
$ConstraintFile = GetConstraintFile
77116
$ConstraintUrl = "https://dl.espressif.com/dl/esp-idf/$ConstraintFile"
@@ -177,20 +216,75 @@ function PrepareIdfPython {
177216
}
178217

179218
function PrepareIdfDocumentation {
180-
$DocumentationBasePath = ".\build\$InstallerType\docs"
181-
$DownloadedZipName = "esp-idf-en-$OfflineBranch.zip"
182-
$DownloadUrl = "https://docs.espressif.com/projects/esp-idf/en/$OfflineBranch/esp32/$DownloadedZipName"
219+
if (CompareVersions -Version1 $OfflineBranch -Version2 'v5.3') {
220+
$DocumentationBasePath = ".\build\$InstallerType\docs"
221+
$DownloadedZipName = "esp-idf-en-$OfflineBranch.zip"
222+
$DownloadUrl = "https://docs.espressif.com/projects/esp-idf/en/$OfflineBranch/esp32/$DownloadedZipName"
183223

184-
if (-Not(Test-Path -Path $DocumentationBasePath -PathType Container)) {
185-
New-Item -ItemType Directory -Path $DocumentationBasePath
186-
}
224+
if (-Not(Test-Path -Path $DocumentationBasePath -PathType Container)) {
225+
New-Item -ItemType Directory -Path $DocumentationBasePath
226+
}
227+
228+
$ZipFilePath = Join-Path -Path $DocumentationBasePath -ChildPath $DownloadedZipName
229+
# Download the ZIP file if it doesn't already exist
230+
if (-Not(Test-Path -Path $ZipFilePath -PathType Leaf)) {
231+
"Downloading: $DownloadUrl"
232+
try {
233+
$Request = Invoke-WebRequest $DownloadUrl -OutFile $ZipFilePath -MaximumRedirection 0
234+
[int]$StatusCode = $Request.StatusCode
235+
}
236+
catch {
237+
[int]$StatusCode = $_.Exception.Response.StatusCode
238+
}
239+
240+
241+
if ($StatusCode -eq 302) {
242+
FailBuild -Message "Failed to download documentation from $DownloadUrl. Status code: $StatusCode"
243+
}
244+
} else {
245+
"Documentation ZIP file already exists: $ZipFilePath"
246+
}
247+
248+
$ExtractedPath = Join-Path -Path $DocumentationBasePath -ChildPath "html"
249+
# Extract the ZIP file if not already extracted
250+
if (-Not(Test-Path -Path $ExtractedPath -PathType Container)) {
251+
"Extracting documentation to: $ExtractedPath"
252+
try {
253+
Expand-Archive -Path $ZipFilePath -DestinationPath $ExtractedPath
254+
} catch {
255+
FailBuild -Message "Failed to extract documentation ZIP file at $ZipFilePath. Error: $_"
256+
}
257+
} else {
258+
"Documentation already extracted to: $ExtractedPath"
259+
}
260+
261+
# Create a symbolic link to the HTML index
262+
$HtmlIndexPath = Join-Path -Path $ExtractedPath -ChildPath "index.html"
263+
if (-Not(Test-Path -Path $HtmlIndexPath -PathType Leaf)) {
264+
FailBuild -Message "Documentation HTML index not found in extracted documentation path: $ExtractedPath."
265+
}
266+
$SymLinkFilePath = ".\build\$InstallerType\IDFdocumentation.html"
267+
if (-Not(Test-Path -Path $SymLinkFilePath -PathType Leaf)) {
268+
"Creating symbolic link: $SymLinkFilePath -> $HtmlIndexPath"
269+
try {
270+
$AbsoluteHtmlIndexPath = Resolve-Path -Path $HtmlIndexPath -ErrorAction SilentlyContinue
271+
New-Item -ItemType SymbolicLink -Path $SymLinkFilePath -Value $AbsoluteHtmlIndexPath > $null
272+
} catch {
273+
"ERROR: Failed to create symbolic link at $SymLinkFilePath. Error: $_"
274+
}
275+
}
276+
} else { # ESP-IDF < v5.3 - documentation is in the PDF file
277+
$FullFilePath = ".\build\$InstallerType\IDFdocumentation.pdf"
278+
$DownloadUrl = "https://docs.espressif.com/projects/esp-idf/en/$OfflineBranch/esp32/esp-idf-en-$OfflineBranch-esp32.pdf"
279+
280+
if (Test-Path -Path $FullFilePath -PathType Leaf) {
281+
"$FullFilePath found."
282+
return
283+
}
187284

188-
$ZipFilePath = Join-Path -Path $DocumentationBasePath -ChildPath $DownloadedZipName
189-
# Download the ZIP file if it doesn't already exist
190-
if (-Not(Test-Path -Path $ZipFilePath -PathType Leaf)) {
191285
"Downloading: $DownloadUrl"
192286
try {
193-
$Request = Invoke-WebRequest $DownloadUrl -OutFile $ZipFilePath -MaximumRedirection 0
287+
$Request = Invoke-WebRequest $DownloadUrl -OutFile $FullFilePath -MaximumRedirection 0
194288
[int]$StatusCode = $Request.StatusCode
195289
}
196290
catch {
@@ -201,37 +295,6 @@ function PrepareIdfDocumentation {
201295
if ($StatusCode -eq 302) {
202296
FailBuild -Message "Failed to download documentation from $DownloadUrl. Status code: $StatusCode"
203297
}
204-
} else {
205-
"Documentation ZIP file already exists: $ZipFilePath"
206-
}
207-
208-
$ExtractedPath = Join-Path -Path $DocumentationBasePath -ChildPath "html"
209-
# Extract the ZIP file if not already extracted
210-
if (-Not(Test-Path -Path $ExtractedPath -PathType Container)) {
211-
"Extracting documentation to: $ExtractedPath"
212-
try {
213-
Expand-Archive -Path $ZipFilePath -DestinationPath $ExtractedPath
214-
} catch {
215-
FailBuild -Message "Failed to extract documentation ZIP file at $ZipFilePath. Error: $_"
216-
}
217-
} else {
218-
"Documentation already extracted to: $ExtractedPath"
219-
}
220-
221-
# Create a symbolic link to the HTML index
222-
$HtmlIndexPath = Join-Path -Path $ExtractedPath -ChildPath "index.html"
223-
if (-Not(Test-Path -Path $HtmlIndexPath -PathType Leaf)) {
224-
FailBuild -Message "Documentation HTML index not found in extracted documentation path: $ExtractedPath."
225-
}
226-
$SymLinkFilePath = ".\build\$InstallerType\IDFdocumentation.html"
227-
if (-Not(Test-Path -Path $SymLinkFilePath -PathType Leaf)) {
228-
"Creating symbolic link: $SymLinkFilePath -> $HtmlIndexPath"
229-
try {
230-
$AbsoluteHtmlIndexPath = Resolve-Path -Path $HtmlIndexPath -ErrorAction SilentlyContinue
231-
New-Item -ItemType SymbolicLink -Path $SymLinkFilePath -Value $AbsoluteHtmlIndexPath > $null
232-
} catch {
233-
"ERROR: Failed to create symbolic link at $SymLinkFilePath. Error: $_"
234-
}
235298
}
236299
}
237300

src/InnoSetup/IdfToolsSetup.iss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,11 @@ Source: "tools_fallback.json"; DestDir: "{app}"; DestName: "tools_fallback.json"
231231
Source: "..\Batch\idf_cmd_init.bat"; DestDir: "{app}";
232232
Source: "..\PowerShell\Initialize-Idf.ps1"; DestDir: "{app}";
233233
Source: "{#BUILD}\espidf.constraints.v*.txt"; DestDir: "{app}"; Flags: skipifsourcedoesntexist;
234+
234235
; IDF Documentation
235236
#if OFFLINE == 'yes'
236-
Source: "{#BUILD}\IDFdocumentation.html"; DestDir: "{app}";
237+
Source: "{#BUILD}\IDFdocumentation.html"; DestDir: "{app}"; Flags: skipifsourcedoesntexist;
238+
Source: "{#BUILD}\IDFdocumentation.pdf"; DestDir: "{app}"; Flags: skipifsourcedoesntexist;
237239
#endif
238240

239241
; createallsubdirs is necessary for git repo. Otherwise empty directories disappears
@@ -383,7 +385,8 @@ Filename: "cmd"; Parameters: "/c start https://docs.espressif.com/projects/esp-i
383385
#endif
384386

385387
#if OFFLINE == 'yes'
386-
Filename: "cmd"; Parameters: "/c start """" ""{app}\IDFdocumentation.html"""; Flags: nowait postinstall; Description: {cm:PointToDocumentation}; Check: IsInstallSuccess;
388+
Filename: "cmd"; Parameters: "/c start """" ""{app}\IDFdocumentation.html"""; Flags: nowait postinstall; Description: {cm:PointToDocumentation}; Check: IsInstallSuccess and FileExists(ExpandConstant('{app}\IDFdocumentation.html'));
389+
Filename: "cmd"; Parameters: "/c start """" ""{app}\IDFdocumentation.pdf"""; Flags: nowait postinstall; Description: {cm:PointToDocumentation}; Check: IsInstallSuccess and FileExists(ExpandConstant('{app}\IDFdocumentation.pdf'));
387390
#endif
388391

389392
; WD registration checkbox is identified by 'Windows Defender' substring anywhere in its caption, not by the position index in WizardForm.TasksList.Items

0 commit comments

Comments
 (0)