def main(): from optparse import OptionParser, OptionGroup parser = OptionParser("usage: %prog [options]") group = OptionGroup(parser, "Input Options") group.add_option("", "--source-root", dest="source_root", metavar="PATH", help="Path to the LLVM source (inferred if not given)", action="store", default=None) group.add_option( "", "--llvmbuild-source-root", dest="llvmbuild_source_root", help=("If given, an alternate path to search for LLVMBuild.txt files"), action="store", default=None, metavar="PATH") group.add_option("", "--build-root", dest="build_root", metavar="PATH", help="Path to the build directory (if needed) [%default]", action="store", default=None) parser.add_option_group(group) group = OptionGroup(parser, "Output Options") group.add_option("", "--print-tree", dest="print_tree", help="Print out the project component tree [%default]", action="store_true", default=False) group.add_option("", "--write-llvmbuild", dest="write_llvmbuild", help="Write out the LLVMBuild.txt files to PATH", action="store", default=None, metavar="PATH") group.add_option("", "--write-library-table", dest="write_library_table", metavar="PATH", help="Write the C++ library dependency table to PATH", action="store", default=None) group.add_option("", "--write-cmake-fragment", dest="write_cmake_fragment", metavar="PATH", help="Write the CMake project information to PATH", action="store", default=None) group.add_option("", "--write-cmake-exports-fragment", dest="write_cmake_exports_fragment", metavar="PATH", help="Write the CMake exports information to PATH", action="store", default=None) group.add_option("", "--write-make-fragment", dest="write_make_fragment", metavar="PATH", help="Write the Makefile project information to PATH", action="store", default=None) group.add_option("", "--configure-target-def-file", dest="configure_target_def_files", help="""Configure the given file at SUBPATH (relative to the inferred or given source root, and with a '.in' suffix) by replacing certain substitution variables with lists of targets that support certain features (for example, targets with AsmPrinters) and write the result to the build root (as given by --build-root) at the same SUBPATH""", metavar="SUBPATH", action="append", default=None) parser.add_option_group(group) group = OptionGroup(parser, "Configuration Options") group.add_option("", "--native-target", dest="native_target", metavar="NAME", help=("Treat the named target as the 'native' one, if " "given [%default]"), action="store", default=None) group.add_option("", "--enable-targets", dest="enable_targets", metavar="NAMES", help=("Enable the given space or semi-colon separated " "list of targets, or all targets if not present"), action="store", default=None) group.add_option("", "--enable-optional-components", dest="optional_components", metavar="NAMES", help=("Enable the given space or semi-colon separated " "list of optional components"), action="store", default="") parser.add_option_group(group) (opts, args) = parser.parse_args() # Determine the LLVM source path, if not given. source_root = opts.source_root if source_root: if not os.path.exists( os.path.join(source_root, 'lib', 'IR', 'Function.cpp')): parser.error('invalid LLVM source root: %r' % source_root) else: llvmbuild_path = os.path.dirname(__file__) llvm_build_path = os.path.dirname(llvmbuild_path) utils_path = os.path.dirname(llvm_build_path) source_root = os.path.dirname(utils_path) if not os.path.exists( os.path.join(source_root, 'lib', 'IR', 'Function.cpp')): parser.error('unable to infer LLVM source root, please specify') # Construct the LLVM project information. llvmbuild_source_root = opts.llvmbuild_source_root or source_root project_info = LLVMProjectInfo.load_from_path(source_root, llvmbuild_source_root) # Add the magic target based components. add_magic_target_components(parser, project_info, opts) # Validate the project component info. project_info.validate_components() # Print the component tree, if requested. if opts.print_tree: project_info.print_tree() # Write out the components, if requested. This is useful for auto-upgrading # the schema. if opts.write_llvmbuild: project_info.write_components(opts.write_llvmbuild) # Write out the required library table, if requested. if opts.write_library_table: project_info.write_library_table(opts.write_library_table, opts.optional_components) # Write out the make fragment, if requested. if opts.write_make_fragment: project_info.write_make_fragment(opts.write_make_fragment, opts.optional_components) # Write out the cmake fragment, if requested. if opts.write_cmake_fragment: project_info.write_cmake_fragment(opts.write_cmake_fragment, opts.optional_components) if opts.write_cmake_exports_fragment: project_info.write_cmake_exports_fragment( opts.write_cmake_exports_fragment, opts.optional_components) # Configure target definition files, if requested. if opts.configure_target_def_files: # Verify we were given a build root. if not opts.build_root: parser.error("must specify --build-root when using " "--configure-target-def-file") # Create the substitution list. available_targets = [ ci for ci in project_info.component_infos if ci.type_name == 'TargetGroup' ] substitutions = [ ("@LLVM_ENUM_TARGETS@", ' '.join('LLVM_TARGET(%s)' % ci.name for ci in available_targets)), ("@LLVM_ENUM_ASM_PRINTERS@", ' '.join('LLVM_ASM_PRINTER(%s)' % ci.name for ci in available_targets if ci.has_asmprinter)), ("@LLVM_ENUM_ASM_PARSERS@", ' '.join('LLVM_ASM_PARSER(%s)' % ci.name for ci in available_targets if ci.has_asmparser)), ("@LLVM_ENUM_DISASSEMBLERS@", ' '.join('LLVM_DISASSEMBLER(%s)' % ci.name for ci in available_targets if ci.has_disassembler)) ] # Configure the given files. for subpath in opts.configure_target_def_files: inpath = os.path.join(source_root, subpath + '.in') outpath = os.path.join(opts.build_root, subpath) result = configutil.configure_file(inpath, outpath, substitutions) if not result: note("configured file %r hasn't changed" % outpath)
def main(): from optparse import OptionParser, OptionGroup parser = OptionParser("usage: %prog [options]") group = OptionGroup(parser, "Input Options") group.add_option("", "--source-root", dest="source_root", metavar="PATH", help="Path to the LLVM source (inferred if not given)", action="store", default=None) group.add_option("", "--llvmbuild-source-root", dest="llvmbuild_source_root", help=( "If given, an alternate path to search for LLVMBuild.txt files"), action="store", default=None, metavar="PATH") group.add_option("", "--build-root", dest="build_root", metavar="PATH", help="Path to the build directory (if needed) [%default]", action="store", default=None) parser.add_option_group(group) group = OptionGroup(parser, "Output Options") group.add_option("", "--print-tree", dest="print_tree", help="Print out the project component tree [%default]", action="store_true", default=False) group.add_option("", "--write-llvmbuild", dest="write_llvmbuild", help="Write out the LLVMBuild.txt files to PATH", action="store", default=None, metavar="PATH") group.add_option("", "--write-library-table", dest="write_library_table", metavar="PATH", help="Write the C++ library dependency table to PATH", action="store", default=None) group.add_option("", "--write-cmake-fragment", dest="write_cmake_fragment", metavar="PATH", help="Write the CMake project information to PATH", action="store", default=None) group.add_option("", "--write-cmake-exports-fragment", dest="write_cmake_exports_fragment", metavar="PATH", help="Write the CMake exports information to PATH", action="store", default=None) group.add_option("", "--write-make-fragment", dest="write_make_fragment", metavar="PATH", help="Write the Makefile project information to PATH", action="store", default=None) group.add_option("", "--configure-target-def-file", dest="configure_target_def_files", help="""Configure the given file at SUBPATH (relative to the inferred or given source root, and with a '.in' suffix) by replacing certain substitution variables with lists of targets that support certain features (for example, targets with AsmPrinters) and write the result to the build root (as given by --build-root) at the same SUBPATH""", metavar="SUBPATH", action="append", default=None) parser.add_option_group(group) group = OptionGroup(parser, "Configuration Options") group.add_option("", "--native-target", dest="native_target", metavar="NAME", help=("Treat the named target as the 'native' one, if " "given [%default]"), action="store", default=None) group.add_option("", "--enable-targets", dest="enable_targets", metavar="NAMES", help=("Enable the given space or semi-colon separated " "list of targets, or all targets if not present"), action="store", default=None) group.add_option("", "--enable-optional-components", dest="optional_components", metavar="NAMES", help=("Enable the given space or semi-colon separated " "list of optional components"), action="store", default="") parser.add_option_group(group) (opts, args) = parser.parse_args() # Determine the LLVM source path, if not given. source_root = opts.source_root if source_root: if not os.path.exists(os.path.join(source_root, 'lib', 'IR', 'Function.cpp')): parser.error('invalid LLVM source root: %r' % source_root) else: llvmbuild_path = os.path.dirname(__file__) llvm_build_path = os.path.dirname(llvmbuild_path) utils_path = os.path.dirname(llvm_build_path) source_root = os.path.dirname(utils_path) if not os.path.exists(os.path.join(source_root, 'lib', 'IR', 'Function.cpp')): parser.error('unable to infer LLVM source root, please specify') # Construct the LLVM project information. llvmbuild_source_root = opts.llvmbuild_source_root or source_root project_info = LLVMProjectInfo.load_from_path( source_root, llvmbuild_source_root) # Add the magic target based components. add_magic_target_components(parser, project_info, opts) # Validate the project component info. project_info.validate_components() # Print the component tree, if requested. if opts.print_tree: project_info.print_tree() # Write out the components, if requested. This is useful for auto-upgrading # the schema. if opts.write_llvmbuild: project_info.write_components(opts.write_llvmbuild) # Write out the required library table, if requested. if opts.write_library_table: project_info.write_library_table(opts.write_library_table, opts.optional_components) # Write out the make fragment, if requested. if opts.write_make_fragment: project_info.write_make_fragment(opts.write_make_fragment) # Write out the cmake fragment, if requested. if opts.write_cmake_fragment: project_info.write_cmake_fragment(opts.write_cmake_fragment, opts.optional_components) if opts.write_cmake_exports_fragment: project_info.write_cmake_exports_fragment(opts.write_cmake_exports_fragment, opts.optional_components) # Configure target definition files, if requested. if opts.configure_target_def_files: # Verify we were given a build root. if not opts.build_root: parser.error("must specify --build-root when using " "--configure-target-def-file") # Create the substitution list. available_targets = [ci for ci in project_info.component_infos if ci.type_name == 'TargetGroup'] substitutions = [ ("@LLVM_ENUM_TARGETS@", ' '.join('LLVM_TARGET(%s)' % ci.name for ci in available_targets)), ("@LLVM_ENUM_ASM_PRINTERS@", ' '.join('LLVM_ASM_PRINTER(%s)' % ci.name for ci in available_targets if ci.has_asmprinter)), ("@LLVM_ENUM_ASM_PARSERS@", ' '.join('LLVM_ASM_PARSER(%s)' % ci.name for ci in available_targets if ci.has_asmparser)), ("@LLVM_ENUM_DISASSEMBLERS@", ' '.join('LLVM_DISASSEMBLER(%s)' % ci.name for ci in available_targets if ci.has_disassembler))] # Configure the given files. for subpath in opts.configure_target_def_files: inpath = os.path.join(source_root, subpath + '.in') outpath = os.path.join(opts.build_root, subpath) result = configutil.configure_file(inpath, outpath, substitutions) if not result: note("configured file %r hasn't changed" % outpath)