Skip to content

Commit

Permalink
Only patch qt_prfxpath for non-relocatable builds of Qt
Browse files Browse the repository at this point in the history
  • Loading branch information
kevle committed Sep 16, 2024
1 parent 61a89d0 commit 28498fa
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions src/appimagetool/appdirtool.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ func AppDirDeploy(path string) {
qtVersionDetected = 4
}

qtPrefixPathRequiresPatch := true

if qtVersionDetected > 0 {
handleQt(appdir, qtVersionDetected)
qtPrefixPathRequiresPatch = handleQt(appdir, qtVersionDetected)
}

fmt.Println("")
Expand Down Expand Up @@ -314,7 +316,8 @@ func AppDirDeploy(path string) {
deployElf(lib, appdir, err)
patchRpathsInElf(appdir, libraryLocationsInAppDir, lib)

if strings.Contains(lib, fmt.Sprintf("libQt%dCore.so.%d", qtVersionDetected, qtVersionDetected)) {
if qtPrefixPathRequiresPatch &&
strings.Contains(lib, fmt.Sprintf("libQt%dCore.so.%d", qtVersionDetected, qtVersionDetected)) {
fmt.Println("Patching Qt prefix path in " + lib)
patchQtPrfxpath(appdir, lib, libraryLocationsInAppDir, ldLinux)
}
Expand Down Expand Up @@ -1252,7 +1255,9 @@ func getCopyrightFile(path string) (string, error) {
}

// Let's see in how many lines of code we can re-implement the guts of linuxdeployqt
func handleQt(appdir helpers.AppDir, qtVersion int) {
func handleQt(appdir helpers.AppDir, qtVersion int) bool {

qtPrefixPathRequiresPatch := true

if qtVersion >= 5 {

Expand All @@ -1265,7 +1270,7 @@ func handleQt(appdir helpers.AppDir, qtVersion int) {
os.Exit(1)
}

qtPrfxpath := getQtPrfxpath(library, qtVersion)
qtPrfxpath, qtPrefixPathRequiresPatch := getQtPrfxpath(library, qtVersion)

if qtPrfxpath == "" {
log.Println("Got empty qtPrfxpath, exiting")
Expand Down Expand Up @@ -1425,7 +1430,7 @@ func handleQt(appdir helpers.AppDir, qtVersion int) {
qmlImportScanners := helpers.FilesWithSuffixInDirectoryRecursive(qtPrfxpath, "qmlimportscanner")
if len(qmlImportScanners) < 1 {
log.Println("qmlimportscanner not found, skipping QML deployment") // TODO: Exit if we have qml files and qmlimportscanner is not there
return
return qtPrefixPathRequiresPatch
} else {
log.Println("Found qmlimportscanner:", qmlImportScanners[0])
}
Expand Down Expand Up @@ -1486,9 +1491,11 @@ func handleQt(appdir helpers.AppDir, qtVersion int) {
}
}
}

return qtPrefixPathRequiresPatch
}

func getQtPrfxpath(library string, qtVersion int) string {
func getQtPrfxpath(library string, qtVersion int) (string, bool) {
// Some notes on Qt behavior:
// https://doc.qt.io/qt-5/qt-conf.html
// https://doc.qt.io/qt-6/qt-conf.html
Expand All @@ -1510,16 +1517,6 @@ func getQtPrfxpath(library string, qtVersion int) string {

// TODO IDEA: Use AppRun to generate qt.conf at application start?

// If the user has set $QTDIR or $QT_ROOT_DIR, use that instead of the one from qt_prfxpath in the library
qtPrefixEnv := os.Getenv("QTDIR")
if qtPrefixEnv == "" {
qtPrefixEnv = os.Getenv("QT_ROOT_DIR")
}
if qtPrefixEnv != "" {
log.Println("Using QTDIR or QT_ROOT_DIR:", qtPrefixEnv)
return qtPrefixEnv
}

f, err := os.Open(library)
if err != nil {
helpers.PrintError(fmt.Sprintf("Could not open libQt%dCore.so.%d", qtVersion, qtVersion), err)
Expand All @@ -1537,10 +1534,12 @@ func getQtPrfxpath(library string, qtVersion int) string {
f.Seek(offset, 0)
length := ScanFile(f, search)

var qt_prfxpath = ""
qt_prfxpath := ""
qtPrefixPathRequiresPatch := true

// When length is 0, Qt has been built as relocatable
if length == 0 {
qtPrefixPathRequiresPatch = false
// Directory should be in ../Qt${qtVersion}
// TODO: Check if this is true for relocatable binaries in Qt5
qt_prfxpath = filepath.Dir(library) + fmt.Sprintf("/../Qt%d", qtVersion)
Expand All @@ -1560,11 +1559,20 @@ func getQtPrfxpath(library string, qtVersion int) string {
qt_prfxpath = strings.TrimSpace(string(buf))
log.Println("qt_prfxpath:", qt_prfxpath)
if qt_prfxpath == "" {
log.Println("Could not get qt_prfxpath")
return ""
log.Println("Could not get qt_prfxpath from", library)
}
}

// If the user has set $QTDIR or $QT_ROOT_DIR, use that instead of the one from qt_prfxpath in the library
qtPrefixEnv := os.Getenv("QTDIR")
if qtPrefixEnv == "" {
qtPrefixEnv = os.Getenv("QT_ROOT_DIR")
}
if qtPrefixEnv != "" {
log.Println("Using QTDIR or QT_ROOT_DIR:", qtPrefixEnv)
qt_prfxpath = qtPrefixEnv
}

// Special case:
// Some distributions, including Ubuntu and Alpine,
// have qt_prfxpath set to '/usr' but the files are actually in e.g., '/usr/lib/qt5'
Expand All @@ -1586,7 +1594,7 @@ func getQtPrfxpath(library string, qtVersion int) string {
}
}

return qt_prfxpath
return qt_prfxpath, qtPrefixPathRequiresPatch
}

// ScanFile returns the offset of the first occurrence of a []byte in a file from the current position,
Expand Down

0 comments on commit 28498fa

Please sign in to comment.