Skip to content

Commit

Permalink
Install plugins with lpm inside meson (lite-xl#1951)
Browse files Browse the repository at this point in the history
* meson: install plugins with lpm

* meson: add cachedir as output

* build.sh: fix bash syntax error

* build.sh: only copy datadir when PGO is enabled

* build.sh: properly install files with meson install

* build.sh: install macOS bundle files with .app suffix

* ci: copy bundle and portable files correctly

* package-dmg: remove extraneous steps

* ci: fix wrong bundle path

* build.sh: force reconfigure bundle=false if bundle is not explicitly given

* build.sh: move wrong bundle=true assignment to the right place

* ci: remove -a flag from cp command

* ci: use xargs and find -print0 to omit spaces in find output

* ci: specify correct path to Info.plist

* ci: correctly run dmgbuild

* dmgbuild: get application path from command line

* ci: organize dmgbuild arguments

* ci: properly escape arguments

* ci: finally correctly specify yaml string

* ci: don't copy Info.plist again

* build.sh: don't install any plugins if -A is not specified

* build.sh: use the latest release from github
  • Loading branch information
takase1121 authored Nov 25, 2024
1 parent 7c5b631 commit 3fe6460
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 46 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
- name: Build & Package Mac (Bundle)
run: |
scripts/build.sh --addons --debug --forcefallback --reconfigure --bundle -b build
tar -C build -czvf lite-xl-${{ needs.version.outputs.ref }}-${{ matrix.config.arch }}-bundle.tar.gz lite-xl Info.plist
tar -C build -czvf lite-xl-${{ needs.version.outputs.ref }}-${{ matrix.config.arch }}-bundle.tar.gz "Lite XL.app"
- name: Build & Package Mac (Portable)
run: |
Expand Down Expand Up @@ -124,20 +124,24 @@ jobs:

- name: Create Universal Binaries
run: |
REF="lite-xl-${{ needs.version.outputs.ref }}"
for TYPE in bundle portable; do
mkdir -p lite-xl-${{ needs.version.outputs.ref }}-{x86_64,aarch64,universal}-darwin-$TYPE/lite-xl
tar -C lite-xl-${{ needs.version.outputs.ref }}-x86_64-darwin-$TYPE -zxvf lite-xl-${{ needs.version.outputs.ref }}-x86_64-darwin-$TYPE.tar.gz
tar -C lite-xl-${{ needs.version.outputs.ref }}-aarch64-darwin-$TYPE -zxvf lite-xl-${{ needs.version.outputs.ref }}-aarch64-darwin-$TYPE.tar.gz
cp -r lite-xl-${{ needs.version.outputs.ref }}-*-$TYPE/lite-xl/data lite-xl-${{ needs.version.outputs.ref }}-universal-darwin-$TYPE/lite-xl
lipo -create -output lite-xl-${{ needs.version.outputs.ref }}-universal-darwin-$TYPE/lite-xl/lite-xl lite-xl-${{ needs.version.outputs.ref }}-*-darwin-$TYPE/lite-xl/lite-xl
mkdir -p $REF-universal-darwin-$TYPE package-$TYPE/{x86_64,aarch64}
tar -C package-$TYPE/x86_64 -zxvf $REF-x86_64-darwin-$TYPE.tar.gz
tar -C package-$TYPE/aarch64 -zxvf $REF-aarch64-darwin-$TYPE.tar.gz
cp -a package-$TYPE/*/* $REF-universal-darwin-$TYPE
find package-$TYPE -type f -name lite-xl -perm +111 -print0 | \
xargs -0 lipo -create -output "$(find $REF-universal-darwin-$TYPE -type f -name lite-xl -perm +111)"
done
cp lite-xl-${{ needs.version.outputs.ref }}-x86_64-darwin-bundle/Info.plist lite-xl-${{ needs.version.outputs.ref }}-universal-darwin-bundle/Info.plist
- name: Package Darwin (Universal DMG Image)
run: scripts/package-dmg.sh lite-xl-${{ needs.version.outputs.ref }}-universal-darwin-bundle lite-xl-${{ needs.version.outputs.ref }}-universal-darwin
run: |
dmgbuild -s resources/macos/lite-xl-dmg.py \
-D "app_path=lite-xl-${{ needs.version.outputs.ref }}-universal-darwin-bundle/Lite XL.app" \
"Lite XL" "lite-xl-${{ needs.version.outputs.ref }}-universal-darwin.dmg"
- name: Package Darwin (Universal Portable)
run: cd lite-xl-${{ needs.version.outputs.ref }}-universal-darwin-portable && tar -zcvf ../lite-xl-${{ needs.version.outputs.ref }}-universal-darwin-portable.tar.gz *
run: tar -C lite-xl-${{ needs.version.outputs.ref }}-universal-darwin-portable -zcvf lite-xl-${{ needs.version.outputs.ref }}-universal-darwin-portable.tar.gz .

- name: Upload (Release)
uses: actions/upload-artifact@v4
Expand Down
20 changes: 20 additions & 0 deletions data/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
if get_option('bundle_plugins').length() > 0
lpm_exe = find_program('lpm')
plugin_bundle = custom_target(
'lpm_plugins',
input: 'meson.build',
output: [lpm_userdir, 'lpm_cache'],
command: [
lpm_exe,
'--datadir', meson.project_source_root() / 'data',
'--userdir', '@OUTPUT0@',
'--cachedir', '@OUTPUT1@',
'--assume-yes',
'install',
get_option('bundle_plugins'),
],
install: true,
install_dir: [lpm_install_dir, false],
build_by_default: true,
)
endif
7 changes: 7 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ if get_option('portable') or host_machine.system() == 'windows'
lite_bindir = '/'
lite_docdir = '/doc'
lite_datadir = '/data'
lpm_userdir = 'data'
lpm_install_dir = '/'
configure_file(
input: 'resources' / 'windows' / 'lite-xl.exe.manifest.in',
output: 'lite-xl.exe.manifest',
Expand All @@ -193,6 +195,8 @@ elif get_option('bundle') and host_machine.system() == 'darwin'
lite_bindir = 'Contents' / 'MacOS'
lite_docdir = 'Contents' / 'Resources'
lite_datadir = 'Contents' / 'Resources'
lpm_userdir = 'Resources'
lpm_install_dir = 'Contents'
conf_data.set(
'CURRENT_YEAR',
run_command('date', '+%Y', capture: true).stdout().strip()
Expand All @@ -210,6 +214,8 @@ else
lite_bindir = 'bin'
lite_docdir = get_option('datadir') / 'doc' / 'lite-xl'
lite_datadir = get_option('datadir') / 'lite-xl'
lpm_userdir = 'lite-xl'
lpm_install_dir = get_option('datadir')
if host_machine.system() == 'linux'
install_data('resources' / 'icons' / 'lite-xl.svg',
install_dir : get_option('datadir') / 'icons' / 'hicolor' / 'scalable' / 'apps'
Expand Down Expand Up @@ -241,4 +247,5 @@ configure_file(
if not get_option('source-only')
subdir('src')
subdir('scripts')
subdir('data')
endif
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ option('renderer', type : 'boolean', value : false, description: 'Use SDL render
option('dirmonitor_backend', type : 'combo', value : '', choices : ['', 'inotify', 'fsevents', 'kqueue', 'win32', 'dummy'], description: 'define what dirmonitor backend to use')
option('arch_tuple', type : 'string', value : '', description: 'Specify a custom architecture tuple')
option('use_system_lua', type : 'boolean', value : false, description: 'Prefer System Lua over a the meson wrap')
option('bundle_plugins', type : 'array', value : [], description: 'Plugins to bundle when building Lite XL')
2 changes: 1 addition & 1 deletion resources/macos/lite-xl-dmg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os.path

app_path = "Lite XL.app"
app_path = defines.get("app_path", "Lite XL.app")
app_name = os.path.basename(app_path)

# Image options
Expand Down
51 changes: 34 additions & 17 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ show_help() {
echo "-d --debug-build Builds a debug build."
echo "-p --prefix PREFIX Install directory prefix. Default: '/'."
echo "-B --bundle Create an App bundle (macOS only)"
echo "-A --addons Add in addons"
echo "-A --addons Install extra plugins."
echo " Default: If specified, install the welcome plugin."
echo " An comma-separated list can be specified after this flag"
echo " to specify a list of plugins to install."
echo " If this option is not specified, no extra plugins will be installed."
echo "-P --portable Create a portable binary package."
echo "-r --reconfigure Tries to reuse the meson build directory, if possible."
echo " Default: Deletes the build directory and recreates it."
Expand All @@ -42,20 +46,21 @@ main() {
local platform="$(get_platform_name)"
local arch="$(get_platform_arch)"
local build_dir
local plugins="welcome"
local plugins="-Dbundle_plugins="
local prefix=/
local addons
local build_type="release"
local force_fallback
local bundle
local portable
local bundle="-Dbundle=false"
local portable="-Dportable=false"
local pgo
local cross
local cross_platform
local cross_arch
local cross_file
local reconfigure
local lpm_path
local should_reconfigure
local destdir="lite-xl"

for i in "$@"; do
case $i in
Expand Down Expand Up @@ -90,14 +95,20 @@ main() {
shift
;;
-A|--addons)
addons="1"
if [[ -n $2 ]] && [[ $2 != -* ]]; then
plugins="-Dbundle_plugins=$2"
shift
else
plugins="-Dbundle_plugins=welcome"
fi
shift
;;
-B|--bundle)
if [[ "$platform" != "darwin" ]]; then
echo "Warning: ignoring --bundle option, works only under macOS."
else
bundle="-Dbundle=true"
destdir="Lite XL.app"
fi
shift
;;
Expand Down Expand Up @@ -138,7 +149,7 @@ main() {
exit 1
fi

if [[ $platform == "macos" && -n $bundle && -n $portable ]]; then
if [[ $platform == "macos" && $bundle == "-Dbundle=true" && $portable == "-Dportable=true" ]]; then
echo "Warning: \"bundle\" and \"portable\" specified; excluding portable package."
portable=""
fi
Expand Down Expand Up @@ -192,6 +203,17 @@ main() {
rm -rf "${build_dir}"
fi

if [[ -n "$plugins" ]] && [[ -z `command -v lpm` ]]; then
mkdir -p "${build_dir}"
lpm_path="$(pwd)/${build_dir}/lpm$(get_executable_extension)"
if [[ ! -e "$lpm_path" ]]; then
curl --insecure -L -o "$lpm_path" \
"https://github.com/lite-xl/lite-xl-plugin-manager/releases/download/${LPM_VERSION:-latest}/lpm.$(get_platform_tuple)$(get_executable_extension)"
chmod u+x "$lpm_path"
fi
export PATH="$(dirname "$lpm_path"):$PATH"
fi

CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS meson setup \
"${build_dir}" \
--buildtype "$build_type" \
Expand All @@ -201,27 +223,22 @@ main() {
$bundle \
$portable \
$pgo \
$plugins \
$reconfigure

meson compile -C "${build_dir}"

cp -r data "${build_dir}/src"

if [[ $pgo != "" ]]; then
cp -r data "${build_dir}/src"
"${build_dir}/src/lite-xl"
meson configure -Db_pgo=use "${build_dir}"
meson compile -C "${build_dir}"
rm -fr "${build_dir}/data"
fi

rm -fr $build_dir/src/lite-xl.*p $build_dir/src/*.o

if [[ $addons != "" ]]; then
[[ ! -e "$build_dir/lpm" ]] && curl --insecure -L "https://github.com/lite-xl/lite-xl-plugin-manager/releases/download/v1.2.9/lpm.$(get_platform_tuple)$(get_executable_extension)" -o "$build_dir/lpm$(get_executable_extension)" && chmod +x "$build_dir/lpm$(get_executable_extension)"
"$build_dir/lpm$(get_executable_extension)" install --datadir ${build_dir}/src/data --userdir ${build_dir}/src/data --arch $(get_platform_tuple) $plugins --assume-yes; "$build_dir/lpm$(get_executable_extension)" purge --datadir ${build_dir}/src/data --userdir ${build_dir}/src/data && chmod -R a+r ${build_dir}
rm -fr "${build_dir}/src/data"
fi

mv "${build_dir}/src" "${build_dir}/lite-xl"
meson install -C "${build_dir}" --destdir "$destdir" \
--skip-subprojects=freetype2,lua,pcre2,sdl2 --no-rebuild
}

main "$@"
18 changes: 0 additions & 18 deletions scripts/package-dmg.sh

This file was deleted.

0 comments on commit 3fe6460

Please sign in to comment.