| 25 | |
| 26 | # Rebuild addons in parallel. |
| 27 | def rebuild_addons(args): |
| 28 | headers_dir = os.path.abspath(args.headers_dir) |
| 29 | out_dir = os.path.abspath(args.out_dir) |
| 30 | node_bin = os.path.join(out_dir, 'node') |
| 31 | if args.is_win: |
| 32 | node_bin += '.exe' |
| 33 | |
| 34 | if os.path.isabs(args.node_gyp): |
| 35 | node_gyp = args.node_gyp |
| 36 | else: |
| 37 | node_gyp = os.path.join(ROOT_DIR, args.node_gyp) |
| 38 | |
| 39 | # Copy node.lib. |
| 40 | if args.is_win: |
| 41 | node_lib_dir = os.path.join(headers_dir, args.config) |
| 42 | os.makedirs(node_lib_dir) |
| 43 | shutil.copy2(os.path.join(args.out_dir, 'node.lib'), |
| 44 | os.path.join(node_lib_dir, 'node.lib')) |
| 45 | |
| 46 | def node_gyp_rebuild(test_dir): |
| 47 | print('Building addon in', test_dir) |
| 48 | try: |
| 49 | process = subprocess.Popen([ |
| 50 | node_bin, |
| 51 | node_gyp, |
| 52 | 'rebuild', |
| 53 | '--directory', test_dir, |
| 54 | '--nodedir', headers_dir, |
| 55 | '--python', sys.executable, |
| 56 | '--loglevel', args.loglevel, |
| 57 | ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 58 | |
| 59 | # We buffer the output and print it out once the process is done in order |
| 60 | # to avoid interleaved output from multiple builds running at once. |
| 61 | stdout, stderr = process.communicate() |
| 62 | return_code = process.returncode |
| 63 | if return_code != 0: |
| 64 | print(f'Failed to build addon in {test_dir}:') |
| 65 | if stdout: |
| 66 | print(stdout.decode()) |
| 67 | if stderr: |
| 68 | print(stderr.decode()) |
| 69 | return return_code |
| 70 | |
| 71 | except Exception as e: |
| 72 | print(f'Unexpected error when building addon in {test_dir}. Error: {e}') |
| 73 | |
| 74 | test_dirs = [] |
| 75 | skip_tests = args.skip_tests.split(',') |
| 76 | only_tests = args.only_tests.split(',') if args.only_tests else None |
| 77 | for child_dir in os.listdir(args.target): |
| 78 | full_path = os.path.join(args.target, child_dir) |
| 79 | if not os.path.isdir(full_path): |
| 80 | continue |
| 81 | if 'binding.gyp' not in os.listdir(full_path): |
| 82 | continue |
| 83 | if child_dir in skip_tests: |
| 84 | continue |