diff --git a/cargo_build.py b/cargo_build.py new file mode 100644 index 00000000..d78ceb9e --- /dev/null +++ b/cargo_build.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +"""This script manages Cargo builds +while keeping the artifact directory within the build tree +instead of the source tree. +""" + +from pathlib import Path +import shlex +import subprocess +import sys + +source_dir = Path(__file__).absolute().parent + +args = sys.argv[1:] +binary_dir = "debug" + +if '--release' in args: + binary_dir = "release" + +# The file produced by Cargo will have a special name +try: + i = args.index('--rename') +except ValueError: + filename = None +else: + args.pop(i) + filename = args.pop(i) + +# The target destination of the produced file is a positional argument +out_path = [arg for arg in args if not arg.startswith('--')] +if out_path: + out_path = out_path[0] + i = args.index(out_path) + args.pop(i) + +subprocess.run(['sh', "{}/cargo.sh".format(shlex.quote(source_dir.as_posix())), 'build'] + + args, + check=True) + +if out_path: + out_path = Path(out_path).absolute() + out_basename = out_path.name + filename = filename or out_basename + subprocess.run(['cp', '-a', + './{}/{}'.format(shlex.quote(binary_dir), shlex.quote(filename)), + out_path], + check=True) + diff --git a/cargo_build.sh b/cargo_build.sh deleted file mode 100755 index 840bc1c6..00000000 --- a/cargo_build.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh - -# This script manages Cargo builds -# while keeping the artifact directory within the build tree -# instead of the source tree - -set -e - -SCRIPT_PATH="$(realpath "$0")" -SOURCE_DIR="$(dirname "$SCRIPT_PATH")" - -RELEASE="" -BINARY_DIR="debug" -if [ "${1}" = "--release" ]; then - shift - BINARY_DIR="release" - RELEASE="--release" -fi - -if [ "${1}" = "--rename" ]; then - shift - FILENAME="${1}" - shift -fi -OUT_PATH="$(realpath "${1}")" -shift -OUT_BASENAME="$(basename "${OUT_PATH}")" -FILENAME="${FILENAME:-"${OUT_BASENAME}"}" - -sh "$SOURCE_DIR"/cargo.sh build $RELEASE "$@" - -if [ -n "${OUT_PATH}" ]; then - cp -a ./"${BINARY_DIR}"/"${FILENAME}" "${OUT_PATH}" -fi diff --git a/debian/control b/debian/control index ff713e71..f57b943a 100644 --- a/debian/control +++ b/debian/control @@ -26,6 +26,7 @@ Build-Depends: librust-xkbcommon-0.4+wayland-dev (>= 0.4), libwayland-dev (>= 1.16), lsb-release, + python3, rustc, wayland-protocols (>= 1.14), Standards-Version: 4.1.3 diff --git a/meson.build b/meson.build index a1a073a4..c0eac362 100644 --- a/meson.build +++ b/meson.build @@ -100,7 +100,7 @@ cargo_toml = custom_target( dep_cargo = find_program('cargo') cargo_script = find_program('cargo.sh') -cargo_build = find_program('cargo_build.sh') +cargo_build = find_program('cargo_build.py') subdir('data') subdir('protocols')