[{"id":2203,"web_url":"https://patchwork.libcamera.org/comment/2203/","msgid":"<20190710115652.GB26525@pendragon.ideasonboard.com>","date":"2019-07-10T11:56:52","subject":"Re: [libcamera-devel] [PATCH] libcamera: skip auto version\n\tgeneration when building for Chromium OS","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\nThank you for the patch.\n\nOn Wed, Jul 10, 2019 at 08:49:16PM +0900, Paul Elder wrote:\n> Commit b817bcec6b53 (\"libcamera: Auto generate version information\")\n> causes the build to fail in the Chromium OS build environment, because\n> git update-index tries to take a lock (ie. write) in the git repo that\n> is outside of the build directory.\n> \n> The solution is to simply skip git update-index if we are building in\n> the Chromium OS build environment, and this decision is made if the\n> build directory is not a subdirectory of the source directory.\n\nIt's a bit of a hack though, so I'd make this clear\n\n\"As the build runs in a sandbox that traps write accesses instead of\ndisallowing them through regular permissions, we can't easily determine\nif write access to the source tree is permitted or will cause a fault.\nTo work around this, check if the build directory is not a subdirectory\nof the source directory, in which case we don't assume write access and\nskip git update-index. This shouldn't generate too many false positives\nas the build directory is typically placed in the source directory\nduring development, and building packages usually doesn't use a dirty\ngit tree.\"\n\n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> ---\n>  meson.build          |  3 ++-\n>  utils/gen-version.sh | 11 +++++++++--\n>  2 files changed, 11 insertions(+), 3 deletions(-)\n> \n> diff --git a/meson.build b/meson.build\n> index 8f3d0ce..99a3a80 100644\n> --- a/meson.build\n> +++ b/meson.build\n> @@ -15,7 +15,8 @@ project('libcamera', 'c', 'cpp',\n>  # git version tag, the build metadata (e.g. +211-c94a24f4) is omitted from\n>  # libcamera_git_version.\n>  libcamera_git_version = run_command('utils/gen-version.sh',\n> -                                    meson.source_root()).stdout().strip()\n> +                                    meson.source_root(),\n> +                                    meson.build_root()).stdout().strip()\n>  if libcamera_git_version == ''\n>      libcamera_git_version = meson.project_version()\n>  endif\n> diff --git a/utils/gen-version.sh b/utils/gen-version.sh\n> index 708c01d..8700479 100755\n> --- a/utils/gen-version.sh\n> +++ b/utils/gen-version.sh\n> @@ -3,7 +3,10 @@\n>  # SPDX-License-Identifier: GPL-2.0-or-later\n>  # Generate a version string using git describe\n>  \n> -if [ -n \"$1\" ]\n> +SRC_DIR=\"$1\"\n> +BUILD_DIR=\"$2\"\n\nWe tend to use lower-case variables.\n\n> +\n> +if [ -n $SRC_DIR ]\n>  then\n>  \tcd \"$1\" 2>/dev/null || exit 1\n>  fi\n> @@ -24,7 +27,11 @@ fi\n>  \n>  # Append a '-dirty' suffix if the working tree is dirty. Prevent false\n>  # positives due to changed timestamps by running git update-index.\n> -git update-index --refresh > /dev/null 2>&1\n> +if [ \\( -n $SRC_DIR \\) -a \\( -n $BUILD_DIR \\) -a\n> +     $(echo $BUILD_DIR | grep $SRC_DIR) ]\n\nHow about simplifying this by just returning at the top of the script if\neither variable isn't set ? The script is only called by meson, so we\ncontrol what parameters get passed to it.\n\n> +then\n> +\tgit update-index --refresh > /dev/null 2>&1\n> +fi\n>  git diff-index --quiet HEAD || version=\"$version-dirty\"\n>  \n>  # Replace first '-' with a '+' to denote build metadata, strip the 'g' in from","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 27C9260C23\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Jul 2019 13:57:20 +0200 (CEST)","from pendragon.ideasonboard.com (softbank126163157105.bbtec.net\n\t[126.163.157.105])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AB47131C;\n\tWed, 10 Jul 2019 13:57:18 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562759839;\n\tbh=P1rA6Tv+E5lMUU0TJaxzoqo6oynAymWzuWVZ4jc0aG8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=PgwhKzscYYkiTfcr4yBSc+iBVFeQ6bSgiTPaYRQXNvPeKsr1Yh7rgKQLrtH6b2IrU\n\t/JpW+OtJgdJd7pPHCf0eAPRIgR7FAR+n2CHtOzA8ov9syf84y8j8si2wzivwrBiL+y\n\tDdtVZcggV86w2YTrYsHLQloei5TeiwMRnPBUdPCo=","Date":"Wed, 10 Jul 2019 14:56:52 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190710115652.GB26525@pendragon.ideasonboard.com>","References":"<20190710114916.29203-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190710114916.29203-1-paul.elder@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH] libcamera: skip auto version\n\tgeneration when building for Chromium OS","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Wed, 10 Jul 2019 11:57:20 -0000"}},{"id":2205,"web_url":"https://patchwork.libcamera.org/comment/2205/","msgid":"<20190710120618.GB1557@wyvern>","date":"2019-07-10T12:06:18","subject":"Re: [libcamera-devel] [PATCH] libcamera: skip auto version\n\tgeneration when building for Chromium OS","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Paul,\n\nThanks for your work.\n\nOn 2019-07-10 20:49:16 +0900, Paul Elder wrote:\n> Commit b817bcec6b53 (\"libcamera: Auto generate version information\")\n> causes the build to fail in the Chromium OS build environment, because\n> git update-index tries to take a lock (ie. write) in the git repo that\n> is outside of the build directory.\n> \n> The solution is to simply skip git update-index if we are building in\n> the Chromium OS build environment, and this decision is made if the\n> build directory is not a subdirectory of the source directory.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> ---\n>  meson.build          |  3 ++-\n>  utils/gen-version.sh | 11 +++++++++--\n>  2 files changed, 11 insertions(+), 3 deletions(-)\n> \n> diff --git a/meson.build b/meson.build\n> index 8f3d0ce..99a3a80 100644\n> --- a/meson.build\n> +++ b/meson.build\n> @@ -15,7 +15,8 @@ project('libcamera', 'c', 'cpp',\n>  # git version tag, the build metadata (e.g. +211-c94a24f4) is omitted from\n>  # libcamera_git_version.\n>  libcamera_git_version = run_command('utils/gen-version.sh',\n> -                                    meson.source_root()).stdout().strip()\n> +                                    meson.source_root(),\n> +                                    meson.build_root()).stdout().strip()\n>  if libcamera_git_version == ''\n>      libcamera_git_version = meson.project_version()\n>  endif\n> diff --git a/utils/gen-version.sh b/utils/gen-version.sh\n> index 708c01d..8700479 100755\n> --- a/utils/gen-version.sh\n> +++ b/utils/gen-version.sh\n> @@ -3,7 +3,10 @@\n>  # SPDX-License-Identifier: GPL-2.0-or-later\n>  # Generate a version string using git describe\n>  \n> -if [ -n \"$1\" ]\n> +SRC_DIR=\"$1\"\n> +BUILD_DIR=\"$2\"\n> +\n> +if [ -n $SRC_DIR ]\n>  then\n>  \tcd \"$1\" 2>/dev/null || exit 1\n>  fi\n> @@ -24,7 +27,11 @@ fi\n>  \n>  # Append a '-dirty' suffix if the working tree is dirty. Prevent false\n>  # positives due to changed timestamps by running git update-index.\n> -git update-index --refresh > /dev/null 2>&1\n> +if [ \\( -n $SRC_DIR \\) -a \\( -n $BUILD_DIR \\) -a\n> +     $(echo $BUILD_DIR | grep $SRC_DIR) ]\n\nWhen doing this you should either 'set -o pipefail' or examine both \n${PIPESTATUS[0]} and ${PIPESTATUS[1]}. In this case the subtle error \nwill only hit if echo fails for some reason tho.\n\nAnother option is to look at the string and ignore the return code of \nthe two commands,\n\n-n \"$(echo $BUILD_DIR | grep $SRC_DIR)\"\n\n> +then\n> +\tgit update-index --refresh > /dev/null 2>&1\n> +fi\n>  git diff-index --quiet HEAD || version=\"$version-dirty\"\n>  \n>  # Replace first '-' with a '+' to denote build metadata, strip the 'g' in from\n> -- \n> 2.20.1\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-pl1-x644.google.com (mail-pl1-x644.google.com\n\t[IPv6:2607:f8b0:4864:20::644])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B8EBE6156D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Jul 2019 14:06:23 +0200 (CEST)","by mail-pl1-x644.google.com with SMTP id i2so1147361plt.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 10 Jul 2019 05:06:23 -0700 (PDT)","from localhost (softbank126163157105.bbtec.net. [126.163.157.105])\n\tby smtp.gmail.com with ESMTPSA id\n\t30sm7352153pjk.17.2019.07.10.05.06.20\n\t(version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256);\n\tWed, 10 Jul 2019 05:06:21 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=5eBtIHWlWkamnVDnAPGmFynGiX62cgwJ7zHwGfr2Hec=;\n\tb=igytFM+IuS5ECpu3XzA+GDpqSJXo02weNrC7YqLW5jXeGo/RFG1ypSa/EYqqBboved\n\tW1CFXKj7sxJEZWrySBGXgf4JaLdmCPd9RO7S4+NO+km+XLoAtdjaSYaSI6AowWD+g3pT\n\tmxNLSDd/Gg8aEAbI0Y+KX/pQrD/FFisRuyASRqUtNzvFBGq9RmFtH9RSDS8U8/t17lzb\n\tgW3ZODwtqBk+5Yx5y6skYPn8DPboczXr78finmMLgVygRGGVeFS9BqwJs/B//K8GtWei\n\tXkqCTJNrGvOm97wdytdLooYXWq1O+p9xPIiyE/MJXPY30QKINXPHNfZi3jbeAhJBbUto\n\tvpHQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=5eBtIHWlWkamnVDnAPGmFynGiX62cgwJ7zHwGfr2Hec=;\n\tb=e02oPvaIshwkWr/RdGU4ZP21WU8PUS3Bt1E94TS5sFt6vCo3nEB/KGRLbx5h3nz8wP\n\t73TIM8ShxJnetdgrZ8ZT07sBCM/dsNlRyA6NNk+L7+9u6kF1hheppCEPERpgAH5vCAQb\n\tp/ZeWstBZBc6YG9jih7udlkw6Qxv2AXnW4KT1eWZi8Z2ZG8J8aFFY7ETuVk+ihIdjtOy\n\t3Th2bX6o40QvLCgx3yR77+b5N+hCxLants/4zC2kDN/71mK0cH1xgppWSszDWCryNGTg\n\tMVZq6JtExyY0KUE0bDm0Ut6RI6pO4GGoOBYbVDoL7cfnrK02mhk7+8JulN6ct17Yi0kI\n\tIBGg==","X-Gm-Message-State":"APjAAAXH61stxFxdqCPxkME24ng+0fDaK/AGuxfxvsl5mTyzerxQJP0J\n\thN7C5wPoPQgqe+vEYJ1voEpcCQ==","X-Google-Smtp-Source":"APXvYqxfng0H5nd3EicAEyfh2ISQbeOZHnxWRA5ydxegk+qVxQsEKBs29rex/aNpDDUFRtxnG4NDlg==","X-Received":"by 2002:a17:902:be03:: with SMTP id\n\tr3mr23240107pls.156.1562760382266; \n\tWed, 10 Jul 2019 05:06:22 -0700 (PDT)","Date":"Wed, 10 Jul 2019 21:06:18 +0900","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190710120618.GB1557@wyvern>","References":"<20190710114916.29203-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190710114916.29203-1-paul.elder@ideasonboard.com>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [libcamera-devel] [PATCH] libcamera: skip auto version\n\tgeneration when building for Chromium OS","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Wed, 10 Jul 2019 12:06:24 -0000"}}]