From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1612936-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id A4306158041
	for <garchives@archives.gentoo.org>; Wed, 20 Mar 2024 21:45:22 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id D4291E29AA;
	Wed, 20 Mar 2024 21:45:21 +0000 (UTC)
Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id B63E1E29AA
	for <gentoo-commits@lists.gentoo.org>; Wed, 20 Mar 2024 21:45:21 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id D90FF335D2B
	for <gentoo-commits@lists.gentoo.org>; Wed, 20 Mar 2024 21:45:20 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 216A21594
	for <gentoo-commits@lists.gentoo.org>; Wed, 20 Mar 2024 21:45:19 +0000 (UTC)
From: "Matt Jolly" <kangie@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, "Matt Jolly" <kangie@gentoo.org>
Message-ID: <1710971100.3b0f8cfc4a3d2e3344be2786a6ea9c255c43f8ee.kangie@gentoo>
Subject: [gentoo-commits] proj/chromium-tools:master commit in: /
X-VCS-Repository: proj/chromium-tools
X-VCS-Files: get_chromium_toolchain_strings.sh
X-VCS-Directories: /
X-VCS-Committer: kangie
X-VCS-Committer-Name: Matt Jolly
X-VCS-Revision: 3b0f8cfc4a3d2e3344be2786a6ea9c255c43f8ee
X-VCS-Branch: master
Date: Wed, 20 Mar 2024 21:45:19 +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: 975e4922-ea52-4273-8f02-0b845daaf0fe
X-Archives-Hash: f2f142d22495541f3cfc6dbdd1e44e71

commit:     3b0f8cfc4a3d2e3344be2786a6ea9c255c43f8ee
Author:     Matt Jolly <kangie <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 20 21:45:00 2024 +0000
Commit:     Matt Jolly <kangie <AT> gentoo <DOT> org>
CommitDate: Wed Mar 20 21:45:00 2024 +0000
URL:        https://gitweb.gentoo.org/proj/chromium-tools.git/commit/?id=3b0f8cfc

New script: get_chromium_toolchain_strings.sh

Just does some awks and seds to enable the automated update
of google toolchain information within / from the specified
ebuild

Signed-off-by: Matt Jolly <kangie <AT> gentoo.org>

 get_chromium_toolchain_strings.sh | 70 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/get_chromium_toolchain_strings.sh b/get_chromium_toolchain_strings.sh
new file mode 100755
index 0000000..483d66f
--- /dev/null
+++ b/get_chromium_toolchain_strings.sh
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+# This script extracts version information from Chromium sources by way of a Gentoo ebuild
+# then plugs the version information into the ebuild file. This is useful for updating the
+# toolchain versions in the ebuild file when a new (major) version of Chromium is released.
+
+# Usage: get_chromium_toolchain_strings.sh <ebuild_file>
+#   <ebuild_file>: The path to the Chromium ebuild file
+
+# Extract the version string from an ebuild
+get_version() {
+  local filename="$1"
+  [[ -z "$filename" ]] && return 1  # Check for empty filename
+  local version_match="${filename##*-}";  # Extract everything after the last hyphen
+  version_match="${version_match%.*}"  # Remove extension (.ebuild)
+  echo "$version_match"
+}
+
+# Display script usage
+usage() {
+  echo "Usage: get_chromium_toolchain_strings.sh <ebuild_file>"
+  echo "  <ebuild_file>: The path to the Chromium ebuild file"
+}
+
+# Get the ebuild filename as the first argument
+ebuild_file="$1"
+
+# Check for missing argument
+if [[ -z "$ebuild_file" ]]; then
+  echo "Error: Please provide an ebuild filename as an argument."
+  usage
+  exit 1
+fi
+
+# Extract version from filename
+version="$(get_version "$ebuild_file")"
+
+# Check if version extraction failed (function return code)
+if [[ $? -ne 0 ]]; then
+  echo "Error: Could not extract version from filename."
+  exit 1
+fi
+
+# Construct S string based on version
+# Bad luck if you don't use /var/tmp/portage, I guess.
+S="/var/tmp/portage/www-client/chromium-${version}/work/chromium-${version}/"
+
+# Run ebuild with clean and unpack options
+ebuild "$ebuild_file" clean unpack
+
+# No secret sauce here - it's just simpler to set the field separator to a single quote
+# and then extract the final character from the sub-revision field.
+# This is a bit of a hack, but it works for now - I haven't see upstream go past the
+# 9th sub-revision yet!
+
+llvm_version=$(awk -F"'" '
+/CLANG_REVISION =/ { revision = $2 }
+/CLANG_SUB_REVISION =/ { printf("%s-%d\n", revision, substr($1, length($1), 1)) }
+' "${S}/tools/clang/scripts/update.py")
+
+rust_version=$(awk -F"'" '
+/RUST_REVISION =/ { revision = $2 }
+/RUST_SUB_REVISION =/ { printf("%s-%d\n", revision, substr($1, length($1), 1)) }
+' "${S}/tools/rust/update_rust.py")
+
+# Substitute versions into ebuild (assuming specific locations)
+sed -i "s/GOOGLE_CLANG_VER=.*/GOOGLE_CLANG_VER=${llvm_version}/" "$ebuild_file"
+sed -i "s/GOOGLE_RUST_VER=.*/GOOGLE_RUST_VER=${rust_version}/" "$ebuild_file"
+
+echo "Successfully substituted versions into $ebuild_file"