build: Fix pssh-box.py targets, installation, and docs (#1279)

pssh-box.py needs Python protos, which we were not building. It also
needs to have those protos installed properly.

This fixes generation of Python proto interfaces and fixes the install
targets to put those protos where they are needed. This also updates the
documentation to match.
This commit is contained in:
Joey Parrish 2023-10-17 12:52:40 -07:00 committed by GitHub
parent 53eb7b1a38
commit 32723f81bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 13 deletions

View File

@ -194,10 +194,15 @@ target_link_libraries(packager_test
configure_file(packager.pc.in packager.pc @ONLY) configure_file(packager.pc.in packager.pc @ONLY)
install(TARGETS mpd_generator packager libpackager
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY ../include/packager install(DIRECTORY ../include/packager
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES tools/pssh/pssh-box.py DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS mpd_generator packager libpackager)
install(FILES ${CMAKE_BINARY_DIR}/packager/packager.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(PROGRAMS ${CMAKE_BINARY_DIR}/pssh-box.py
DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY ${CMAKE_BINARY_DIR}/pssh-box-protos
DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${CMAKE_BINARY_DIR}/packager/packager.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

View File

@ -7,7 +7,8 @@
# Define a custom function to create protobuf libraries. This is similar to # Define a custom function to create protobuf libraries. This is similar to
# the one defined in the CMake FindProtobuf.cmake module, but allows us to more # the one defined in the CMake FindProtobuf.cmake module, but allows us to more
# easily hook into the protobuf submodule to do the work instead of searching # easily hook into the protobuf submodule to do the work instead of searching
# for a system-wide installation. # for a system-wide installation. Generates both C++ library targets and
# Python proto modules.
function(add_proto_library NAME) function(add_proto_library NAME)
cmake_parse_arguments(PARSE_ARGV cmake_parse_arguments(PARSE_ARGV
@ -51,9 +52,13 @@ function(add_proto_library NAME)
add_custom_command( add_custom_command(
OUTPUT ${_generated_cpp} ${_generated_h} OUTPUT ${_generated_cpp} ${_generated_h}
COMMAND protoc COMMAND protoc
ARGS -I${CMAKE_CURRENT_SOURCE_DIR}/${_dir} --cpp_out=${CMAKE_CURRENT_BINARY_DIR}/${_dir} ${CMAKE_CURRENT_SOURCE_DIR}/${_path} ARGS
-I${CMAKE_CURRENT_SOURCE_DIR}/${_dir}
--cpp_out=${CMAKE_CURRENT_BINARY_DIR}/${_dir}
--python_out=${CMAKE_CURRENT_BINARY_DIR}/${_dir}
${CMAKE_CURRENT_SOURCE_DIR}/${_path}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_path} protoc DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_path} protoc
COMMENT "Running C++ protocol buffer compiler on ${_path}" COMMENT "Running protocol buffer compiler on ${_path}"
VERBATIM) VERBATIM)
endforeach() endforeach()

View File

@ -17,3 +17,5 @@ add_library(license_notice STATIC
# Anyone who depends on this library will need this include directory. # Anyone who depends on this library will need this include directory.
target_include_directories(license_notice PUBLIC "${CMAKE_BINARY_DIR}") target_include_directories(license_notice PUBLIC "${CMAKE_BINARY_DIR}")
add_subdirectory(pssh)

View File

@ -0,0 +1,33 @@
# Copyright 2023 Google LLC. All rights reserved.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
# Copy the pssh-box.py script and its protos into the required directory
# structure.
set(PSSH_BOX_OUTPUTS
${CMAKE_BINARY_DIR}/pssh-box.py
${CMAKE_BINARY_DIR}/pssh-box-protos
${CMAKE_BINARY_DIR}/pssh-box-protos/widevine_common_encryption_pb2.py
${CMAKE_BINARY_DIR}/pssh-box-protos/widevine_pssh_data_pb2.py)
add_custom_command(
DEPENDS
widevine_protos
pssh-box.py
OUTPUT ${PSSH_BOX_OUTPUTS}
COMMAND
${CMAKE_COMMAND} -E make_directory
${CMAKE_BINARY_DIR}/pssh-box-protos/
COMMAND
${CMAKE_COMMAND} -E copy
${CMAKE_BINARY_DIR}/packager/media/base/widevine_common_encryption_pb2.py
${CMAKE_BINARY_DIR}/packager/media/base/widevine_pssh_data_pb2.py
${CMAKE_BINARY_DIR}/pssh-box-protos/
COMMAND
${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/pssh-box.py
${CMAKE_BINARY_DIR}/)
add_custom_target(pssh_box_py ALL DEPENDS ${PSSH_BOX_OUTPUTS})

View File

@ -3,7 +3,7 @@ pssh-box - Utility to parse and generate PSSH boxes
## Prerequisite ## Prerequisite
- Python 2.6 or newer. - Python 3.
## Build the utility using Shaka Packager build setup ## Build the utility using Shaka Packager build setup
@ -16,11 +16,10 @@ https://github.com/shaka-project/shaka-packager/blob/master/docs/source/build_in
With the build environment set up, use `ninja` to build the utility: With the build environment set up, use `ninja` to build the utility:
```bash ```bash
$ ninja -C out/Release pssh_box_py $ ninja -C build/ pssh-box.py
``` ```
Then you can use the built utility in `out/Release/pssh_box.py`. You can add Then you can use the built utility in `build/pssh-box.py`.
`out/Release` to your `PATH` so you can run it from anywhere.
## Usage ## Usage

View File

@ -32,11 +32,12 @@ def to_code_point(value):
_script_dir = os.path.dirname(os.path.realpath(__file__)) _script_dir = os.path.dirname(os.path.realpath(__file__))
_proto_path = os.path.join(_script_dir, 'pyproto') _proto_path = os.path.join(_script_dir, 'pssh-box-protos')
_widevine_proto_path = os.path.join(_proto_path, 'packager/media/base') _widevine_proto_path = os.path.join(_proto_path, 'packager/media/base')
assert os.path.exists(_proto_path), ( assert os.path.exists(_proto_path), (
'Please run from output directory, e.g. out/Debug/pssh-box.py') 'Failed to find proto, please run built/installed version. ' +
' e.g. build/packager/pssh-box.py')
sys.path.insert(0, _proto_path) sys.path.insert(0, _proto_path)
sys.path.insert(0, _widevine_proto_path) sys.path.insert(0, _widevine_proto_path)