Skip to content

Commit

Permalink
Merge 6bc899d into e29dc3c
Browse files Browse the repository at this point in the history
  • Loading branch information
eunovm authored Sep 16, 2019
2 parents e29dc3c + 6bc899d commit 723e7bc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 10 deletions.
28 changes: 18 additions & 10 deletions clade/extensions/opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,14 +466,7 @@
"-U",
]

cl_preprocessor_deps_opts = [
"/EP",
"-EP",
"/E",
"-E",
"/P",
"-P",
]
cl_preprocessor_deps_opts = ["/EP", "-EP", "/E", "-E", "/P", "-P"]

requires_value = {
"CC": set(gcc_opts + clang_opts),
Expand All @@ -491,6 +484,7 @@
"-isystem",
"-idirafter",
"-imacros",
"-isysroot",
]

gcc_optimization_opts = [
Expand Down Expand Up @@ -519,6 +513,11 @@ def filter_opts(opts, get_storage_path=None):
return []

filtered_opts = []

# Do not overwrite absolute paths within options except for the one
# corresponding to isysroot when this option is specified.
is_isysroot = any(opt.startswith("-isysroot") for opt in opts)

opts = iter(opts)
for opt in opts:
if not s_regex.match(opt):
Expand All @@ -534,18 +533,27 @@ def filter_opts(opts, get_storage_path=None):

continue

name = m.group(1)
path = m.group(2)

if path:
if get_storage_path and os.path.isabs(path):
if (
get_storage_path
and os.path.isabs(path)
and (not is_isysroot or name == "-isysroot")
):
opt = opt.replace(path, get_storage_path(path))

filtered_opts.append(opt)
elif opt in requires_value["CC"]:
filtered_opts.append(opt)
path = next(opts)

if get_storage_path and os.path.isabs(path):
if (
get_storage_path
and os.path.isabs(path)
and (not is_isysroot or name == "-isysroot")
):
path = get_storage_path(path)

filtered_opts.append(path)
Expand Down
52 changes: 52 additions & 0 deletions tests/test_opts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (c) 2019 ISP RAS (http://www.ispras.ru)
# Ivannikov Institute for System Programming of the Russian Academy of Sciences
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from clade import Clade
from clade.extensions.opts import filter_opts


def test_isysroot(tmpdir):
c = Clade(tmpdir)

opts = ["-isysroot=/test/path/", "-I/usr/include"]

filtered_opts = filter_opts(opts, c.get_storage_path)

assert len(filtered_opts) == len(opts)
assert filtered_opts[0] == "-isysroot={}/test/path/".format(c.storage_dir)
assert filtered_opts[1] == opts[1]


def test_no_isysroot(tmpdir):
c = Clade(tmpdir)

opts = ["-I/usr/include"]

filtered_opts = filter_opts(opts, c.get_storage_path)

assert len(filtered_opts) == len(opts)
assert filtered_opts[0] == "-I{}/usr/include".format(c.storage_dir)


def test_no_get_storage_path():
opts = ["-I/usr/include"]

assert filter_opts(opts) == opts


def test_bad_opt():
opts = ["-ABC", "-Dtest"]

assert filter_opts(opts) == ["-Dtest"]

0 comments on commit 723e7bc

Please sign in to comment.