1#===----------------------------------------------------------------------===## 2# 3# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4# See https://llvm.org/LICENSE.txt for license information. 5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6# 7#===----------------------------------------------------------------------===## 8 9def _getSubstitution(substitution, config): 10 for (orig, replacement) in config.substitutions: 11 if orig == substitution: 12 return replacement 13 raise ValueError('Substitution {} is not in the config.'.format(substitution)) 14 15def configure(parameters, features, config, lit_config): 16 # Apply the actions supplied by parameters to the configuration first, since 17 # parameters are things that we request explicitly and which might influence 18 # what features are implicitly made available next. 19 for param in parameters: 20 actions = param.getActions(config, lit_config.params) 21 for action in actions: 22 action.applyTo(config) 23 lit_config.note("Applied '{}' as a result of parameter '{}'".format( 24 action.pretty(config, lit_config.params), 25 param.pretty(config, lit_config.params))) 26 27 # Then, apply the automatically-detected features. 28 for feature in features: 29 actions = feature.getActions(config) 30 for action in actions: 31 action.applyTo(config) 32 lit_config.note("Applied '{}' as a result of implicitly detected feature '{}'".format( 33 action.pretty(config, lit_config.params), 34 feature.pretty(config))) 35 36 # Print the basic substitutions 37 for sub in ('%{cxx}', '%{flags}', '%{compile_flags}', '%{link_flags}', '%{exec}'): 38 lit_config.note("Using {} substitution: '{}'".format(sub, _getSubstitution(sub, config))) 39