From e28f04a241e84af2c19804faccd918cd4a8a701d Mon Sep 17 00:00:00 2001
From: Ryan Brue <ryanbrue.dev@gmail.com>
Date: Sep 29 2024 07:03:15 +0000
Subject: [PATCH 1/2] more automation tools, etc


Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>

---

diff --git a/cosmic-packaging-tool/extra_scripts/build.sh b/cosmic-packaging-tool/extra_scripts/build.sh
new file mode 100755
index 0000000..bcd5513
--- /dev/null
+++ b/cosmic-packaging-tool/extra_scripts/build.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+# Define a list of strings
+# list=("cosmic-app-library" "cosmic-applets" "cosmic-bg" "cosmic-comp" "cosmic-edit" "cosmic-files" "cosmic-greeter" "cosmic-icon-theme" "cosmic-osd" "cosmic-settings" "cosmic-settings-daemon" "cosmic-store" "cosmic-notifications" "cosmic-panel" "cosmic-randr" "cosmic-screenshot" "cosmic-workspaces" "xdg-desktop-portal-cosmic")
+list=("cosmic-edit" "cosmic-files" "cosmic-greeter" "cosmic-icon-theme" "cosmic-osd" "cosmic-settings" "cosmic-settings-daemon" "cosmic-store" "cosmic-notifications" "cosmic-panel" "cosmic-randr" "cosmic-screenshot" "cosmic-workspaces" "xdg-desktop-portal-cosmic")
+
+# Loop through the list
+for item in "${list[@]}"
+do
+    # Run a command for each string
+    echo "Processing: $item"
+    cargo run -- setup-build ~/workdir $item --build-branch f41 --source-branch rawhide
+done
diff --git a/cosmic-packaging-tool/src/main.rs b/cosmic-packaging-tool/src/main.rs
index bdea719..7220b4d 100644
--- a/cosmic-packaging-tool/src/main.rs
+++ b/cosmic-packaging-tool/src/main.rs
@@ -5,6 +5,8 @@ use std::{
     io::{self, BufRead, Write},
     path::{Path, PathBuf},
     process::Command,
+    thread,
+    time::Duration,
 };
 
 use clap::{Parser, Subcommand};
@@ -52,11 +54,30 @@ enum Commands {
         workdir: PathBuf,
         /// Package name (cosmic-comp for example)
         package_name: String,
+        /// Optionally specify the branch to build
+        #[arg(long)]
+        build_branch: Option<String>,
         /// Srpm url (check the copr)
-        srpm_url: String,
+        #[arg(long)]
+        srpm_url: Option<String>,
+        /// Optional source branch to get content from
+        #[arg(long)]
+        source_branch: Option<String>,
         /// Version (i.e. 1.0.0~alpha.2)
-        version: String,
+        #[arg(long)]
+        version: Option<String>,
     },
+    // /// Sets up a fedpkg build from the rawhide branch to a different branch
+    // BuildForBranch {
+    //     /// Working directory
+    //     workdir: PathBuf,
+    //     /// Package name (cosmic-comp for example)
+    //     package_name: String,
+    //     /// Other branch (rawhide for example)
+    //     from_branch: String,
+    //     /// To branch (f41 for example)
+    //     to_branch: String,
+    // },
     /// Build a dependency graph of the packages
     DependencyGraph { packaging_dir: PathBuf },
 }
@@ -193,7 +214,16 @@ fn main() -> anyhow::Result<()> {
             package_name,
             srpm_url,
             version,
-        } => setup_build_command(&workdir, &package_name, &srpm_url, &version),
+            build_branch,
+            source_branch,
+        } => setup_build_command(
+            &workdir,
+            &package_name,
+            srpm_url.as_deref(),
+            version.as_deref(),
+            build_branch.as_deref(),
+            source_branch.as_deref(),
+        ),
         Commands::DependencyGraph { packaging_dir } => dependency_graph_command(&packaging_dir),
     }
 }
@@ -254,8 +284,10 @@ fn dependency_graph_command(packaging_dir: &Path) -> anyhow::Result<()> {
 fn setup_build_command(
     workdir: &Path,
     package_name: &str,
-    srpm_url: &str,
-    version: &str,
+    srpm_url: Option<&str>,
+    version: Option<&str>,
+    build_branch: Option<&str>,
+    source_branch: Option<&str>,
 ) -> anyhow::Result<()> {
     let _ = create_dir(workdir);
     let rpm_path = workdir.join(&format!("{}.rpm", package_name));
@@ -271,63 +303,102 @@ fn setup_build_command(
     {
         panic!("Failed: fedpkg clone {}", package_name);
     }
-    println!("wget -O {:?} {}", &rpm_path, srpm_url);
-    if !Command::new("wget")
-        .current_dir(workdir)
-        .arg("-O")
-        .arg(&rpm_path)
-        .arg(srpm_url)
-        .status()
-        .unwrap()
-        .success()
-    {
-        panic!("Failed: wget -O {:?} {}", &rpm_path, srpm_url);
-    }
-    println!("fedpkg import --skip-diffs {:?}", &rpm_path);
-    if !Command::new("fedpkg")
-        .current_dir(&package_folder)
-        .arg("import")
-        .arg("--skip-diffs")
-        .arg(&rpm_path)
-        .status()
-        .unwrap()
-        .success()
-    {
-        panic!("Failed: fedpkg import --skip-diffs {:?}", &rpm_path);
+    if let Some(build_branch) = build_branch {
+        println!("fedpkg switch-branch {}", build_branch);
+        if !Command::new("fedpkg")
+            .current_dir(&package_folder)
+            .arg("switch-branch")
+            .arg(build_branch)
+            .status()
+            .unwrap()
+            .success()
+        {
+            panic!("Failed: fedpkg switch-branch {}", build_branch);
+        }
     }
-    let commit_msg = format!("\"Update to {}\"", version);
-    println!("fedpkg commit -m {}", &commit_msg);
-    if !Command::new("fedpkg")
-        .current_dir(&package_folder)
-        .arg("commit")
-        .arg("-m")
-        .arg(&commit_msg)
-        .status()
-        .unwrap()
-        .success()
-    {
-        panic!("Failed: fedpkg commit -m {}", &commit_msg);
+    if let Some(source_branch) = source_branch {
+        println!("git reset --hard {}", source_branch);
+        if !Command::new("git")
+            .current_dir(&package_folder)
+            .arg("reset")
+            .arg("--hard")
+            .arg(source_branch)
+            .status()
+            .unwrap()
+            .success()
+        {
+            panic!("Failed: git reset --hard {}", source_branch);
+        }
+        println!("fedpkg push --force");
+        if !Command::new("fedpkg")
+            .current_dir(&package_folder)
+            .arg("push")
+            .arg("--force")
+            .status()
+            .unwrap()
+            .success()
+        {
+            panic!("Failed: fedpkg push --force");
+        }
     }
-    println!("fedpkg push");
-    if !Command::new("fedpkg")
-        .current_dir(&package_folder)
-        .arg("push")
-        .status()
-        .unwrap()
-        .success()
-    {
-        panic!("Failed: fedpkg push");
+    if let Some(srpm_url) = srpm_url {
+        println!("wget -O {:?} {}", &rpm_path, srpm_url);
+        if !Command::new("wget")
+            .current_dir(workdir)
+            .arg("-O")
+            .arg(&rpm_path)
+            .arg(srpm_url)
+            .status()
+            .unwrap()
+            .success()
+        {
+            panic!("Failed: wget -O {:?} {}", &rpm_path, srpm_url);
+        }
+        println!("fedpkg import --skip-diffs {:?}", &rpm_path);
+        if !Command::new("fedpkg")
+            .current_dir(&package_folder)
+            .arg("import")
+            .arg("--skip-diffs")
+            .arg(&rpm_path)
+            .status()
+            .unwrap()
+            .success()
+        {
+            panic!("Failed: fedpkg import --skip-diffs {:?}", &rpm_path);
+        }
+        let commit_msg = format!("\"Update to {}\"", version.unwrap_or(srpm_url));
+        println!("fedpkg commit -m {}", &commit_msg);
+        if !Command::new("fedpkg")
+            .current_dir(&package_folder)
+            .arg("commit")
+            .arg("-m")
+            .arg(&commit_msg)
+            .status()
+            .unwrap()
+            .success()
+        {
+            panic!("Failed: fedpkg commit -m {}", &commit_msg);
+        }
+        println!("fedpkg push");
+        if !Command::new("fedpkg")
+            .current_dir(&package_folder)
+            .arg("push")
+            .status()
+            .unwrap()
+            .success()
+        {
+            panic!("Failed: fedpkg push");
+        }
     }
     println!("fedpkg build");
-    if !Command::new("fedpkg")
+    let mut handle = Command::new("fedpkg")
         .current_dir(&package_folder)
         .arg("build")
-        .status()
-        .unwrap()
-        .success()
-    {
-        panic!("Failed: fedpkg build");
-    }
+        .spawn()
+        .unwrap();
+    println!("Waiting 10 secs for the build to commence");
+    thread::sleep(Duration::from_secs(10));
+    handle.kill().unwrap();
     Ok(())
 }
 
diff --git a/docs/src/building-for-rawhide.md b/docs/src/building-for-rawhide.md
index 81fa91e..3a51405 100644
--- a/docs/src/building-for-rawhide.md
+++ b/docs/src/building-for-rawhide.md
@@ -17,45 +17,28 @@ To build (1.0.0~alpha.2 2024-09-28):
 
 > **TODO:** Build these, but first I have to wait on the ssh key to refresh 
 
-- ~~cosmic-comp~~
-- ~~cosmic-icon-theme~~
 - ~~cosmic-app-library~~
-- ~~xdg-desktop-portal-cosmic~~
+- ~~cosmic-applets~~
+- ~~cosmic-bg~~
+- ~~cosmic-comp~~
 - ~~cosmic-edit~~
 - ~~cosmic-files~~
-- ~~cosmic-randr~~
-- ~~cosmic-settings~~
-- ~~cosmic-settings-daemon~~
 - ~~cosmic-greeter~~
+- ~~cosmic-icon-theme~~
 - ~~cosmic-osd~~
+- ~~cosmic-settings~~
+- ~~cosmic-settings-daemon~~
 - ~~cosmic-store~~
-- ~~cosmic-workspaces~~
-- ~~cosmic-screenshot~~
+- ~~cosmic-notifications~~
 - ~~cosmic-panel~~
-
-
-- cosmic-app-library
-- cosmic-comp
-- cosmic-edit
-- cosmic-files
-- cosmic-greeter
-- cosmic-icon-theme
-- cosmic-osd
-- cosmic-panel
-- cosmic-randr
-- cosmic-screenshot
-- cosmic-settings
-- cosmic-settings-daemon
-- cosmic-store
-- cosmic-workspaces
-- xdg-desktop-portal-cosmic
+- ~~cosmic-randr~~
+- ~~cosmic-screenshot~~
+- ~~cosmic-workspaces~~
+- ~~xdg-desktop-portal-cosmic~~
 
 Missing:
 
-- cosmic-applets
-- cosmic-bg
 - cosmic-launcher
-- cosmic-notifications
 - cosmic-session
 - cosmic-term
 - pop-launcher

From 884f747cbd4944b56766a72340fb70f1ccf2cd81 Mon Sep 17 00:00:00 2001
From: Ryan Brue <ryanbrue.dev@gmail.com>
Date: Sep 29 2024 21:26:09 +0000
Subject: [PATCH 2/2] add pop-launcher and cosmic-launcher patches


these patches make pop-launcher use /usr/libexec instead of /usr/lib

Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>

---

diff --git a/rpms/cosmic-launcher/cosmic-launcher.spec b/rpms/cosmic-launcher/cosmic-launcher.spec
index bc4f617..77b68a9 100644
--- a/rpms/cosmic-launcher/cosmic-launcher.spec
+++ b/rpms/cosmic-launcher/cosmic-launcher.spec
@@ -29,6 +29,8 @@ Source1:        vendor-%{shortcommit}.tar.gz
 # * mv vendor-config-%%{shortcommit}.toml ..
 Source2:        vendor-config-%{shortcommit}.toml
 
+# See: https://github.com/pop-os/launcher/pull/242
+Patch0: pop-launcher-libexec.patch
 
 BuildRequires:  cargo-rpm-macros >= 26
 BuildRequires:  rustc
diff --git a/rpms/cosmic-launcher/pop-launcher-libexec.patch b/rpms/cosmic-launcher/pop-launcher-libexec.patch
new file mode 100644
index 0000000..59b6852
--- /dev/null
+++ b/rpms/cosmic-launcher/pop-launcher-libexec.patch
@@ -0,0 +1,204 @@
+From b255c1b7d48a8a3405ceacd5a78f201ba3ae748b Mon Sep 17 00:00:00 2001
+From: Ryan Brue <ryanbrue.dev@gmail.com>
+Date: Sun, 29 Sep 2024 16:20:58 -0500
+Subject: [PATCH] patch: use pop-launcher patch
+ https://github.com/pop-os/launcher/pull/242
+
+Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
+---
+ Cargo.lock | 67 ++++++++++++++++++++----------------------------------
+ Cargo.toml |  4 ++--
+ 2 files changed, 27 insertions(+), 44 deletions(-)
+
+diff --git a/Cargo.lock b/Cargo.lock
+index e3f8963..ed947c3 100644
+--- a/Cargo.lock
++++ b/Cargo.lock
+@@ -616,15 +616,15 @@ dependencies = [
+ 
+ [[package]]
+ name = "base64"
+-version = "0.13.1"
++version = "0.21.7"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+-checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
++checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
+ 
+ [[package]]
+ name = "base64"
+-version = "0.21.7"
++version = "0.22.1"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+-checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
++checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
+ 
+ [[package]]
+ name = "bit-set"
+@@ -1436,15 +1436,6 @@ dependencies = [
+  "dirs-sys 0.3.7",
+ ]
+ 
+-[[package]]
+-name = "dirs"
+-version = "4.0.0"
+-source = "registry+https://github.com/rust-lang/crates.io-index"
+-checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
+-dependencies = [
+- "dirs-sys 0.3.7",
+-]
+-
+ [[package]]
+ name = "dirs"
+ version = "5.0.1"
+@@ -1712,7 +1703,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
+ checksum = "887d93f60543e9a9362ef8a21beedd0a833c5d9610e18c67abe15a5963dcb1a4"
+ dependencies = [
+  "bit_field",
+- "flume 0.11.0",
++ "flume",
+  "half",
+  "lebe",
+  "miniz_oxide",
+@@ -1843,23 +1834,13 @@ dependencies = [
+ 
+ [[package]]
+ name = "flume"
+-version = "0.10.14"
++version = "0.11.0"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+-checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577"
++checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181"
+ dependencies = [
+  "futures-core",
+  "futures-sink",
+  "nanorand",
+- "pin-project 1.1.5",
+- "spin",
+-]
+-
+-[[package]]
+-name = "flume"
+-version = "0.11.0"
+-source = "registry+https://github.com/rust-lang/crates.io-index"
+-checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181"
+-dependencies = [
+  "spin",
+ ]
+ 
+@@ -2492,7 +2473,7 @@ dependencies = [
+  "httpdate",
+  "itoa",
+  "pin-project-lite",
+- "socket2 0.5.7",
++ "socket2 0.4.10",
+  "tokio",
+  "tower-service",
+  "tracing",
+@@ -2874,6 +2855,7 @@ checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
+ dependencies = [
+  "equivalent",
+  "hashbrown 0.14.5",
++ "serde",
+ ]
+ 
+ [[package]]
+@@ -3970,11 +3952,11 @@ checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2"
+ 
+ [[package]]
+ name = "pop-launcher"
+-version = "1.2.2"
+-source = "git+https://github.com/pop-os/launcher/?rev=091581c#091581c3620a4cf3979e70f68c4af23654104bec"
++version = "1.2.3"
++source = "git+https://github.com/ryanabx-contrib/launcher/?rev=e79a9500cc2ff58e02af1e115efebda025c5480a#e79a9500cc2ff58e02af1e115efebda025c5480a"
+ dependencies = [
+  "const_format",
+- "dirs 4.0.0",
++ "dirs 5.0.1",
+  "futures",
+  "serde",
+  "serde_json",
+@@ -3985,14 +3967,14 @@ dependencies = [
+ 
+ [[package]]
+ name = "pop-launcher-service"
+-version = "1.2.2"
+-source = "git+https://github.com/pop-os/launcher/?rev=091581c#091581c3620a4cf3979e70f68c4af23654104bec"
++version = "1.2.3"
++source = "git+https://github.com/ryanabx-contrib/launcher/?rev=e79a9500cc2ff58e02af1e115efebda025c5480a#e79a9500cc2ff58e02af1e115efebda025c5480a"
+ dependencies = [
+  "anyhow",
+  "async-oneshot",
+  "async-trait",
+- "dirs 4.0.0",
+- "flume 0.10.14",
++ "dirs 5.0.1",
++ "flume",
+  "futures",
+  "futures_codec",
+  "gen-z",
+@@ -4004,12 +3986,11 @@ dependencies = [
+  "serde_json",
+  "serde_with",
+  "slab",
+- "strsim 0.10.0",
++ "strsim 0.11.1",
+  "tokio",
+  "tokio-stream",
+- "toml 0.5.11",
++ "toml 0.8.16",
+  "tracing",
+- "tracing-subscriber",
+ ]
+ 
+ [[package]]
+@@ -4615,15 +4596,17 @@ dependencies = [
+ 
+ [[package]]
+ name = "serde_with"
+-version = "2.3.3"
++version = "3.9.0"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+-checksum = "07ff71d2c147a7b57362cead5e22f772cd52f6ab31cfcd9edcd7f6aeb2a0afbe"
++checksum = "69cecfa94848272156ea67b2b1a53f20fc7bc638c4a46d2f8abde08f05f4b857"
+ dependencies = [
+- "base64 0.13.1",
++ "base64 0.22.1",
+  "chrono",
+  "hex",
+  "indexmap 1.9.3",
++ "indexmap 2.2.6",
+  "serde",
++ "serde_derive",
+  "serde_json",
+  "serde_with_macros",
+  "time",
+@@ -4631,9 +4614,9 @@ dependencies = [
+ 
+ [[package]]
+ name = "serde_with_macros"
+-version = "2.3.3"
++version = "3.9.0"
+ source = "registry+https://github.com/rust-lang/crates.io-index"
+-checksum = "881b6f881b17d13214e5d494c939ebab463d01264ce1811e9d4ac3a882e7695f"
++checksum = "a8fee4991ef4f274617a51ad4af30519438dacb2f56ac773b08a1922ff743350"
+ dependencies = [
+  "darling",
+  "proc-macro2",
+diff --git a/Cargo.toml b/Cargo.toml
+index 38bcf79..ac0b9fd 100644
+--- a/Cargo.toml
++++ b/Cargo.toml
+@@ -30,8 +30,8 @@ libcosmic = { git = "https://github.com/pop-os/libcosmic/", features = [
+ tracing = "0.1"
+ nix = { version = "0.27.1", features = ["process"] }
+ once_cell = "1.17"
+-pop-launcher = { git = "https://github.com/pop-os/launcher/", rev = "091581c" }
+-pop-launcher-service = { git = "https://github.com/pop-os/launcher/", rev = "091581c" }
++pop-launcher = { git = "https://github.com/ryanabx-contrib/launcher/", rev = "e79a9500cc2ff58e02af1e115efebda025c5480a" }
++pop-launcher-service = { git = "https://github.com/ryanabx-contrib/launcher/", rev = "e79a9500cc2ff58e02af1e115efebda025c5480a" }
+ pretty_env_logger = "0.5"
+ rust-embed = "6.3.0"
+ serde = { version = "1.0.152", features = ["derive"] }
+-- 
+2.46.2
+
diff --git a/rpms/pop-launcher/pop-launcher.spec b/rpms/pop-launcher/pop-launcher.spec
index a04a5f1..f7c274e 100644
--- a/rpms/pop-launcher/pop-launcher.spec
+++ b/rpms/pop-launcher/pop-launcher.spec
@@ -26,6 +26,9 @@ Source1:        vendor-%{shortcommit}.tar.gz
 # * mv vendor-config-%%{shortcommit}.toml ..
 Source2:        vendor-config-%{shortcommit}.toml
 
+# See: https://github.com/pop-os/launcher/pull/242
+Patch0: https://patch-diff.githubusercontent.com/raw/pop-os/launcher/pull/242.patch
+
 BuildRequires:  cargo-rpm-macros >= 25
 BuildRequires:  rustc
 BuildRequires:  lld
@@ -87,8 +90,8 @@ export VERGEN_GIT_SHA="%{commit}"
 %license cargo-vendor.txt
 %doc README.md
 %{_bindir}/pop-launcher
-%dir %{_prefix}/lib/pop-launcher
-%{_prefix}/lib/pop-launcher/*
+%dir %{_prefix}/libexec/pop-launcher
+%{_prefix}/libexec/pop-launcher/*
 
 %changelog
 %autochangelog

