From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1125354-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id E0E51138334
	for <garchives@archives.gentoo.org>; Mon, 25 Nov 2019 19:51:42 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id AD53CE09BA;
	Mon, 25 Nov 2019 19:51:41 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 8BEF7E09BA
	for <gentoo-commits@lists.gentoo.org>; Mon, 25 Nov 2019 19:51:41 +0000 (UTC)
Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 3162934D381
	for <gentoo-commits@lists.gentoo.org>; Mon, 25 Nov 2019 19:51:40 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id A6A7D26C
	for <gentoo-commits@lists.gentoo.org>; Mon, 25 Nov 2019 19:51:38 +0000 (UTC)
From: "Fabian Groffen" <grobian@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" <grobian@gentoo.org>
Message-ID: <1574711453.4df5c3e4cd84692da9b6cdcc04315fa37b8dddea.grobian@gentoo>
Subject: [gentoo-commits] proj/portage-utils:master commit in: /
X-VCS-Repository: proj/portage-utils
X-VCS-Files: main.c
X-VCS-Directories: /
X-VCS-Committer: grobian
X-VCS-Committer-Name: Fabian Groffen
X-VCS-Revision: 4df5c3e4cd84692da9b6cdcc04315fa37b8dddea
X-VCS-Branch: master
Date: Mon, 25 Nov 2019 19:51:38 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: f421c10b-6408-4c28-9852-a44cfdc87ff5
X-Archives-Hash: 29650c0db0159b87319f2406fa3701f7

commit:     4df5c3e4cd84692da9b6cdcc04315fa37b8dddea
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Nov 25 19:50:53 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Nov 25 19:50:53 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=4df5c3e4

read_portage_profile: process in order as specified by PMS 5.2.1

Ensure that value overrides work as intended.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 main.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/main.c b/main.c
index 6033429..5ffe0ba 100644
--- a/main.c
+++ b/main.c
@@ -494,9 +494,6 @@ read_portage_profile(const char *profile, env_vars vars[])
 	size_t buf_len = 0;
 	char *saveptr;
 
-	if (getenv("DEBUG"))
-		fprintf(stderr, "profile %s\n", profile);
-
 	/* create mutable/appendable copy */
 	profile_len = snprintf(profile_file, sizeof(profile_file), "%s/", profile);
 
@@ -504,11 +501,9 @@ read_portage_profile(const char *profile, env_vars vars[])
 	if (sizeof(profile_file) - profile_len < sizeof("make.defaults"))
 		return;
 
-	/* first consume the profile's make.defaults */
-	strcpy(profile_file + profile_len, "make.defaults");
-	read_portage_env_file(profile_file, vars);
-
-	/* now walk all the parents */
+	/* first walk all the parents, PMS 5.2.1 defines that it should
+	 * treat parent profiles as defaults, that can be overridden by
+	 * *this* profile. */
 	strcpy(profile_file + profile_len, "parent");
 	if (eat_file(profile_file, &buf, &buf_len) == 0)
 		return;
@@ -552,6 +547,10 @@ read_portage_profile(const char *profile, env_vars vars[])
 	}
 
 	free(buf);
+
+	/* now consume *this* profile's make.defaults */
+	strcpy(profile_file + profile_len, "make.defaults");
+	read_portage_env_file(profile_file, vars);
 }
 
 static bool nocolor = 0;
@@ -749,6 +748,12 @@ initialize_portage_env(void)
 				(char *)array_get_elem(overlay_src, 0));
 	}
 
+	/* consider Portage's defaults */
+	snprintf(pathbuf, sizeof(pathbuf),
+			"%.*s/usr/share/portage/config/make.globals",
+			(int)i, configroot);
+	read_portage_env_file(pathbuf, vars_to_read);
+
 	/* walk all the stacked profiles */
 	snprintf(pathbuf, sizeof(pathbuf), "%.*s/etc/make.profile",
 			(int)i, configroot);
@@ -758,10 +763,6 @@ initialize_portage_env(void)
 	read_portage_profile(pathbuf, vars_to_read);
 
 	/* now read all the config files */
-	snprintf(pathbuf, sizeof(pathbuf),
-			"%.*s/usr/share/portage/config/make.globals",
-			(int)i, configroot);
-	read_portage_env_file(pathbuf, vars_to_read);
 	snprintf(pathbuf, sizeof(pathbuf), "%.*s/etc/make.conf",
 			(int)i, configroot);
 	read_portage_env_file(pathbuf, vars_to_read);