@@ -282,7 +282,8 @@ def read_args(args):
282
282
sdk_dir = dev_path + 'Platforms/MacOSX.platform/Developer/SDKs'
283
283
libclang = lib_dir + 'libclang.dylib'
284
284
285
- if os .path .exists (libclang ):
285
+ # if os.path.exists(libclang):
286
+ if cindex .Config .library_path is None and os .path .exists (libclang ):
286
287
cindex .Config .set_library_path (os .path .dirname (libclang ))
287
288
288
289
if os .path .exists (sdk_dir ):
@@ -297,7 +298,8 @@ def read_args(args):
297
298
else :
298
299
raise FileNotFoundError ("Failed to find libclang.dll! "
299
300
"Set the LIBCLANG_PATH environment variable to provide a path to it." )
300
- else :
301
+ # else:
302
+ elif cindex .Config .library_path is None :
301
303
library_file = ctypes .util .find_library ('libclang.dll' )
302
304
if library_file is not None :
303
305
cindex .Config .set_library_file (library_file )
@@ -318,7 +320,8 @@ def folder_version(d):
318
320
# Ability to override LLVM/libclang paths
319
321
if 'LLVM_DIR_PATH' in os .environ :
320
322
llvm_dir = os .environ ['LLVM_DIR_PATH' ]
321
- elif llvm_dir is None :
323
+ elif llvm_dir is None and cindex .Config .library_path is None :
324
+ # elif llvm_dir is None:
322
325
raise FileNotFoundError (
323
326
"Failed to find a LLVM installation providing the file "
324
327
"/usr/lib{32,64}/llvm-{VER}/lib/libclang.so.1. Make sure that "
@@ -331,11 +334,16 @@ def folder_version(d):
331
334
"variables." )
332
335
333
336
if 'LIBCLANG_PATH' in os .environ :
334
- libclang_dir = os .environ ['LIBCLANG_PATH' ]
335
- else :
336
- libclang_dir = os .path .join (llvm_dir , 'lib' , 'libclang.so.1' )
337
+ # libclang_dir = os.environ['LIBCLANG_PATH']
338
+ # else:
339
+ # libclang_dir = os.path.join(llvm_dir, 'lib', 'libclang.so.1')
340
+ cindex .Config .set_library_file (os .environ ['LIBCLANG_PATH' ])
341
+ elif cindex .Config .library_path is None :
342
+ cindex .Config .set_library_file (os .path .join (llvm_dir , 'lib' ,
343
+ 'libclang.so.1' ))
344
+
337
345
338
- cindex .Config .set_library_file (libclang_dir )
346
+ # cindex.Config.set_library_file(libclang_dir)
339
347
cpp_dirs = [ ]
340
348
341
349
if '-stdlib=libc++' not in args :
@@ -347,11 +355,17 @@ def folder_version(d):
347
355
glob ('/usr/include/%s-linux-gnu/c++/*' % platform .machine ()
348
356
), default = None , key = folder_version ))
349
357
else :
358
+ if llvm_dir is None :
359
+ raise FileNotFoundError (
360
+ "-stdlib=libc++ has been specified, but no LLVM "
361
+ "installation have been found on the system." )
362
+
350
363
cpp_dirs .append (os .path .join (llvm_dir , 'include' , 'c++' , 'v1' ))
351
364
352
365
if 'CLANG_INCLUDE_DIR' in os .environ :
353
366
cpp_dirs .append (os .environ ['CLANG_INCLUDE_DIR' ])
354
- else :
367
+ # else:
368
+ elif llvm_dir is not None :
355
369
cpp_dirs .append (max (
356
370
glob (os .path .join (llvm_dir , 'lib' , 'clang' , '*' , 'include' )
357
371
), default = None , key = folder_version ))
@@ -441,6 +455,60 @@ def write_header(comments, out_file=sys.stdout):
441
455
''' , file = out_file )
442
456
443
457
458
+ def write_header2 (comments , out_file = sys .stdout ):
459
+ print ('''/*
460
+ This file contains docstrings for use in the Python bindings.
461
+ Do not edit! They were automatically extracted by pybind11_mkdoc.
462
+ */
463
+
464
+ #define stringify_literal( x ) # x
465
+ #define QUOTE( x ) stringify_literal( x )
466
+ #define __EXPAND(x) x
467
+ #define __COUNT(_1, _2, _3, _4, _5, _6, _7, COUNT, ...) COUNT
468
+ #define __VA_SIZE(...) __EXPAND(__COUNT(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0))
469
+ #define __CAT1(a, b) a ## b
470
+ #define __CAT2(a, b) __CAT1(a, b)
471
+ #define __DOC1(n1) __doc_##n1
472
+ #define __DOC2(n1, n2) __doc_##n1##_##n2
473
+ #define __DOC3(n1, n2, n3) __doc_##n1##_##n2##_##n3
474
+ #define __DOC4(n1, n2, n3, n4) __doc_##n1##_##n2##_##n3##_##n4
475
+ #define __DOC5(n1, n2, n3, n4, n5) __doc_##n1##_##n2##_##n3##_##n4##_##n5
476
+ #define __DOC6(n1, n2, n3, n4, n5, n6) __doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6
477
+ #define __DOC7(n1, n2, n3, n4, n5, n6, n7) __doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7
478
+ #define DOC(...) get_docs(QUOTE(__EXPAND(__EXPAND(__CAT2(__DOC, __VA_SIZE(__VA_ARGS__)))(__VA_ARGS__))))
479
+
480
+ #if defined(__GNUG__)
481
+ #pragma GCC diagnostic push
482
+ #pragma GCC diagnostic ignored "-Wunused-variable"
483
+ #endif
484
+
485
+ #include <map>
486
+ #include <string>
487
+
488
+ const char * get_docs(const std::string & key) {
489
+ static std::map<const std::string, const char *> docs{
490
+ ''' , file = out_file )
491
+
492
+ name_ctr = 1
493
+ name_prev = None
494
+ for name , _ , comment in list (sorted (comments , key = lambda x : (x [0 ], x [1 ]))):
495
+ if name == name_prev :
496
+ name_ctr += 1
497
+ name = name + "_%i" % name_ctr
498
+ else :
499
+ name_prev = name
500
+ name_ctr = 1
501
+ # print('\n{"%s", R"doc(%s)doc"},' % (name, comment), file=out_file)
502
+ print ('''
503
+ };
504
+ return docs[key];
505
+ }
506
+ #if defined(__GNUG__)
507
+ #pragma GCC diagnostic pop
508
+ #endif
509
+ ''' , file = out_file )
510
+
511
+
444
512
def mkdoc (args , width , output = None ):
445
513
if width != None :
446
514
global docstring_width
0 commit comments