llvm.org GIT mirror llvm / 68f9d72
Remove llvm-build's --configure-target-def-file. It was added 6.5 years ago in r144345, but was never hooked up and has been unused since. If _you_ do use this, feel free to revert, but add a comment on where it's used. https://reviews.llvm.org/D45262 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330455 91177308-0d34-0410-b5e6-96231b3b80d8 Nico Weber 2 years ago
2 changed file(s) with 1 addition(s) and 114 deletion(s). Raw diff Collapse all Expand all
+0
-66
utils/llvm-build/llvmbuild/configutil.py less more
None """
1 Defines utilities useful for performing standard "configuration" style tasks.
2 """
3
4 import re
5 import os
6
7 def configure_file(input_path, output_path, substitutions):
8 """configure_file(input_path, output_path, substitutions) -> bool
9
10 Given an input and output path, "configure" the file at the given input path
11 by replacing variables in the file with those given in the substitutions
12 list. Returns true if the output file was written.
13
14 The substitutions list should be given as a list of tuples (regex string,
15 replacement), where the regex and replacement will be used as in 're.sub' to
16 execute the variable replacement.
17
18 The output path's parent directory need not exist (it will be created).
19
20 If the output path does exist and the configured data is not different than
21 it's current contents, the output file will not be modified. This is
22 designed to limit the impact of configured files on build dependencies.
23 """
24
25 # Read in the input data.
26 f = open(input_path, "rb")
27 try:
28 data = f.read()
29 finally:
30 f.close()
31
32 # Perform the substitutions.
33 for regex_string,replacement in substitutions:
34 regex = re.compile(regex_string)
35 data = regex.sub(replacement, data)
36
37 # Ensure the output parent directory exists.
38 output_parent_path = os.path.dirname(os.path.abspath(output_path))
39 if not os.path.exists(output_parent_path):
40 os.makedirs(output_parent_path)
41
42 # If the output path exists, load it and compare to the configured contents.
43 if os.path.exists(output_path):
44 current_data = None
45 try:
46 f = open(output_path, "rb")
47 try:
48 current_data = f.read()
49 except:
50 current_data = None
51 f.close()
52 except:
53 current_data = None
54
55 if current_data is not None and current_data == data:
56 return False
57
58 # Write the output contents.
59 f = open(output_path, "wb")
60 try:
61 f.write(data)
62 finally:
63 f.close()
64
65 return True
33 import sys
44
55 import llvmbuild.componentinfo as componentinfo
6 import llvmbuild.configutil as configutil
76
87 from llvmbuild.util import fatal, note
98
375374 f.write("""\
376375 //===- llvm-build generated file --------------------------------*- C++ -*-===//
377376 //
378 // Component Library Depenedency Table
377 // Component Library Dependency Table
379378 //
380379 // Automatically generated file, do not edit!
381380 //
760759 help=(
761760 "If given, an alternate path to search for LLVMBuild.txt files"),
762761 action="store", default=None, metavar="PATH")
763 group.add_option("", "--build-root", dest="build_root", metavar="PATH",
764 help="Path to the build directory (if needed) [%default]",
765 action="store", default=None)
766762 parser.add_option_group(group)
767763
768764 group = OptionGroup(parser, "Output Options")
784780 dest="write_cmake_exports_fragment", metavar="PATH",
785781 help="Write the CMake exports information to PATH",
786782 action="store", default=None)
787 group.add_option("", "--configure-target-def-file",
788 dest="configure_target_def_files",
789 help="""Configure the given file at SUBPATH (relative to
790 the inferred or given source root, and with a '.in' suffix) by replacing certain
791 substitution variables with lists of targets that support certain features (for
792 example, targets with AsmPrinters) and write the result to the build root (as
793 given by --build-root) at the same SUBPATH""",
794 metavar="SUBPATH", action="append", default=None)
795783 parser.add_option_group(group)
796784
797785 group = OptionGroup(parser, "Configuration Options")
862850 project_info.write_cmake_exports_fragment(opts.write_cmake_exports_fragment,
863851 opts.optional_components)
864852
865 # Configure target definition files, if requested.
866 if opts.configure_target_def_files:
867 # Verify we were given a build root.
868 if not opts.build_root:
869 parser.error("must specify --build-root when using "
870 "--configure-target-def-file")
871
872 # Create the substitution list.
873 available_targets = [ci for ci in project_info.component_infos
874 if ci.type_name == 'TargetGroup']
875 substitutions = [
876 ("@LLVM_ENUM_TARGETS@",
877 ' '.join('LLVM_TARGET(%s)' % ci.name
878 for ci in available_targets)),
879 ("@LLVM_ENUM_ASM_PRINTERS@",
880 ' '.join('LLVM_ASM_PRINTER(%s)' % ci.name
881 for ci in available_targets
882 if ci.has_asmprinter)),
883 ("@LLVM_ENUM_ASM_PARSERS@",
884 ' '.join('LLVM_ASM_PARSER(%s)' % ci.name
885 for ci in available_targets
886 if ci.has_asmparser)),
887 ("@LLVM_ENUM_DISASSEMBLERS@",
888 ' '.join('LLVM_DISASSEMBLER(%s)' % ci.name
889 for ci in available_targets
890 if ci.has_disassembler))]
891
892 # Configure the given files.
893 for subpath in opts.configure_target_def_files:
894 inpath = os.path.join(source_root, subpath + '.in')
895 outpath = os.path.join(opts.build_root, subpath)
896 result = configutil.configure_file(inpath, outpath, substitutions)
897 if not result:
898 note("configured file %r hasn't changed" % outpath)
899
900853 if __name__=='__main__':
901854 main()