Skip to content

Commit 7a7376f

Browse files
committed
fix(doctor): use header check for bzip2 detection
Switch dependency check for bzip2 from pkg-config to header file verification, as libbz2 often lacks pkg-config support. Implement checkHeader to search for bzlib.h in common system paths.
1 parent e1b7f87 commit 7a7376f

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

internal/doctor/check.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func Check() *DoctorResult {
5252
result.Checks = append(result.Checks, checkPkgConfig("zlib", false))
5353
result.Checks = append(result.Checks, checkPkgConfig("libxml-2.0", false))
5454
result.Checks = append(result.Checks, checkPkgConfig("oniguruma", false))
55-
result.Checks = append(result.Checks, checkPkgConfig("libbz2", false))
55+
result.Checks = append(result.Checks, checkHeader("bzip2", "bzlib.h", false, getInstallHint("bz2")))
5656
result.Checks = append(result.Checks, checkPkgConfig("readline", false))
5757
result.Checks = append(result.Checks, checkPkgConfig("sqlite3", false))
5858

@@ -118,6 +118,33 @@ func checkPkgConfig(name string, required bool) CheckResult { //nolint:unparam /
118118
return result
119119
}
120120

121+
// checkHeader checks if a C header file is available.
122+
func checkHeader(name, header string, required bool, helpText string) CheckResult {
123+
result := CheckResult{
124+
Name: name + " (lib)",
125+
Required: required,
126+
HelpText: helpText,
127+
}
128+
129+
// Common include paths to check
130+
includePaths := []string{
131+
"/usr/include",
132+
"/usr/local/include",
133+
"/opt/homebrew/include",
134+
}
135+
136+
for _, path := range includePaths {
137+
headerPath := path + "/" + header
138+
if _, err := exec.Command("test", "-f", headerPath).CombinedOutput(); err == nil {
139+
result.Found = true
140+
result.Path = headerPath
141+
return result
142+
}
143+
}
144+
145+
return result
146+
}
147+
121148
// getCommandVersion tries to get the version of a command.
122149
func getCommandVersion(name string) string {
123150
versionFlags := []string{"--version", "-v", "-V", "version"}
@@ -323,7 +350,7 @@ func getPackageName(name, distro string) string {
323350
"libxml-2.0": "libxml2-dev",
324351
"readline": "libreadline-dev",
325352
"bz2": "libbz2-dev",
326-
"libbz2": "libbz2-dev",
353+
"bzip2": "libbz2-dev",
327354
"sqlite3": "libsqlite3-dev",
328355
"oniguruma": "libonig-dev",
329356
}
@@ -344,7 +371,7 @@ func getPackageName(name, distro string) string {
344371
"libxml-2.0": "libxml2-devel",
345372
"readline": "readline-devel",
346373
"bz2": "bzip2-devel",
347-
"libbz2": "bzip2-devel",
374+
"bzip2": "bzip2-devel",
348375
"sqlite3": "sqlite-devel",
349376
"oniguruma": "oniguruma-devel",
350377
}
@@ -365,7 +392,7 @@ func getPackageName(name, distro string) string {
365392
"libxml-2.0": "libxml2",
366393
"readline": "readline",
367394
"bz2": "bzip2",
368-
"libbz2": "bzip2",
395+
"bzip2": "bzip2",
369396
"sqlite3": "sqlite",
370397
"oniguruma": "oniguruma",
371398
}

0 commit comments

Comments
 (0)