diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-27 22:07:43 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-27 22:07:43 +0000 |
commit | a4b0f408ac92589d244e6d0ca05309865c5ec5aa (patch) | |
tree | 571bf91e0cb5a3a378f79067b3c16a787a7f539d /mojo/public | |
parent | 16dcbb6a94d4d5ac8d1f0761718de38a0eeacd0b (diff) | |
download | chromium_src-a4b0f408ac92589d244e6d0ca05309865c5ec5aa.zip chromium_src-a4b0f408ac92589d244e6d0ca05309865c5ec5aa.tar.gz chromium_src-a4b0f408ac92589d244e6d0ca05309865c5ec5aa.tar.bz2 |
Mojo: Include "path/to/foo.mojom.h"
Given path/to/foo.mojom, change the code generator to output:
<(SHARED_INTERMEDIATE_DIR)/path/to/foo.mojom.cc
<(SHARED_INTERMEDIATE_DIR)/path/to/foo.mojom.h
<(SHARED_INTERMEDIATE_DIR)/path/to/foo.mojom-internal.h
This involves shelling out to a python script to compute "path/to" part as that is not otherwise available from GYP. See build/inverse_depth.py.
DEPTH is now passed to mojom_bindings_generator.py so that it can similarly compute "path/to". With that, we no longer need the include_dir argument, so I dropped it.
R=davemoore@chromium.org, mark@chromium.org
Review URL: https://codereview.chromium.org/177183002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253937 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/public')
-rw-r--r-- | mojo/public/bindings/generators/cpp_templates/module-internal.h.tmpl (renamed from mojo/public/bindings/generators/cpp_templates/module_internal.h.tmpl) | 6 | ||||
-rw-r--r-- | mojo/public/bindings/generators/cpp_templates/module.h.tmpl | 6 | ||||
-rw-r--r-- | mojo/public/bindings/generators/mojom_cpp_generator.py | 5 | ||||
-rw-r--r-- | mojo/public/bindings/mojom_bindings_generator.gypi | 21 | ||||
-rwxr-xr-x | mojo/public/bindings/mojom_bindings_generator.py | 18 | ||||
-rw-r--r-- | mojo/public/bindings/pylib/generate/mojom.py | 1 | ||||
-rw-r--r-- | mojo/public/bindings/pylib/generate/mojom_generator.py | 4 | ||||
-rw-r--r-- | mojo/public/bindings/tests/handle_passing_unittest.cc | 2 | ||||
-rw-r--r-- | mojo/public/bindings/tests/remote_ptr_unittest.cc | 4 | ||||
-rw-r--r-- | mojo/public/bindings/tests/sample_service_unittest.cc | 2 | ||||
-rw-r--r-- | mojo/public/bindings/tests/type_conversion_unittest.cc | 2 | ||||
-rw-r--r-- | mojo/public/shell/application.h | 2 | ||||
-rw-r--r-- | mojo/public/shell/service.h | 2 | ||||
-rw-r--r-- | mojo/public/shell/shell.mojom (renamed from mojo/public/shell/lib/shell.mojom) | 0 |
14 files changed, 42 insertions, 33 deletions
diff --git a/mojo/public/bindings/generators/cpp_templates/module_internal.h.tmpl b/mojo/public/bindings/generators/cpp_templates/module-internal.h.tmpl index 6d483df..22236c0 100644 --- a/mojo/public/bindings/generators/cpp_templates/module_internal.h.tmpl +++ b/mojo/public/bindings/generators/cpp_templates/module-internal.h.tmpl @@ -2,15 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -{%- set header_guard = "MOJO_GENERATED_BINDINGS_%s_%s_INTERNAL_H_"| - format(module_name|upper, module_name|upper) %} +{%- set header_guard = "%s_INTERNAL_H_"| + format(module_name|upper|replace("/","_")|replace(".","_")) %} #ifndef {{header_guard}} #define {{header_guard}} #include "mojo/public/bindings/lib/bindings_internal.h" {%- for import in imports %} -#include "{{include_prefix}}{{import.module_name|camel_to_underscores}}_internal.h" +#include "{{include_prefix}}{{import.module_name|camel_to_underscores}}-internal.h" {%- endfor %} namespace {{namespace}} { diff --git a/mojo/public/bindings/generators/cpp_templates/module.h.tmpl b/mojo/public/bindings/generators/cpp_templates/module.h.tmpl index ad22921..ca5aee8 100644 --- a/mojo/public/bindings/generators/cpp_templates/module.h.tmpl +++ b/mojo/public/bindings/generators/cpp_templates/module.h.tmpl @@ -2,15 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -{%- set header_guard = "MOJO_GENERATED_BINDINGS_%s_%s_H_"| - format(module_name|upper, module_name|upper) %} +{%- set header_guard = "%s_H_"| + format(module_path|upper|replace("/","_")|replace(".","_")) %} #ifndef {{header_guard}} #define {{header_guard}} #include "mojo/public/bindings/array.h" #include "mojo/public/bindings/interface.h" -#include "{{include_prefix}}{{module_name|camel_to_underscores}}_internal.h" +#include "{{include_prefix}}{{module_name|camel_to_underscores}}-internal.h" {%- for import in imports %} #include "{{include_prefix}}{{import.module_name|camel_to_underscores}}.h" {%- endfor %} diff --git a/mojo/public/bindings/generators/mojom_cpp_generator.py b/mojo/public/bindings/generators/mojom_cpp_generator.py index 4420aaf..dcff240 100644 --- a/mojo/public/bindings/generators/mojom_cpp_generator.py +++ b/mojo/public/bindings/generators/mojom_cpp_generator.py @@ -141,6 +141,7 @@ class Generator(mojom_generator.Generator): return { "module": self.module, "module_name": self.module.name, + "module_path": self.module.path, "namespace": self.module.namespace, "imports": self.module.imports, "kinds": self.module.kinds, @@ -154,7 +155,7 @@ class Generator(mojom_generator.Generator): def GenerateModuleHeader(self): return self.GetJinjaExports() - @UseJinja("cpp_templates/module_internal.h.tmpl", filters=cpp_filters) + @UseJinja("cpp_templates/module-internal.h.tmpl", filters=cpp_filters) def GenerateModuleInternalHeader(self): return self.GetJinjaExports() @@ -165,7 +166,7 @@ class Generator(mojom_generator.Generator): def GenerateFiles(self): self.Write(self.GenerateModuleHeader(), "%s.h" % self.module.name) self.Write(self.GenerateModuleInternalHeader(), - "%s_internal.h" % self.module.name) + "%s-internal.h" % self.module.name) self.Write(self.GenerateModuleSource(), "%s.cc" % self.module.name) def GetIncludePrefix(self): diff --git a/mojo/public/bindings/mojom_bindings_generator.gypi b/mojo/public/bindings/mojom_bindings_generator.gypi index c72b9c0..2b7554a 100644 --- a/mojo/public/bindings/mojom_bindings_generator.gypi +++ b/mojo/public/bindings/mojom_bindings_generator.gypi @@ -3,14 +3,13 @@ # found in the LICENSE file. { - 'variables': { - 'output_dir': '<(SHARED_INTERMEDIATE_DIR)/mojom', - }, 'rules': [ { 'rule_name': 'Generate C++ source files from mojom files', 'extension': 'mojom', 'variables': { + 'mojom_base_output_dir': + '<!(python <(DEPTH)/build/inverse_depth.py <(DEPTH))', 'mojom_bindings_generator': '<(DEPTH)/mojo/public/bindings/mojom_bindings_generator.py', }, @@ -23,7 +22,7 @@ '<(DEPTH)/mojo/public/bindings/generators/cpp_templates/interface_stub_declaration.tmpl', '<(DEPTH)/mojo/public/bindings/generators/cpp_templates/module.cc.tmpl', '<(DEPTH)/mojo/public/bindings/generators/cpp_templates/module.h.tmpl', - '<(DEPTH)/mojo/public/bindings/generators/cpp_templates/module_internal.h.tmpl', + '<(DEPTH)/mojo/public/bindings/generators/cpp_templates/module-internal.h.tmpl', '<(DEPTH)/mojo/public/bindings/generators/cpp_templates/params_definition.tmpl', '<(DEPTH)/mojo/public/bindings/generators/cpp_templates/struct_builder_definition.tmpl', '<(DEPTH)/mojo/public/bindings/generators/cpp_templates/struct_declaration.tmpl', @@ -49,18 +48,18 @@ '<(DEPTH)/mojo/public/bindings/pylib/generate/template_expander.py', ], 'outputs': [ - '<(output_dir)/<(RULE_INPUT_ROOT).cc', - '<(output_dir)/<(RULE_INPUT_ROOT).h', - '<(output_dir)/<(RULE_INPUT_ROOT).js', - '<(output_dir)/<(RULE_INPUT_ROOT)_internal.h', + '<(SHARED_INTERMEDIATE_DIR)/<(mojom_base_output_dir)/<(RULE_INPUT_PATH).cc', + '<(SHARED_INTERMEDIATE_DIR)/<(mojom_base_output_dir)/<(RULE_INPUT_PATH).h', + '<(SHARED_INTERMEDIATE_DIR)/<(mojom_base_output_dir)/<(RULE_INPUT_PATH).js', + '<(SHARED_INTERMEDIATE_DIR)/<(mojom_base_output_dir)/<(RULE_INPUT_PATH)-internal.h', ], 'action': [ 'python', '<@(mojom_bindings_generator)', '<(RULE_INPUT_PATH)', - '-i', 'mojom', - '-o', '<(output_dir)', + '-d', '<(DEPTH)', + '-o', '<(SHARED_INTERMEDIATE_DIR)/<(mojom_base_output_dir)/<(RULE_INPUT_DIRNAME)', ], - 'message': 'Generating C++ from mojom <(RULE_INPUT_PATH)', + 'message': 'Generating C++ from <(RULE_INPUT_PATH)', 'process_outputs_as_sources': 1, } ], diff --git a/mojo/public/bindings/mojom_bindings_generator.py b/mojo/public/bindings/mojom_bindings_generator.py index 87b055d..7c05a82 100755 --- a/mojo/public/bindings/mojom_bindings_generator.py +++ b/mojo/public/bindings/mojom_bindings_generator.py @@ -44,6 +44,7 @@ def LoadGenerators(generators_string): generators.append(generator_module) return generators + def ProcessFile(args, generator_modules, filename, processed_files): # Ensure we only visit each file once. if filename in processed_files: @@ -53,7 +54,6 @@ def ProcessFile(args, generator_modules, filename, processed_files): processed_files[filename] = None dirname, name = os.path.split(filename) - name = os.path.splitext(name)[0] # TODO(darin): There's clearly too many layers of translation here! We can # at least avoid generating the serialized Mojom IR. tree = mojo_parser.Parse(filename) @@ -69,21 +69,29 @@ def ProcessFile(args, generator_modules, filename, processed_files): args, generator_modules, import_filename, processed_files) module = mojom_data.OrderedModuleFromData(mojom) + + # Set the path as relative to the source root. + module.path = os.path.relpath(os.path.abspath(filename), + os.path.abspath(args.depth)) + + # Normalize to unix-style path here to keep the generators simpler. + module.path = module.path.replace('\\', '/') + for generator_module in generator_modules: - generator = generator_module.Generator(module, args.include_dir, - args.output_dir) + generator = generator_module.Generator(module, args.output_dir) generator.GenerateFiles() processed_files[filename] = module return module + def Main(): parser = argparse.ArgumentParser( description="Generate bindings from mojom files.") parser.add_argument("filename", nargs="+", help="mojom input file") - parser.add_argument("-i", "--include_dir", dest="include_dir", default=".", - help="include path for #includes") + parser.add_argument("-d", "--depth", dest="depth", default=".", + help="depth from source root") parser.add_argument("-o", "--output_dir", dest="output_dir", default=".", help="output directory for generated files") parser.add_argument("-g", "--generators", dest="generators_string", diff --git a/mojo/public/bindings/pylib/generate/mojom.py b/mojo/public/bindings/pylib/generate/mojom.py index 4e8ef13..7cb7518 100644 --- a/mojo/public/bindings/pylib/generate/mojom.py +++ b/mojo/public/bindings/pylib/generate/mojom.py @@ -166,6 +166,7 @@ class Enum(object): class Module(object): def __init__(self, name = None, namespace = None): self.name = name + self.path = name self.namespace = namespace self.structs = [] self.interfaces = [] diff --git a/mojo/public/bindings/pylib/generate/mojom_generator.py b/mojo/public/bindings/pylib/generate/mojom_generator.py index 1148764..cf3a84f 100644 --- a/mojo/public/bindings/pylib/generate/mojom_generator.py +++ b/mojo/public/bindings/pylib/generate/mojom_generator.py @@ -64,9 +64,9 @@ def ExpressionMapper(expression, mapper): class Generator(object): # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all # files to stdout. - def __init__(self, module, header_dir, output_dir=None): + def __init__(self, module, output_dir=None): self.module = module - self.header_dir = header_dir + self.header_dir = os.path.dirname(module.path); self.output_dir = output_dir def GetStructsFromMethods(self): diff --git a/mojo/public/bindings/tests/handle_passing_unittest.cc b/mojo/public/bindings/tests/handle_passing_unittest.cc index d49adf2..60e1d9b 100644 --- a/mojo/public/bindings/tests/handle_passing_unittest.cc +++ b/mojo/public/bindings/tests/handle_passing_unittest.cc @@ -4,10 +4,10 @@ #include "mojo/public/bindings/allocation_scope.h" #include "mojo/public/bindings/remote_ptr.h" +#include "mojo/public/bindings/tests/sample_factory.mojom.h" #include "mojo/public/environment/environment.h" #include "mojo/public/tests/test_utils.h" #include "mojo/public/utility/run_loop.h" -#include "mojom/sample_factory.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { diff --git a/mojo/public/bindings/tests/remote_ptr_unittest.cc b/mojo/public/bindings/tests/remote_ptr_unittest.cc index 4853ee0..b4f02cd 100644 --- a/mojo/public/bindings/tests/remote_ptr_unittest.cc +++ b/mojo/public/bindings/tests/remote_ptr_unittest.cc @@ -4,10 +4,10 @@ #include "mojo/public/bindings/error_handler.h" #include "mojo/public/bindings/remote_ptr.h" +#include "mojo/public/bindings/tests/math_calculator.mojom.h" +#include "mojo/public/bindings/tests/sample_service.mojom.h" #include "mojo/public/environment/environment.h" #include "mojo/public/utility/run_loop.h" -#include "mojom/math_calculator.h" -#include "mojom/sample_service.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { diff --git a/mojo/public/bindings/tests/sample_service_unittest.cc b/mojo/public/bindings/tests/sample_service_unittest.cc index 4c8a9a0..877f336 100644 --- a/mojo/public/bindings/tests/sample_service_unittest.cc +++ b/mojo/public/bindings/tests/sample_service_unittest.cc @@ -7,8 +7,8 @@ #include <string> #include "mojo/public/bindings/allocation_scope.h" +#include "mojo/public/bindings/tests/sample_service.mojom.h" #include "mojo/public/environment/environment.h" -#include "mojom/sample_service.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { diff --git a/mojo/public/bindings/tests/type_conversion_unittest.cc b/mojo/public/bindings/tests/type_conversion_unittest.cc index 723d036..49772e1 100644 --- a/mojo/public/bindings/tests/type_conversion_unittest.cc +++ b/mojo/public/bindings/tests/type_conversion_unittest.cc @@ -3,8 +3,8 @@ // found in the LICENSE file. #include "mojo/public/bindings/allocation_scope.h" +#include "mojo/public/bindings/tests/test_structs.mojom.h" #include "mojo/public/environment/environment.h" -#include "mojom/test_structs.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { diff --git a/mojo/public/shell/application.h b/mojo/public/shell/application.h index 34aac68..c4707c0 100644 --- a/mojo/public/shell/application.h +++ b/mojo/public/shell/application.h @@ -9,8 +9,8 @@ #include "mojo/public/bindings/remote_ptr.h" #include "mojo/public/shell/service.h" +#include "mojo/public/shell/shell.mojom.h" #include "mojo/public/system/core_cpp.h" -#include "mojom/shell.h" namespace mojo { diff --git a/mojo/public/shell/service.h b/mojo/public/shell/service.h index bd3b0af..490eef2 100644 --- a/mojo/public/shell/service.h +++ b/mojo/public/shell/service.h @@ -9,8 +9,8 @@ #include "mojo/public/bindings/error_handler.h" #include "mojo/public/bindings/remote_ptr.h" +#include "mojo/public/shell/shell.mojom.h" #include "mojo/public/system/core_cpp.h" -#include "mojom/shell.h" // Utility classes for creating ShellClients that vend service instances. // To use define a class that implements your specific server api, e.g. FooImpl diff --git a/mojo/public/shell/lib/shell.mojom b/mojo/public/shell/shell.mojom index 39eae78..39eae78 100644 --- a/mojo/public/shell/lib/shell.mojom +++ b/mojo/public/shell/shell.mojom |