From ba47adc21d4c9bc316f3c7c32b0faaef952c111e Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Wed, 13 May 2020 23:48:59 -0700 Subject: [PATCH] Allow empty `sapi_embedded_dir` flag in the header generator PiperOrigin-RevId: 311478848 Change-Id: If94d2279989b3cfc76304bb0bb8624e0f0532ba6 --- sandboxed_api/tools/generator2/code.py | 10 ++++++---- sandboxed_api/tools/generator2/sapi_generator.py | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sandboxed_api/tools/generator2/code.py b/sandboxed_api/tools/generator2/code.py index 5a8f59d..5d1e686 100644 --- a/sandboxed_api/tools/generator2/code.py +++ b/sandboxed_api/tools/generator2/code.py @@ -679,7 +679,7 @@ class Generator(object): GUARD_START = ('#ifndef {0}\n' '#define {0}') GUARD_END = '#endif // {}' - EMBED_INCLUDE = '#include \"{}/{}_embed.h"' + EMBED_INCLUDE = '#include "{}"' EMBED_CLASS = ('class {0}Sandbox : public ::sapi::Sandbox {{\n' ' public:\n' ' {0}Sandbox() : ::sapi::Sandbox({1}_embed_create()) {{}}\n' @@ -903,8 +903,10 @@ class Generator(object): result.append('#include "sandboxed_api/sandbox.h"') result.append('#include "sandboxed_api/vars.h"') - if embed_dir and embed_name: - result.append(Generator.EMBED_INCLUDE.format(embed_dir, embed_name)) + if (embed_dir is not None) and (embed_name is not None): + result.append( + Generator.EMBED_INCLUDE.format( + os.path.join(embed_dir, embed_name) + '_embed.h')) if namespaces: result.append('') @@ -918,7 +920,7 @@ class Generator(object): result.append('') - if embed_dir and embed_name: + if (embed_dir is not None) and (embed_name is not None): result.append( Generator.EMBED_CLASS.format(name, embed_name.replace('-', '_'))) diff --git a/sandboxed_api/tools/generator2/sapi_generator.py b/sandboxed_api/tools/generator2/sapi_generator.py index dbb0774..39f6c42 100644 --- a/sandboxed_api/tools/generator2/sapi_generator.py +++ b/sandboxed_api/tools/generator2/sapi_generator.py @@ -31,8 +31,8 @@ flags.DEFINE_string('sapi_ns', '', 'namespace') flags.DEFINE_string('sapi_isystem', '', 'system includes') flags.DEFINE_list('sapi_functions', [], 'function list to analyze') flags.DEFINE_list('sapi_in', None, 'input files to analyze') -flags.DEFINE_string('sapi_embed_dir', None, 'directory with embed includes') -flags.DEFINE_string('sapi_embed_name', None, 'name of the embed object') +flags.DEFINE_string('sapi_embed_dir', '', 'directory with embed includes') +flags.DEFINE_string('sapi_embed_name', '', 'name of the embed object') flags.DEFINE_bool( 'sapi_limit_scan_depth', False, 'scan only functions from top level file in compilation unit')