Show a patch.

GET /api/1.1/patches/1632/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 1632,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/1632/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1632/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20190708131212.15275-1-laurent.pinchart@ideasonboard.com>",
    "date": "2019-07-08T13:12:12",
    "name": "[libcamera-devel,v2] libcamera: Rework automatic version generation to avoid rebuilds",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "83f5114d593942d72261296e44cd65fc2401a2b4",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/1632/mbox/",
    "series": [
        {
            "id": 409,
            "url": "https://patchwork.libcamera.org/api/1.1/series/409/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=409",
            "date": "2019-07-08T13:12:12",
            "name": "[libcamera-devel,v2] libcamera: Rework automatic version generation to avoid rebuilds",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/409/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1632/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1632/checks/",
    "tags": {},
    "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 11C1160C1C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  8 Jul 2019 15:12:47 +0200 (CEST)",
            "from pendragon.ideasonboard.com (softbank126163157105.bbtec.net\n\t[126.163.157.105])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 02FA656A;\n\tMon,  8 Jul 2019 15:12:44 +0200 (CEST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562591566;\n\tbh=2CewJXOPEQsPT/MTsD2tlPqftErNJwsxw9/d3/LllQg=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=cMmq50pv9Llwz33iPMW0B8FUUHNSwHWQDKFs2DykHrioBJnj390iLLwwYKJMGBxtd\n\tOlaCd4FWKin6cIT0u1hW+tdD+kdIora0rOlrSy5NiRL9nwxO0Q6koSFOoiWgXvyoLG\n\te+e8jUMT4mKAo/nnMMPJzidbnQIbfdFXw4iC/I9k=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon,  8 Jul 2019 16:12:12 +0300",
        "Message-Id": "<20190708131212.15275-1-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.21.0",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2] libcamera: Rework automatic version\n\tgeneration to avoid rebuilds",
        "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": "Mon, 08 Jul 2019 13:12:47 -0000"
    },
    "content": "Commit b817bcec6b53 (\"libcamera: Auto generate version information\")\ngenerates version information in order to automatically include it\nvarious locations (Sphinx and Doxygen documentation, libcamera::version\nvariable available at runtime, and version.h available at compile time).\nUnfortunately this causes lots of unnecessary rebuilds when modifying\nthe git tree state, which hinders development.\n\nThe problem is caused by the generated version.h being listed as a\ndependency for the whole libcamera. This is required as meson (to the\nbest of my knowledge) doesn't provide a way to explicitly specify the\ndependency of a single object file (camera_manager.o in this case, as\ncamera_manager.cpp is the only consumer of the generated version string)\non the custom target used to generate version.h. The dependency can't be\nautomatically detected at build time, like dependencies on normal\nheaders that are generated by parsing the source, because the version.h\nheader may not exist yet. The build could then fail in a racy way.\n\nThis change attempts at solving the issue by generating a version.cpp\ninstead of a version.h to set the git-based version. This minimises the\nnumber of files that need to be rebuild when then git tree state\nchanges, while retaining the main purpose of the original automatic\nversion generation, the ability to access the git-based version string\nat runtime. We however lose the ability to access git-based version\ninformation at build time in an application building against libcamera,\nbut there is no expected use case for this.\n\nOn the other hand, major, minor and patch level version numbers are\nuseful at build time. This commit changes the generation of version.h in\norder to add three macros named LIBCAMERA_VERSION_MAJOR,\nLIBCAMERA_VERSION_MINOR and LIBCAMERA_VERSION_PATCH for this purpose.\nversion.h is not included by any other libcamera header or source file,\nand thus doesn't force a rebuild of the library.\n\nThe Sphinx and Doxygen documentation keep their git-based version\ninformation, which is set during the configuration of the build and then\ndoesn't track git commits. We may want to investigate how to improve\nthis, but given that git-based version for the documentation has very\nfew use cases outside of tagging nightly builds, this isn't considered\nan issue at the moment.\n\nThe documentation install directory now uses the base version string, in\norder to avoid increasing the number of documentation directories\nneedlessly. This shouldn't cause any issue as the API should not change\nwithout a change to the version number.\n\nThe version number generation and handling code now also standardises\nthe version variables to not start with a 'v' prefix in meson, in order\nto simplify their handling. The prefix is added when generating the\nrelevant files.\n\nNote that we go back to specifying the fallback version in the main\nmeson.build, in the call to the project() function. For the time being I\nbelieve this should be a good compromise to avoid unnecessary\nrecompilation, and moving the fallback version to a different file for\ntarball releases can be built on top of this.\n\nFixes: b817bcec6b53 (\"libcamera: Auto generate version information\")\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n Documentation/meson.build          |  6 +++---\n include/libcamera/camera_manager.h |  3 +++\n include/libcamera/gen-header.sh    |  6 +++++-\n include/libcamera/meson.build      | 18 +++++++++++-------\n include/libcamera/version.h.in     | 12 +++---------\n meson.build                        | 19 ++++++++++++++++---\n src/libcamera/camera_manager.cpp   | 14 +++++++-------\n src/libcamera/meson.build          | 10 +++++++++-\n src/libcamera/version.cpp.in       | 16 ++++++++++++++++\n src/qcam/main_window.cpp           |  2 +-\n utils/gen-version.sh               | 23 ++++++++++-------------\n 11 files changed, 84 insertions(+), 45 deletions(-)\n create mode 100644 src/libcamera/version.cpp.in",
    "diff": "diff --git a/Documentation/meson.build b/Documentation/meson.build\nindex c355d5feb504..b1720b05f5ee 100644\n--- a/Documentation/meson.build\n+++ b/Documentation/meson.build\n@@ -1,5 +1,5 @@\n doc_install_dir = join_paths(get_option('datadir'), 'doc',\n-                             'libcamera-@0@'.format(meson.project_version()))\n+                             'libcamera-@0@'.format(libcamera_version))\n \n #\n # Doxygen\n@@ -9,7 +9,7 @@ doxygen = find_program('doxygen', required : false)\n \n if doxygen.found()\n     cdata = configuration_data()\n-    cdata.set('VERSION', meson.project_version())\n+    cdata.set('VERSION', 'v@0@'.format(libcamera_git_version))\n     cdata.set('TOP_SRCDIR', meson.source_root())\n     cdata.set('TOP_BUILDDIR', meson.build_root())\n \n@@ -48,7 +48,7 @@ if sphinx.found()\n         'index.rst',\n     ]\n \n-    release = 'release=' + meson.project_version()\n+    release = 'release=v' + libcamera_git_version\n \n     custom_target('documentation',\n                   command : [sphinx, '-D', release, '-q', '-W', '-b', 'html',\ndiff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h\nindex cf3a85ae8fe3..633d27d17ebf 100644\n--- a/include/libcamera/camera_manager.h\n+++ b/include/libcamera/camera_manager.h\n@@ -31,6 +31,7 @@ public:\n \tvoid removeCamera(Camera *camera);\n \n \tstatic CameraManager *instance();\n+\tstatic const std::string &version() { return version_; }\n \n \tvoid setEventDispatcher(std::unique_ptr<EventDispatcher> dispatcher);\n \tEventDispatcher *eventDispatcher();\n@@ -46,6 +47,8 @@ private:\n \tstd::vector<std::shared_ptr<Camera>> cameras_;\n \n \tstd::unique_ptr<EventDispatcher> dispatcher_;\n+\n+\tstatic const std::string version_;\n };\n \n } /* namespace libcamera */\ndiff --git a/include/libcamera/gen-header.sh b/include/libcamera/gen-header.sh\nindex e171c08c20b8..ccd3414bd8ca 100755\n--- a/include/libcamera/gen-header.sh\n+++ b/include/libcamera/gen-header.sh\n@@ -16,8 +16,12 @@ cat <<EOF > \"$dst_file\"\n \n EOF\n \n-for header in \"$src_dir\"/*.h ; do\n+headers=$(for header in $\"$src_dir\"/*.h ; do\n \theader=$(basename \"$header\")\n+\techo $header\n+done ; echo \"version.h\" | sort)\n+\n+for header in $(echo $headers) ; do\n \techo \"#include <libcamera/$header>\" >> \"$dst_file\"\n done\n \ndiff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 6f81f1117318..972513fc2df5 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -16,13 +16,6 @@ libcamera_api = files([\n     'timer.h',\n ])\n \n-gen_version = join_paths(meson.source_root(), 'utils', 'gen-version.sh')\n-\n-version_h = vcs_tag(command : [gen_version, meson.current_source_dir()],\n-                    input : 'version.h.in',\n-                    output : 'version.h',\n-                    fallback : 'v0.0')\n-\n gen_header = files('gen-header.sh')\n \n libcamera_h = custom_target('gen-header',\n@@ -32,5 +25,16 @@ libcamera_h = custom_target('gen-header',\n                             install : true,\n                             install_dir : 'include/libcamera')\n \n+version = libcamera_version.split('.')\n+libcamera_version_config = configuration_data()\n+libcamera_version_config.set('LIBCAMERA_VERSION_MAJOR', version[0])\n+libcamera_version_config.set('LIBCAMERA_VERSION_MINOR', version[1])\n+libcamera_version_config.set('LIBCAMERA_VERSION_PATCH', version[2])\n+\n+configure_file(input : 'version.h.in',\n+               output : 'version.h',\n+               configuration : libcamera_version_config,\n+               install_dir : 'include/libcamera')\n+\n install_headers(libcamera_api,\n                 subdir : 'libcamera')\ndiff --git a/include/libcamera/version.h.in b/include/libcamera/version.h.in\nindex e49b36962aed..5e9a30911d12 100644\n--- a/include/libcamera/version.h.in\n+++ b/include/libcamera/version.h.in\n@@ -9,14 +9,8 @@\n #ifndef __LIBCAMERA_VERSION_H__\n #define __LIBCAMERA_VERSION_H__\n \n-#include <string>\n-\n-#define LIBCAMERA_VERSION \"@VCS_TAG@\"\n-\n-namespace libcamera {\n-\n-extern const std::string version;\n-\n-} /* namespace libcamera */\n+#define LIBCAMERA_VERSION_MAJOR\t\t@LIBCAMERA_VERSION_MAJOR@\n+#define LIBCAMERA_VERSION_MINOR\t\t@LIBCAMERA_VERSION_MINOR@\n+#define LIBCAMERA_VERSION_PATCH\t\t@LIBCAMERA_VERSION_PATCH@\n \n #endif /* __LIBCAMERA_VERSION_H__ */\ndiff --git a/meson.build b/meson.build\nindex 342b3cc76a93..8f3d0ce91cb8 100644\n--- a/meson.build\n+++ b/meson.build\n@@ -1,8 +1,6 @@\n project('libcamera', 'c', 'cpp',\n     meson_version : '>= 0.40',\n-    version : run_command('utils/gen-version.sh',\n-                          '@0@'.format(meson.source_root()),\n-                          check : true).stdout().strip(),\n+    version : '0.0.0',\n     default_options : [\n         'werror=true',\n         'warning_level=2',\n@@ -10,6 +8,21 @@ project('libcamera', 'c', 'cpp',\n     ],\n     license : 'LGPL 2.1+')\n \n+# Generate version information. The libcamera_git_version variable contains the\n+# full version with git patch count and SHA1 (e.g. 1.2.3+211-c94a24f4), while\n+# the libcamera_version variable contains the major.minor.patch (e.g. 1.2.3)\n+# only. If the source tree isn't under git control, or if it matches the last\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+if libcamera_git_version == ''\n+    libcamera_git_version = meson.project_version()\n+endif\n+\n+libcamera_version = libcamera_git_version.split('+')[0]\n+\n+# Configure the build environment.\n cc = meson.get_compiler('c')\n config_h = configuration_data()\n \ndiff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\nindex c5da46b4062d..337496c21cfc 100644\n--- a/src/libcamera/camera_manager.cpp\n+++ b/src/libcamera/camera_manager.cpp\n@@ -9,7 +9,6 @@\n \n #include <libcamera/camera.h>\n #include <libcamera/event_dispatcher.h>\n-#include <libcamera/version.h>\n \n #include \"device_enumerator.h\"\n #include \"event_dispatcher_poll.h\"\n@@ -26,11 +25,6 @@ namespace libcamera {\n \n LOG_DEFINE_CATEGORY(Camera)\n \n-/**\n- * \\brief The library global version string\n- */\n-const std::string version(LIBCAMERA_VERSION);\n-\n /**\n  * \\class CameraManager\n  * \\brief Provide access and manage all cameras in the system\n@@ -85,7 +79,7 @@ int CameraManager::start()\n \tif (enumerator_)\n \t\treturn -EBUSY;\n \n-\tLOG(Camera, Info) << \"libcamera \" << version;\n+\tLOG(Camera, Info) << \"libcamera \" << version_;\n \n \tenumerator_ = DeviceEnumerator::create();\n \tif (!enumerator_ || enumerator_->enumerate())\n@@ -232,6 +226,12 @@ CameraManager *CameraManager::instance()\n \treturn &manager;\n }\n \n+/**\n+ * \\fn const std::string &CameraManager::version()\n+ * \\brief Retrieve the libcamera version string\n+ * \\return The libcamera version string\n+ */\n+\n /**\n  * \\brief Set the event dispatcher\n  * \\param[in] dispatcher Pointer to the event dispatcher\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 336f4f066fac..97ff86e2167f 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -79,8 +79,16 @@ control_types_cpp = custom_target('control_types_cpp',\n \n libcamera_sources += control_types_cpp\n \n+gen_version = join_paths(meson.source_root(), 'utils', 'gen-version.sh')\n+\n+version_cpp = vcs_tag(command : [gen_version, meson.source_root()],\n+                      input : 'version.cpp.in',\n+                      output : 'version.cpp',\n+                      fallback : meson.project_version())\n+\n+libcamera_sources += version_cpp\n+\n libcamera_deps = [\n-    declare_dependency(sources : version_h),\n     cc.find_library('dl'),\n     libudev,\n ]\ndiff --git a/src/libcamera/version.cpp.in b/src/libcamera/version.cpp.in\nnew file mode 100644\nindex 000000000000..5aec08a189f3\n--- /dev/null\n+++ b/src/libcamera/version.cpp.in\n@@ -0,0 +1,16 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * version.cpp - libcamera version\n+ *\n+ * This file is auto-generated. Do not edit.\n+ */\n+\n+#include <libcamera/camera_manager.h>\n+\n+namespace libcamera {\n+\n+const std::string CameraManager::version_(\"v@VCS_TAG@\");\n+\n+} /* namespace libcamera */\ndiff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\nindex b2f3a1f324f2..907d2423ed15 100644\n--- a/src/qcam/main_window.cpp\n+++ b/src/qcam/main_window.cpp\n@@ -26,7 +26,7 @@ MainWindow::MainWindow(const OptionsParser::Options &options)\n {\n \tint ret;\n \n-\ttitle_ = \"QCam \" + QString::fromStdString(libcamera::version);\n+\ttitle_ = \"QCam \" + QString::fromStdString(CameraManager::version());\n \tsetWindowTitle(title_);\n \tconnect(&titleTimer_, SIGNAL(timeout()), this, SLOT(updateTitle()));\n \ndiff --git a/utils/gen-version.sh b/utils/gen-version.sh\nindex b3003d7a80d3..1800d71642c0 100755\n--- a/utils/gen-version.sh\n+++ b/utils/gen-version.sh\n@@ -8,6 +8,9 @@ then\n \tcd \"$1\" 2>/dev/null || exit 1\n fi\n \n+# Bail out if the directory isn't under git control\n+git rev-parse --git-dir >/dev/null 2>&1 || exit 1\n+\n # Get a short description from the tree.\n version=$(git describe --abbrev=8 --match \"v[0-9]*\" 2>/dev/null)\n \n@@ -16,22 +19,16 @@ then\n \t# Handle an un-tagged repository\n \tsha=$(git describe --abbrev=8 --always 2>/dev/null)\n \tcommits=$(git log --oneline | wc -l 2>/dev/null)\n-\tversion=v0.0.$commits.$sha\n+\tversion=\"v0.0.0-$commits-g$sha\"\n fi\n \n-# Prevent changed timestamps causing -dirty labels\n+# Append a '-dirty' suffix is 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-dirty=$(git diff-index --name-only HEAD 2>/dev/null) || dirty=\n+git diff-index --quiet HEAD || version=\"$version-dirty\"\n \n-# Strip the 'g', and replace the preceeding '-' with a '+' to denote a label\n-version=$(echo \"$version\" | sed -e 's/-g/+/g')\n-\n-# Fix the '-' (the patch count) to a '.' as a version increment.\n-version=$(echo \"$version\" | sed -e 's/-/./g')\n-\n-if [ -n \"$dirty\" ]\n-then\n-\tversion=$version-dirty\n-fi\n+# Replace first '-' with a '+' to denote build metadata, strip the 'g' in from\n+# of the git SHA1 and remove the initial 'v'.\n+version=$(echo \"$version\" | sed -e 's/-/+/' | sed -e 's/-g/-/' | cut -c 2-)\n \n echo \"$version\"\n",
    "prefixes": [
        "libcamera-devel",
        "v2"
    ]
}