[gtkmm-documentation/gtkmm-3-24] examples/book/buildapp: Replace shell script with Python script
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation/gtkmm-3-24] examples/book/buildapp: Replace shell script with Python script
- Date: Fri, 4 Oct 2019 11:53:15 +0000 (UTC)
commit 7b0552fc8866a79c97929e1836d9aa69f78d3c93
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Fri Oct 4 13:46:42 2019 +0200
examples/book/buildapp: Replace shell script with Python script
.../{exampleapp.desktop => exampleapp.desktop.in} | 0
examples/book/buildapp/step1/install-cmd.py | 57 ++++++++++++++++++++++
examples/book/buildapp/step1/install-cmd.sh | 28 -----------
examples/book/buildapp/step1/meson.build | 18 +++++--
examples/book/buildapp/step2/meson.build | 19 ++++++--
examples/book/buildapp/step3/meson.build | 19 ++++++--
examples/book/buildapp/step4/meson.build | 19 ++++++--
examples/book/buildapp/step5/meson.build | 24 ++++++---
examples/book/buildapp/step6/meson.build | 24 ++++++---
examples/book/buildapp/step7/meson.build | 24 ++++++---
examples/book/buildapp/step8/meson.build | 24 ++++++---
examples/book/buildapp/step9/meson.build | 24 ++++++---
12 files changed, 206 insertions(+), 74 deletions(-)
---
diff --git a/examples/book/buildapp/step1/exampleapp.desktop
b/examples/book/buildapp/step1/exampleapp.desktop.in
similarity index 100%
rename from examples/book/buildapp/step1/exampleapp.desktop
rename to examples/book/buildapp/step1/exampleapp.desktop.in
diff --git a/examples/book/buildapp/step1/install-cmd.py b/examples/book/buildapp/step1/install-cmd.py
new file mode 100755
index 0000000..3cb1872
--- /dev/null
+++ b/examples/book/buildapp/step1/install-cmd.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+
+# External command, intended to be called from
+# ninja install-desktop-file
+# and
+# ninja install-gschema-file
+
+import os
+import sys
+import shutil
+import subprocess
+
+# install-cmd.py desktop <program_name> <desktop_file> <icon_file>
+def desktop():
+ program_name = sys.argv[2]
+ desktop_file = sys.argv[3]
+ icon_file = sys.argv[4]
+
+ desktop_install_dir = os.path.expanduser(
+ os.path.join('~' , '.local', 'share', 'applications'))
+ icon_install_dir = os.path.expanduser(
+ os.path.join('~' , '.local', 'share', 'icons', 'hicolor', '48x48', 'apps'))
+
+ # Create the installation directories, if they do not exist.
+ os.makedirs(desktop_install_dir, exist_ok=True)
+ os.makedirs(icon_install_dir, exist_ok=True)
+
+ shutil.copy(desktop_file, os.path.join(desktop_install_dir, program_name + '.desktop'))
+ shutil.copy(icon_file, icon_install_dir)
+ return 0
+
+# install-cmd.py gschema <gschema_file>
+def gschema():
+ gschema_file = sys.argv[2]
+
+ # Don't do anything, if GSETTINGS_SCHEMA_DIR is not set,
+ # or if it is set to the current directory.
+ if 'GSETTINGS_SCHEMA_DIR' not in os.environ:
+ return 0
+ gschema_install_dir = os.environ['GSETTINGS_SCHEMA_DIR']
+ if not gschema_install_dir or gschema_install_dir == '.':
+ return 0
+
+ # Create the installation directory, if it does not exist.
+ os.makedirs(gschema_install_dir, exist_ok=True)
+
+ shutil.copy(gschema_file, gschema_install_dir)
+ return subprocess.run(['glib-compile-schemas', gschema_install_dir]).returncode
+
+# ----- Main -----
+subcommand = sys.argv[1]
+if subcommand == 'desktop':
+ sys.exit(desktop())
+if subcommand == 'gschema':
+ sys.exit(gschema())
+print(sys.argv[0], ': illegal subcommand,', subcommand)
+sys.exit(1)
diff --git a/examples/book/buildapp/step1/meson.build b/examples/book/buildapp/step1/meson.build
index cf9b034..4c7225d 100644
--- a/examples/book/buildapp/step1/meson.build
+++ b/examples/book/buildapp/step1/meson.build
@@ -20,12 +20,22 @@ executable(program_name,
dependencies: gtkmm_dep
)
-install_cmd = './install-cmd.sh'
+python3 = import('python').find_installation('python3')
+install_cmd = meson.current_source_dir() / 'install-cmd.py'
+
+conf_data = configuration_data()
+conf_data.set('bindir', meson.current_build_dir())
+desktop_file = configure_file(
+ input: 'exampleapp.desktop.in',
+ output: '@BASENAME@',
+ configuration: conf_data,
+)
run_target('install-desktop-file',
- command: [install_cmd, 'desktop',
+ command: [
+ python3, install_cmd, 'desktop',
program_name,
- 'exampleapp.desktop',
- 'exampleapp.png'
+ desktop_file,
+ meson.current_source_dir() / 'exampleapp.png',
]
)
diff --git a/examples/book/buildapp/step2/meson.build b/examples/book/buildapp/step2/meson.build
index 4597b08..698241c 100644
--- a/examples/book/buildapp/step2/meson.build
+++ b/examples/book/buildapp/step2/meson.build
@@ -24,12 +24,23 @@ executable(program_name,
dependencies: gtkmm_dep
)
-install_cmd = '../step1/install-cmd.sh'
+python3 = import('python').find_installation('python3')
+source_step1_dir = meson.current_source_dir() / '..' / 'step1'
+install_cmd = source_step1_dir / 'install-cmd.py'
+
+conf_data = configuration_data()
+conf_data.set('bindir', meson.current_build_dir())
+desktop_file = configure_file(
+ input: '..' / 'step1' / 'exampleapp.desktop.in',
+ output: '@BASENAME@',
+ configuration: conf_data,
+)
run_target('install-desktop-file',
- command: [install_cmd, 'desktop',
+ command: [
+ python3, install_cmd, 'desktop',
program_name,
- '../step1/exampleapp.desktop',
- '../step1/exampleapp.png'
+ desktop_file,
+ source_step1_dir / 'exampleapp.png',
]
)
diff --git a/examples/book/buildapp/step3/meson.build b/examples/book/buildapp/step3/meson.build
index 4597b08..698241c 100644
--- a/examples/book/buildapp/step3/meson.build
+++ b/examples/book/buildapp/step3/meson.build
@@ -24,12 +24,23 @@ executable(program_name,
dependencies: gtkmm_dep
)
-install_cmd = '../step1/install-cmd.sh'
+python3 = import('python').find_installation('python3')
+source_step1_dir = meson.current_source_dir() / '..' / 'step1'
+install_cmd = source_step1_dir / 'install-cmd.py'
+
+conf_data = configuration_data()
+conf_data.set('bindir', meson.current_build_dir())
+desktop_file = configure_file(
+ input: '..' / 'step1' / 'exampleapp.desktop.in',
+ output: '@BASENAME@',
+ configuration: conf_data,
+)
run_target('install-desktop-file',
- command: [install_cmd, 'desktop',
+ command: [
+ python3, install_cmd, 'desktop',
program_name,
- '../step1/exampleapp.desktop',
- '../step1/exampleapp.png'
+ desktop_file,
+ source_step1_dir / 'exampleapp.png',
]
)
diff --git a/examples/book/buildapp/step4/meson.build b/examples/book/buildapp/step4/meson.build
index 4597b08..698241c 100644
--- a/examples/book/buildapp/step4/meson.build
+++ b/examples/book/buildapp/step4/meson.build
@@ -24,12 +24,23 @@ executable(program_name,
dependencies: gtkmm_dep
)
-install_cmd = '../step1/install-cmd.sh'
+python3 = import('python').find_installation('python3')
+source_step1_dir = meson.current_source_dir() / '..' / 'step1'
+install_cmd = source_step1_dir / 'install-cmd.py'
+
+conf_data = configuration_data()
+conf_data.set('bindir', meson.current_build_dir())
+desktop_file = configure_file(
+ input: '..' / 'step1' / 'exampleapp.desktop.in',
+ output: '@BASENAME@',
+ configuration: conf_data,
+)
run_target('install-desktop-file',
- command: [install_cmd, 'desktop',
+ command: [
+ python3, install_cmd, 'desktop',
program_name,
- '../step1/exampleapp.desktop',
- '../step1/exampleapp.png'
+ desktop_file,
+ source_step1_dir / 'exampleapp.png',
]
)
diff --git a/examples/book/buildapp/step5/meson.build b/examples/book/buildapp/step5/meson.build
index 7fefc21..15414b1 100644
--- a/examples/book/buildapp/step5/meson.build
+++ b/examples/book/buildapp/step5/meson.build
@@ -27,18 +27,30 @@ executable(program_name,
dependencies: gtkmm_dep
)
-install_cmd = '../step1/install-cmd.sh'
+python3 = import('python').find_installation('python3')
+source_step1_dir = meson.current_source_dir() / '..' / 'step1'
+install_cmd = source_step1_dir / 'install-cmd.py'
+
+conf_data = configuration_data()
+conf_data.set('bindir', meson.current_build_dir())
+desktop_file = configure_file(
+ input: '..' / 'step1' / 'exampleapp.desktop.in',
+ output: '@BASENAME@',
+ configuration: conf_data,
+)
run_target('install-desktop-file',
- command: [install_cmd, 'desktop',
+ command: [
+ python3, install_cmd, 'desktop',
program_name,
- '../step1/exampleapp.desktop',
- '../step1/exampleapp.png'
+ desktop_file,
+ source_step1_dir / 'exampleapp.png',
]
)
run_target('install-gschema-file',
- command: [install_cmd, 'gschema',
- 'org.gtkmm.exampleapp.gschema.xml'
+ command: [
+ python3, install_cmd, 'gschema',
+ meson.current_source_dir() / 'org.gtkmm.exampleapp.gschema.xml',
]
)
diff --git a/examples/book/buildapp/step6/meson.build b/examples/book/buildapp/step6/meson.build
index 7fefc21..15414b1 100644
--- a/examples/book/buildapp/step6/meson.build
+++ b/examples/book/buildapp/step6/meson.build
@@ -27,18 +27,30 @@ executable(program_name,
dependencies: gtkmm_dep
)
-install_cmd = '../step1/install-cmd.sh'
+python3 = import('python').find_installation('python3')
+source_step1_dir = meson.current_source_dir() / '..' / 'step1'
+install_cmd = source_step1_dir / 'install-cmd.py'
+
+conf_data = configuration_data()
+conf_data.set('bindir', meson.current_build_dir())
+desktop_file = configure_file(
+ input: '..' / 'step1' / 'exampleapp.desktop.in',
+ output: '@BASENAME@',
+ configuration: conf_data,
+)
run_target('install-desktop-file',
- command: [install_cmd, 'desktop',
+ command: [
+ python3, install_cmd, 'desktop',
program_name,
- '../step1/exampleapp.desktop',
- '../step1/exampleapp.png'
+ desktop_file,
+ source_step1_dir / 'exampleapp.png',
]
)
run_target('install-gschema-file',
- command: [install_cmd, 'gschema',
- 'org.gtkmm.exampleapp.gschema.xml'
+ command: [
+ python3, install_cmd, 'gschema',
+ meson.current_source_dir() / 'org.gtkmm.exampleapp.gschema.xml',
]
)
diff --git a/examples/book/buildapp/step7/meson.build b/examples/book/buildapp/step7/meson.build
index 7fefc21..15414b1 100644
--- a/examples/book/buildapp/step7/meson.build
+++ b/examples/book/buildapp/step7/meson.build
@@ -27,18 +27,30 @@ executable(program_name,
dependencies: gtkmm_dep
)
-install_cmd = '../step1/install-cmd.sh'
+python3 = import('python').find_installation('python3')
+source_step1_dir = meson.current_source_dir() / '..' / 'step1'
+install_cmd = source_step1_dir / 'install-cmd.py'
+
+conf_data = configuration_data()
+conf_data.set('bindir', meson.current_build_dir())
+desktop_file = configure_file(
+ input: '..' / 'step1' / 'exampleapp.desktop.in',
+ output: '@BASENAME@',
+ configuration: conf_data,
+)
run_target('install-desktop-file',
- command: [install_cmd, 'desktop',
+ command: [
+ python3, install_cmd, 'desktop',
program_name,
- '../step1/exampleapp.desktop',
- '../step1/exampleapp.png'
+ desktop_file,
+ source_step1_dir / 'exampleapp.png',
]
)
run_target('install-gschema-file',
- command: [install_cmd, 'gschema',
- 'org.gtkmm.exampleapp.gschema.xml'
+ command: [
+ python3, install_cmd, 'gschema',
+ meson.current_source_dir() / 'org.gtkmm.exampleapp.gschema.xml',
]
)
diff --git a/examples/book/buildapp/step8/meson.build b/examples/book/buildapp/step8/meson.build
index 7fefc21..15414b1 100644
--- a/examples/book/buildapp/step8/meson.build
+++ b/examples/book/buildapp/step8/meson.build
@@ -27,18 +27,30 @@ executable(program_name,
dependencies: gtkmm_dep
)
-install_cmd = '../step1/install-cmd.sh'
+python3 = import('python').find_installation('python3')
+source_step1_dir = meson.current_source_dir() / '..' / 'step1'
+install_cmd = source_step1_dir / 'install-cmd.py'
+
+conf_data = configuration_data()
+conf_data.set('bindir', meson.current_build_dir())
+desktop_file = configure_file(
+ input: '..' / 'step1' / 'exampleapp.desktop.in',
+ output: '@BASENAME@',
+ configuration: conf_data,
+)
run_target('install-desktop-file',
- command: [install_cmd, 'desktop',
+ command: [
+ python3, install_cmd, 'desktop',
program_name,
- '../step1/exampleapp.desktop',
- '../step1/exampleapp.png'
+ desktop_file,
+ source_step1_dir / 'exampleapp.png',
]
)
run_target('install-gschema-file',
- command: [install_cmd, 'gschema',
- 'org.gtkmm.exampleapp.gschema.xml'
+ command: [
+ python3, install_cmd, 'gschema',
+ meson.current_source_dir() / 'org.gtkmm.exampleapp.gschema.xml',
]
)
diff --git a/examples/book/buildapp/step9/meson.build b/examples/book/buildapp/step9/meson.build
index 7fefc21..15414b1 100644
--- a/examples/book/buildapp/step9/meson.build
+++ b/examples/book/buildapp/step9/meson.build
@@ -27,18 +27,30 @@ executable(program_name,
dependencies: gtkmm_dep
)
-install_cmd = '../step1/install-cmd.sh'
+python3 = import('python').find_installation('python3')
+source_step1_dir = meson.current_source_dir() / '..' / 'step1'
+install_cmd = source_step1_dir / 'install-cmd.py'
+
+conf_data = configuration_data()
+conf_data.set('bindir', meson.current_build_dir())
+desktop_file = configure_file(
+ input: '..' / 'step1' / 'exampleapp.desktop.in',
+ output: '@BASENAME@',
+ configuration: conf_data,
+)
run_target('install-desktop-file',
- command: [install_cmd, 'desktop',
+ command: [
+ python3, install_cmd, 'desktop',
program_name,
- '../step1/exampleapp.desktop',
- '../step1/exampleapp.png'
+ desktop_file,
+ source_step1_dir / 'exampleapp.png',
]
)
run_target('install-gschema-file',
- command: [install_cmd, 'gschema',
- 'org.gtkmm.exampleapp.gschema.xml'
+ command: [
+ python3, install_cmd, 'gschema',
+ meson.current_source_dir() / 'org.gtkmm.exampleapp.gschema.xml',
]
)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]