feat: install a Flatpak's data under /app/share
A program packaged as a Flatpak could only have its files beside it in files/bin, where cfg.files goes. One that finds its data at <its directory>/../share/<name>, as Crafter.Review finds its process/ directory, had no way to get it there: files/share belongs to the writer, which removes anything it did not put there, and a module of flatpak-builder's would have placed it only in the installed app, never under -r. cfg.flatpak.share lists files and directories of the project and the path under /app/share each goes to. The writer copies them into files/share with the desktop entry, metainfo and icons, keeps them while they are listed and removes them once they are not, as it does those. -r runs the program from files/bin, so the same ../share lookup finds them there. What is exported of them is flatpak build-finish's to decide, by its own rules, as for any app's files: the app's D-Bus services, MIME types, search providers and KRunner plugins, which have no field of their own, are placed like any other file. A library's are not passed on to the programs built on it, since data a library needs at run time already goes through cfg.files. A dependency that packages its own executable has the sources rebased by the loader, as its cfg.files are. Share entries change files/share and not what is compiled, so they are not keyed into VariantId, which its test checks. Every file bound for files/share, the desktop entry, metainfo and icons included, now goes through one placement check, which refuses two files for one path, a field's file among them, and a file where another needs a directory, naming both. A target that is absolute or leaves share/ is refused too. Any other place is open to a share entry, a second desktop entry, an add-on's metainfo and any icon included, as for any app's files: flatpak build-export refuses an exported icon that is not a square image and a D-Bus service that is not a key file, warns of the app's own desktop entry where desktop-file-validate rejects it or its Icon= is not the app's, and exports a second desktop entry, a MIME package or metainfo as it is. The app's own desktop entry, applications/<app-id>.desktop, is held to cfg.flatpak.desktopFile's checks whichever placed it: its Icon= and desktop-file-validate are keyed to that place now, not to the field. A source directory that holds what the build writes is refused as well, since it would be copied into itself, growing each time the app is built or exported: files/, and the app's directory, where install and bundle put another copy of files/ and the exported app, compared as written and where links lead, so that the project's own directory is refused where its bin/ is a link elsewhere too. So is one that lies in them, the build's own output, which the next build, install or bundle writes again. The loader leaves an empty source empty, as it does an empty desktop file. FlatpakShareLarge holds the writer to comparing an entry with its copy at constant memory, which the program's data, gigabytes of it in a game, needs on every build: it rewrites a files/ holding a 32 MiB entry, with nothing changed, in a child process whose address space may grow by 16 MiB, with a stand-in llvm-readelf, since the real one, which a write starts for the libraries, would not fit under that limit, and a change in the entry's last byte, in the short block a comparison reads last, is still copied.
This commit is contained in:
parent
52a767fadc
commit
e0ac8ee600
17 changed files with 557 additions and 20 deletions
|
|
@ -24,6 +24,16 @@ export namespace Crafter {
|
|||
Sdk,
|
||||
};
|
||||
|
||||
// A file or directory of the project installed under /app/share.
|
||||
struct FlatpakShareEntry {
|
||||
// A file, or a directory: every regular file in it, at its path
|
||||
// inside it, leaving out empty directories and links to directories.
|
||||
fs::path source;
|
||||
// Where under /app/share, relative to it: "crafter-review/process",
|
||||
// "licenses/net.example.App/LICENSE".
|
||||
fs::path target;
|
||||
};
|
||||
|
||||
// What an executable packaged as a Flatpak is installed as. Read for an
|
||||
// executable whose Configuration::packaging makes it one, except
|
||||
// `permissions`, which every configuration may declare: a library's
|
||||
|
|
@ -44,13 +54,34 @@ export namespace Crafter {
|
|||
// not know. The build itself does not read them.
|
||||
std::vector<std::string> permissions;
|
||||
// A desktop entry, installed as <appId>.desktop. Its Icon= has to be
|
||||
// the app-id. Empty: none, and the app gets no menu entry.
|
||||
// the app-id, and desktop-file-validate, where there is one, has to
|
||||
// pass it, as one a share entry places under that name has to. Empty:
|
||||
// the app has none but what a share entry places.
|
||||
fs::path desktopFile;
|
||||
// AppStream metadata, installed as <appId>.metainfo.xml.
|
||||
fs::path metainfo;
|
||||
// The app's icons, each installed under the app-id: an .svg as
|
||||
// scalable, a .png at its own size, which has to be square.
|
||||
std::vector<fs::path> icons;
|
||||
// Files the program reads that belong in /app/share rather than next
|
||||
// to it, where cfg.files goes: data a program finds at <its
|
||||
// directory>/../share/<name>, licences. They are copied into
|
||||
// files/share, kept there as long as they are listed, and gone from
|
||||
// it once they are not; files/share is the writer's, and anything
|
||||
// else in it is removed. -r runs the program from files/bin, so the
|
||||
// same ../share lookup finds them there. Any file may be one, a
|
||||
// second desktop entry or an add-on's metainfo among them: flatpak
|
||||
// build-finish exports what it exports of them by its own rules, as
|
||||
// for any app's, and build-export refuses an icon that is not a
|
||||
// square image or a D-Bus service that is not a key file, and warns
|
||||
// of the app's own desktop entry where desktop-file-validate rejects
|
||||
// it. None may go where another file goes, a field's included, and a
|
||||
// directory may neither hold what the build writes, which it would
|
||||
// copy into itself, nor lie in it, the build's own output: files/,
|
||||
// and the app's directory, FlatpakAppDir(), where install and bundle
|
||||
// put another copy of files/ and the exported app, however their
|
||||
// links lead.
|
||||
std::vector<FlatpakShareEntry> share;
|
||||
// flatpak-builder module files, in Flatpak's own format (JSON or
|
||||
// YAML), for what the app needs in /app besides the program: a
|
||||
// runtime it starts, a tool it runs, data built from source. With
|
||||
|
|
@ -83,6 +114,10 @@ export namespace Crafter {
|
|||
fs::path desktopFile;
|
||||
fs::path metainfo;
|
||||
std::vector<fs::path> icons;
|
||||
std::vector<FlatpakShareEntry> share;
|
||||
// FlatpakAppDir(): build-dir/files there is files/ again once install
|
||||
// or bundle has run, so no share entry may copy from it.
|
||||
fs::path appDir;
|
||||
// Where the toolchain's clang++ and llvm-readelf are: clang names the
|
||||
// LLVM runtime libraries the program links, readelf what it needs.
|
||||
fs::path clangxx;
|
||||
|
|
@ -100,14 +135,15 @@ export namespace Crafter {
|
|||
};
|
||||
// Lays out what becomes /app around the program Build() linked into
|
||||
// files/bin: files/share with the desktop file, metainfo and icons under
|
||||
// the app-id, and files/lib with the shared libraries the program needs
|
||||
// that the runtime does not have. Those are the LLVM runtime libraries
|
||||
// the toolchain links into every program, and whatever else of its
|
||||
// NEEDED entries, and theirs, `libraryDirs` holds; a name found in
|
||||
// neither is the runtime's. That is the files/ of a Flatpak build
|
||||
// directory; its metadata and export/ are flatpak build-finish's to
|
||||
// write, which decides what the sandbox's permissions mean and what the
|
||||
// host sees of the app.
|
||||
// the app-id and the `share` entries at the paths they name, and
|
||||
// files/lib with the shared libraries the program needs that the
|
||||
// runtime does not have. Those are the LLVM runtime libraries the
|
||||
// toolchain links into every program, and whatever else of its NEEDED
|
||||
// entries, and theirs, `libraryDirs` holds; a name found in neither is
|
||||
// the runtime's. That is the files/ of a Flatpak build directory; its
|
||||
// metadata and export/ are flatpak build-finish's to write, which
|
||||
// decides what the sandbox's permissions mean and what the host sees of
|
||||
// the app.
|
||||
//
|
||||
// The writer owns files/lib and files/share outright, and changes a file
|
||||
// only when what it would write differs, so a build that changed nothing
|
||||
|
|
|
|||
Loading…
Reference in a new issue