Add auxiliary eh_elfs directories
This commit is contained in:
parent
da05f6b9f1
commit
21dcd7969e
3 changed files with 50 additions and 27 deletions
|
@ -9,7 +9,7 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
from shared_python import elf_so_deps, readlink_rec
|
from shared_python import elf_so_deps, readlink_rec, DEFAULT_AUX_DIRS
|
||||||
|
|
||||||
|
|
||||||
''' An ELF object, including the path to the ELF itself, and the path to its
|
''' An ELF object, including the path to the ELF itself, and the path to its
|
||||||
|
@ -83,6 +83,11 @@ def objects_list(args):
|
||||||
|
|
||||||
out = []
|
out = []
|
||||||
|
|
||||||
|
eh_elfs_dirs = (
|
||||||
|
args.eh_elfs
|
||||||
|
+ ([] if args.no_dft_aux else DEFAULT_AUX_DIRS)
|
||||||
|
)
|
||||||
|
|
||||||
if args.deps:
|
if args.deps:
|
||||||
objects = set(args.object)
|
objects = set(args.object)
|
||||||
for obj in args.object:
|
for obj in args.object:
|
||||||
|
@ -95,7 +100,7 @@ def objects_list(args):
|
||||||
objects = list(map(readlink_rec, objects))
|
objects = list(map(readlink_rec, objects))
|
||||||
|
|
||||||
for obj in objects:
|
for obj in objects:
|
||||||
out.append(ElfObject(obj, matching_eh_elf(args.eh_elfs, obj)))
|
out.append(ElfObject(obj, matching_eh_elf(eh_elfs_dirs, obj)))
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
@ -115,6 +120,8 @@ def process_args():
|
||||||
parser.add_argument('--eh-elfs', required=True, action='append',
|
parser.add_argument('--eh-elfs', required=True, action='append',
|
||||||
help=("Indicate the directory in which eh_elfs are "
|
help=("Indicate the directory in which eh_elfs are "
|
||||||
"located"))
|
"located"))
|
||||||
|
parser.add_argument('-A', '--no-dft-aux', action='store_true',
|
||||||
|
help=("Do not use the default eh_elf locations"))
|
||||||
parser.add_argument('object', nargs='+',
|
parser.add_argument('object', nargs='+',
|
||||||
help="The ELF object(s) to process")
|
help="The ELF object(s) to process")
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
|
@ -13,7 +13,13 @@ import tempfile
|
||||||
import argparse
|
import argparse
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
from shared_python import elf_so_deps, do_remote, is_newer
|
from shared_python import \
|
||||||
|
elf_so_deps, \
|
||||||
|
do_remote, \
|
||||||
|
is_newer, \
|
||||||
|
to_eh_elf_path, \
|
||||||
|
find_eh_elf_dir, \
|
||||||
|
DEFAULT_AUX_DIRS
|
||||||
from extract_pc import generate_pc_list
|
from extract_pc import generate_pc_list
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,9 +40,7 @@ class SwitchGenPolicy(Enum):
|
||||||
class Config:
|
class Config:
|
||||||
''' Holds the run's settings '''
|
''' Holds the run's settings '''
|
||||||
|
|
||||||
default_aux = [
|
default_aux = DEFAULT_AUX_DIRS
|
||||||
'~/.cache/eh_elfs',
|
|
||||||
]
|
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
output,
|
output,
|
||||||
|
@ -137,25 +141,11 @@ def resolve_symlink_chain(objpath):
|
||||||
return (out_path, chain)
|
return (out_path, chain)
|
||||||
|
|
||||||
|
|
||||||
def to_eh_elf_path(so_path, out_dir, base=False):
|
|
||||||
''' Transform a library path into its eh_elf counterpart '''
|
|
||||||
base_path = os.path.basename(so_path) + '.eh_elf'
|
|
||||||
if base:
|
|
||||||
return base_path
|
|
||||||
return os.path.join(out_dir, base_path + '.so')
|
|
||||||
|
|
||||||
|
|
||||||
def find_out_dir(obj_path, config):
|
def find_out_dir(obj_path, config):
|
||||||
''' Find the directory in which the eh_elf corresponding to `obj_path` will
|
''' Find the directory in which the eh_elf corresponding to `obj_path` will
|
||||||
be outputted, among the output directory and the aux directories '''
|
be outputted, among the output directory and the aux directories '''
|
||||||
|
|
||||||
for candidate in config.aux_dirs():
|
return find_eh_elf_dir(obj_path, config.aux_dirs(), config.output)
|
||||||
eh_elf_path = to_eh_elf_path(obj_path, candidate)
|
|
||||||
if os.path.exists(eh_elf_path):
|
|
||||||
return candidate
|
|
||||||
|
|
||||||
# No match among the aux dirs
|
|
||||||
return config.output
|
|
||||||
|
|
||||||
|
|
||||||
def gen_eh_elf(obj_path, config):
|
def gen_eh_elf(obj_path, config):
|
||||||
|
@ -169,8 +159,8 @@ def gen_eh_elf(obj_path, config):
|
||||||
print("> {}...".format(os.path.basename(obj_path)))
|
print("> {}...".format(os.path.basename(obj_path)))
|
||||||
|
|
||||||
link_chain = map(
|
link_chain = map(
|
||||||
lambda elt:
|
lambda elt: (
|
||||||
(to_eh_elf_path(elt[0], out_dir),
|
to_eh_elf_path(elt[0], out_dir),
|
||||||
os.path.basename(to_eh_elf_path(elt[1], out_dir))),
|
os.path.basename(to_eh_elf_path(elt[1], out_dir))),
|
||||||
link_chain)
|
link_chain)
|
||||||
|
|
||||||
|
@ -264,6 +254,8 @@ def gen_eh_elfs(obj_path,
|
||||||
|
|
||||||
config = Config(
|
config = Config(
|
||||||
out_dir,
|
out_dir,
|
||||||
|
[],
|
||||||
|
False,
|
||||||
[obj_path],
|
[obj_path],
|
||||||
sw_gen_policy=switch_gen_policy,
|
sw_gen_policy=switch_gen_policy,
|
||||||
remote=remote,
|
remote=remote,
|
||||||
|
@ -271,7 +263,6 @@ def gen_eh_elfs(obj_path,
|
||||||
|
|
||||||
if deps:
|
if deps:
|
||||||
return gen_all_eh_elf([obj_path], config)
|
return gen_all_eh_elf([obj_path], config)
|
||||||
else:
|
|
||||||
return gen_eh_elf([obj_path], config)
|
return gen_eh_elf([obj_path], config)
|
||||||
|
|
||||||
|
|
||||||
|
@ -364,7 +355,6 @@ def process_args():
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = process_args()
|
args = process_args()
|
||||||
print(args)
|
|
||||||
config = Config(
|
config = Config(
|
||||||
args.output,
|
args.output,
|
||||||
args.aux,
|
args.aux,
|
||||||
|
|
|
@ -6,6 +6,32 @@ import os
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_AUX_DIRS = [
|
||||||
|
'~/.cache/eh_elfs',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def to_eh_elf_path(so_path, out_dir, base=False):
|
||||||
|
''' Transform a library path into its eh_elf counterpart '''
|
||||||
|
base_path = os.path.basename(so_path) + '.eh_elf'
|
||||||
|
if base:
|
||||||
|
return base_path
|
||||||
|
return os.path.join(out_dir, base_path + '.so')
|
||||||
|
|
||||||
|
|
||||||
|
def find_eh_elf_dir(obj_path, aux_dirs, out_dir):
|
||||||
|
''' Find the directory in which the eh_elf corresponding to `obj_path` will
|
||||||
|
be outputted, among the output directory and the aux directories '''
|
||||||
|
|
||||||
|
for candidate in aux_dirs:
|
||||||
|
eh_elf_path = to_eh_elf_path(obj_path, candidate)
|
||||||
|
if os.path.exists(eh_elf_path):
|
||||||
|
return candidate
|
||||||
|
|
||||||
|
# No match among the aux dirs
|
||||||
|
return out_dir
|
||||||
|
|
||||||
|
|
||||||
def readlink_rec(path):
|
def readlink_rec(path):
|
||||||
''' Returns the canonical path of `path`, resolving multiple layers of
|
''' Returns the canonical path of `path`, resolving multiple layers of
|
||||||
symlinks '''
|
symlinks '''
|
||||||
|
|
Loading…
Reference in a new issue