• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2
3# Copyright (C) 2022 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#   http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16"""Generate queryview xml data for testing purposes."""
17
18import xml.etree.ElementTree as ElementTree
19
20
21def make_module(full_name,
22                name,
23                kind,
24                variant='',
25                dep_names=[],
26                soong_module_type=None,
27                srcs=None):
28  rule = ElementTree.Element('rule', attrib={'class': kind, 'name': full_name})
29  ElementTree.SubElement(
30      rule, 'string', attrib={
31          'name': 'soong_module_name',
32          'value': name
33      })
34  ElementTree.SubElement(
35      rule, 'string', attrib={
36          'name': 'soong_module_variant',
37          'value': variant
38      })
39  if soong_module_type:
40    ElementTree.SubElement(
41        rule,
42        'string',
43        attrib={
44            'name': 'soong_module_type',
45            'value': soong_module_type
46        })
47  for dep in dep_names:
48    ElementTree.SubElement(rule, 'rule-input', attrib={'name': dep})
49
50  if not srcs:
51    return rule
52
53  src_element = ElementTree.SubElement(rule, 'list', attrib={'name': 'srcs'})
54  for src in srcs:
55    ElementTree.SubElement(src_element, 'string', attrib={'value': src})
56
57  return rule
58
59
60def make_graph(modules):
61  graph = ElementTree.Element('query', attrib={'version': '2'})
62  graph.extend(modules)
63  return graph
64