Index: tools/json_schema_compiler/cpp_util.py |
diff --git a/tools/json_schema_compiler/cpp_util.py b/tools/json_schema_compiler/cpp_util.py |
index e7c29ac0777de2efdc31ec7bc5a77e2e67d95b69..187d99f0b2b685259992013650f81555f053d905 100644 |
--- a/tools/json_schema_compiler/cpp_util.py |
+++ b/tools/json_schema_compiler/cpp_util.py |
@@ -90,13 +90,16 @@ def GetParameterDeclaration(param, type_): |
} |
-def GenerateIfndefName(path, filename): |
- """Formats a path and filename as a #define name. |
+def GenerateIfndefName(file_path): |
+ """Formats |file_path| as a #define name. Presumably |file_path| is a header |
+ file, or there's little point in generating a #define for it. |
- e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__. |
+ e.g chrome/extensions/gen/file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__. |
""" |
- return (('%s_%s_H__' % (path, filename)) |
- .upper().replace(os.sep, '_').replace('/', '_')) |
+ return (('%s__' % file_path).upper() |
+ .replace('\\', '_') |
+ .replace('/', '_') |
+ .replace('.', '_')) |
def PadForGenerics(var): |
@@ -106,28 +109,21 @@ def PadForGenerics(var): |
return ('%s ' % var) if var.endswith('>') else var |
-def OpenNamespace(namespace): |
+ |
+def OpenNamespace(cpp_namespace): |
"""Get opening root namespace declarations. |
""" |
c = Code() |
- # In lieu of GYP supporting None for the namespace variable the '' namespace |
- # implies there is no root namespace. |
- if namespace == '': |
- return c |
- for component in namespace.split('::'): |
+ for component in cpp_namespace.split('::'): |
c.Append('namespace %s {' % component) |
return c |
-def CloseNamespace(namespace): |
+def CloseNamespace(cpp_namespace): |
"""Get closing root namespace declarations. |
""" |
c = Code() |
- # In lieu of GYP supporting None for the namespace variable the '' namespace |
- # implies there is no root namespace. |
- if namespace == '': |
- return c |
- for component in reversed(namespace.split('::')): |
+ for component in reversed(cpp_namespace.split('::')): |
c.Append('} // namespace %s' % component) |
return c |
@@ -145,3 +141,18 @@ def CamelCase(unix_name): |
def ClassName(filepath): |
return CamelCase(os.path.split(filepath)[1]) |
+ |
+ |
+def GetCppNamespace(pattern, namespace): |
+ '''Returns the C++ namespace given |pattern| which includes a %(namespace)s |
+ substitution, and the |namespace| to substitute. It is expected that |pattern| |
+ has been passed as a flag to compiler.py from GYP/GN. |
+ ''' |
+ # For some reason Windows builds escape the % characters, so unescape them. |
+ # This means that %% can never appear legitimately within a pattern, but |
+ # that's ok. It should never happen. |
+ cpp_namespace = pattern.replace('%%', '%') % { 'namespace': namespace } |
not at google - send to devlin
2014/08/05 04:37:59
after some debugging, turns out I needed to do thi
|
+ assert '%' not in cpp_namespace, \ |
+ ('Did not manage to fully substitute namespace "%s" into pattern "%s"' |
+ % (namespace, pattern)) |
+ return cpp_namespace |