From 9432e26017e1470fbfea9997106b24c14538086f Mon Sep 17 00:00:00 2001 From: Paul Cresswell Date: Wed, 3 Sep 2025 12:17:43 +0000 Subject: [PATCH] Apply bundle.yml options in command-line order --- ecbundle/build.py | 23 ++++++++++++++++++----- ecbundle/util.py | 12 ++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/ecbundle/build.py b/ecbundle/build.py index 97f1c02..a65a41f 100644 --- a/ecbundle/build.py +++ b/ecbundle/build.py @@ -469,6 +469,8 @@ def cmake_args(self): return return_cmake_args def create_scripts(self): + from .util import remove_prefix, remove_suffix + src_dir = self.src_dir() build_dir = self.build_dir() install_dir = self.install_dir() @@ -517,11 +519,22 @@ def create_scripts(self): cmake_args += " -DECBUILD_LOG_LEVEL=" + self.log() options = self.bundle().options() - for opt in options: - arg = self.get(opt.key()) - if arg: - if opt.cmake(): - cmake_args += " " + " ".join(["-D" + o for o in opt.cmake(arg)]) + + # Apply bundle options in order given by user: + for posarg in sys.argv[1:]: + if posarg.startswith("--"): + posarg = remove_suffix(remove_prefix(posarg, "--"), "=.*").replace( + "-", "_" + ) + for opt in options: + arg = self.get(opt.key()) + if opt.key() == posarg: + if arg: + if opt.cmake(): + cmake_args += " " + " ".join( + ["-D" + o for o in opt.cmake(arg)] + ) + break if self.without_tests(): cmake_args += " -DENABLE_TESTS=OFF" diff --git a/ecbundle/util.py b/ecbundle/util.py index 5417b02..cd77af1 100644 --- a/ecbundle/util.py +++ b/ecbundle/util.py @@ -99,6 +99,18 @@ def mkdir_p(path): raise RuntimeError() +def remove_prefix(string, prefix): + import re + + return re.sub(r"^{0}".format(prefix), "", string) + + +def remove_suffix(string, suffix): + import re + + return re.sub(r"{0}$".format(suffix), "", string) + + def symlink_force(target, link_name): import errno import os