Skip to content

Commit

Permalink
fix: Embed full python protobuf library
Browse files Browse the repository at this point in the history
This embeds the full python protobuf library into the output in
pssh-box-protos, which is used by installation targets and Docker
images.  Without this, the installed pssh-box.py tool would depend on
a separate installation of the python protobuf library.

Closes #1436
  • Loading branch information
joeyparrish committed Oct 2, 2024
1 parent 4bf8b5e commit 797299a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packager/third_party/protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ add_definitions(-DNDEBUG)

# With these set in scope of this folder, load the library's own CMakeLists.txt.
add_subdirectory(source)

# Build generated python sources for the protobuf library.
include("protobuf_py.cmake")
63 changes: 63 additions & 0 deletions packager/third_party/protobuf/protobuf_py.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2022 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

# Build generated python sources for the protobuf library.
set(protobuf_py_proto_path ${CMAKE_CURRENT_SOURCE_DIR}/source/src)
set(protobuf_py_library_path ${CMAKE_CURRENT_SOURCE_DIR}/source/python)
set(protobuf_py_output_path ${CMAKE_CURRENT_BINARY_DIR}/py)

# Copy the library without the generated sources.
add_custom_command(
DEPENDS
${protobuf_py_proto_path}
OUTPUT
${protobuf_py_output_path}/google
COMMAND
${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/source/python/google
${protobuf_py_output_path}/google)

# This list was taken from packager/third_party/protobuf/source/python/setup.py
set(protobuf_py_filenames
google/protobuf/descriptor
google/protobuf/compiler/plugin
google/protobuf/any
google/protobuf/api
google/protobuf/duration
google/protobuf/empty
google/protobuf/field_mask
google/protobuf/source_context
google/protobuf/struct
google/protobuf/timestamp
google/protobuf/type
google/protobuf/wrappers)

# For each proto in the list, generate a _pb2.py file to add to the library.
set(protobuf_py_outputs "")
foreach (filename ${protobuf_py_filenames})
set(proto_path "${protobuf_py_proto_path}/${filename}.proto")
set(output_path "${protobuf_py_output_path}/${filename}_pb2.py")

list(APPEND protobuf_py_outputs "${output_path}")

add_custom_command(
DEPENDS
protoc
${proto_path}
${protobuf_py_output_path}/google
OUTPUT
${output_path}
COMMAND
protoc
ARGS
-I${protobuf_py_proto_path}
--python_out=${protobuf_py_output_path}
${proto_path})
endforeach ()

# The entire python protobuf library (repo source and generated) to the output
# folder.
add_custom_target(protobuf_py ALL DEPENDS ${protobuf_py_outputs})
5 changes: 5 additions & 0 deletions packager/tools/pssh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(PSSH_BOX_OUTPUTS

add_custom_command(
DEPENDS
protobuf_py
widevine_protos
pssh-box.py
OUTPUT ${PSSH_BOX_OUTPUTS}
Expand All @@ -25,6 +26,10 @@ add_custom_command(
${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}/packager/pssh-box-protos/
COMMAND
${CMAKE_COMMAND} -E copy_directory
${CMAKE_BINARY_DIR}/packager/third_party/protobuf/py/google
${CMAKE_BINARY_DIR}/packager/pssh-box-protos/google
COMMAND
${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/pssh-box.py
Expand Down
4 changes: 1 addition & 3 deletions packager/tools/pssh/pssh-box.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
# Copyright 2016 Google LLC. All rights reserved.
#
# Use of this source code is governed by a BSD-style
Expand All @@ -11,8 +11,6 @@
# the filename: pssh-box.py
# pylint: disable=invalid-name

from __future__ import print_function

import argparse
import base64
import itertools
Expand Down

0 comments on commit 797299a

Please sign in to comment.