Commit Graph

27 Commits

Author SHA1 Message Date
Eli Schwartz 680b5ff819
treewide: add future annotations import 2023-02-01 17:01:30 -05:00
Eli Schwartz 34da721ec2
gettext: explicitly pass source root / subdir as cli args
Because this is a wrapper script and we could/should do this, we even
have half the infra for it.
2022-05-29 18:23:03 -04:00
Eli Schwartz 768616b0f8
scripts: accept the path of the gettext commands to run as an argument
Don't assume itstool, msgfmt et al. are just magically on the path.
Normally for commands being processed in build.ninja we'd look up the
program in order to run it. Offer the same guarantee for programs being
passed through an awkward script wrapper.
2022-03-06 10:48:34 -05:00
Eli Schwartz 487d45c1e5
i18n: use real build/install targets for gmo files
Don't just create a .PHONY target which runs a script that magically
generates files ninja doesn't know about. It results in untracked files,
and `meson install` has to run additional commands instead of copying
over files, and then cannot track them to uninstall them later.

I'm not even really sure why it was originally done via a proxy script,
most likely bad legacy design. This is after all one of the oldest
modules...

One side effect of this is that meson doesn't know how to rename
build.CustomTarget files on install (only data files are supported?),
and every file needs to be installed as "domainname.mo" so it must be
named that in-tree too. To prevent clashes, every locale gets its own
locale-specific subdirectory.

Once we are doing that anyway, we can output them to the actual
structure required by the gettext family of functions, and
bindtextdomain() can therefore point to this location if desired. This
might be useful for running localized programs from the build tree.
2021-08-09 18:25:17 -04:00
Daniel Mensinger 3e396b3782
fix: Always explicitly set encoding for text files (fixes #8263) 2021-06-29 11:28:08 +02:00
Eli Schwartz 6a0fabc647
mass rewrite of string formatting to use f-strings everywhere
performed by running "pyupgrade --py36-plus" and committing the results
2021-03-04 17:16:11 -05:00
Daan De Meyer afb5184ec9 Respect MESON_INSTALL_QUIET in gettext.py
Fixes #8068.
2020-12-10 00:29:40 +02:00
Daniel Mensinger a4f4379c44
typing: fully annotate scripts 2020-09-08 20:15:56 +02:00
Eli Schwartz 86b47250c6 simplify shutil usage by invoking copy2 where appropriate
It's equivalent to copyfile + copystat with the same arguments.
2020-08-20 23:47:54 +03:00
Eli Schwartz 4f9ecbee09 gettext: prefer POTFILES.in if it exists
If POTFILES.in exists, then it will have come from autotools, in which
case it is explicitly the file passed to xgettext -f, and the POTFILES
file itself is generated by autotools as a proxy file which eventually
gets inlined into the final Makefile as a variable "POTFILES = ......"

In this case, attempting to use POTFILES as the input file will simply
result in syntax errors and the inability to find files with a literal
trailing " \" in the name. Usually POTFILES will not exist at all, and
we would fallback on POTFILES.in, but if the source tree happens to be
dirty, this would result in errors. Since it's never going to be right
to use it, we can just do the right thing from the start and carry on.
2019-03-28 23:22:23 +02:00
Philip Chimento d9efee01d0 gettext: Install .mo files atomically
Without this, building a module in a Flatpak app manifest that is a
newer version of a module already present in the Flatpak runtime will
fail. (The Flatpak file system is a bunch of hard links to readonly
files, which can be replaced but not written to.)

This instead creates a temporary file in the same directory as the
destination (to avoid cross-device renaming errors) and atomically
renames the temporary file to the destination, replacing it instead of
rewriting it as shutil.copyfile() would do.
2018-06-07 00:18:21 +03:00
Aleksey Filippov 2cf85ae16f Use os.path: basename() and dirname() instead of split()
According to Python documentation[1] dirname and basename
are defined as follows:
    os.path.dirname() = os.path.split()[0]
    os.path.basename() = os.path.split()[1]
For the purpose of better readability split() is replaced
by appropriate function if only one part of returned tuple
is used.

[1]: https://docs.python.org/3/library/os.path.html#os.path.split
2018-01-30 07:08:22 +11:00
Corentin Noël 93d2ced31f Create the .po file with the `update_po` subcommand if it doesn't exist 2017-10-07 18:03:22 +03:00
Rene Lopez 94f46447bb Allow empty extra arguments in gettext script 2017-06-03 21:31:27 +03:00
Peter Hutterer 6a4efe8a82 Drop terminating fullstop from "Installing blah to blah" messages
Grammatically, this full stop isn't needed and with file names it has a
potential to be confusing:
    Installing /foo/bar/filename.1 to /foo/bar/dirname.

The full stop caused me to do a double-take more than once, so let's drop it.
2017-04-19 16:11:37 +03:00
Igor Gnatenko ef3cc6b3fa style: fix E127 violations
E127: continuation line over-indented for visual indent

Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2017-01-02 19:16:56 +01:00
Thibault Saunier 5b5edd6b33 gettext: Respect the --subdir argument before the MESON_SUBDIR var
In the case of subproject we will properly setup the --subdir argument
but the MESON_SUBDIR is never adapted and will point to an empty string
leading to the following backtrace when building `gst-build`:

  msgfmt: error while opening "/home/thiblahute/devel/gstreamer/gst-build/af.po" for reading: No such file or directory
  Traceback (most recent call last):
    File "/home/thiblahute/devel/gstreamer/gst-build/meson/meson.py", line 37, in <module>
      sys.exit(main())
    File "/home/thiblahute/devel/gstreamer/gst-build/meson/meson.py", line 34, in main
      return mesonmain.run(launcher, sys.argv[1:])
    File "/home/thiblahute/devel/gstreamer/gst-build/meson/mesonbuild/mesonmain.py", line 248, in run
      sys.exit(run_script_command(args[1:]))
    File "/home/thiblahute/devel/gstreamer/gst-build/meson/mesonbuild/mesonmain.py", line 236, in run_script_command
      return cmdfunc(cmdargs)
    File "/home/thiblahute/devel/gstreamer/gst-build/meson/mesonbuild/scripts/gettext.py", line 111, in run
      if gen_gmo(src_sub, bld_sub, langs) != 0:
    File "/home/thiblahute/devel/gstreamer/gst-build/meson/mesonbuild/scripts/gettext.py", line 66, in gen_gmo
      '-o', os.path.join(bld_sub, l + '.gmo')])
    File "/usr/lib/python3.5/subprocess.py", line 581, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['msgfmt', '/home/thiblahute/devel/gstreamer/gst-build/af.po', '-o', '/home/thiblahute/devel/gstreamer/gst-build/build/af.gmo']' returned non-zero exit status 1
  Failed to run install script: /usr/bin/python3 /home/thiblahute/devel/gstreamer/gst-build/meson/meson.py --internal gettext install --subdir=subprojects/gstreamer/po --localedir=share/locale --pkgname=gstreamer-1.0 --langs=af@@az@@be@@bg@@ca@@cs@@da@@de@@el@@en_GB@@eo@@es@@eu@@fi@@fr@@gl@@hr@@hu@@id@@it@@ja@@lt@@nb@@nl@@pl@@pt_BR@@ro@@ru@@rw@@sk@@sl@@sq@@sr@@sv@@tr@@uk@@vi@@zh_CN@@zh_TW
  FAILED: install
  '/usr/bin/python3' '/home/thiblahute/devel/gstreamer/gst-build/meson/meson.py' '--internal' 'install' '/home/thiblahute/devel/gstreamer/gst-build/build/meson-private/install.dat'
2016-12-17 14:21:27 +02:00
Nirbheek Chauhan b9a7c0cf39 misc: Use relative imports everywhere
Using 'mesonbuild' as the module can cause it to use the
system-installed module and can also break if we rename the directory,
so avoid that by always using relative imports.
2016-12-07 00:24:17 +05:30
Patrick Griffis 155617e539 i18n: Improve language handling
- Fix LINGUAS changes not being picked up
- Fix multiple langs per line in LINGUAS
- Make empty languages acceptable

Fixes #1127
2016-12-06 20:29:20 +02:00
Patrick Griffis 314eb5110e gettext: Use argparse to handle arguments 2016-11-02 13:54:57 -07:00
Patrick Griffis 423c8dbb40 gettext: Add update-po target
For each project this creates a <project>-update-po target.
When ran this updates the pot file and then merges it back
into the po files in the source directory with `msgmerge`
for project maintainers and translators.

Fixes #819
2016-10-23 08:46:48 -07:00
Patrick Griffis f30be6fb92 gettext: Add ability to set GETTEXTDATADIRS
Some projects use this to allow using local its files
2016-10-16 17:54:16 +03:00
Jussi Pakkanen 1f4cce86ad Remove shebangs on files that are not runnable and add execute bits to those that are. 2016-10-07 21:10:33 +03:00
Tim-Philipp Müller 5ebc77f722 i18n: use POTFILES.in as fallback if there's no POTFILES in po dir
In autotools POTFILES is generated at configure time from POTFILES.in,
but Meson only looks for a po/POTFILES in the source directory, which
is awkward when trying to maintain both build systems in parallel.
Instead just use POTFILES.in as fallback if it exists but POTFILES
does not. Also print an error if neither exists.

Fixes #818
2016-09-25 20:06:02 +01:00
Nirbheek Chauhan b2fb4f9d66 scripts: Use destdir_join fix for all DESTDIR prefixing (#598) 2016-06-16 20:43:23 +03:00
Jussi Pakkanen 3b3c05f6b1 Can pass extra args to xgettext. Closes #554. 2016-05-26 01:09:37 +03:00
Jussi Pakkanen dc148e0702 Remove all special casing for gettext and use elementary operations instead. 2016-05-21 18:21:23 +03:00