Skip to content

Commit

Permalink
Use org.flatpak.Builder (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonnyp authored Jul 7, 2024
1 parent 60cfdb3 commit 2d9b184
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install host dependencies
run: |
sudo apt-get update
sudo apt-get install flatpak flatpak-builder mutter
sudo apt-get install flatpak mutter
# Restore caches
- name: Restore Flatpak dependencies
Expand Down
5 changes: 1 addition & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,5 @@
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"vala.languageServerPath": "${workspaceFolder}/.flatpak/vala-language-server.sh",
"mesonbuild.configureOnOpen": false,
"mesonbuild.buildFolder": "_build",
"mesonbuild.mesonPath": "${workspaceFolder}/.flatpak/meson.sh"
"vala.languageServerPath": "${workspaceFolder}/.flatpak/vala-language-server.sh"
}
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ setup:
@echo "✅ You can use "make build" to build Workbench"

stable:
flatpak-builder --delete-build-dirs --disable-updates --build-only --ccache --force-clean flatpak build-aux/re.sonny.Workbench.json
flatpak run org.flatpak.Builder --delete-build-dirs --disable-updates --build-only --ccache --force-clean flatpak build-aux/re.sonny.Workbench.json

devel:
flatpak-builder --version
flatpak-builder --delete-build-dirs --disable-updates --build-only --ccache --force-clean flatpak build-aux/re.sonny.Workbench.Devel.json
flatpak run org.flatpak.Builder --delete-build-dirs --disable-updates --build-only --ccache --force-clean flatpak build-aux/re.sonny.Workbench.Devel.json

build: devel

Expand Down Expand Up @@ -72,12 +71,12 @@ sandbox: setup
flatpak run --command="bash" re.sonny.Workbench.Devel

flatpak:
flatpak run org.flatpak.Builder --ccache --force-clean flatpak build-aux/re.sonny.Workbench.Devel.json
flatpak run org.flatpak.Builder --ccache --force-clean flatpak build-aux/re.sonny.Workbench.Devel.json
# This is what Flathub does - consider moving to lint
flatpak run --env=G_DEBUG=fatal-criticals --command=appstream-util org.flatpak.Builder validate flatpak/files/share/appdata/re.sonny.Workbench.Devel.appdata.xml
flatpak run --command="desktop-file-validate" --filesystem=host:ro org.freedesktop.Sdk//23.08 flatpak/files/share/applications/re.sonny.Workbench.Devel.desktop
# appstreamcli validate --override=release-time-missing=info /path/to/your/app.metainfo.xml
flatpak run org.flatpak.Builder --run flatpak build-aux/re.sonny.Workbench.Devel.json bash
flatpak run org.flatpak.Builder --run flatpak build-aux/re.sonny.Workbench.Devel.json bash

# Sync with .gitignore
clean:
Expand Down
1 change: 1 addition & 0 deletions build-aux/re.sonny.Workbench.Devel.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://raw.githubusercontent.com/flatpak/flatpak-builder/main/data/flatpak-manifest.schema.json",
"id": "re.sonny.Workbench.Devel",
"runtime": "org.gnome.Sdk",
"runtime-version": "master",
Expand Down
1 change: 1 addition & 0 deletions build-aux/re.sonny.Workbench.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://raw.githubusercontent.com/flatpak/flatpak-builder/main/data/flatpak-manifest.schema.json",
"id": "re.sonny.Workbench",
"runtime": "org.gnome.Sdk",
"runtime-version": "46",
Expand Down
3 changes: 0 additions & 3 deletions src/Extensions/Extensions.blp
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,14 @@ Adw.Dialog dialog {

$Extension extension_rust {
title: _("Rust");
command: "flatpak install flathub org.freedesktop.Sdk.Extension.rust-stable//24.08 org.freedesktop.Sdk.Extension.llvm18//24.08";
}

$Extension extension_vala {
title: _("Vala");
command: "flatpak install flathub org.freedesktop.Sdk.Extension.vala//24.08";
}

$Extension extension_typescript {
title: _("TypeScript");
command: "flatpak install flathub org.freedesktop.Sdk.Extension.node20//24.08 org.freedesktop.Sdk.Extension.typescript//24.08";
}
}

Expand Down
21 changes: 16 additions & 5 deletions src/Extensions/Extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Interface from "./Extensions.blp" with { type: "uri" };
import illustration from "./extensions.svg";

import "./Extension.js";
import { getFlatpakInfo } from "../util.js";

export const action_extensions = new Gio.SimpleAction({
name: "extensions",
Expand All @@ -26,8 +27,13 @@ export function Extensions({ window }) {
picture_illustration.set_resource(illustration);

extension_rust.enabled = isRustEnabled();
extension_rust.command = `flatpak install flathub org.freedesktop.Sdk.Extension.rust-stable//${freedesktop_version} org.freedesktop.Sdk.Extension.${llvm}//${freedesktop_version}`;

extension_vala.enabled = isValaEnabled();
extension_vala.command = `flatpak install flathub org.freedesktop.Sdk.Extension.vala//${freedesktop_version}`;

extension_typescript.enabled = isTypeScriptEnabled();
extension_typescript.command = `flatpak install flathub org.freedesktop.Sdk.Extension.${node}//${freedesktop_version} org.freedesktop.Sdk.Extension.typescript//${freedesktop_version}`;

for (const extension of [
extension_rust,
Expand All @@ -47,25 +53,30 @@ export function Extensions({ window }) {
window.add_action(action_extensions);
}

let rust_enabled;
let rust_enabled = false;
export function isRustEnabled() {
rust_enabled ??=
Gio.File.new_for_path("/usr/lib/sdk/rust-stable").query_exists(null) &&
Gio.File.new_for_path("/usr/lib/sdk/llvm18").query_exists(null);
Gio.File.new_for_path(`/usr/lib/sdk/${llvm}`).query_exists(null);
return rust_enabled;
}

let vala_enabled;
let vala_enabled = false;
export function isValaEnabled() {
vala_enabled ??=
Gio.File.new_for_path("/usr/lib/sdk/vala").query_exists(null);
return vala_enabled;
}

let typescript_enabled;
let typescript_enabled = false;
export function isTypeScriptEnabled() {
typescript_enabled ??=
Gio.File.new_for_path("/usr/lib/sdk/typescript").query_exists(null) &&
Gio.File.new_for_path("/usr/lib/sdk/node20").query_exists(null);
Gio.File.new_for_path(`/usr/lib/sdk/${node}`).query_exists(null);
return typescript_enabled;
}

const llvm = "llvm18";
const node = "node20";
const runtime = getFlatpakInfo().get_string("Application", "runtime");
const freedesktop_version = runtime.endsWith("master") ? "24.08beta" : "23.08";
8 changes: 5 additions & 3 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ export function ensureDir(file) {
}
}

let flatpak_info;
export function getFlatpakInfo() {
const keyFile = new GLib.KeyFile();
if (flatpak_info) return flatpak_info;
flatpak_info = new GLib.KeyFile();
try {
keyFile.load_from_file("/.flatpak-info", GLib.KeyFileFlags.NONE);
flatpak_info.load_from_file("/.flatpak-info", GLib.KeyFileFlags.NONE);
} catch (err) {
if (!err.matches(GLib.FileError, GLib.FileError.NOENT)) {
console.error(err);
}
return null;
}
return keyFile;
return flatpak_info;
}

export { getLanguage };
Expand Down

0 comments on commit 2d9b184

Please sign in to comment.