1+ <?php
2+
3+ /*
4+ - go through all zip files in the given dirs non recursively
5+ - read all the lib filenames from those zips
6+ - create mappings between lib filename and zip filename
7+
8+ Usage:
9+ php libmap.php [--pretty] path0 [ path1 ... ] > libmapping.json
10+ */
11+
12+
13+ /*$dirs = array(
14+ "C:\\tmp\\core_deps\\vc9\\x86",
15+ "C:\\tmp\\core_deps\\vc11\\x86",
16+ "C:\\tmp\\core_deps\\vc11\\x64",
17+ );*/
18+
19+ /*$dirs = array(
20+ "C:\\tmp\\libs",
21+ );*/
22+
23+ $ sopt = "p " ;
24+ $ lopt = array (
25+ "pretty " ,
26+ );
27+
28+ $ flags = 0 ;
29+ $ opt = getopt ($ sopt , $ lopt );
30+ foreach ($ opt as $ name => $ val ) {
31+ switch ($ name ) {
32+ case "p " :
33+ case "pretty " :
34+ $ flags = JSON_PRETTY_PRINT ;
35+ break ;
36+ }
37+ }
38+
39+
40+ $ dirs = array ();
41+ foreach (array_slice ($ _SERVER ["argv " ], (0 == $ flags ? 1 : 2 )) as $ item ) {
42+ if (file_exists ($ item ) && is_dir ($ item )) {
43+ $ dirs [] = $ item ;
44+ }
45+ }
46+
47+ if (empty ($ dirs )) {
48+ echo "Nothing to do \n" ;
49+ die;
50+ }
51+
52+ $ out = array ();
53+
54+ foreach ($ dirs as $ path ) {
55+ $ dir = new DirectoryIterator ($ path );
56+ foreach ($ dir as $ fileinfo ) {
57+ if ($ fileinfo ->isDot () || $ fileinfo ->isDir ()) {
58+ continue ;
59+ }
60+
61+ $ pathname = $ fileinfo ->getPathname ();
62+ $ filename = $ fileinfo ->getFilename ();
63+
64+ if (substr ($ filename , -3 ) != "zip " ) {
65+ continue ;
66+ }
67+
68+ if (!preg_match (",.*-(v[c|s]\d+)-(x\d\d)\.zip, " , $ filename , $ m )) {
69+ continue ;
70+ }
71+
72+ $ crt = $ m [1 ];
73+ $ arch = $ m [2 ];
74+
75+ if (!isset ($ out [$ crt ])) {
76+ $ out [$ crt ] = array ();
77+ }
78+ if (!isset ($ out [$ crt ][$ arch ])) {
79+ $ out [$ crt ][$ arch ] = array ();
80+ }
81+
82+ $ zip = new ZipArchive ();
83+
84+ $ zip ->open ($ pathname );
85+
86+ $ libs = array ();
87+
88+ for ($ i = 0 ; $ i < $ zip ->numFiles ; $ i ++) {
89+ $ stat = $ zip ->statIndex ($ i );
90+
91+ if (substr ($ stat ['name ' ], -3 ) != "lib " ) {
92+ continue ;
93+ }
94+
95+ $ libs [] = basename ($ stat ['name ' ]);
96+ }
97+
98+ $ zip ->close ();
99+ unset($ zip );
100+
101+
102+ if (!empty ($ libs )) {
103+ $ out [$ crt ][$ arch ][$ filename ] = $ libs ;
104+ }
105+ }
106+ }
107+
108+ echo json_encode ($ out , $ flags );
109+
110+ /*
111+ * Local variables:
112+ * tab-width: 4
113+ * c-basic-offset: 4
114+ * End:
115+ * vim600: sw=4 ts=4 fdm=marker
116+ * vim<600: sw=4 ts=4
117+ */
0 commit comments