Skip to content

Commit f07fd0d

Browse files
authored
fix: Embed full python protobuf library (#1438)
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
1 parent 4bf8b5e commit f07fd0d

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

packager/third_party/protobuf/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ add_definitions(-DNDEBUG)
3030

3131
# With these set in scope of this folder, load the library's own CMakeLists.txt.
3232
add_subdirectory(source)
33+
34+
# Build generated python sources for the protobuf library.
35+
include("protobuf_py.cmake")
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright 2022 Google LLC. All rights reserved.
2+
#
3+
# Use of this source code is governed by a BSD-style
4+
# license that can be found in the LICENSE file or at
5+
# https://developers.google.com/open-source/licenses/bsd
6+
7+
# Build generated python sources for the protobuf library.
8+
set(protobuf_py_proto_path ${CMAKE_CURRENT_SOURCE_DIR}/source/src)
9+
set(protobuf_py_library_path ${CMAKE_CURRENT_SOURCE_DIR}/source/python)
10+
set(protobuf_py_output_path ${CMAKE_CURRENT_BINARY_DIR}/py)
11+
12+
# Copy the library without the generated sources.
13+
add_custom_command(
14+
DEPENDS
15+
${protobuf_py_proto_path}
16+
OUTPUT
17+
${protobuf_py_output_path}/google
18+
COMMAND
19+
${CMAKE_COMMAND} -E copy_directory
20+
${CMAKE_CURRENT_SOURCE_DIR}/source/python/google
21+
${protobuf_py_output_path}/google)
22+
23+
# This list was taken from packager/third_party/protobuf/source/python/setup.py
24+
set(protobuf_py_filenames
25+
google/protobuf/descriptor
26+
google/protobuf/compiler/plugin
27+
google/protobuf/any
28+
google/protobuf/api
29+
google/protobuf/duration
30+
google/protobuf/empty
31+
google/protobuf/field_mask
32+
google/protobuf/source_context
33+
google/protobuf/struct
34+
google/protobuf/timestamp
35+
google/protobuf/type
36+
google/protobuf/wrappers)
37+
38+
# For each proto in the list, generate a _pb2.py file to add to the library.
39+
set(protobuf_py_outputs "")
40+
foreach (filename ${protobuf_py_filenames})
41+
set(proto_path "${protobuf_py_proto_path}/${filename}.proto")
42+
set(output_path "${protobuf_py_output_path}/${filename}_pb2.py")
43+
44+
list(APPEND protobuf_py_outputs "${output_path}")
45+
46+
add_custom_command(
47+
DEPENDS
48+
protoc
49+
${proto_path}
50+
${protobuf_py_output_path}/google
51+
OUTPUT
52+
${output_path}
53+
COMMAND
54+
protoc
55+
ARGS
56+
-I${protobuf_py_proto_path}
57+
--python_out=${protobuf_py_output_path}
58+
${proto_path})
59+
endforeach ()
60+
61+
# The entire python protobuf library (repo source and generated) to the output
62+
# folder.
63+
add_custom_target(protobuf_py ALL DEPENDS ${protobuf_py_outputs})

packager/tools/pssh/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set(PSSH_BOX_OUTPUTS
1414

1515
add_custom_command(
1616
DEPENDS
17+
protobuf_py
1718
widevine_protos
1819
pssh-box.py
1920
OUTPUT ${PSSH_BOX_OUTPUTS}
@@ -25,6 +26,10 @@ add_custom_command(
2526
${CMAKE_BINARY_DIR}/packager/media/base/widevine_common_encryption_pb2.py
2627
${CMAKE_BINARY_DIR}/packager/media/base/widevine_pssh_data_pb2.py
2728
${CMAKE_BINARY_DIR}/packager/pssh-box-protos/
29+
COMMAND
30+
${CMAKE_COMMAND} -E copy_directory
31+
${CMAKE_BINARY_DIR}/packager/third_party/protobuf/py/google
32+
${CMAKE_BINARY_DIR}/packager/pssh-box-protos/google
2833
COMMAND
2934
${CMAKE_COMMAND} -E copy
3035
${CMAKE_CURRENT_SOURCE_DIR}/pssh-box.py

packager/tools/pssh/pssh-box.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22
# Copyright 2016 Google LLC. All rights reserved.
33
#
44
# Use of this source code is governed by a BSD-style
@@ -11,8 +11,6 @@
1111
# the filename: pssh-box.py
1212
# pylint: disable=invalid-name
1313

14-
from __future__ import print_function
15-
1614
import argparse
1715
import base64
1816
import itertools

0 commit comments

Comments
 (0)