[llvm] 1e29766 - [CMake] Add Python script to generate version script symbol exports

Andrew Ng via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 18 05:48:30 PDT 2022


Author: Andrew Ng
Date: 2022-10-18T13:47:43+01:00
New Revision: 1e297663142028db81de6f8941185cd934f8507b

URL: https://github.com/llvm/llvm-project/commit/1e297663142028db81de6f8941185cd934f8507b
DIFF: https://github.com/llvm/llvm-project/commit/1e297663142028db81de6f8941185cd934f8507b.diff

LOG: [CMake] Add Python script to generate version script symbol exports

Using a Python script instead of the various shell commands means that
it is now possible to cross compile LLVM for Linux on Windows.

Differential Revision: https://reviews.llvm.org/D136092

Added: 
    llvm/utils/add_llvm_symbol_exports.py

Modified: 
    llvm/cmake/modules/AddLLVM.cmake

Removed: 
    


################################################################################
diff  --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 83fb25b400494..30ac0040e5650 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -103,11 +103,7 @@ function(add_llvm_symbol_exports target_name export_file)
     # FIXME: Don't write the "local:" line on OpenBSD.
     # in the export file, also add a linker script to version LLVM symbols (form: LLVM_N.M)
     add_custom_command(OUTPUT ${native_export_file}
-      COMMAND echo "LLVM_${LLVM_VERSION_MAJOR} {" > ${native_export_file}
-      COMMAND grep -q "[[:alnum:]]" ${export_file} && echo "  global:" >> ${native_export_file} || :
-      COMMAND sed -e "s/$/;/" -e "s/^/    /" < ${export_file} >> ${native_export_file}
-      COMMAND echo "  local: *;" >> ${native_export_file}
-      COMMAND echo "};" >> ${native_export_file}
+      COMMAND "${Python3_EXECUTABLE}" ${LLVM_MAIN_SRC_DIR}/utils/add_llvm_symbol_exports.py ${LLVM_VERSION_MAJOR} ${export_file} ${native_export_file}
       DEPENDS ${export_file}
       VERBATIM
       COMMENT "Creating export file for ${target_name}")

diff  --git a/llvm/utils/add_llvm_symbol_exports.py b/llvm/utils/add_llvm_symbol_exports.py
new file mode 100644
index 0000000000000..ed444cc45848d
--- /dev/null
+++ b/llvm/utils/add_llvm_symbol_exports.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+#===----------------------------------------------------------------------===##
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+#===----------------------------------------------------------------------===##
+
+import os
+import sys
+
+if (len(sys.argv) != 4):
+    print('usage: ' + sys.argv[0] + ' <LLVM major version> <input> <output>')
+    sys.exit(1)
+
+with open(sys.argv[3], 'w') as out_fd:
+    out_fd.write('LLVM_' + sys.argv[1] + ' {\n')
+    if os.stat(sys.argv[2]).st_size > 0:
+        out_fd.write('  global:\n')
+        with open(sys.argv[2], 'r') as in_fd:
+            for e in in_fd.readlines():
+                out_fd.write('    ' + e.rstrip() + ';\n')
+    out_fd.write('  local: *;\n};\n')
+
+sys.exit(0)


        


More information about the llvm-commits mailing list