linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: n.schier@avm.de
To: "Masahiro Yamada" <masahiroy@kernel.org>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 10/10] [for next only] kconfig: generate include/generated/rustc_cfg
Date: Fri, 1 Oct 2021 13:28:31 +0200	[thread overview]
Message-ID: <20211001112831.499A27FEFB@deb-nschier.ads.avm.de> (raw)
In-Reply-To: <20211001053253.1223316-10-masahiroy@kernel.org>

On Fri, Oct 01, 2021 at 02:32:53PM +0900, Masahiro Yamada wrote:
> This patch is not intended for the mainline.
> 
> I created this patch for Stephen Rothwell to resolve the merge
> conflicts more easily.
> 
> The Rust tree is touching scripts/kconfig/confdata.c to generate
> include/generated/rustc_cfg, which would cause complicated conflicts
> with changes from the kbuild tree.
> 
> I re-implemented it to produce the equaivalent rustc_cfg.
> 
> I also fixed the memory leak; the original code from the Rust tree
> did not free the malloc'ed pointer.
> 
> Stephen:
> When you resolve the conflicts in confdata.c, please take this one.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
>  scripts/kconfig/confdata.c | 42 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)
> 
> diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> index 9ece2f3b61a6..4767f3810cf4 100644
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
> @@ -603,6 +603,9 @@ static const struct comment_style comment_style_c = {
>  
>  static void conf_write_heading(FILE *fp, const struct comment_style *cs)
>  {
> +	if (!cs) /* no heading for rustc_cfg? */
> +		return;
> +
>  	fprintf(fp, "%s\n", cs->comment_block_begin);
>  
>  	fprintf(fp, "%s Automatically generated file; DO NOT EDIT.\n",
> @@ -750,6 +753,39 @@ static void print_symbol_for_c(FILE *fp, struct symbol *sym)
>  	free(escaped);
>  }
>  
> +/* rustc configuration */
> +static void print_symbol_for_rustc_cfg(FILE *fp, struct symbol *sym)
> +{
> +	const char *val;
> +	char *escaped;
> +
> +	if (sym->type == S_UNKNOWN)
> +		return;
> +
> +	val = sym_get_string_value(sym);
> +	escaped = escape_string_value(val);
> +
> +	if (sym->type == S_BOOLEAN || sym->type == S_TRISTATE) {
> +		if (*val == 'n')
> +			return;

I'd expect a "free(escaped);" here.

> +
> +		/*
> +		 * To have similar functionality to the C macro `IS_ENABLED()`
> +		 * we provide an empty `--cfg CONFIG_X` here in both `y`
> +		 * and `m` cases.
> +		 *
> +		 * Then, the common `fprintf()` below will also give us
> +		 * a `--cfg CONFIG_X="y"` or `--cfg CONFIG_X="m"`, which can
> +		 * be used as the equivalent of `IS_BUILTIN()`/`IS_MODULE()`.
> +		 */
> +		fprintf(fp, "--cfg=%s%s\n", CONFIG_, sym->name);
> +	}
> +
> +	fprintf(fp, "--cfg=%s%s=%s\n", CONFIG_, sym->name, escaped);
> +
> +	free(escaped);
> +}
> +
>  /*
>   * Write out a minimal config.
>   * All values that has default values are skipped as this is redundant.
> @@ -1129,6 +1165,12 @@ int conf_write_autoconf(int overwrite)
>  	if (ret)
>  		return ret;
>  
> +	ret = __conf_write_autoconf("include/generated/rustc_cfg",
> +				    print_symbol_for_rustc_cfg,
> +				    NULL);
> +	if (ret)
> +		return ret;
> +
>  	/*
>  	 * Create include/config/auto.conf. This must be the last step because
>  	 * Kbuild has a dependency on auto.conf and this marks the successful
> -- 
> 2.30.2
> 

  reply	other threads:[~2021-10-01 11:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01  5:32 [PATCH 01/10] kconfig: remove 'const' from the return type of sym_escape_string_value() Masahiro Yamada
2021-10-01  5:32 ` [PATCH 02/10] kconfig: refactor conf_write_heading() Masahiro Yamada
2021-10-01  5:32 ` [PATCH 03/10] kconfig: refactor conf_write_symbol() Masahiro Yamada
2021-10-28  5:16   ` Boris Kolpackov
2021-11-05  8:46     ` Masahiro Yamada
2021-11-05 11:40       ` Boris Kolpackov
2021-10-01  5:32 ` [PATCH 04/10] kconfig: refactor listnewconfig code Masahiro Yamada
2021-10-01  5:32 ` [PATCH 05/10] kconfig: move sym_escape_string_value() to confdata.c Masahiro Yamada
2021-10-01  5:32 ` [PATCH 06/10] kconfig: add conf_get_autoheader_name() Masahiro Yamada
2021-10-01  5:32 ` [PATCH 07/10] kconfig: refactor conf_write_autoconf() Masahiro Yamada
2021-10-01  5:32 ` [PATCH 08/10] kconfig: refactor conf_write_dep() Masahiro Yamada
2021-10-01  5:32 ` [PATCH 09/10] kconfig: refactor conf_touch_dep() Masahiro Yamada
2021-10-01  5:32 ` [PATCH 10/10] [for next only] kconfig: generate include/generated/rustc_cfg Masahiro Yamada
2021-10-01 11:28   ` n.schier [this message]
2021-10-02  8:59     ` Masahiro Yamada
2021-10-05 15:37 ` [PATCH 01/10] kconfig: remove 'const' from the return type of sym_escape_string_value() Masahiro Yamada

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=20211001112831.499A27FEFB@deb-nschier.ads.avm.de \
    --to=n.schier@avm.de \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).