Skip to content

Commit

Permalink
command: add platform property
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Dudemanguy committed Feb 27, 2023
1 parent 8ea7aa5 commit 80feac6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions DOCS/interface-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
6 changes: 6 additions & 0 deletions DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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},
Expand Down
12 changes: 11 additions & 1 deletion waftools/checks/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

__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')

Expand Down Expand Up @@ -168,3 +168,13 @@ def fn(ctx, dependency_identifier, **kw):
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
2 changes: 2 additions & 0 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 80feac6

Please sign in to comment.