• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3# Copyright 2019 The Chromium Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# Replacement for the deprecated sysroot_ld_path.sh implementation in Chrome.
8"""
9Reads etc/ld.so.conf and/or etc/ld.so.conf.d/*.conf and returns the
10appropriate linker flags.
11"""
12
13from __future__ import print_function
14import argparse
15import glob
16import os
17import sys
18
19LD_SO_CONF_REL_PATH = "etc/ld.so.conf"
20LD_SO_CONF_D_REL_PATH = "etc/ld.so.conf.d"
21
22
23def parse_args(args):
24    p = argparse.ArgumentParser(__doc__)
25    p.add_argument('sysroot_path', nargs=1, help='Path to sysroot root folder')
26    return os.path.abspath(p.parse_args(args).sysroot_path[0])
27
28
29def process_entry(sysroot_path, entry):
30    assert (entry.startswith('/'))
31    print(os.path.join(sysroot_path, entry.strip()[1:]))
32
33def process_ld_conf_file(sysroot_path, conf_file_path):
34    with open(conf_file_path, 'r') as f:
35        for line in f.readlines():
36            if line.startswith('#'):
37                continue
38            process_entry(sysroot_path, line)
39
40
41def process_ld_conf_folder(sysroot_path, ld_conf_path):
42    files = glob.glob(os.path.join(ld_conf_path, '*.conf'))
43    for file in files:
44        process_ld_conf_file(sysroot_path, file)
45
46
47def process_ld_conf_files(sysroot_path):
48    conf_path = os.path.join(sysroot_path, LD_SO_CONF_REL_PATH)
49    conf_d_path = os.path.join(sysroot_path, LD_SO_CONF_D_REL_PATH)
50
51    if os.path.isdir(conf_path):
52        process_ld_conf_folder(sysroot_path, conf_path)
53    elif os.path.isdir(conf_d_path):
54        process_ld_conf_folder(sysroot_path, conf_d_path)
55
56
57def main(args):
58    sysroot_path = parse_args(args)
59    process_ld_conf_files(sysroot_path)
60
61
62if __name__ == '__main__':
63    try:
64        sys.exit(main(sys.argv[1:]))
65    except Exception as e:
66        sys.stderr.write(str(e) + '\n')
67        sys.exit(1)
68