[libcamera-devel,v2,1/2] utils: update-mojo.sh: Add script for updating mojo
diff mbox series

Message ID 20210525100750.1239934-1-paul.elder@ideasonboard.com
State Superseded
Headers show
Series
  • [libcamera-devel,v2,1/2] utils: update-mojo.sh: Add script for updating mojo
Related show

Commit Message

Paul Elder May 25, 2021, 10:07 a.m. UTC
Add a script to ease updating mojo from a chromium source tree.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

---
Changes in v2:
- clean mojo/public/tools/* first
- use [ instead of test
- use scope instead of restoring cd
- add todo to remove the jinja2 3.0.0 patch

Note that this script includes the little patch to template_expander.py
to enable it to work with jinja2 3.0.0 (it still works with jinja2
2.10.x).
---
 utils/update-mojo.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100755 utils/update-mojo.sh

Patch
diff mbox series

diff --git a/utils/update-mojo.sh b/utils/update-mojo.sh
new file mode 100755
index 00000000..ebcf7836
--- /dev/null
+++ b/utils/update-mojo.sh
@@ -0,0 +1,72 @@ 
+#!/bin/sh
+
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Update mojo copy from a chromium source tree
+
+if [ $# != 1 ] ; then
+	echo "Usage: $0 <chromium dir>"
+	exit 1
+fi
+
+ipc_dir="$(dirname "$(realpath "$0")")/ipc"
+chromium_dir="$1"
+
+if [ ! -d "${chromium_dir}/mojo" ] ; then
+	echo "Directory ${chromium_dir} doesn't contain mojo"
+	exit 1
+fi
+
+if [ ! -d "${chromium_dir}/.git" ] ; then
+	echo "Directory ${chromium_dir} doesn't contain a git tree"
+	exit 1
+fi
+
+# Get the chromium commit id
+version=$(git -C "${chromium_dir}" rev-parse --short HEAD)
+
+# Reject dirty trees
+if [ -n "$(git -C "${chromium_dir}" status --porcelain)" ] ; then
+	echo "Chromium tree in ${chromium_dir} is dirty"
+	exit 1
+fi
+
+# Copy the diagnosis file
+cp "${chromium_dir}/tools/diagnosis/crbug_1001171.py" "${ipc_dir}/tools/diagnosis"
+
+# Copy the rest of mojo
+cp "${chromium_dir}/mojo/public/LICENSE" "${ipc_dir}/mojo/public"
+
+rm -rf "${ipc_dir}/mojo/public/tools/*"
+
+(
+	cd "${chromium_dir}" || exit
+	find ./mojo/public/tools -type f \
+	     -not -path "*/generators/*" \
+	     -not -path "*/fuzzers/*" \
+	     -exec cp --parents "{}" "${ipc_dir}" ";"
+)
+
+# Update the README files
+readme=$(cat <<EOF
+# SPDX-License-Identifier: CC0-1.0
+
+Files in this directory are imported from ${version} of Chromium. Do not
+modify them manually.
+EOF
+)
+
+echo "$readme" > "${ipc_dir}/mojo/README"
+echo "$readme" > "${ipc_dir}/tools/README"
+
+# Fix mojo support for jinja2 3.0.0
+# TODO: remove this after this is merged:
+# https://chromium-review.googlesource.com/c/chromium/src/+/2908396
+template_expander="${ipc_dir}/mojo/public/tools/mojom/mojom/generate/template_expander.py"
+sed -i "/py_compile=.*$/d" "${template_expander}"
+
+cat <<EOF
+------------------------------------------------------------
+mojo updated. Please review and up-port local changes before
+committing.
+------------------------------------------------------------
+EOF