OpenToonz - An open-source full-featured 2D animation creation software
C
Make Linux installs work without the launcher script
Chan84251b0e0beb
diff --git a/.github/workflows/workflow_linux.yml b/.github/workflows/workflow_linux.ymlindex 72abb5f54..79fce8665 100644--- a/.github/workflows/workflow_linux.yml+++ b/.github/workflows/workflow_linux.yml@@ -86,8 +86,11 @@ jobs:cp appdir/usr/share/icons/hicolor/*/apps/*.png appdirmkdir artifact- mv appdir/usr/share/opentoonz/stuff artifact/portablestuff- rmdir appdir/usr/share/opentoonz+ # Copy rather than move: the AppImage keeps its own+ # usr/share/opentoonz/stuff so it can seed a config when run on its+ # own, while the tarball still ships portablestuff next to it for+ # portable-mode testing.+ cp -r appdir/usr/share/opentoonz/stuff artifact/portablestuffwget -q -c 'https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage'wget -q -c 'https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage'@@ -120,6 +123,39 @@ jobs:mv artifact ${ARTIFACT_NAME}tar zcf ${ARTIFACT_NAME}.tar.gz ${ARTIFACT_NAME}+ - name: Smoke test the installed tree+ # Nothing else in CI runs a built binary. tconverter seeds before it+ # parses arguments, so a bare invocation does the work and exits 1.+ run: |+ set -eu+ export QT_QPA_PLATFORM=offscreen+ CONF=.config/OpenToonz++ # $ORIGIN RPATH resolves the bundled libraries without LD_LIBRARY_PATH+ ! ldd /opt/opentoonz/bin/tconverter | grep 'not found'++ # first run seeds the default root+ export HOME="$(mktemp -d)"+ timeout 120 /opt/opentoonz/bin/tconverter || true+ test -d "$HOME/$CONF/stuff/profiles"+ grep -q "^TOONZROOT=$HOME/$CONF/stuff$" "$HOME/$CONF/SystemVar.ini"++ # a root configured elsewhere is left alone, present or not+ export HOME="$(mktemp -d)"+ mkdir -p "$HOME/$CONF"+ printf '[General]\nTOONZROOT=/nonexistent/elsewhere\n' > "$HOME/$CONF/SystemVar.ini"+ timeout 120 /opt/opentoonz/bin/tconverter || true+ test ! -e "$HOME/$CONF/stuff"+ grep -q '^TOONZROOT=/nonexistent/elsewhere$' "$HOME/$CONF/SystemVar.ini"++ # an ini without a root gets one, and keeps its other keys (#7001)+ export HOME="$(mktemp -d)"+ mkdir -p "$HOME/$CONF"+ printf '[General]\nTOONZPROFILES=/keep/me\n' > "$HOME/$CONF/SystemVar.ini"+ timeout 120 /opt/opentoonz/bin/tconverter || true+ grep -q "^TOONZROOT=$HOME/$CONF/stuff$" "$HOME/$CONF/SystemVar.ini"+ grep -q '^TOONZPROFILES=/keep/me$' "$HOME/$CONF/SystemVar.ini"+- uses: actions/upload-artifact@v6with:name: Opentoonz-${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }}diff --git a/toonz/sources/CMakeLists.txt b/toonz/sources/CMakeLists.txtindex 2cf8bd87c..e5d26587d 100644--- a/toonz/sources/CMakeLists.txt+++ b/toonz/sources/CMakeLists.txt@@ -634,8 +634,7 @@ elseif(BUILD_ENV_APPLE)elseif(BUILD_ENV_UNIXLIKE)set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)- # Mirror relative bin/lib location for installation- # so the generated shell script works in both cases.+ # build tree mirrors the installed bin/lib layoutset(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/opentoonz)set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/opentoonz)set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)@@ -643,6 +642,11 @@ elseif(BUILD_ENV_UNIXLIKE)if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)set(CMAKE_INSTALL_PREFIX "/opt/opentoonz" CACHE PATH "OpenToonz install prefix" FORCE)endif()++ # $ORIGIN RPATH: bin/<exe> finds ../lib/opentoonz, libraries find+ # siblings. The build tree mirrors that layout, so no relink on install.+ set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib/opentoonz:$ORIGIN")+ set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)endif()if(BUILD_ENV_MSVC AND MSVC_VERSION EQUAL 1800)diff --git a/toonz/sources/common/tapptools/tenv.cpp b/toonz/sources/common/tapptools/tenv.cppindex 29b2e6ca4..87bc37a29 100644--- a/toonz/sources/common/tapptools/tenv.cpp+++ b/toonz/sources/common/tapptools/tenv.cpp@@ -4,10 +4,15 @@#include "tfilepath_io.h"#include "tversion.h"+#include <QCoreApplication>#include <QDir>+#include <QFile>+#include <QFileInfo>#include <QSettings>#include <QStandardPaths>+#include <iostream>+#ifdef LEVO_MACOSX#include "macofflinegl.h"@@ -70,30 +75,34 @@ public:return &_instance;}- TFilePath getSystemVarPath(std::string varName) {-#ifdef _WIN32- return m_registryRoot + varName;-#else- QString settingsPath;-+#ifndef _WIN32+ // Location of the ini file holding the system variables. Split out of+ // getSystemVarPath() so that first-run seeding writes the file where this+ // reads it, instead of duplicating the per-platform layout.+ QString getSystemVarFile() {#ifdef MACOSX- settingsPath = QString::fromStdString(getApplicationFileName()) +- QString(".app") +- QString("/Contents/Resources/SystemVar.ini");-#else-#ifdef HAIKU- settingsPath =- QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) +- "/SystemVar.ini";+ return QString::fromStdString(getApplicationFileName()) + QString(".app") ++ QString("/Contents/Resources/SystemVar.ini");+#elif defined(HAIKU)+ return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) ++ "/SystemVar.ini";#else /* Generic Unix */// TODO: use QStandardPaths::ConfigLocation when we drop Qt4- settingsPath = QDir::homePath();+ QString settingsPath = QDir::homePath();settingsPath.append("/.config/");settingsPath.append(getApplicationName().c_str());settingsPath.append("/SystemVar.ini");+ return settingsPath;#endif+ }#endif+ TFilePath getSystemVarPath(std::string varName) {+#ifdef _WIN32+ return m_registryRoot + varName;+#else+ QString settingsPath = getSystemVarFile();+QSettings settings(settingsPath, QSettings::IniFormat);QString qStr = QString::fromStdString(varName);QString systemVar = settings.value(qStr).toString();@@ -616,6 +625,103 @@ TFilePath TEnv::getConfigDir() {return configDir;}+#if !defined(_WIN32) && !defined(MACOSX)+namespace {++// TSystem::copyDir() ignores mkdir/copy failures, so recurse and report here.+bool copyDirOrFail(const QString &dst, const QString &src) {+ if (!QDir().mkpath(dst)) return false;++ const QFileInfoList entries = QDir(src).entryInfoList(+ QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);+ for (const QFileInfo &fi : entries) {+ const QString target = dst + "/" + fi.fileName();+ // copy symlinks as files: following them could recurse forever+ if (fi.isDir() && !fi.isSymLink()) {+ if (!copyDirOrFail(target, fi.filePath())) return false;+ } else if (!QFile::copy(fi.filePath(), target)) {+ return false;+ }+ }+ return true;+}++// installed layout: <prefix>/bin/<exe>, <prefix>/share/opentoonz/stuff+TFilePath getInstalledStuffDir() {+ TFilePath exeDir(QCoreApplication::applicationDirPath().toStdWString());+ return exeDir.getParentDir() + "share" + "opentoonz" + "stuff";+}++// Derived from the ini TEnv reads; not every platform uses ~/.config.+TFilePath getUserStuffDir(EnvGlobals *eg) {+ TFilePath systemVarFile(eg->getSystemVarFile().toStdWString());+ return systemVarFile.getParentDir() + "stuff";+}++bool seedStuffTreeIfMissing(const TFilePath &userStuffDir) {+ if (TFileStatus(userStuffDir).doesExist()) return true;++ TFilePath installedStuffDir = getInstalledStuffDir();+ if (!TFileStatus(installedStuffDir).isDirectory())+ return false; // build tree: nothing to copy from++ const QString userStuffDirStr = userStuffDir.getQString();+ const QString stagingDirStr = userStuffDirStr + ".incomplete";++ // Rename into place only after a complete copy, so a failed one leaves+ // nothing a later run would mistake for finished stuff.+ QDir(stagingDirStr).removeRecursively(); // leftovers from a failed attempt+ if (!copyDirOrFail(stagingDirStr, installedStuffDir.getQString()) ||+ !QDir().rename(stagingDirStr, userStuffDirStr)) {+ QDir(stagingDirStr).removeRecursively();+ std::cerr << "Failed to initialize " << userStuffDirStr.toStdString()+ << " from " << installedStuffDir.getQString().toStdString()+ << std::endl;+ return false;+ }++ // writable dirs the app expects, possibly absent from the packaged tree+ QDir().mkpath((userStuffDir + "projects" + "library").getQString());+ QDir().mkpath((userStuffDir + "projects" + "fxs").getQString());+ return true;+}++// Only the root is required; the rest falls back to <stuff>/<subdir>.+// setValue() merges, so an ini missing just the root keeps its other keys.+void writeRootVar(EnvGlobals *eg, const TFilePath &userStuffDir) {+ QSettings settings(eg->getSystemVarFile(), QSettings::IniFormat);+ settings.setValue(QString::fromStdString(eg->getRootVarName()),+ userStuffDir.getQString());+ settings.sync();+}++} // namespace+#endif++void TEnv::initUserStuffDir() {+#if !defined(_WIN32) && !defined(MACOSX)+ EnvGlobals *eg = EnvGlobals::instance();++ // portable builds carry their own stuff; nothing to seed+ if (eg->getIsPortable()) return;++ // respect an explicit -TOONZROOT command-line override+ if (eg->getArgPathValue(eg->getRootVarName()) != "") return;++ TFilePath userStuffDir = getUserStuffDir(eg);++ // Leave a root configured elsewhere alone even when it is gone: usually an+ // unmounted volume, and the ini is not rewritten either way. String compare,+ // so an equivalent spelling also counts as elsewhere.+ TFilePath configuredRoot = eg->getRootVarPath();+ if (!configuredRoot.isEmpty() && configuredRoot != userStuffDir) return;++ if (!QDir().mkpath(userStuffDir.getParentDir().getQString())) return;+ if (!seedStuffTreeIfMissing(userStuffDir)) return;+ if (configuredRoot.isEmpty()) writeRootVar(eg, userStuffDir);+#endif+}+/*TFilePath TEnv::getProfilesDir(){TFilePath fp(getStuffDir());diff --git a/toonz/sources/include/tenv.h b/toonz/sources/include/tenv.hindex a9130b5d7..6b4ec30e1 100644--- a/toonz/sources/include/tenv.h+++ b/toonz/sources/include/tenv.h@@ -137,6 +137,11 @@ DVAPI TFilePath getStuffDir();DVAPI TFilePath getConfigDir();// DVAPI TFilePath getProfilesDir();+// Linux/*BSD: seed the per-user stuff folder from the installed copy and+// point SystemVar.ini at it. Call after the Q*Application exists. No-op on+// Windows/macOS, in portable mode, with a custom root, or once seeded.+DVAPI void initUserStuffDir();+// per l'utilizzo di ToonzLib senza che sia definita una TOONZROOT// bisogna chiamare TEnv::setStuffDir(stuffdir) prima di ogni altra operazioneDVAPI void setStuffDir(const TFilePath &stuffDir);diff --git a/toonz/sources/tcleanupper/tcleanupper.cpp b/toonz/sources/tcleanupper/tcleanupper.cppindex 34d4a019b..f97202e2a 100644--- a/toonz/sources/tcleanupper/tcleanupper.cpp+++ b/toonz/sources/tcleanupper/tcleanupper.cpp@@ -498,6 +498,8 @@ int main(int argc, char *argv[]) {TEnv::setSystemVarPrefix(systemVarPrefix);TEnv::setApplicationFileName(argv[0]);+ TEnv::initUserStuffDir();+QCoreApplication::setOrganizationName("OpenToonz");QCoreApplication::setOrganizationDomain("");QCoreApplication::setApplicationName(diff --git a/toonz/sources/tcomposer/tcomposer.cpp b/toonz/sources/tcomposer/tcomposer.cppindex 785425faa..b9454b610 100644--- a/toonz/sources/tcomposer/tcomposer.cpp+++ b/toonz/sources/tcomposer/tcomposer.cpp@@ -695,6 +695,8 @@ int main(int argc, char *argv[]) {TEnv::setSystemVarPrefix(systemVarPrefix);TEnv::setApplicationFileName(argv[0]);+ TEnv::initUserStuffDir();+QCoreApplication::setOrganizationName("OpenToonz");QCoreApplication::setOrganizationDomain("");QCoreApplication::setApplicationName(diff --git a/toonz/sources/tconverter/tconverter.cpp b/toonz/sources/tconverter/tconverter.cppindex 696d113df..073d94952 100644--- a/toonz/sources/tconverter/tconverter.cpp+++ b/toonz/sources/tconverter/tconverter.cpp@@ -31,6 +31,8 @@#if defined(LINUX) || defined(FREEBSD)#include <QGuiApplication>+#elif !defined(_WIN32) && !defined(MACOSX)+#include <QCoreApplication>#endif// Add memory header for smart pointers@@ -457,12 +459,18 @@ void convert(const TFilePath &source, const TFilePath &dest,int main(int argc, char *argv[]) {#if defined(LINUX) || defined(FREEBSD)QGuiApplication app(argc, argv);+#elif !defined(_WIN32) && !defined(MACOSX)+ // initUserStuffDir() needs applicationDirPath(), so an instance must exist.+ // QCoreApplication needs no display, unlike QGuiApplication.+ QCoreApplication app(argc, argv);#endifTEnv::setRootVarName(rootVarName);TEnv::setSystemVarPrefix(systemVarPrefix);TEnv::setApplicationFileName(argv[0]);+ TEnv::initUserStuffDir();+std::string msg;// Initialize qualifiersdiff --git a/toonz/sources/toonz/CMakeLists.txt b/toonz/sources/toonz/CMakeLists.txtindex bd70d5672..f2858a2ab 100644--- a/toonz/sources/toonz/CMakeLists.txt+++ b/toonz/sources/toonz/CMakeLists.txt@@ -733,54 +733,8 @@ elseif(BUILD_ENV_UNIXLIKE AND NOT BUILD_TARGET_WIN)DESTINATION bin)- # Shell script that copies files to the home directory as needed- # and sets the library preload path.- file(WRITE ${CMAKE_BINARY_DIR}/bin/opentoonz-"#!/bin/sh-OPENTOONZ_BASE=\$(dirname \"\$0\")/..--if [ ! -d \$HOME/.config/OpenToonz ]; then- mkdir -p \$HOME/.config/OpenToonz-fi--if [ ! -d \$HOME/.config/OpenToonz/stuff ]; then- cp -r \$OPENTOONZ_BASE/share/opentoonz/stuff \$HOME/.config/OpenToonz-fi--if [ ! -d \$HOME/.config/OpenToonz/stuff/projects/library ]; then- mkdir -p \$HOME/.config/OpenToonz/stuff/projects/library-fi--if [ ! -d \$HOME/.config/OpenToonz/stuff/projects/fxs ]; then- mkdir -p \$HOME/.config/OpenToonz/stuff/projects/fxs-fi--if [ ! -e \$HOME/.config/OpenToonz/SystemVar.ini ]; then- cat << EOF > $HOME/.config/OpenToonz/SystemVar.ini-[General]-OPENTOONZROOT=\"\$HOME/.config/OpenToonz/stuff\"-OpenToonzPROFILES=\"\$HOME/.config/OpenToonz/stuff/profiles\"-TOONZCACHEROOT=\"\$HOME/.config/OpenToonz/stuff/cache\"-TOONZCONFIG=\"\$HOME/.config/OpenToonz/stuff/config\"-TOONZFXPRESETS=\"\$HOME/.config/OpenToonz/stuff/fxs\"-TOONZLIBRARY=\"\$HOME/.config/OpenToonz/stuff/library\"-TOONZPROFILES=\"\$HOME/.config/OpenToonz/stuff/profiles\"-TOONZPROJECTS=\"$HOME/.config/OpenToonz/stuff/projects\"-TOONZROOT=\"\$HOME/.config/OpenToonz/stuff\"-TOONZSTUDIOPALETTE=\"\$HOME/.config/OpenToonz/stuff/studiopalette\"-EOF-fi--export ${PRELOAD_VARIABLE}=\${OPENTOONZ_BASE}/lib/opentoonz:\${${PRELOAD_VARIABLE}}--exec \$OPENTOONZ_BASE/bin/OpenToonz \"\$@\"-")- # only needed for executing without installing- execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/bin/opentoonz)-install(PROGRAMS- ${CMAKE_BINARY_DIR}/bin/opentoonz"$<TARGET_FILE:tcleanup>""$<TARGET_FILE:tcomposer>""$<TARGET_FILE:tconverter>"@@ -789,6 +743,14 @@ exec \$OPENTOONZ_BASE/bin/OpenToonz \"\$@\"DESTINATION bin)+ # lowercase symlink so the .desktop file's Exec=opentoonz keeps working+ install(CODE "+ file(REMOVE \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin/opentoonz\")+ execute_process(COMMAND \"${CMAKE_COMMAND}\" -E create_symlink+ OpenToonz+ \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/bin/opentoonz\")+ ")+if(LZODRIVER_FOUND)install(PROGRAMSdiff --git a/toonz/sources/toonz/main.cpp b/toonz/sources/toonz/main.cppindex 2ab63bfa1..0cf23bb43 100644--- a/toonz/sources/toonz/main.cpp+++ b/toonz/sources/toonz/main.cpp@@ -176,6 +176,8 @@ static void initToonzEnv(QHash<QString, QString> &argPathValues) {Check if the xxxroot is defined and corresponds to an existing folder--*/+ TEnv::initUserStuffDir();+TFilePath stuffDir = TEnv::getStuffDir();if (stuffDir == TFilePath())fatalError("Undefined or empty: \"" + toQString(TEnv::getRootVarPath()) +