command: add platform property

This returns the value of the target OS that mpv was built on as
reported by the build system. It is quite conceivable that script
writers and API users would need to make OS-dependent choices in some
cases. Such people end up writing boilerplate/hacks to guess what OS
they are on. Assuming you trust the build system (if you don't, we're in
really deep trouble), then mpv actually knows exactly what OS it was
built on. Simply take this information at configuration time, make it a
define, and let mp_property_platform return the value.

Note that mpv has two build systems (waf and meson), so the names of the
detected OSes may not be exactly the same. Since meson is the newer
build system, the value of this property follows meson's naming
conventions*. In the waf build, there is a small function to map known
naming deviations to match meson (i.e. changing "win32" to "windows").
waf's documentation is a nightmare to follow, but it seems to simply
take the output of sys.platform in python and strip away any trailing
numbers if they exist (exception being win32 and os2)*.

*: https://mesonbuild.com/Reference-tables.html#operating-system-names
*: https://waf.io/apidocs/Utils.html#waflib.Utils.unversioned_sys_platform
This commit is contained in:
Dudemanguy 2022-01-22 23:06:26 -06:00
parent 8ea7aa5471
commit 80feac62f1
6 changed files with 28 additions and 1 deletions

View File

@ -57,6 +57,7 @@ Interface changes
- add `--tone-mapping-visualize`
- change type of `--brightness`, `--saturation`, `--contrast`, `--hue` and
`--gamma` to float.
- add `platform` property
--- mpv 0.35.0 ---
- add the `--vo=gpu-next` video output driver, as well as the options
`--allow-delayed-peak-detect`, `--builtin-scalers`,

View File

@ -3341,6 +3341,12 @@ Property list
somewhat weird form (apparently "hex BCD"), indicating the release version
of the libass library linked to mpv.
``platform``
Returns a string describing what target platform mpv was built for. The value
of this is dependent on what the underlying build system detects. Some of the
most common values are: ``windows``, ``darwin`` (macos or ios), ``linux``,
``android``, and ``freebsd``. Note that this is not a complete listing.
``options/<name>`` (RW)
The value of option ``--<name>``. Most options can be changed at runtime by
writing to this property. Note that many options require reloading the file

View File

@ -1652,6 +1652,7 @@ sys.stdout.write(features)
feature_str = run_command(python, '-c', feature_sort, feature_keys, check: true).stdout()
conf_data.set_quoted('FULLCONFIG', feature_str)
conf_data.set_quoted('MPV_CONFDIR', join_paths(get_option('prefix'), get_option('sysconfdir'), 'mpv'))
conf_data.set_quoted('PLATFORM', host_machine.system())
configure_file(output : 'config.h', configuration : conf_data)
message('List of enabled features: ' + feature_str)

View File

@ -3293,6 +3293,12 @@ static int mp_property_libass_version(void *ctx, struct m_property *prop,
return m_property_int64_ro(action, arg, ass_library_version());
}
static int mp_property_platform(void *ctx, struct m_property *prop,
int action, void *arg)
{
return m_property_strdup_ro(action, arg, PLATFORM);
}
static int mp_property_alias(void *ctx, struct m_property *prop,
int action, void *arg)
{
@ -3916,6 +3922,7 @@ static const struct m_property mp_properties_base[] = {
{"mpv-configuration", mp_property_configuration},
{"ffmpeg-version", mp_property_ffmpeg},
{"libass-version", mp_property_libass_version},
{"platform", mp_property_platform},
{"options", mp_property_options},
{"file-local-options", mp_property_local_options},

View File

@ -6,7 +6,7 @@ import os
__all__ = ["check_pthreads", "check_iconv", "check_lua",
"check_cocoa", "check_wl_protocols", "check_swift",
"check_egl_provider"]
"check_egl_provider", "check_platform"]
pthreads_program = load_fragment('pthreads.c')
@ -168,3 +168,13 @@ def check_egl_provider(minVersion=None, name='egl', check=None):
else:
return False
return fn
# Strictly for matching the platform names to what
# the meson build calls them.
def check_platform(ctx):
if ctx.env.DEST_OS == "win32":
return "windows"
elif ctx.dependency_satisfied("android"):
return "android"
else:
return ctx.env.DEST_OS

View File

@ -1054,6 +1054,8 @@ def configure(ctx):
ctx.parse_dependencies(video_output_features)
ctx.parse_dependencies(hwaccel_features)
ctx.define('PLATFORM', check_platform(ctx))
if ctx.options.SWIFT_FLAGS:
ctx.env.SWIFT_FLAGS.extend(split(ctx.options.SWIFT_FLAGS))