Skip to content

Commit

Permalink
[AutotoolsToolchain] Improve update_xxxxx_args behavior (#12889)
Browse files Browse the repository at this point in the history
* Fixed bad overwriting of configuration arguments

* Added target calculation and let users configure them

* Minor changes

* Added update_xxxx_args to add/prune flags effortlessly

* Typo

* Improved helpers

* Removed target triplet

* Fixed test

* Now, add/update/remove args

* Update conan/tools/gnu/autotoolstoolchain.py

Co-authored-by: James <memsharded@gmail.com>

* Update conan/tools/gnu/autotoolstoolchain.py

Co-authored-by: James <memsharded@gmail.com>

Co-authored-by: James <memsharded@gmail.com>
  • Loading branch information
franramirez688 and memsharded authored Jan 11, 2023
1 parent ea235dc commit 33aec0b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
35 changes: 20 additions & 15 deletions conan/tools/gnu/autotoolstoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,28 @@ def update_autoreconf_args(self, updated_flags):

# FIXME: Remove all these update_xxxx whenever xxxx_args are dicts or new ones replace them
def _update_flags(self, attr_name, updated_flags):
_new_flags = []
self_args = getattr(self, attr_name)
for index, flag in enumerate(self_args):
flag_name = flag.split("=")[0]
if flag_name in updated_flags:
new_flag_value = updated_flags[flag_name]
# if {"build": None} is passed, then "--build=xxxx" will be pruned
if new_flag_value is None:
continue
elif not new_flag_value:
_new_flags.append(flag_name)

def _list_to_dict(flags):
ret = {}
for flag in flags:
# Only splitting if "=" is there
option = flag.split("=", 1)
if len(option) == 2:
ret[option[0]] = option[1]
else:
_new_flags.append(f"{flag_name}={new_flag_value}")
else:
_new_flags.append(flag)
ret[option[0]] = ""
return ret

def _dict_to_list(flags):
return [f"{k}={v}" if v else k for k, v in flags.items() if v is not None]

self_args = getattr(self, attr_name)
# FIXME: if xxxxx_args -> dict-type at some point, all these lines could be removed
options = _list_to_dict(self_args)
# Add/update/remove the current xxxxx_args with the new flags given
options.update(updated_flags)
# Update the current ones
setattr(self, attr_name, _new_flags)
setattr(self, attr_name, _dict_to_list(options))

def generate_args(self):
args = {"configure_args": args_to_string(self.configure_args),
Expand Down
12 changes: 7 additions & 5 deletions conans/test/unittests/tools/gnu/autotoolschain_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,22 @@ def test_check_configure_args_overwriting_and_deletion(save_args, cross_building
def test_update_or_prune_any_args(cross_building_conanfile):
at = AutotoolsToolchain(cross_building_conanfile)
at.configure_args.append("--enable-flag1=false")
at.make_args.append("--complex-flag=complex-value")
# Update configure_args
at.update_configure_args({"--prefix": "/my/other/prefix",
"--build": None, # prune value
"--enable-flag1": ""})
"--enable-flag1": "", # without value
"-NEW-FLAG": "no" # new flag
})
new_configure_args = args_to_string(at.configure_args)
assert "--prefix=/my/other/prefix" in new_configure_args
assert "--build=" not in new_configure_args # pruned
assert "--enable-flag1" in new_configure_args # flag without value
assert "-NEW-FLAG=no" in new_configure_args # new flag
# Update autoreconf_args
at.update_autoreconf_args({"--force": None})
new_autoreconf_args = args_to_string(at.autoreconf_args)
assert "'--force" not in new_autoreconf_args
# Update make_args
at.update_make_args({"--complex-flag": "new-value"})
# Add new value to make_args
at.update_make_args({"--new-complex-flag": "new-value"})
new_make_args = args_to_string(at.make_args)
assert "--complex-flag=new-value" in new_make_args
assert "--new-complex-flag=new-value" in new_make_args

0 comments on commit 33aec0b

Please sign in to comment.