Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51A9E42A92 for ; Sun, 1 Jun 2025 18:47:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748803666; cv=none; b=AhoxX3K/OJ5naQYYFmRWvnZf3MYH9goug8zo4qRkujh8uFEQhIxZECPg5jIl6FehitbU6Kf9QTlDVx6+5HrgyK4HM2z7SK9NthXLzaR9p4nkxQxE7ciSlXUO0qK0SNblwBFgnozkH9Pk7oCmhMGxSqeHJcY4LwDUcpytOC71jtU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748803666; c=relaxed/simple; bh=yfFo+dvmhOzFnxe05Oozbg7KNpGQL/y2fcE6hYYIZAI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CaQlnU6fwHAS7Vyt+3tNFemSH9BFqswRPIBrFwi5qDkypn3qcYE4QkqMoeQfxXU2irWBS24UsudOKmPHENlLxaPwfagC1GZZ6l0lhkPU7oR1ESEwi4RqzhrtpGEhxSdbYZt1Jbt86FxTq6imuR2qp0+pOVdiH7pzCHFKV/qOxRM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OsNsCbIm; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OsNsCbIm" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-adb4e36904bso228241166b.1 for ; Sun, 01 Jun 2025 11:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748803663; x=1749408463; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CVUJ76WE7x163ppwNJzzSTd+z/PMd+LB7bf6jRUYCUc=; b=OsNsCbImB+bNEPaIa/hIsLiSiiuiREHwABTObHhWv6HPNxHah59sTOIgTn8NvOrRGf qmDJNMxLpGjgPl7k25jhm2L/U5OSrwr85xK8aDzHsiBxWdJRBMj4nn1XSwlELVaJC7kl UE6eWygnq/1Zfv1fcigGtzQg/vYYJpNRi5tboIhgjAvqJ1784zZJEpixVaM6104dG47+ M/naLC4wQ+Yyh/RCXkX6ZxOMBhXotZuFPRKut2gepvhpOxeIXjxT9KJrMAUF0Aop8n59 oYeCIiVtkYO5RPORVCUKwIC9yy3D7KunLsBOSBM9+hdrlcTqjgi6gRcLN8UD0i0yDq3q W2fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748803663; x=1749408463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CVUJ76WE7x163ppwNJzzSTd+z/PMd+LB7bf6jRUYCUc=; b=bwTpuyJUjUFVztY1pf9K9alABPo8IuIbZr1p5OnwsImMwq668Rw/QbtN93dibxVz/F Ix7cRpz7973jAL2Gfdz8wxT3y0BzzHMAqWkyB6ekvLb7ph2KGLkqJWlmBx/jSthdeYNj VQ/5ogirnJ1V74/VXBXbdYUxi6s+VR5RHKzlglF7eAqeVyjI7K5hNM+PQfVngjVVaCFr Aa94IN6RN3DBZDcZ6kqKTHwcYIkyn9Q7KjwzYEG7g8xkL2kx39PKxpv2mx3zHRBHdIIm iNhU+vBV5zFqedrITpq9C+ujiWnHDWwWQaopGlvf59xE5d7453cE8YzJjtwJ9N7zRQWw uYMQ== X-Gm-Message-State: AOJu0Yxu1ir/TJyrntxLOocGH4ODfj4JZbdBGkRmBEx8QwTYcpNE3b93 t2dDqj5CxXR07zTxf2Aho2wxZy2Qb/ouRmr2/rQSm8KX1waqohyQ2Ilq X-Gm-Gg: ASbGnct3chVLYmbTRIjsvB0RAqzuhRgYGD3+Ou8sadeZfL++CcuF6oQ81bNEXnp4dWu fldBVxgZbLAKg7N/kqUeyv4pIp0SaizzrR45mOhy+Kc2BGlwd7pfccr+0MqrVOaTjPV0DpSEGdd 7JzxK7gpv0N++G5ljxMB4JjoRTmvRNoBJZU1hGnHGQSIhXOMlET8xDt3/LDhvKroPB/c4DOw/Eu Tv8XI1yKpQoavujLebuVEOpsVNVpgQ3hyURJOxPEHpt+utJxpgd9lxJajsoVWj8ih3mneprwqW3 RMtbA5SDG1EffG0u2ZhXRjQBqZmYyMpPt+FigpwWFdzM0tAM8G4UMMsM8Ygcz46KGQcwj+7/e1V 0bQdsliDEQAU/RbPv8sN6RAfI5QY= X-Google-Smtp-Source: AGHT+IEAxfhcmerRbqcv2bHOG9izdkt5fgJbZJSrHAvAV6W8c3WcuOtuvSvFzgf4scGkhzdlkC+Urg== X-Received: by 2002:a17:907:94ca:b0:ad8:9a86:cf52 with SMTP id a640c23a62f3a-adb36b0530amr850921966b.11.1748803662296; Sun, 01 Jun 2025 11:47:42 -0700 (PDT) Received: from itek.frank67.it. (mob-5-90-139-122.net.vodafone.it. [5.90.139.122]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ada5d82e80csm677487266b.71.2025.06.01.11.47.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Jun 2025 11:47:41 -0700 (PDT) From: Franco Martelli To: masahiroy@kernel.org Cc: linux-kbuild@vger.kernel.org, Franco Martelli Subject: [PATCH 1/1] Kconfig: Added compare capabilities for mconf Date: Sun, 1 Jun 2025 20:40:50 +0200 Message-Id: <20250601184049.368419-2-martellif67@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250601184049.368419-1-martellif67@gmail.com> References: <20250601184049.368419-1-martellif67@gmail.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Signed-off-by: Franco Martelli --- scripts/kconfig/confdata.c | 165 ++++++++++++++++++++++++- scripts/kconfig/expr.h | 9 ++ scripts/kconfig/lkc.h | 11 ++ scripts/kconfig/lkc_proto.h | 4 + scripts/kconfig/lxdialog/menubox.c | 13 +- scripts/kconfig/mconf.c | 192 ++++++++++++++++++++++++++--- 6 files changed, 376 insertions(+), 18 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index ac95661a1c9d..078d058c01d7 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -257,7 +257,7 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) sym->flags |= def_flags; break; } - if (def != S_DEF_AUTO) + if (def != S_DEF_AUTO && def != S_DEF_COMP) conf_warning("symbol value '%s' invalid for %s", p, sym->name); return 1; @@ -386,6 +386,7 @@ int conf_read_simple(const char *name, int def) def_flags = SYMBOL_DEF << def; for_all_symbols(sym) { sym->flags &= ~def_flags; + sym->comp_is_avail = false; switch (sym->type) { case S_INT: case S_HEX: @@ -445,6 +446,8 @@ int conf_read_simple(const char *name, int def) sym = sym_find(sym_name); if (!sym) { + if (def == S_DEF_COMP) + continue; if (def == S_DEF_AUTO) { /* * Reading from include/config/auto.conf. @@ -462,6 +465,9 @@ int conf_read_simple(const char *name, int def) continue; } + if (def == S_DEF_COMP) + sym->comp_is_avail = true; + if (sym->flags & def_flags) conf_warning("override: reassigning to symbol %s", sym->name); @@ -529,6 +535,91 @@ int conf_read(const char *name) return 0; } +const char sym_get_comp_tristate_char(struct symbol *sym) +{ + char ch = '#'; + + if (sym_get_comp_is_avail(sym)) + switch (sym_get_comp_tristate_value(sym)) { + case yes: ch = '*'; break; + case mod: ch = 'M'; break; + case no: ch = '_'; break; + } + + return ch; +} + +static char * masked_xrealloc(char *s, size_t len, size_t *size) +{ + char *ls = s; + + if (s == NULL) + *size = 0; + if (len > *size) + ls = xrealloc(s, (*size = ((len / SYMBOL_MAXLENGTH) + 1) * SYMBOL_MAXLENGTH)); + + return ls; +} + +#define LINE_LENGTH (SYMBOL_MAXLENGTH +32) + +char * comp_get_list_diff(void) +{ + char *line, *l_rst, *list = NULL, ch_comp; + size_t idx = 0, szs; + struct symbol *sym; + tristate tri_val, tri_comp_val; + + l_rst = line = xmalloc(LINE_LENGTH); + + for_all_symbols(sym) { + if (!sym->name) + continue; + tri_val = sym_get_tristate_value(sym); + tri_comp_val = sym_get_comp_tristate_value(sym); + + if (tri_val != tri_comp_val) { + ch_comp = sym_get_comp_tristate_char(sym); + switch (tri_val) { + case yes: + snprintf(line, LINE_LENGTH, "%s%s=y --- %c\n", CONFIG_, sym->name, ch_comp); + break; + case mod: + snprintf(line, LINE_LENGTH, "%s%s=m --- %c\n", CONFIG_, sym->name, ch_comp); + break; + case no: + snprintf(line, LINE_LENGTH, "# %s%s is not set --- %c\n", + CONFIG_, sym->name, ch_comp); + break; + } + + for (; *line; ++idx) { + list = masked_xrealloc(list, idx + 2, &szs); + list[idx] = *line++; + } + line = l_rst; + } + } + free(line); + + if (list) + list[idx] = '\0'; + else { + list = xmalloc(32); + strcpy(list, "No differences found."); + } + + return list; +} + +int conf_read_comp(const char *name) +{ + if (conf_read_simple(name, S_DEF_COMP)) + return 1; + + return 0; +} + struct comment_style { const char *decoration; const char *prefix; @@ -801,6 +892,78 @@ int conf_write_defconfig(const char *filename) return 0; } +bool conf_write_comp(const char *name) +{ + FILE *fptemp, *fplist; + char *list = NULL, f_old[PATH_MAX +1], tmpfile[] = "file_XXXXXX"; + int ch; + + if (!name) + return false; + + if (is_present(name)) { + if (is_dir(name)) + return false; + snprintf(f_old, PATH_MAX, "%s.old", name); + if (rename(name, f_old)) { + fprintf(stderr, "Failed to rename file: %s to %s\n", name, f_old); + return false; + } + } + + list = comp_get_list_diff(); + int tmpfd = mkstemp(tmpfile); + + if (tmpfd < 0) { + fprintf( stderr, "Failed to create temporary file.\n" ); + return false; + } + + if ((fptemp = fdopen(tmpfd, "w")) == NULL) { + remove(tmpfile); + fprintf(stderr, "Failed to open a stream for the temporary file: %s\n", tmpfile); + return false; + } + + if ((fplist = fmemopen(list, strlen(list), "r")) == NULL ) { + fclose(fptemp); + remove(tmpfile); + fprintf( stderr, "Failed to open a stream for fplist.\n" ); + if (list) + free(list); + return false; + } + + while ((ch = fgetc(fplist)) != EOF) + fputc(ch, fptemp); + + if (ferror(fptemp)) { /* checks whether fputc has encountered errors while writing the file */ + fclose(fptemp); + fclose(fplist); + if (list) + free(list); + fprintf( stderr, "An error occured when writing the file: %s", tmpfile); + return false; + } + + if (rename(tmpfile, name)) { + fprintf(stderr, "Failed to rename file: %s to %s\n", tmpfile, name); + fclose(fptemp); + fclose(fplist); + if (list) + free(list); + remove(tmpfile); + return false; + } + + fclose(fptemp); + fclose(fplist); + if (list) + free(list); + + return true; +} + int conf_write(const char *name) { FILE *out; diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 21578dcd4292..89b5d1cde63d 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -76,6 +76,7 @@ enum { S_DEF_AUTO, /* values read from auto.conf */ S_DEF_DEF3, /* Reserved for UI usage */ S_DEF_DEF4, /* Reserved for UI usage */ + S_DEF_COMP, /* values for comparison purposes */ S_DEF_COUNT }; @@ -140,6 +141,13 @@ struct symbol { * "Weak" reverse dependencies through being implied by other symbols */ struct expr_value implied; + + /* + * Used by comparison code. "true" when the symbol is present in the compared + * .config, "false" if it's missing in the compared .config, meaning + * therefore a new feature. + */ + bool comp_is_avail; }; #define SYMBOL_CONST 0x0001 /* symbol is const */ @@ -156,6 +164,7 @@ struct symbol { #define SYMBOL_DEF_AUTO 0x20000 /* symbol.def[S_DEF_AUTO] is valid */ #define SYMBOL_DEF3 0x40000 /* symbol.def[S_DEF_3] is valid */ #define SYMBOL_DEF4 0x80000 /* symbol.def[S_DEF_4] is valid */ +#define SYMBOL_DEF_COMP 0x100000 /* symbol.def[S_DEF_COMP] is valid */ #define SYMBOL_MAXLENGTH 256 diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index b8ebc3094a23..0ddf142ec7e8 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "expr.h" @@ -129,6 +130,16 @@ static inline bool sym_has_value(const struct symbol *sym) return sym->flags & SYMBOL_DEF_USER ? true : false; } +static inline bool sym_get_comp_is_avail(struct symbol *sym) +{ + return sym->comp_is_avail; +} + +static inline tristate sym_get_comp_tristate_value(struct symbol *sym) +{ + return sym->def[S_DEF_COMP].tri; +} + #ifdef __cplusplus } #endif diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 8914b4e8f2a8..0f71786b4245 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -7,6 +7,10 @@ /* confdata.c */ void conf_parse(const char *name); int conf_read(const char *name); +int conf_read_comp(const char *name); +bool conf_write_comp(const char *name); +const char sym_get_comp_tristate_char(struct symbol *sym); +char * comp_get_list_diff(void); int conf_read_simple(const char *name, int); int conf_write_defconfig(const char *name); int conf_write(const char *name); diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c index 6e6244df0c56..11e92da37e9f 100644 --- a/scripts/kconfig/lxdialog/menubox.c +++ b/scripts/kconfig/lxdialog/menubox.c @@ -141,6 +141,7 @@ static void print_buttons(WINDOW * win, int height, int width, int selected) print_button(win, " Help ", y, x + 24, selected == 2); print_button(win, " Save ", y, x + 36, selected == 3); print_button(win, " Load ", y, x + 48, selected == 4); + print_button(win, "Compare", y, x + 60, selected == 5); wmove(win, y, x + 1 + 12 * selected); wrefresh(win); @@ -354,11 +355,14 @@ int dialog_menu(const char *title, const char *prompt, case TAB: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) - ? 4 : (button > 4 ? 0 : button); + ? 5 : (button > 5 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh(menu); break; + case KEY_F(1): + case KEY_F(2): + case KEY_F(4): case ' ': case 's': case 'y': @@ -376,6 +380,7 @@ int dialog_menu(const char *title, const char *prompt, item_set(scroll + choice); item_set_selected(1); switch (key) { + case KEY_F(1): case 'h': case '?': return 2; @@ -392,8 +397,12 @@ int dialog_menu(const char *title, const char *prompt, return 9; case 'z': return 10; + case KEY_F(2): /* Differences between .config files view */ + return 40; + case KEY_F(4): /* Save to file differences between .config files */ + return 60; case '\n': - return button; + return button == 5 ? 50 : button; /* Workaround for Compare button */ } return 0; case 'e': diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c index 84ea9215c0a7..85917f4baea8 100644 --- a/scripts/kconfig/mconf.c +++ b/scripts/kconfig/mconf.c @@ -73,7 +73,7 @@ static const char mconf_readme[] = "o To get help with an item, use the cursor keys to highlight \n" " and press .\n" "\n" -" Shortcut: Press or .\n" +" Shortcut: Press , or .\n" "\n" "o To toggle the display of hidden options, press .\n" "\n" @@ -89,7 +89,7 @@ static const char mconf_readme[] = "o To see available help for the item, use the cursor keys to highlight\n" " and Press .\n" "\n" -" Shortcut: Press or .\n" +" Shortcut: Press , or .\n" "\n" " Also, the and cursor keys will cycle between