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 9import os 10 11 12def _getSubstitution(substitution, config): 13 for (orig, replacement) in config.substitutions: 14 if orig == substitution: 15 return replacement 16 raise ValueError("Substitution {} is not in the config.".format(substitution)) 17 18 19def configure(parameters, features, config, lit_config): 20 note = lambda s: lit_config.note("({}) {}".format(config.name, s)) 21 config.environment = dict(os.environ) 22 23 # Apply the actions supplied by parameters to the configuration first, since 24 # parameters are things that we request explicitly and which might influence 25 # what features are implicitly made available next. 26 for param in parameters: 27 actions = param.getActions(config, lit_config.params) 28 for action in actions: 29 action.applyTo(config) 30 if lit_config.debug: 31 note( 32 "Applied '{}' as a result of parameter '{}'".format( 33 action.pretty(config, lit_config.params), 34 param.pretty(config, lit_config.params), 35 ) 36 ) 37 38 # Then, apply the automatically-detected features. 39 for feature in features: 40 actions = feature.getActions(config) 41 for action in actions: 42 action.applyTo(config) 43 if lit_config.debug: 44 note( 45 "Applied '{}' as a result of implicitly detected feature '{}'".format( 46 action.pretty(config, lit_config.params), feature.pretty(config) 47 ) 48 ) 49 50 # Print the basic substitutions 51 for sub in ("%{cxx}", "%{flags}", "%{compile_flags}", "%{link_flags}", "%{exec}"): 52 note("Using {} substitution: '{}'".format(sub, _getSubstitution(sub, config))) 53 54 # Print all available features 55 note("All available features: {}".format(", ".join(sorted(config.available_features)))) 56