Skip to content

Commit

Permalink
Add support for -l options in LD
Browse files Browse the repository at this point in the history
  • Loading branch information
17451k committed Nov 18, 2020
1 parent b37a228 commit 96646ea
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
69 changes: 69 additions & 0 deletions clade/extensions/ld.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import re

from clade.extensions.common import Common


Expand All @@ -29,5 +32,71 @@ def parse_cmd(self, cmd):
self.dump_bad_cmd_by_id(parsed_cmd["id"], parsed_cmd)
return

self.__parse_opts(parsed_cmd)

self.debug("Parsed command: {}".format(parsed_cmd))
self.dump_cmd_by_id(cmd["id"], parsed_cmd)

def __parse_opts(self, parsed_cmd):
archives = []

searchdirs = self.__get_searchdirs(parsed_cmd)

opts = iter(parsed_cmd["opts"])
for opt in opts:
if opt in ["-l", "--library"]:
name = next(opts)

self.__find_archive(name, searchdirs, parsed_cmd)
elif opt.startswith("-l") or opt.startswith("--library="):
name = re.sub(r"^-l", "", opt)
name = re.sub(r"^--library=", "", name)

self.__find_archive(name, searchdirs, parsed_cmd)

return archives

def __get_searchdirs(self, parsed_cmd):
# sysroot paths are not supported (searchdir begins with "=")
searchdirs = self.conf.get("LD.searchdirs", [])

opts = iter(parsed_cmd["opts"])
for opt in opts:
if opt in ["-L", "--library-path"]:
path = next(opts)

searchdirs.append(os.path.normpath(path))
elif opt.startswith("-L") or opt.startswith("--library-path="):
path = re.sub(r"^-L", "", opt)
path = re.sub(r"^--library-path=", "", path)

searchdirs.append(os.path.normpath(path))

return searchdirs

def __find_archive(self, name, searchdirs, parsed_cmd):
if not searchdirs:
self.warning("Search directories are empty")
return

names = []

if name.startswith(":"):
names.append(name[1:])
else:
names.append("lib" + name + ".so")
names.append("lib" + name + ".a")
names.append(name + ".a")

for searchdir in searchdirs:
for name in names:
archive = os.path.normpath(os.path.join(searchdir, name))
if os.path.exists(archive):
if archive not in parsed_cmd["in"]:
parsed_cmd["in"].append(archive)
break
else:
continue
break
else:
self.warning("Couldn't find {!r} archive in {}".format(name, searchdirs))
2 changes: 2 additions & 0 deletions clade/extensions/opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@
"--out-implib",
"--stack",
"--subsystem",
"--library-path",
"--library",
"-A",
"-F",
"-G",
Expand Down
4 changes: 3 additions & 1 deletion clade/extensions/presets/presets.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"CC.with_system_header_files": true,
"CL.deps_encoding": null,
"CL.pre_encoding": null,
"LD.searchdirs": [],
"Compiler.deps_encoding": null,
"Compiler.store_deps": true,
"Compiler.preprocess_cmds": false,
Expand Down Expand Up @@ -54,7 +55,8 @@
"aspectator$"
],
"LD.which_list": [
"(/|-)ld$"
"(/|-)ld$",
"ld.lld$"
],
"MV.which_list": [
"/mv$"
Expand Down
1 change: 0 additions & 1 deletion clade/scripts/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def compare(self):
self.compare_functions()
self.compare_macros()
self.compare_callgraphs()
pass

def compare_extension_lists(self):
a = self.__get_extension_list(self.work_dir1)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def finalize_options(self):

setuptools.setup(
name="clade",
version="3.2.13",
version="3.2.14",
author="Ilya Shchepetkov",
author_email="shchepetkov@ispras.ru",
url="https://github.com/17451k/clade",
Expand Down

0 comments on commit 96646ea

Please sign in to comment.