Skip to content

Commit

Permalink
Make mediasoup work with Python 3 (related to #207)
Browse files Browse the repository at this point in the history
Note that gyp source code has been manually modified within the worker/deps/gyp
folder (credits to @saghul)
  • Loading branch information
ibc committed May 28, 2019
1 parent cb076b7 commit acf9417
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
1 change: 0 additions & 1 deletion doc/Building.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ Read the [Fuzzer](Fuzzer.md) documentation for detailed information.
Builds a Xcode project for the mediasoup-worker subproject.



### `make lint`

Validates mediasoup-worker C++ files using [clang-format](https://clang.llvm.org/docs/ClangFormat.html) and rules in `worker/.clang-format`.
Expand Down
27 changes: 15 additions & 12 deletions worker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
# make tasks for mediasoup-worker.
#

# Best effort to get Python 2 executable and also allow custom PYTHON
# environment variable set by the user.
PYTHON ?= $(shell command -v python2 2> /dev/null || echo python)
PYTHON ?= python
LCOV = ./deps/lcov/bin/lcov
GULP = ../node_modules/.bin/gulp
BEAR ?= bear
JQ ?= jq
SED ?= sed
DOCKER ?= docker
MEDIASOUP_BUILDTYPE ?= Release

.PHONY: \
Expand All @@ -22,7 +25,7 @@ test:
ifeq ($(MEDIASOUP_WORKER_BIN),)
$(PYTHON) ./scripts/configure.py -R mediasoup-worker-test
$(MAKE) BUILDTYPE=$(MEDIASOUP_BUILDTYPE) -C out
./deps/lcov/bin/lcov --directory ./ --zerocounters
$(LCOV) --directory ./ --zerocounters
./out/$(MEDIASOUP_BUILDTYPE)/mediasoup-worker-test --invisibles --use-colour=yes $(MEDIASOUP_TEST_TAGS)
endif

Expand All @@ -43,13 +46,13 @@ format:

bear:
$(MAKE) clean
bear -o compile_commands_template.tmp.json $(MAKE)
jq 'del(.[] | select(.file == "$(PWD)/src/Utils/IP.cpp"))' compile_commands_template.tmp.json > compile_commands_template.json
rm compile_commands_template.tmp.json
sed -i "s|$(PWD)|PATH|g" compile_commands_template.json
$(BEAR) -o compile_commands_template.tmp.json $(MAKE)
$(JQ) 'del(.[] | select(.file == "$(PWD)/src/Utils/IP.cpp"))' compile_commands_template.tmp.json > compile_commands_template.json
$(RM) -f compile_commands_template.tmp.json
$(SED) -i "s|$(PWD)|PATH|g" compile_commands_template.json

tidy:
sed "s|PATH|$(PWD)|g" compile_commands_template.json > compile_commands.json
$(SED) "s|PATH|$(PWD)|g" compile_commands_template.json > compile_commands.json
$(PYTHON) ./scripts/clang-tidy.py \
-clang-tidy-binary=../node_modules/.bin/clang-tidy \
-clang-apply-replacements-binary=../node_modules/.bin/clang-apply-replacements \
Expand Down Expand Up @@ -81,13 +84,13 @@ clean-all:

docker-build:
ifeq ($(DOCKER_NO_CACHE),true)
docker build -f Dockerfile --no-cache --tag mediasoup/docker:latest .
$(DOCKER) build -f Dockerfile --no-cache --tag mediasoup/docker:latest .
else
docker build -f Dockerfile --tag mediasoup/docker:latest .
$(DOCKER) build -f Dockerfile --tag mediasoup/docker:latest .
endif

docker-run:
docker run \
$(DOCKER) run \
--name=mediasoupDocker -it --rm \
--cap-add SYS_PTRACE \
-v $(shell pwd)/../:/mediasoup \
Expand Down
8 changes: 4 additions & 4 deletions worker/deps/gyp/pylib/gyp/xcode_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def _XcodeSdkPath(self, sdk_root):
XcodeSettings._sdk_path_cache[sdk_root] = sdk_path
if sdk_root:
XcodeSettings._sdk_root_cache[sdk_path] = sdk_root
return XcodeSettings._sdk_path_cache[sdk_root]
return XcodeSettings._sdk_path_cache[sdk_root].decode()

def _AppendPlatformVersionMinFlags(self, lst):
self._Appendf(lst, 'MACOSX_DEPLOYMENT_TARGET', '-mmacosx-version-min=%s')
Expand Down Expand Up @@ -1413,7 +1413,7 @@ def XcodeVersion():
version = version_list[0]
build = version_list[-1]
# Be careful to convert "4.2" to "0420":
version = version.split()[-1].replace('.', '')
version = version.split()[-1].decode().replace('.', '')
version = (version + '0' * (3 - len(version))).zfill(4)
if build:
build = build.split()[-1]
Expand Down Expand Up @@ -1450,9 +1450,9 @@ def GetStdout(cmdlist):
job = subprocess.Popen(cmdlist, stdout=subprocess.PIPE)
out = job.communicate()[0]
if job.returncode != 0:
sys.stderr.write(out + '\n')
sys.stderr.write(out + b'\n')
raise GypError('Error %d running %s' % (job.returncode, cmdlist[0]))
return out.rstrip('\n')
return out.rstrip(b'\n')


def MergeGlobalXcodeSettingsToSpec(global_dict, spec):
Expand Down
5 changes: 0 additions & 5 deletions worker/scripts/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
import subprocess
import sys

version = sys.version_info[0]

if version != 2:
raise RuntimeError('gyp requires Python 2, but this is Python ' + str(version) + ', ensure your python2 or python command points to the Python 2 executable')

CC = os.environ.get('CC', 'cc')
script_dir = os.path.dirname(__file__)
root = os.path.normpath(os.path.join(script_dir, '..'))
Expand Down

0 comments on commit acf9417

Please sign in to comment.