File tree Expand file tree Collapse file tree 5 files changed +68
-8
lines changed Expand file tree Collapse file tree 5 files changed +68
-8
lines changed Original file line number Diff line number Diff line change @@ -12,5 +12,6 @@ dependencies = [
1212 " readthedocs-sphinx-ext" ,
1313 " absl-py" ,
1414 " typing-extensions" ,
15- " sphinx-reredirects"
15+ " sphinx-reredirects" ,
16+ " pefile"
1617]
Original file line number Diff line number Diff line change @@ -111,9 +111,9 @@ colorama==0.4.6 ; sys_platform == 'win32' \
111111 --hash =sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44 \
112112 --hash =sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6
113113 # via sphinx
114- docutils == 0.22 \
115- --hash =sha256:4ed966a0e96a0477d852f7af31bdcb3adc049fbb35ccba358c2ea8a03287615e \
116- --hash =sha256:ba9d57750e92331ebe7c08a1bbf7a7f8143b86c476acd51528b042216a6aad0f
114+ docutils == 0.21.2 \
115+ --hash =sha256:3a6b18732edf182daa3cd12775bbb338cf5691468f91eeeb109deff6ebfa986f \
116+ --hash =sha256:dafca5b9e384f0e419294eb4d2ff9fa826435bf15f15b7bd45723e8ad76811b2
117117 # via
118118 # myst-parser
119119 # sphinx
@@ -232,6 +232,10 @@ packaging==25.0 \
232232 # via
233233 # readthedocs-sphinx-ext
234234 # sphinx
235+ pefile == 2024.8.26 \
236+ --hash =sha256:3ff6c5d8b43e8c37bb6e6dd5085658d658a7a0bdcd20b6a07b1fcfc1c4e9d632 \
237+ --hash =sha256:76f8b485dcd3b1bb8166f1128d395fa3d87af26360c2358fb75b80019b957c6f
238+ # via rules-python-docs (docs/pyproject.toml)
235239pygments == 2.19.2 \
236240 --hash =sha256:636cb2477cec7f8952536970bc533bc43743542f70392ae026374600add5b887 \
237241 --hash =sha256:86540386c03d588bb81d44bc3928634ff26449851e99741617ecb9037ee5ec0b
Original file line number Diff line number Diff line change 1414
1515load ("@rules_cc//cc:cc_binary.bzl" , "cc_binary" )
1616load ("@rules_shell//shell:sh_test.bzl" , "sh_test" )
17+ load ("//python:py_test.bzl" , "py_test" )
1718load (":current_py_cc_headers_tests.bzl" , "current_py_cc_headers_test_suite" )
1819
1920current_py_cc_headers_test_suite (name = "current_py_cc_headers_tests" )
@@ -28,9 +29,20 @@ cc_binary(
2829 ],
2930)
3031
31- sh_test (
32- name = "abi3_headers_linkage_test" ,
33- srcs = ["abi3_headers_linkage_test.sh" ],
32+ #sh_test(
33+ # name = "abi3_headers_linkage_test",
34+ # srcs = ["abi3_headers_linkage_test.sh"],
35+ # data = [":bin_abi3"],
36+ # deps = ["@bazel_tools//tools/bash/runfiles"],
37+ #)
38+
39+ py_test (
40+ name = "abi3_headers_linkage_test_py" ,
41+ srcs = ["abi3_headers_linkage_test.py" ],
3442 data = [":bin_abi3" ],
35- deps = ["@bazel_tools//tools/bash/runfiles" ],
43+ main = "abi3_headers_linkage_test.py" ,
44+ deps = [
45+ "//python/runfiles" ,
46+ "@dev_pip//pefile" ,
47+ ],
3648)
Original file line number Diff line number Diff line change 1+
2+ import os .path
3+ import sys
4+ import pefile
5+ import unittest
6+
7+ class CheckLinkageTest (unittest .TestCase ):
8+ def test_linkage (self ):
9+
10+ file_path = rf .Rlocation ("_main/tests/cc/current_py_cc_headers/libbin_abi3.dll" )
11+ if not file_path :
12+ self .fail ("dll not found" )
13+
14+ print (f"[*] Analyzing dependencies for: { os .path .basename (file_path )} \n " )
15+
16+ try :
17+ # Parse the PE file
18+ pe = pefile .PE (file_path )
19+
20+ if not hasattr (pe , 'DIRECTORY_ENTRY_IMPORT' ):
21+ print ("[!] No import directory found. The file may not have dependencies or is packed." )
22+ raise Exception ("no deps?" )
23+
24+ print ("Imported DLLs:" )
25+
26+ # Iterate over the import directory entries
27+ # Each 'entry' corresponds to one imported DLL
28+ for entry in pe .DIRECTORY_ENTRY_IMPORT :
29+ # entry.dll is a bytes string, so we decode it to utf-8
30+ dll_name = entry .dll .decode ('utf-8' )
31+ print (f" - { dll_name } " )
32+
33+ except pefile .PEFormatError as e :
34+ print (f"Error: Not a valid PE file (DLL/EXE). \n Details: { e } " )
35+ except Exception as e :
36+ print (f"An unexpected error occurred: { e } " )
37+
38+ raise Exception ("done" )
39+
40+ if __name__ == "__main__" :
41+ unittest .main ()
Original file line number Diff line number Diff line change @@ -20,4 +20,6 @@ lib=$(rlocation _main/tests/cc/current_py_cc_headers/libbin_abi3.so)
2020dumpbin /nologo /DEPENDENTS " $lib "
2121dumpbin.exe /nologo /DEPENDENTS " $lib "
2222
23+ ls
24+
2325exit 1
You can’t perform that action at this time.
0 commit comments