Skip to content

Commit

Permalink
generator2: Rename to python_generator.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 623067612
Change-Id: I7c172630b263974bf748df72dd08195c38f56b9a
  • Loading branch information
okunz authored and Copybara-Service committed Apr 9, 2024
1 parent 95c0e54 commit fd928c8
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 31 deletions.
2 changes: 1 addition & 1 deletion cmake/SapiBuildDefs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function(add_sapi_library)
list(JOIN _sapi_full_inputs "," _sapi_full_inputs)
list(APPEND _sapi_generator_command
"${SAPI_PYTHON3_EXECUTABLE}" -B
"${SAPI_SOURCE_DIR}/sandboxed_api/tools/generator2/sapi_generator.py"
"${SAPI_SOURCE_DIR}/sandboxed_api/tools/python_generator/sapi_generator.py"
${_sapi_generator_args}
"--sapi_isystem=${_sapi_isystem}"
"--sapi_in=${_sapi_full_inputs}"
Expand Down
4 changes: 2 additions & 2 deletions sandboxed_api/bazel/sapi.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ sapi_interface = rule(
values = [1, 2],
),
"_generator_v1": make_exec_label(
"//sandboxed_api/tools/generator2:sapi_generator",
"//sandboxed_api/tools/python_generator:sapi_generator",
),
"_generator_v2": make_exec_label(
# TODO(cblichmann): Add prebuilt version of Clang based generator
Expand Down Expand Up @@ -286,7 +286,7 @@ def sapi_library(
deps: Extra dependencies to add to the SAPI library
tags: Extra tags to associate with the target
generator_version: Which version the the interface generator to use
(experimental). Version 1 uses the Python/libclang based `generator2`,
(experimental). Version 1 uses the Python/libclang based `python_generator`,
version 2 uses the newer C++ implementation that uses the full clang
compiler front-end for parsing. Both emit equivalent Sandboxed APIs.
visibility: Target visibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//sandboxed_api/bazel:build_defs.bzl", "sapi_platform_copts")
load("//sandboxed_api/bazel:sapi.bzl", "sapi_library")

licenses(["notice"])

py_library(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from absl.testing import absltest
from absl.testing import parameterized
from clang import cindex
from com_google_sandboxed_api.sandboxed_api.tools.generator2 import code
from com_google_sandboxed_api.sandboxed_api.tools.generator2 import code_test_util
from com_google_sandboxed_api.sandboxed_api.tools.python_generator import code
from com_google_sandboxed_api.sandboxed_api.tools.python_generator import code_test_util

CODE = """
typedef int(fun*)(int,int);
Expand Down Expand Up @@ -93,10 +93,15 @@ def testExternC(self):
for x in translation_unit._walk_preorder()
if x.kind != cindex.CursorKind.MACRO_DEFINITION
]
self.assertListEqual(cursor_kinds, [
cindex.CursorKind.TRANSLATION_UNIT, cindex.CursorKind.LINKAGE_SPEC,
cindex.CursorKind.FUNCTION_DECL, cindex.CursorKind.PARM_DECL
])
self.assertListEqual(
cursor_kinds,
[
cindex.CursorKind.TRANSLATION_UNIT,
cindex.CursorKind.LINKAGE_SPEC,
cindex.CursorKind.FUNCTION_DECL,
cindex.CursorKind.PARM_DECL,
],
)

@parameterized.named_parameters(
('1:', '/tmp/test.h', 'tmp', 'tmp/test.h'),
Expand Down Expand Up @@ -128,8 +133,13 @@ def testCodeGeneratorOutput(self):
}
"""
functions = [
'function_a', 'types_1', 'types_2', 'types_3', 'types_4', 'types_5',
'types_6'
'function_a',
'types_1',
'types_2',
'types_3',
'types_4',
'types_5',
'types_6',
]
generator = code.Generator([analyze_string(body, func_names=functions)])
result = generator.generate('Test', 'sapi::Tests', None, None)
Expand Down Expand Up @@ -175,11 +185,16 @@ def testGetHeaderGuard(self, path, expected):
self.assertEqual(code.get_header_guard(path), expected)

@parameterized.named_parameters(
('function with return value and arguments',
'extern "C" int function(bool arg_bool, char* arg_ptr);',
['arg_bool', 'arg_ptr']),
('function without return value and no arguments',
'extern "C" void function();', []),
(
'function with return value and arguments',
'extern "C" int function(bool arg_bool, char* arg_ptr);',
['arg_bool', 'arg_ptr'],
),
(
'function without return value and no arguments',
'extern "C" void function();',
[],
),
)
def testArgumentNames(self, body, names):
generator = code.Generator([analyze_string(body)])
Expand Down Expand Up @@ -445,18 +460,19 @@ def testForwardDeclaration(self):
names = [t._clang_type.spelling for t in types]
self.assertLen(types, 4)
self.assertSameElements(
names, ['struct_6p', 'struct_6', 'struct_6_def', 'function_p3'])
names, ['struct_6p', 'struct_6', 'struct_6_def', 'function_p3']
)

self.assertLen(generator.translation_units, 1)
self.assertLen(generator.translation_units[0].forward_decls, 1)

t = next(
x for x in types if x._clang_type.spelling == 'struct_6_def')
t = next(x for x in types if x._clang_type.spelling == 'struct_6_def')
self.assertIn(t, generator.translation_units[0].forward_decls)

names = [t._clang_type.spelling for t in generator._get_related_types()]
self.assertEqual(
names, ['struct_6', 'struct_6p', 'function_p3', 'struct_6_def'])
names, ['struct_6', 'struct_6p', 'function_p3', 'struct_6_def']
)

# Extra check for generation, in case rendering throws error for this test.
forward_decls = generator._get_forward_decls(generator._get_related_types())
Expand Down Expand Up @@ -573,8 +589,12 @@ def testTypeOrder(self, func, a1, a2):
typedef unsigned char uchar;"""
file3_code = 'typedef unsigned long ulong;'
file4_code = 'typedef char chr;'
files = [('f1.h', file1_code), ('/f2.h', file2_code), ('/f3.h', file3_code),
('/f4.h', file4_code)]
files = [
('f1.h', file1_code),
('/f2.h', file2_code),
('/f3.h', file3_code),
('/f4.h', file4_code),
]
generator = code.Generator([analyze_strings('f1.h', files)])
functions = generator._get_functions()
self.assertLen(functions, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "sandboxed_api/tools/generator2/tests_sapi_generator.sapi.h"
#include "sandboxed_api/tools/python_generator/tests_sapi_generator.sapi.h"

int main() {
sapi::tests::struct_t a;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// be passed as arguments, returned by function or be part of structure
// dependency chain

#include "sandboxed_api/tools/generator2/testdata/tests.h"
#include "sandboxed_api/tools/python_generator/testdata/tests.h" // IWYU pragma: keep

namespace a {
namespace b {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef SANDBOXED_API_TOOLS_GENERATOR2_TESTDATA_TESTS_H_
#define SANDBOXED_API_TOOLS_GENERATOR2_TESTDATA_TESTS_H_
#ifndef SANDBOXED_API_TOOLS_PYTHON_GENERATOR_TESTDATA_TESTS_H_
#define SANDBOXED_API_TOOLS_PYTHON_GENERATOR_TESTDATA_TESTS_H_

#endif // SANDBOXED_API_TOOLS_GENERATOR2_TESTDATA_TESTS_H_
#endif // SANDBOXED_API_TOOLS_PYTHON_GENERATOR_TESTDATA_TESTS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "sandboxed_api/tools/generator2/testdata/tests.h"
#include "sandboxed_api/tools/python_generator/testdata/tests.h" // IWYU pragma: keep

// This compilation unit should have this structure partially defined
struct struct_2* function_returning_struct_ptr() {
Expand Down

0 comments on commit fd928c8

Please sign in to comment.