1#
2# Copyright 2024, The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from abc import ABC
17
18
19class OptimizedBuildTarget(ABC):
20  """A representation of an optimized build target.
21
22  This class will determine what targets to build given a given build_cotext and
23  will have a packaging function to generate any necessary output zips for the
24  build.
25  """
26
27  def __init__(self, build_context, args):
28    self.build_context = build_context
29    self.args = args
30
31  def get_build_targets(self):
32    pass
33
34  def package_outputs(self):
35    pass
36
37
38class NullOptimizer(OptimizedBuildTarget):
39  """No-op target optimizer.
40
41  This will simply build the same target it was given and do nothing for the
42  packaging step.
43  """
44
45  def __init__(self, target):
46    self.target = target
47
48  def get_build_targets(self):
49    return {self.target}
50
51  def package_outputs(self):
52    pass
53
54
55def get_target_optimizer(target, enabled_flag, build_context, optimizer):
56  if enabled_flag in build_context['enabled_build_features']:
57    return optimizer
58
59  return NullOptimizer(target)
60
61
62# To be written as:
63#    'target': lambda target, build_context, args: get_target_optimizer(
64#        target,
65#        'target_enabled_flag',
66#        build_context,
67#        TargetOptimizer(build_context, args),
68#    )
69OPTIMIZED_BUILD_TARGETS = dict()
70