Skip to content

Commit

Permalink
Introduce 'localbase' Meson option.
Browse files Browse the repository at this point in the history
Some Linux distributions as well as FreeBSD OS install 3rd party software into
a prefix that differs from "/usr". This change makes asgen work in such cases.

Sponsored by:	Serenity Cybersecurity, LLC
  • Loading branch information
arrowd committed May 6, 2024
1 parent 8a74be5 commit 6645648
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 24 deletions.
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ option('gir-dir',
value: '',
description: 'Override the directory where gir-to-d searches for GIR files.'
)
option('localbase', type : 'string', value : '/usr', description : 'Prefix under which all 3rd party software is installed')
6 changes: 5 additions & 1 deletion src/asgen/contentsstore.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import std.stdio;
import std.string;
import std.conv : to, octal;
import std.file : mkdirRecurse;
import std.path : buildPath;
import std.array : appender, join, split, empty;

import asgen.bindings.lmdb;
import asgen.config;
import asgen.defines : LOCALBASE;
import asgen.logging;

/**
Expand Down Expand Up @@ -239,7 +241,9 @@ public:
auto iconInfo = appender!(string[]);
auto localeInfo = appender!(string[]);
foreach (ref f; contents) {
if ((f.startsWith("/usr/share/icons/")) ||
if ((f.startsWith (buildPath (LOCALBASE, "share/icons/"))) ||
(f.startsWith (buildPath (LOCALBASE, "share/pixmaps/"))) ||
(f.startsWith ("/usr/share/icons/")) ||
(f.startsWith("/usr/share/pixmaps/"))) {
iconInfo ~= f;
continue;
Expand Down
7 changes: 4 additions & 3 deletions src/asgen/datainjectpkg.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import std.array : empty;
import std.path : buildPath, buildNormalizedPath, relativePath, baseName;

import asgen.backends.interfaces;
import asgen.defines : LOCALBASE;
import asgen.utils : GENERIC_BUFFER_SIZE, existsAndIsDir;
import asgen.logging;

Expand Down Expand Up @@ -142,7 +143,7 @@ public:
if (iconLocation.existsAndIsDir) {
foreach (iconFname; iconLocation.dirEntries("*.{svg,svgz,png}", SpanMode.breadth, true)) {
immutable iconBasePath = relativePath(iconFname, iconLocation);
_contents[buildPath("/usr/share/icons/hicolor", iconBasePath)] = iconFname;
_contents[buildPath (LOCALBASE, "share/icons/hicolor", iconBasePath)] = iconFname;
}
} else {
logInfo("No icons found in '%s' for injected metadata.", iconLocation);
Expand All @@ -152,7 +153,7 @@ public:
foreach (miFname; _dataLocation.dirEntries("*.xml", SpanMode.shallow, false)) {
immutable miBasename = miFname.baseName;
logDebug("Found injected metainfo [%s]: %s", "all", miBasename);
_contents[buildPath("/usr/share/metainfo", miBasename)] = miFname;
_contents[buildPath (LOCALBASE, "share/metainfo", miBasename)] = miFname;
}

if (!archDataLocation.existsAndIsDir)
Expand All @@ -161,7 +162,7 @@ public:
// load arch-specific override metainfo files
foreach (miFname; archDataLocation.dirEntries("*.xml", SpanMode.shallow, false)) {
immutable miBasename = miFname.baseName;
immutable fakePath = buildPath("/usr/share/metainfo", miBasename);
immutable fakePath = buildPath (LOCALBASE, "share/metainfo", miBasename);

if (fakePath in _contents)
logDebug ("Found injected metainfo [%s]: %s (replacing generic one)", arch, miBasename);
Expand Down
3 changes: 3 additions & 0 deletions src/asgen/defines.d.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ module asgen.defines;
// location of arch-indep data for asgen
public enum DATADIR = "@datadir@";

// prefix into which all 3rd party software is installed
public enum LOCALBASE = "@localbase@";

// current version of the tool
public enum ASGEN_VERSION = "@asgen_version@";

Expand Down
5 changes: 3 additions & 2 deletions src/asgen/engine.d
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ static import std.file;
import appstream.Component;

import asgen.config;
import asgen.defines : LOCALBASE;
import asgen.logging;
import asgen.extractor;
import asgen.datastore;
Expand Down Expand Up @@ -211,9 +212,9 @@ public:
{
auto contents = pkg.contents;
foreach (ref c; contents) {
if (c.startsWith("/usr/share/applications/"))
if (c.startsWith (buildPath (LOCALBASE, "share/applications/")))
return true;
if (c.startsWith("/usr/share/metainfo/"))
if (c.startsWith (buildPath (LOCALBASE, "share/metainfo/")))
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/asgen/extractor.d
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import glib.Bytes : Bytes;
import glib.c.types : GPtrArray;

import asgen.config : Config, DataType;
import asgen.defines : LOCALBASE;
import asgen.logging;
import asgen.hintregistry;
import asgen.result;
Expand Down Expand Up @@ -76,7 +77,7 @@ public:
modInj = modInjInfo;

compose = new Compose;
//compose.setPrefix ("/usr");
compose.setPrefix (LOCALBASE);
compose.setMediaResultDir(db.mediaExportPoolDir);
compose.setMediaBaseurl("");
compose.setCheckMetadataEarlyFunc(&checkMetadataIntermediate, cast(void*) this);
Expand Down
36 changes: 19 additions & 17 deletions src/asgen/iconhandler.d
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import ascompose.c.types : ImageFormat, ImageLoadFlags, ImageSaveFlags, IconStat
static import std.file;

import asgen.utils;
import asgen.defines : LOCALBASE;
import asgen.logging;
import asgen.result;
import asgen.backends.interfaces;
Expand Down Expand Up @@ -147,7 +148,7 @@ public:

this (const string name, Package pkg)
{
auto indexData = pkg.getFileData(buildPath("/usr/share/icons", name, "index.theme"));
auto indexData = pkg.getFileData (buildPath (LOCALBASE, "share/icons", name, "index.theme"));
this(name, indexData);
}

Expand Down Expand Up @@ -238,10 +239,11 @@ public:

string front () const @property
{
return "/usr/share/icons/%s/%s/%s.%s".format(theme.name,
theme.directories[idxThemeDir]["path"].get!(string),
iname,
extensions[idxExt]);
return buildPath (LOCALBASE,
"share/icons/%s/%s/%s.%s".format (theme.name,
theme.directories[idxThemeDir]["path"].get!(string),
iname,
extensions[idxExt]));
}

void popFront ()
Expand Down Expand Up @@ -357,7 +359,7 @@ public:
foreach (info; parallel(filesPkids.byKeyValue, 100)) {
immutable fname = info.key;
immutable pkgid = info.value;
if (fname.startsWith("/usr/share/pixmaps/")) {
if (fname.startsWith (buildPath (LOCALBASE, "share/pixmaps/"))) {
auto pkg = getPackage(pkgid);
if (pkg is null)
continue;
Expand All @@ -368,18 +370,18 @@ public:

// optimization: check if we actually have an interesting path before
// entering the foreach loop.
if (!fname.startsWith("/usr/share/icons/"))
if (!fname.startsWith (buildPath (LOCALBASE, "share/icons/")))
continue;

auto pkg = getPackage(filesPkids[fname]);
if (pkg is null)
continue;

foreach (name; themeNames) {
if (fname == "/usr/share/icons/%s/index.theme".format(name)) {
if (fname == buildPath (LOCALBASE, "share/icons/%s/index.theme".format (name))) {
synchronized (this)
tmpThemes[name] = new Theme(name, pkg);
} else if (fname.startsWith("/usr/share/icons/%s".format(name))) {
} else if (fname.startsWith (buildPath (LOCALBASE, "share/icons/%s".format (name)))) {
synchronized (this)
iconFiles[fname] = pkg;
}
Expand Down Expand Up @@ -477,14 +479,14 @@ public:
// this is "wrong", but we support it for compatibility reasons.
// However, we only ever use it to satisfy the 64x64px requirement
foreach (extension; possibleIconExts)
yield ("/usr/share/icons/%s%s".format(iconName, extension));
yield (buildPath (LOCALBASE, "share/icons/%s%s".format (iconName, extension)));

// check pixmaps directory for icons
// we only ever use the pixmap directory contents to satisfy the minimum 64x64px icon
// requirement. Otherwise we get weird upscaling to higher sizes or HiDPI sizes happening,
// as later code tries to downscale "bigger" sizes.
foreach (extension; possibleIconExts)
yield ("/usr/share/pixmaps/%s%s".format(iconName, extension));
yield (buildPath (LOCALBASE, "share/pixmaps/%s%s".format (iconName, extension)));
}
});

Expand Down Expand Up @@ -1013,9 +1015,9 @@ unittest {
auto theme = new Theme("hicolor", indexData);
foreach (fname; theme.matchingIconFilenames("accessories-calculator", ImageSize(48))) {
bool valid = false;
if (fname.startsWith("/usr/share/icons/hicolor/48x48/"))
if (fname.startsWith (buildPath (LOCALBASE, "share/icons/hicolor/48x48/")))
valid = true;
if (fname.startsWith("/usr/share/icons/hicolor/scalable/"))
if (fname.startsWith (buildPath (LOCALBASE, "share/icons/hicolor/scalable/")))
valid = true;
assert(valid);

Expand All @@ -1031,13 +1033,13 @@ unittest {
}

foreach (fname; theme.matchingIconFilenames("accessories-text-editor", ImageSize(192))) {
if (fname.startsWith("/usr/share/icons/hicolor/192x192/"))
if (fname.startsWith (buildPath (LOCALBASE, "share/icons/hicolor/192x192/")))
continue;
if (fname.startsWith("/usr/share/icons/hicolor/256x256/"))
if (fname.startsWith (buildPath (LOCALBASE, "share/icons/hicolor/256x256/")))
continue;
if (fname.startsWith("/usr/share/icons/hicolor/512x512/"))
if (fname.startsWith (buildPath (LOCALBASE, "share/icons/hicolor/512x512/")))
continue;
if (fname.startsWith("/usr/share/icons/hicolor/scalable/"))
if (fname.startsWith (buildPath (LOCALBASE, "share/icons/hicolor/scalable/")))
continue;
assert(0);
}
Expand Down
1 change: 1 addition & 0 deletions src/asgen/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

conf_data = configuration_data()
conf_data.set('datadir', join_paths(get_option('prefix'), get_option('datadir'), 'appstream'))
conf_data.set('localbase', get_option('localbase'))
conf_data.set('asgen_version', asgen_version)
conf_data.set('build_rpmmd', get_option('rpmmd')? 'true' : 'false')
configure_file(input : 'defines.d.in',
Expand Down

0 comments on commit 6645648

Please sign in to comment.