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