process_headers.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Copyright 2024 Google LLC
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from waflib.TaskGen import before_method, feature
  15. from waflib import Context, Task
  16. from sdk_helpers import get_node_from_abspath
  17. @feature('headers')
  18. @before_method('make_lib_bundle')
  19. def process_headers(task_gen):
  20. """
  21. Process all of the headers specified in the wscript file, as well as the headers generated
  22. during the build process for the resource ids and message keys, as needed.
  23. Keyword arguments:
  24. includes -- A list of header files to copy
  25. :param task_gen: the task generator instance
  26. :return: None
  27. """
  28. header_nodes = task_gen.to_nodes(task_gen.includes)
  29. for platform in task_gen.env.TARGET_PLATFORMS:
  30. env = task_gen.bld.all_envs[platform]
  31. header_nodes.append(get_node_from_abspath(task_gen.bld, env['RESOURCE_ID_HEADER']))
  32. # Add .h file containing app message keys
  33. if 'MESSAGE_KEYS_HEADER' in dict(task_gen.env):
  34. header_nodes.append(
  35. get_node_from_abspath(task_gen.bld, task_gen.env['MESSAGE_KEYS_HEADER']))
  36. # Copy header files to build/include/<libname> to provide naming collision protection in
  37. # #includes
  38. lib_name = str(task_gen.env.PROJECT_INFO['name'])
  39. lib_include_node = task_gen.bld.path.get_bld().make_node('include').make_node(lib_name)
  40. target_nodes = []
  41. for header in header_nodes:
  42. base_node = (task_gen.bld.path.get_bld() if header.is_child_of(task_gen.bld.path.get_bld())
  43. else task_gen.bld.path)
  44. if header.is_child_of(base_node.find_node('include')):
  45. header_path = header.path_from(base_node.find_node('include'))
  46. else:
  47. header_path = header.path_from(base_node)
  48. target_node = lib_include_node.make_node(header_path)
  49. target_node.parent.mkdir()
  50. target_nodes.append(target_node)
  51. task_gen.includes = target_nodes
  52. task_gen.create_task('copy_headers', src=header_nodes, tgt=target_nodes)
  53. @Task.update_outputs
  54. class copy_headers(Task.Task):
  55. """
  56. Task class to copy specified headers from a source location to a target location
  57. """
  58. def run(self):
  59. """
  60. This method executes when the copy headers task runs
  61. :return: N/A
  62. """
  63. bld = self.generator.bld
  64. if len(self.inputs) != len(self.outputs):
  65. bld.fatal("Number of input headers ({}) does not match number of target headers ({})".
  66. format(len(self.inputs), len(self.outputs)))
  67. for i in range(len(self.inputs)):
  68. bld.cmd_and_log('cp "{src}" "{tgt}"'.
  69. format(src=self.inputs[i].abspath(), tgt=self.outputs[i].abspath()),
  70. quiet=Context.BOTH)