diff --git a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn --- a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn @@ -327,13 +327,6 @@ "LLVM_DEFAULT_TARGET_TRIPLE=$llvm_target_triple", "LLVM_HAS_ATOMICS=1", "LLVM_HOST_TRIPLE=$llvm_current_triple", - "LLVM_NATIVE_ARCH=$native_target", - "LLVM_NATIVE_ASMPARSER=1", - "LLVM_NATIVE_ASMPRINTER=1", - "LLVM_NATIVE_DISASSEMBLER=1", - "LLVM_NATIVE_TARGET=1", - "LLVM_NATIVE_TARGETINFO=1", - "LLVM_NATIVE_TARGETMC=1", "LLVM_USE_INTEL_JITEVENTS=", "LLVM_USE_OPROFILE=", "LLVM_USE_PERF=", @@ -342,8 +335,29 @@ "LLVM_VERSION_PATCH=$llvm_version_patch", "PACKAGE_VERSION=${llvm_version}svn", "LLVM_FORCE_ENABLE_STATS=", + "LLVM_NATIVE_ARCH=$native_target", ] + if (llvm_build_native_target) { + values += [ + "LLVM_NATIVE_ASMPARSER=1", + "LLVM_NATIVE_ASMPRINTER=1", + "LLVM_NATIVE_DISASSEMBLER=1", + "LLVM_NATIVE_TARGET=1", + "LLVM_NATIVE_TARGETINFO=1", + "LLVM_NATIVE_TARGETMC=1", + ] + } else { + values += [ + "LLVM_NATIVE_ASMPARSER=", + "LLVM_NATIVE_ASMPRINTER=", + "LLVM_NATIVE_DISASSEMBLER=", + "LLVM_NATIVE_TARGET=", + "LLVM_NATIVE_TARGETINFO=", + "LLVM_NATIVE_TARGETMC=", + ] + } + if (current_os == "win") { values += [ "LLVM_ON_UNIX=" ] } else { diff --git a/llvm/utils/gn/secondary/llvm/lib/MC/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/MC/BUILD.gn --- a/llvm/utils/gn/secondary/llvm/lib/MC/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/lib/MC/BUILD.gn @@ -2,6 +2,7 @@ output_name = "LLVMMC" deps = [ "//llvm/include/llvm/Config:config", + "//llvm/lib/BinaryFormat", "//llvm/lib/DebugInfo/CodeView", "//llvm/lib/Support", ] diff --git a/llvm/utils/gn/secondary/llvm/lib/Target/targets.gni b/llvm/utils/gn/secondary/llvm/lib/Target/targets.gni --- a/llvm/utils/gn/secondary/llvm/lib/Target/targets.gni +++ b/llvm/utils/gn/secondary/llvm/lib/Target/targets.gni @@ -35,6 +35,19 @@ ] } +# FIXME: This should be based off target_cpu once cross compiles work. +if (host_cpu == "arm64") { + native_target = "AArch64" +} else if (host_cpu == "arm") { + native_target = "ARM" +} else if (host_cpu == "ppc" || host_cpu == "ppc64") { + native_target = "PowerPC" +} else if (host_cpu == "x86" || host_cpu == "x64") { + native_target = "X86" +} else { + assert(false, "Unsuppored host_cpu '$host_cpu'.") +} + # Validate that llvm_targets_to_build is set to a list of valid targets, # and remember which targets are built. llvm_build_AArch64 = false @@ -43,6 +56,7 @@ llvm_build_PowerPC = false llvm_build_WebAssembly = false llvm_build_X86 = false +llvm_build_native_target = false foreach(target, llvm_targets_to_build) { if (target == "AArch64") { llvm_build_AArch64 = true @@ -74,17 +88,8 @@ # FIXME: Port the remaining targets. assert(false, "Unknown target '$target'.") } -} -# FIXME: This should be based off target_cpu once cross compiles work. -if (host_cpu == "arm64") { - native_target = "AArch64" -} else if (host_cpu == "arm") { - native_target = "ARM" -} else if (host_cpu == "ppc" || host_cpu == "ppc64") { - native_target = "PowerPC" -} else if (host_cpu == "x86" || host_cpu == "x64") { - native_target = "X86" -} else { - assert(false, "Unsuppored host_cpu '$host_cpu'.") + if (target == native_target) { + llvm_build_native_target = true + } } diff --git a/llvm/utils/llvm-build/llvmbuild/main.py b/llvm/utils/llvm-build/llvmbuild/main.py --- a/llvm/utils/llvm-build/llvmbuild/main.py +++ b/llvm/utils/llvm-build/llvmbuild/main.py @@ -188,6 +188,32 @@ visit(c, depth + 1) visit(self.component_info_map['$ROOT']) + def gn_check(self): + from subprocess import check_output, CalledProcessError + from difflib import unified_diff + + def togn(c): + return "//llvm" + c.subpath + ":" + c.subpath.rsplit("/", 1)[1] + indent = lambda l: " " * 4 + l + + bypath = {v.subpath: v for v in self.component_info_map.values()} + + for name in sorted(bypath): + comp = bypath[name] + if not hasattr(comp, "required_libraries"): + continue + + print(togn(comp)) + + try: + cmd = "/usr/local/bin/gn desc /tmp/b {} deps".format(togn(comp)).split() + gndeps = sorted(check_output(cmd).strip().splitlines()) + except CalledProcessError, e: + print(indent(" had trouble..." + str(e))) + else: + lldeps = sorted(togn(self.component_info_map[req_]) for req_ in comp.required_libraries) + print("\n".join(indent(l) for l in unified_diff(lldeps, gndeps))) + def write_components(self, output_path): # Organize all the components by the directory their LLVMBuild file # should go in. @@ -808,7 +834,7 @@ 'Function.cpp')): parser.error('invalid LLVM source root: %r' % source_root) else: - llvmbuild_path = os.path.dirname(__file__) + llvmbuild_path = os.path.dirname(os.path.abspath(__file__)) llvm_build_path = os.path.dirname(llvmbuild_path) utils_path = os.path.dirname(llvm_build_path) source_root = os.path.dirname(utils_path) @@ -829,7 +855,7 @@ # Print the component tree, if requested. if opts.print_tree: - project_info.print_tree() + project_info.gn_check() # Write out the components, if requested. This is useful for auto-upgrading # the schema.