All of lore.kernel.org
 help / color / mirror / Atom feed
From: TIAN Yuanhao <tianyuanhao3@163.com>
To: Christian Stewart <christian@paral.in>
Cc: "Yann E. MORIN" <yann.morin.1998@free.fr>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	buildroot@buildroot.org
Subject: Re: [Buildroot] [PATCH v2 1/1] package/pkg-utils: prevent kconfig_enable_opt from changing =m to =y
Date: Mon, 23 May 2022 04:53:26 -0700	[thread overview]
Message-ID: <80e2a4c8-4c41-b9b7-25e3-a075b573f7f6@163.com> (raw)
In-Reply-To: <20220518202129.GX1597494@scaer>

All,

On 5/18/22 13:21, Yann E. MORIN wrote:
> Christian, Arnout, All,
>
> On 2022-05-18 20:01 +0200, Arnout Vandecappelle spake thusly:
>> On 17/05/2022 12:36, Christian Stewart via buildroot wrote:
>>> This patch changes KCONFIG_MUNGE_DOT_CONFIG to prevent changing `=m` to `=y`.
>>   Good catch!
>>   Patch is a bit over-complicated, but I don't know how to do better.
> [--SNIP--]
>>> @@ -21,8 +21,14 @@ KCONFIG_DOT_CONFIG = $(strip \
>>>   )
>>>   # KCONFIG_MUNGE_DOT_CONFIG (option, newline [, file])
>>> +# If setting to =y and the option is already set to =m, ignore.
>>>   define KCONFIG_MUNGE_DOT_CONFIG
>>> -	$(SED) "/\\<$(strip $(1))\\>/d" $(call KCONFIG_DOT_CONFIG,$(3))
>>> +	if [[ "$(lastword $(subst =, ,$(strip $(2))))" == "y" ]]; then \
>>   This part we could avoid by adding a 4th option and setting it only on
>> KCONFIG_ENABLE_OPT.
>>
>>> +		if grep -q "$(strip $(1))=m" $(call KCONFIG_DOT_CONFIG,$(3)); then \
>>> +			exit 0; \
>>   This is a kind of hard-to-follow control structure - better turn around the
>> condition and do the replacement inside it. So, combined with the above:
>>
>> 	if $(if $(4),grep -q ...,true); then \
>> 		sed ...; \
>> 		echo ...; \
>> 	fi
> Actually, I think the check should not be in KCONFIG_MUNGE_DOT_CONFIG,
> as it really belongs to KCONFIG_ENABLE_OPT.
>
> Maybe something like:
>
>      diff --git a/package/pkg-utils.mk b/package/pkg-utils.mk
>      index 7d1aea7710..56cd72a9a9 100644
>      --- a/package/pkg-utils.mk
>      +++ b/package/pkg-utils.mk
>      @@ -22,12 +22,16 @@ KCONFIG_DOT_CONFIG = $(strip \
>       
>       # KCONFIG_MUNGE_DOT_CONFIG (option, newline [, file])
>       define KCONFIG_MUNGE_DOT_CONFIG
>      -	$(SED) "/\\<$(strip $(1))\\>/d" $(call KCONFIG_DOT_CONFIG,$(3))
>      +	$(SED) "/\\<$(strip $(1))\\>/d" $(call KCONFIG_DOT_CONFIG,$(3)) && \
>       	echo '$(strip $(2))' >> $(call KCONFIG_DOT_CONFIG,$(3))
>       endef
>       
>       # KCONFIG_ENABLE_OPT (option [, file])
>      -KCONFIG_ENABLE_OPT  = $(call KCONFIG_MUNGE_DOT_CONFIG, $(1), $(1)=y, $(2))
>      +define KCONFIG_ENABLE_OPT
>      +	if ! grep -q -E '^$(1)=' $(call KCONFIG_DOT_CONFIG,$(2)); then \
>      +		$(call KCONFIG_MUNGE_DOT_CONFIG, $(1), $(1)=y, $(2)) || exit 1; \
>      +	fi
>      +endif
>       # KCONFIG_SET_OPT (option, value [, file])
>       KCONFIG_SET_OPT     = $(call KCONFIG_MUNGE_DOT_CONFIG, $(1), $(1)=$(2), $(3))
>       # KCONFIG_DISABLE_OPT  (option [, file])
I prefer this:

  # KCONFIG_MUNGE_DOT_CONFIG (option, newline [, file])
  define KCONFIG_MUNGE_DOT_CONFIG
-    $(SED) "/\\<$(strip $(1))\\>/d" $(call KCONFIG_DOT_CONFIG,$(3))
+    $(SED) '/^\(# \)\?$(strip $(1))\>/d' $(call 
KCONFIG_DOT_CONFIG,$(3)) && \
      echo '$(strip $(2))' >> $(call KCONFIG_DOT_CONFIG,$(3))
  endef

  # KCONFIG_ENABLE_OPT (option [, file])
-KCONFIG_ENABLE_OPT  = $(call KCONFIG_MUNGE_DOT_CONFIG, $(1), $(1)=y, $(2))
+define KCONFIG_ENABLE_OPT
+    $(Q)if ! grep -q '^$(strip $(1))=[my]' $(call 
KCONFIG_DOT_CONFIG,$(2)); then \
+        $(call KCONFIG_MUNGE_DOT_CONFIG, $(1), $(1)=y, $(2)) || exit 1; \
+    fi
+endef

Regards,
Yuanhao
>
> Or maybe just that:
>
>      diff --git a/package/pkg-utils.mk b/package/pkg-utils.mk
>      index 7d1aea7710..8aebd14114 100644
>      --- a/package/pkg-utils.mk
>      +++ b/package/pkg-utils.mk
>      @@ -27,7 +27,7 @@ define KCONFIG_MUNGE_DOT_CONFIG
>       endef
>       
>       # KCONFIG_ENABLE_OPT (option [, file])
>      -KCONFIG_ENABLE_OPT  = $(call KCONFIG_MUNGE_DOT_CONFIG, $(1), $(1)=y, $(2))
>      +KCONFIG_ENABLE_OPT  = $(call KCONFIG_MUNGE_DOT_CONFIG, $(1) is not set, $(1)=y, $(2))
>       # KCONFIG_SET_OPT (option, value [, file])
>       KCONFIG_SET_OPT     = $(call KCONFIG_MUNGE_DOT_CONFIG, $(1), $(1)=$(2), $(3))
>       # KCONFIG_DISABLE_OPT  (option [, file])
>
> Also, I notice now that this KCONFIG_MUNGE_DOT_CONFIG is pretty fragile.
> Given a .config with:
>
>      FOO="1234"
>      BAR="$(FOO)"
>
> and then:
>
>      $(call KCONFIG_SET_OPT,FOO,azerty)
>
> would yield a .config with just:
>
>      FOO="azerty"
>
> because \<FOO\> would match the assignement to BAR.
>
> So we may need to revisit that mess of mine...
>
> Regards,
> Yann E. MORIN.
>

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  reply	other threads:[~2022-05-23 12:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-17 10:36 [Buildroot] [PATCH v2 1/1] package/pkg-utils: prevent kconfig_enable_opt from changing =m to =y Christian Stewart via buildroot
2022-05-18 18:01 ` Arnout Vandecappelle
2022-05-18 20:21   ` Yann E. MORIN
2022-05-23 11:53     ` TIAN Yuanhao [this message]
2022-07-23 22:13       ` Arnout Vandecappelle
2022-07-25 12:09 ` [Buildroot] [PATCH] package/pkg-utils: prevent KCONFIG_ENABLE_OPT " TIAN Yuanhao
2022-07-25 14:28   ` Yann E. MORIN
2022-07-25 15:03     ` Arnout Vandecappelle
2022-07-25 15:19       ` Yann E. MORIN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=80e2a4c8-4c41-b9b7-25e3-a075b573f7f6@163.com \
    --to=tianyuanhao3@163.com \
    --cc=buildroot@buildroot.org \
    --cc=christian@paral.in \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=yann.morin.1998@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.