[chrome-gnome-shell/wip/split-repos: 5/8] build: switch to meson and update readme
- From: Yuri Konotopov <ykonotopov src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chrome-gnome-shell/wip/split-repos: 5/8] build: switch to meson and update readme
- Date: Fri, 1 Jul 2022 21:27:13 +0000 (UTC)
commit 459400bc19e4ab88a5e34a5b5f879396fedc01f9
Author: Yuri Konotopov <ykonotopov gnome org>
Date: Thu Jun 23 12:43:28 2022 +0400
build: switch to meson and update readme
Fixes: https://gitlab.gnome.org/GNOME/chrome-gnome-shell/-/issues/35
.gitignore | 1 +
CMakeLists.txt | 305 --------------------------------------------------
README.md | 70 +++++++++---
contrib/cp.py | 50 +++++++++
contrib/merge_json.py | 43 +++++++
meson.build | 164 +++++++++++++++++++++++++++
meson_options.txt | 10 ++
7 files changed, 321 insertions(+), 322 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 2c97106..95cedbc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,3 +13,4 @@
# Our stuff
po/*.po~
*.pyc
+/builddir
diff --git a/README.md b/README.md
index 4fd48dd..9486438 100644
--- a/README.md
+++ b/README.md
@@ -1,22 +1,58 @@
-GNOME Shell integration for Chrome
-============================================
-[![Code
Health](https://landscape.io/github/nE0sIghT/chrome-gnome-shell-mirror/master/landscape.svg?style=flat)](https://landscape.io/github/nE0sIghT/chrome-gnome-shell-mirror/master)
+# GNOME Shell browser extension
+## Introduction
-Introduction
-------------
+This repository contains browser extension that provides integration with GNOME Shell and the corresponding
+extensions repository https://extensions.gnome.org/.
-This repository contains Browser extension for Google Chrome/Chromium, Firefox, Vivaldi, Opera (and other
-Browser Extension, Chrome Extension or WebExtensions capable browsers) and native host messaging connector
-that provides integration with GNOME Shell and the corresponding extensions repository
https://extensions.gnome.org/.
+This extension works in conjuction with [os-native
counterpart](https://gitlab.gnome.org/nE0sIghT/gnome-browser-connector).
-Requirements
-------------
- * GNOME Shell
- * Python 2.7+ or 3.x
- * PyGObject
- * Python Requests >= 2.4.2
+## Build
-Installation
-------------
+First you need to install build requirements:
+- meson
+- python3
+- gettext
+- p7zip
+- polib python module
-Recent installation instructions are [available in GNOME
wiki](https://wiki.gnome.org/Projects/GnomeShellIntegrationForChrome/Installation).
+Then invoke meson to build extension:
+```shell
+ meson setup build
+ cd build
+ meson compile
+```
+
+This will produce 2 zip files in `build` folder:
+- extension-chrome.zip
+- extension-firefox
+
+Those files can be uploaded to corresponding browser Addons website.
+There are also unpacked extensions available under `build/extension` folder that can be loaded in web
browsers for development purposes.
+
+## Translations
+
+This project uses [GNOME Translation Project](https://wiki.gnome.org/TranslationProject). Translation
statistics can be obtained on corresponding Damned Lies page.
+
+### Translation strings handling
+
+All user-visible web extension strings are maintained by developers in messages.json file at
`extension/extension/_locale/en/` folder. File format is described
[here](https://developer.chrome.com/extensions/i18n-messages).
+
+Gettext template located in `po/chrome-gnome-shell.pot` and auto generated using meson:
+
+```shell
+ meson -Dbuild_messages=true -Dbuild_extension=false builddir
+ cd builddir
+ meson compile
+```
+
+As result of those commands:
+1. New gettext template will be saved to `po/chrome-gnome-shell.pot` file.
+2. All `po/*.po` files will be updated by `msgmerge` using new gettext template.
+3. All extension locales (messages.json) will be generated from gettext po files.
+
+This process is fully compatible with Damned Lies.
+
+There is limited number of [supported
locales](https://developer.chrome.com/webstore/i18n?csw=1#localeTable).
+If you use an unsupported locale, Google Chrome will ignore it.
+
+To create a new translation you can use msginit command (or any po editor) and gettext template. Please
refer [Translation Project wiki page](https://wiki.gnome.org/TranslationProject) for further info about
optimal translation workflow.
diff --git a/contrib/cp.py b/contrib/cp.py
new file mode 100755
index 0000000..8de9ac8
--- /dev/null
+++ b/contrib/cp.py
@@ -0,0 +1,50 @@
+#!/usr/bin/python3
+
+import argparse
+import os
+import shutil
+import sys
+
+
+def main():
+ parser = argparse.ArgumentParser(os.path.basename(sys.argv[0]))
+ parser.add_argument(
+ "--ignore",
+ help="Ignore files when copying directory"
+ )
+ parser.add_argument(
+ "--rename",
+ help="Rename file"
+ )
+ parser.add_argument(
+ "src",
+ help="Source"
+ )
+ parser.add_argument(
+ "dest",
+ help="Destination"
+ )
+ args = parser.parse_args()
+
+ os.makedirs(args.dest, exist_ok=True)
+
+ if os.path.isdir(args.src):
+ shutil.copytree(
+ args.src,
+ args.dest,
+ ignore=shutil.ignore_patterns(args.ignore),
+ dirs_exist_ok=True
+ )
+ else:
+ shutil.copy(
+ args.src,
+ (
+ args.dest
+ if not args.rename
+ else os.path.join(args.dest, args.rename)
+ )
+ )
+
+
+if __name__ == '__main__':
+ main()
diff --git a/contrib/merge_json.py b/contrib/merge_json.py
new file mode 100755
index 0000000..870f07c
--- /dev/null
+++ b/contrib/merge_json.py
@@ -0,0 +1,43 @@
+#!/usr/bin/python3
+
+import argparse
+import json
+import os
+import sys
+
+
+def main():
+ parser = argparse.ArgumentParser(os.path.basename(sys.argv[0]))
+ parser.add_argument(
+ "--delete",
+ default='',
+ help="Remove keys from json, comma separated"
+ )
+ parser.add_argument(
+ "--output",
+ required=True,
+ help="Write output to file"
+ )
+ parser.add_argument(
+ "input",
+ nargs='+',
+ help="Chrome extension key"
+ )
+ args = parser.parse_args()
+
+ output = {}
+ for file in args.input:
+ with open(file, 'r') as fp:
+ data = json.load(fp)
+ for key in args.delete.split(','):
+ if key in data:
+ del data[key]
+
+ output = {**output, **data}
+
+ with open(args.output, 'w') as fp:
+ json.dump(output, fp, ensure_ascii=False, indent=2)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..a90c913
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,164 @@
+project('gnome-browser-extension',
+ license: 'GPL-3',
+ version : '10.1',
+ default_options: [
+ 'prefix=' + meson.current_build_dir(),
+ 'python.platlibdir=.',
+ 'python.purelibdir=.',
+ ]
+)
+
+# Constants
+CONTRIB_PATH = meson.global_source_root() / 'contrib'
+EXTENSION_PATH = meson.global_source_root() / 'extension'
+PO_PATH = meson.global_source_root() / 'po'
+
+EXTENSION_BUILD_DIR = meson.current_build_dir() / 'extension'
+CHROME_BUILD_DIR = EXTENSION_BUILD_DIR / 'chrome'
+FIREFOX_BUILD_DIR = EXTENSION_BUILD_DIR / 'firefox'
+
+# Copy helper
+cp = CONTRIB_PATH / 'cp.py'
+
+# Filter that excludes manifest templates
+extension_exclude = 'manifest*.json'
+
+# Build requirements
+msgmerge = find_program('msgmerge', required: get_option('build_messages'))
+sevenz = find_program('7z', required: get_option('build_source_package'))
+
+if get_option('build_messages')
+ py_modules = ['polib']
+else
+ py_modules = []
+endif
+
+py = import('python')
+py.find_installation('python3', required: true, modules: py_modules)
+
+# Chrome Store public extension key
+chrome_key =
'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlig8TAPPQZinMkJnptC0ldizx6fG9jSjZDJ9c8GuLcXeGRH+NMlQuPC9bR5IQlT7+4VY/1tm1+IZ4xvITx1wXCNTR+KXzZv3VNc2D+logehK7oIRTRj0fLhixrx4NLSNK7L7HgV2xcIoW6QV0jOdFcTPL0mWXodXSzZePrvXuflF7qpwNxLzYVi04Vh3xu2oR2Pc9SwfZ4SNbyCaunH/p8n5AYmDuogI2Ah++RZw0ctnqn7mmHrGXteBu/vkpcHZu3B3eW9PFSrv69rRs8duybYR9C91hJm6yzRqZqIpindIU3k2HnNWeCFWkRVpZPhaNVoxcBUO7wWUUwdIflW2JwIDAQAB'
+
+# Simple python helper that enumerates translations
+lang_glob = '''
+import glob
+import os
+
+os.chdir(os.path.join(os.getenv("MESON_SOURCE_ROOT"), "po"))
+print("\n".join([l.split('.')[0] for l in glob.glob("*.po")]), end='')
+'''
+
+if get_option('build_extension')
+ conf_data = configuration_data()
+ conf_data.set('PUBLIC_KEY', chrome_key)
+
+ # Prepare Chrome manifest
+ configure_file(
+ input: EXTENSION_PATH / 'manifest.json',
+ output: 'manifest-chrome.json',
+ configuration: conf_data,
+ format: 'cmake',
+ )
+
+ # Prepare Firefox manifest
+ configure_file(
+ input: [
+ EXTENSION_PATH / 'manifest.json',
+ EXTENSION_PATH / 'manifest.firefox.json',
+ ],
+ output: 'manifest-firefox.json',
+ command: [
+ CONTRIB_PATH / 'merge_json.py',
+ '--delete', 'key',
+ '--output', '@OUTPUT@',
+ '@INPUT@'
+ ],
+ )
+
+ # Build Chrome extension
+ run_command(
+ cp,
+ '--rename', 'manifest.json',
+ meson.current_build_dir() / 'manifest-chrome.json',
+ CHROME_BUILD_DIR,
+ check: true,
+ )
+ run_command(
+ cp,
+ '--ignore', extension_exclude,
+ EXTENSION_PATH,
+ CHROME_BUILD_DIR,
+ check: true,
+ )
+ custom_target('chrome-zip',
+ command: [
+ sevenz, 'a', '-tzip',
+ meson.current_build_dir() / 'extension-chrome.zip',
+ CHROME_BUILD_DIR / '*',
+ ],
+ output: 'extension-chrome.zip',
+ build_by_default: true,
+ )
+
+ # Build Firefox extension
+ run_command(
+ cp,
+ '--rename', 'manifest.json',
+ meson.current_build_dir() / 'manifest-firefox.json',
+ FIREFOX_BUILD_DIR,
+ check: true,
+ )
+ run_command(
+ cp,
+ '--ignore', extension_exclude,
+ EXTENSION_PATH,
+ FIREFOX_BUILD_DIR,
+ check: true,
+ )
+ custom_target('firefox-zip',
+ command: [
+ sevenz, 'a', '-tzip',
+ meson.current_build_dir() / 'extension-firefox.zip',
+ FIREFOX_BUILD_DIR / '*',
+ ],
+ output: 'extension-firefox.zip',
+ build_by_default: true,
+ )
+endif
+
+if get_option('build_messages')
+ messages_deps = []
+
+ # Update gettext's pot template from Chrome's messages.json
+ run_command(
+ meson.global_source_root() / 'contrib/chrome-messages2po.py',
+ '--email', get_option('gettext_report_email'),
+ '--reference-lang', 'en',
+ '--write-pot',
+ meson.global_source_root() / 'contrib/chrome-web-store/',
+ meson.global_source_root() / 'extension/_locales/',
+ meson.global_source_root() / 'po/',
+ check: true,
+ )
+
+ # Update *.po from generated template
+ langs = run_command('python3', '-c', lang_glob, check: true).stdout().split('\n')
+ foreach lang : langs
+ run_command(
+ msgmerge, '-q', '--update',
+ PO_PATH / lang + '.po',
+ PO_PATH / 'chrome-gnome-shell.pot',
+ check: true,
+ )
+ endforeach
+
+ # Regenerate extension locales
+ run_command(
+ CONTRIB_PATH / 'po2chrome-messages.py',
+ '--reference-lang', 'en',
+ CONTRIB_PATH / 'chrome-web-store/',
+ meson.global_source_root() / 'extension' / '_locales/',
+ PO_PATH,
+ check: true,
+ )
+endif
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..43ed6ae
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,10 @@
+option('build_extension', type: 'boolean', value: true, description: 'Build extension zip package')
+option('build_messages', type: 'boolean', value: false, description: 'Update translation strings')
+option('build_source_package', type: 'boolean', value: false, description: 'Build source package')
+
+option(
+ 'gettext_report_email',
+ type: 'string',
+ value: 'ykonotopov gnome org',
+ description : 'Report-Msgid-Bugs-To field value in pot file'
+)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]