mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
Find libclang so that Python3 works, remove PY2
annotations
We now require that Debian users install the `python3` and `python3-pip` packages. This change lets the Python code search for `libclang.so`, which can be located in different directories, depending on version, and is not found by default otherwise. Fixes #28 PiperOrigin-RevId: 254745872 Change-Id: Ia77680da2a3235c0a9518125676aa8a460e38e76
This commit is contained in:
parent
4bcea59309
commit
97b5f0767a
|
@ -68,8 +68,9 @@ echo "deb http://storage.googleapis.com/bazel-apt stable jdk1.8" | \
|
|||
sudo tee /etc/apt/sources.list.d/bazel.list
|
||||
wget -qO - https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
|
||||
sudo apt-get update
|
||||
sudo apt-get install -qy python-typing python-clang-7 libclang-7-dev
|
||||
sudo apt-get install -qy build-essential linux-libc-dev bazel
|
||||
sudo apt-get install -qy build-essential linux-libc-dev bazel python3 \
|
||||
python3-pip libclang-7-dev
|
||||
pip3 install clang
|
||||
```
|
||||
|
||||
Clone and run the build:
|
||||
|
|
|
@ -29,7 +29,6 @@ py_test(
|
|||
"code_test.py",
|
||||
"code_test_util.py",
|
||||
],
|
||||
python_version = "PY2",
|
||||
deps = [
|
||||
":code",
|
||||
"@com_google_absl_py//absl/testing:absltest",
|
||||
|
@ -40,7 +39,6 @@ py_test(
|
|||
py_binary(
|
||||
name = "sapi_generator",
|
||||
srcs = ["sapi_generator.py"],
|
||||
python_version = "PY2",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":code",
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from ctypes import util
|
||||
import itertools
|
||||
import os
|
||||
from clang import cindex
|
||||
|
@ -32,6 +33,23 @@ _PARSE_OPTIONS = (cindex.TranslationUnit.PARSE_SKIP_FUNCTION_BODIES |
|
|||
cindex.TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD)
|
||||
|
||||
|
||||
def _init_libclang():
|
||||
"""Finds and initializes the libclang library."""
|
||||
if cindex.Config.loaded:
|
||||
return
|
||||
# Try to find libclang in the standard location and a few versioned paths
|
||||
# that are used on Debian (and others). If LD_LIBRARY_PATH is set, it is
|
||||
# used as well.
|
||||
for lib in [
|
||||
'clang', 'clang-9', 'clang-8', 'clang-7', 'clang-6.0', 'clang-5.0',
|
||||
'clang-4.0'
|
||||
]:
|
||||
libclang = util.find_library(lib)
|
||||
if libclang:
|
||||
cindex.Config.set_library_file(libclang)
|
||||
break
|
||||
|
||||
|
||||
def get_header_guard(path):
|
||||
# type: (Text) -> Text
|
||||
"""Generates header guard string from path."""
|
||||
|
@ -610,6 +628,7 @@ class Analyzer(object):
|
|||
@staticmethod
|
||||
def process_files(input_paths, compile_flags):
|
||||
# type: (Text, List[Text]) -> List[_TranslationUnit]
|
||||
_init_libclang()
|
||||
return [Analyzer._analyze_file_for_tu(path, compile_flags=compile_flags)
|
||||
for path in input_paths]
|
||||
|
||||
|
@ -663,9 +682,9 @@ class Generator(object):
|
|||
facultative. If not given, then one is computed for each element of
|
||||
input_paths
|
||||
"""
|
||||
|
||||
self.translation_units = translation_units
|
||||
self.functions = None
|
||||
_init_libclang()
|
||||
|
||||
def generate(self, name, function_names, namespace=None, output_file=None,
|
||||
embed_dir=None, embed_name=None):
|
||||
|
|
Loading…
Reference in New Issue
Block a user