From 80feac62f175173d7a4a002450482e4be6a02a83 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Sat, 22 Jan 2022 23:06:26 -0600 Subject: [PATCH] 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 --- DOCS/interface-changes.rst | 1 + DOCS/man/input.rst | 6 ++++++ meson.build | 1 + player/command.c | 7 +++++++ waftools/checks/custom.py | 12 +++++++++++- wscript | 2 ++ 6 files changed, 28 insertions(+), 1 deletion(-) diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst index bff74cd16c..785a39b1e7 100644 --- a/DOCS/interface-changes.rst +++ b/DOCS/interface-changes.rst @@ -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`, diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index ea305af615..4f9e68d567 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -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/`` (RW) The value of option ``--``. Most options can be changed at runtime by writing to this property. Note that many options require reloading the file diff --git a/meson.build b/meson.build index 527ac58bb1..8f90aa9137 100644 --- a/meson.build +++ b/meson.build @@ -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) diff --git a/player/command.c b/player/command.c index 2ad83cb703..a284a4c047 100644 --- a/player/command.c +++ b/player/command.c @@ -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}, diff --git a/waftools/checks/custom.py b/waftools/checks/custom.py index 79bfcf2ade..9e060c522d 100644 --- a/waftools/checks/custom.py +++ b/waftools/checks/custom.py @@ -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 diff --git a/wscript b/wscript index 567fc67ff0..da90c97253 100644 --- a/wscript +++ b/wscript @@ -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))