From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2247CC433FE for ; Thu, 3 Nov 2022 20:46:41 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 04332850B9; Thu, 3 Nov 2022 21:46:39 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="SFSq9mU2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 42622850A6; Thu, 3 Nov 2022 21:46:38 +0100 (CET) Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 284E8850BD for ; Thu, 3 Nov 2022 21:46:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd35.google.com with SMTP id n191so2363188iod.13 for ; Thu, 03 Nov 2022 13:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=QW88dP2XOzG4LUzwQ3B6DsUYWbkuqdH9h4A1hPDEQCY=; b=SFSq9mU20hdw0S1msyzg16VTAMYoST4GAU8QmfImtzluwBHwl+JGYq8btetl1A6nx0 LeuBqOS/iJAdzxa0PUDxIKyDOhABt4gv+ojQ2AfJj/UW7fcH9A+8z66o6RjswBzwCrMz fHY61xi0gnEAn4w3fBFhBDUJM5gGJoacpEq1U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QW88dP2XOzG4LUzwQ3B6DsUYWbkuqdH9h4A1hPDEQCY=; b=RaVXRj1YRKQnbnEdLyoBhMLJE+3Idj4332n/vck+QrIdB/w2/4unnIc7jNQB4S1s8V N82zq3qwDbMKNuBz5qPpsfYUMfYCE65rnguma36zJh2PdIsM++fKsfRIIYweuDUaKRXV Pb4oUxetSg+jAHR6x9TQnnb4Tdp0cv0RxH+EAGFbRI0C9teM8ACroo2kdNO3rFPvAXEq MsZycpvcZ0I5/ifW+Y8gvc2FKSrZkBLtiqys6z6qxaTOQmu7NbT9dFfZr3wq4bfRhFSE B7eaJkAEOGznVjLLspTbJDcXM3Q++S8ugPpbTNuYykiRkPQyVbCCq2JHq4tYwmtZ1Pyc UlhA== X-Gm-Message-State: ACrzQf0FF3BXw9QleZgJMiicAttGVjKx2vIIv3prAKWnpKbmxFwustwS cn7izsoR+UHM3oDoAUTErou/2thSvBimfw== X-Google-Smtp-Source: AMsMyM5qb6TEyg50ditHHlwzJy0+XXgg2UzpGp7MBAxsNZnuyBkonhBsYvI7N8ksVrfXUDFiO8Xwng== X-Received: by 2002:a05:6602:13c8:b0:68a:db5d:269d with SMTP id o8-20020a05660213c800b0068adb5d269dmr20247575iov.209.1667508392166; Thu, 03 Nov 2022 13:46:32 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id j4-20020a056e02218400b002f66aacb98asm635060ila.70.2022.11.03.13.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 13:46:31 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Holger Brunck , Tom Rini , Simon Glass , Heinrich Schuchardt , Joe Hershberger , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Wolfgang Denk Subject: [PATCH] env: Allow string CONFIG options in the text environment Date: Thu, 3 Nov 2022 14:46:23 -0600 Message-Id: <20221103204623.376634-1-sjg@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Sometimes it is useful to include a CONFIG option that contains a string. This is hard to do in general, since in many cases it is useful to have the quotes around the string so that, for example: bootcmd=run CONFIG_BOARD_CMD becomes bootcmd=run "boot_board" But for the special case where there is a single quoted, it seems reasonable to suppress the quotes, so that: board=CONFIG_SYS_BOARD becomes board=sandbox Update the script, documentation and tests accordingly. Signed-off-by: Simon Glass --- doc/usage/environment.rst | 7 ++++++- scripts/env2string.awk | 8 ++++++++ test/py/tests/test_env.py | 10 +++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/usage/environment.rst b/doc/usage/environment.rst index 15897f63dd9..7272c6abbb4 100644 --- a/doc/usage/environment.rst +++ b/doc/usage/environment.rst @@ -55,7 +55,12 @@ variable but assigning to a new one:: This file can include C-style comments. Blank lines and multi-line variables are supported, and you can use normal C preprocessor directives -and CONFIG defines from your board config also. +and CONFIG defines from your board config also. If the CONFIG value consists of +a string and this is the only thing in the variable, the quotes will be +dropped:: + + something=CONFIG_SYS_BOARD + # where CONFIG_SYS_BOARD is "sandbox" this becomes: something=sandbox For example, for snapper9260 you would create a text file called `board/bluewater/snapper9260.env` containing the environment text. diff --git a/scripts/env2string.awk b/scripts/env2string.awk index de470a49941..3a0fac47d07 100644 --- a/scripts/env2string.awk +++ b/scripts/env2string.awk @@ -43,6 +43,14 @@ NF { var = substr($0, 1, RLENGTH - 1) env = substr($0, RLENGTH + 1) + # If the env value consists entirely of a quoted string, drop + # the quotes. This handles things like fred=CONFIG_SYS_BOARD + # which would otherwise result in fred=\"sandbox\" in this + # output and fred="sandbox" in the final environment. + if (length(env) != 0 && match(env, /^\\"([^"]*)\\"$/)) { + env = substr(env, RSTART + 2, RLENGTH - 4) + } + # Deal with += which concatenates the new string to the existing # variable. Again we are careful to use POSIX match() if (length(env) != 0 && match(var, "^(.*)[+]$")) { diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py index 6d08565f0b5..9bec12a2269 100644 --- a/test/py/tests/test_env.py +++ b/test/py/tests/test_env.py @@ -588,8 +588,16 @@ e=456 m+= 456''', 'e=456\\0m=123 456\\0') # contains quotes + check_script('''fred=run "my var" +mary=another"''', 'fred=run \\"my var\\"\\0mary=another\\"\\0') + + # contains only a quoted strings, so quotes are removed check_script('''fred="my var" -mary=another"''', 'fred=\\"my var\\"\\0mary=another\\"\\0') +mary=another"''', 'fred=my var\\0mary=another\\"\\0') + + # contains more than one quoted string + check_script('''fred="my var" or "this var" +mary=another"''', 'fred=\\"my var\\" or \\"this var\\"\\0mary=another\\"\\0') # variable name ending in + check_script('''fred\\+=my var -- 2.38.1.431.g37b22c650d-goog