[gnome-tour/bilelmoussaoui/fixes: 3/11] build-aux: replace the bash script with a python one




commit 7d8f3e4653b18892184a37cd0e7b2e2a7276eed8
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Fri Dec 31 18:01:46 2021 +0100

    build-aux: replace the bash script with a python one

 build-aux/cargo.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 build-aux/cargo.sh | 21 ---------------------
 meson.build        |  2 +-
 src/meson.build    |  4 ++--
 4 files changed, 55 insertions(+), 24 deletions(-)
---
diff --git a/build-aux/cargo.py b/build-aux/cargo.py
new file mode 100644
index 0000000..cd4186c
--- /dev/null
+++ b/build-aux/cargo.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+
+from os import environ, path
+from subprocess import run
+from argparse import ArgumentParser
+from shutil import copy
+
+parser = ArgumentParser()
+parser.add_argument("build_root")
+parser.add_argument("source_root")
+parser.add_argument("output")
+parser.add_argument("profile")
+parser.add_argument("project_name")
+parser.add_argument("features")
+args = parser.parse_args()
+
+environ["CARGO_TARGET_DIR"] = path.join(args.build_root, "target")
+environ["CARGO_HOME"] = path.join(args.build_root, "cargo-home")
+
+cargo_toml_path = path.join(args.source_root, "Cargo.toml")
+
+if args.profile == "Devel":
+    print("DEBUG MODE")
+    run(
+        [
+            "cargo",
+            "build",
+            "--manifest-path",
+            cargo_toml_path,
+            "--features",
+            args.features,
+        ],
+        check=True,
+    )
+    build_dir = path.join(environ["CARGO_TARGET_DIR"], "debug", args.project_name)
+    copy(build_dir, args.output)
+else:
+    print("RELEASE MODE")
+    run(
+        [
+            "cargo",
+            "build",
+            "--manifest-path",
+            cargo_toml_path,
+            "--release",            
+            "--features",
+            args.features,
+        ],
+        check=True,
+    )
+    build_dir = path.join(environ["CARGO_TARGET_DIR"], "release", args.project_name)
+    copy(build_dir, args.output)
diff --git a/meson.build b/meson.build
index 9f668ab..43f9d25 100644
--- a/meson.build
+++ b/meson.build
@@ -24,7 +24,7 @@ glib_compile_resources = find_program('glib-compile-resources', required: true)
 desktop_file_validate = find_program('desktop-file-validate', required: false)
 appstream_util = find_program('appstream-util', required: false)
 cargo = find_program('cargo', required: false)
-cargo_script = find_program('build-aux/cargo.sh')
+cargo_script = find_program('build-aux/cargo.py')
 
 version = meson.project_version()
 
diff --git a/src/meson.build b/src/meson.build
index 35f2841..801b3a1 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -53,6 +53,7 @@ features = ''
 if get_option('video_path') != ''
   features = '--features video'
 endif
+
 custom_target(
   'cargo-build',
   build_by_default: true,
@@ -69,7 +70,6 @@ custom_target(
     '@OUTPUT@',
     profile,
     meson.project_name(),
-    features
+    features,
   ]
 )
-


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]