[PATCH setup] add --build-depend option

John Haugabook via Cygwin-apps <[email protected]>
Newsgroups gmane.os.cygwin.applications
Message-ID <CAKrZaUvKhgATqkeECWWDw9Ar+jGfs4Tucz_wgbBxK0bog+MNDA@mail.gmail.com>
Hello,

This patch adds an option --build-depend that, when called; installs the
packages listed in the build-depends property of setup.ini. It is for
someone who wants to build the binaries of a package themselves, enabling
them to pass one stringed package in lieu of a vector of packages.

Right now this is more or less a rough draft as feedback requested i.e.
what's the best way to implement this, and to get specific detailed
hand-holding help on two things (unless better approach):
 1. Using the correct setup.ini file (debugged using copy of setup.ini) and
    passing it as a string to the "stream" parameter of build_depend(), which
    is declared as:
    - std::string build_depend(std::string pkg_search, std::string stream)
    in build_depends.h.

 2. Convert and handle successful output of build_depend(), passing it to
    "PackageOption" in package_meta.cc (unless better way) as a vector as
    if the output from build_depend() was passed to -P, --packages.

Currently only the results are output to the Cygwin terminal, but from
the several
commands I've tested (see bottom); the output seems good. The process I have
in mind is:
   I. --build-depend <package> == true
  II. <package> is searched in setup.ini
 III. if <package> found and has "build-depends" property, then send an array
      of packages to be used by -P, --packages, else some not found message.

So essentially if, e.g.
`setup -q --build-depend cxsparse-debuginfo`,
then the process will run as if,
`setup -q -P cmake,cygport,gcc-fortran,liblapack-devel,libmetis-devel,libopenblas,libsuitesparseconfig-devel,pkg-config`
were called. But I'm not sure if this is the best approach.

If it is, though; then what remains:
 1. Correct use of setup.ini, converting identified file to string so
it can be passed
     to build_depend().
 2. Convert build_depend() output to vector and use that to create
    "PackageOption" class.

Additional Quasi-JSON Info:
{
  syntax: setup [-q] --build-depend <package>,
  example:
 """"""""""""""""""""""""
 * # PASS or has build-depend property
 * ######
 * $ ./setup -q --build-depend cxsparse-debuginfo
 * build-depends:
cmake,cygport,gcc-fortran,liblapack-devel,libmetis-devel,libopenblas,libsuitesparseconfig-devel,pkg-config
 * Starting cygwin install, version 2.934-4-g9f595e-dirty
 * User has backup/restore rights
 * User has symlink creation right
 * Current Directory: C:\Users\name
 * root: C:\cygwin64 user
 * Changing gid back to original
 * Selected local directory: C:\Users\name
 * net: Preconfig
 * Segmentation fault
 *
 * # FAIL or does not have build-depend property
 * ######
 * $ ./setup -q --build-depend autossh
 * build-depends: no
 * Starting cygwin install, ...
 * ...
 * Segmentation fault
 """"""""""""""""""""""""
 """"""""""""""""""""""""
  terminals: {
   // NOTE - outputs    = build-depends: package1,package2,.. was
parsed by terminal.
  //               no output = nothing broke, but build-depends did not output.
   cygwin: outputs,
   Windows: no output,
   wsl(Ubuntu): no output
  }
  packages-tested: {
   pass: [ automake, automake1.13, autoconf, curl, cxsparse-debuginfo, cygwin,
           gawk, gvim, make, nano, vim, vim-cmake ],
   // NOTE - fail = no build-depends property, returning "build-depends: no".
   fail: [ autossh, awk, cat, cvs, cxsparse, fzf-vim, ls,
           (an assorment of special characters i.e. cxsparse-de*),
           (an assortment of misspellings i.e. nanoo) ],
  },
  optional-parameter: false, so:
  > setup --build-depend
  > Error during option processing
  > # then command help() outputs.
}

---
From 3ad9c8d346f90ce22408b97c2effb4cb5225e1bd Mon Sep 17 00:00:00 2001
From: John Haugabook <[email protected]>
Date: Wed, 16 Jul 2025 22:51:09 +0100
Subject: [PATCH setup] add --build-depend option

add --build-depend option initial debugging

add --build-depend option
---
 Makefile.am      |  2 ++
 build_depends.cc | 92 ++++++++++++++++++++++++++++++++++++++++++++++++
 build_depends.h  | 24 +++++++++++++
 main.cc          |  8 ++++-
 res/en/res.rc    |  1 +
 resource.h       |  1 +
 6 files changed, 127 insertions(+), 1 deletion(-)
 create mode 100644 build_depends.cc
 create mode 100644 build_depends.h

diff --git a/Makefile.am b/Makefile.am
index 4046d37..daf1609 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -136,6 +136,8 @@ endif
  archive_tar.cc \
  archive_tar.h \
  archive_tar_file.cc \
+ build_depends.h \
+ build_depends.cc \
  choose.cc \
  choose.h \
  compactos.cc \
diff --git a/build_depends.cc b/build_depends.cc
new file mode 100644
index 0000000..6829f2c
--- /dev/null
+++ b/build_depends.cc
@@ -0,0 +1,92 @@
+/*
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ */
+
+
+#include <fstream>
+#include <algorithm>
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <cstdio>
+
+#include "io_stream.h"
+#include "ini.h"
+#include "resource.h"
+
+
+std::string
+build_depend(std::string pkg_search, std::string stream)
+{
+  // Use option passed as argument.
+  std::string target_pkg = pkg_search;
+
+  // Mark and property for identifying package and extracting value.
+  std::string pkg_marker = "@";
+  std::string key = "build-depends:";
+
+  std::string depend_packages; // for final output
+  // NEXT
+  //std::ifstream infile("setup.ini");
+  std::ifstream infile(stream);
+
+  // Ensure setup.ini was identified
+  if (!infile) {
+    depend_packages = "Error opening setup.ini";
+  }
+
+  // Start process of reading setup.
+  std::string line;
+  bool inPkg = false;
+  //io_stream *infile = stream;
+  while (std::getline(infile, line)) {
+    std::istringstream iss(line);
+    std::string first, second;
+    iss >> first >> second;
+
+    // For each pkg_marker check if name matches option.
+    if (first == pkg_marker)
+    {
+      if (second == target_pkg)
+      {
+        // Package found, handle next lines accordingly.
+        inPkg = true;
+        continue;
+      }
+      else
+      {
+        inPkg = false;
+        continue;
+      }
+    }
+
+    // If package found and hsa property build-depends.
+    if (inPkg && line.find(key) == 0) {
+      /* Extract by property length, then remove space character
+      using ASCII encoding. */
+      std::string depend_packages = line.substr(key.size());
+      replace(depend_packages.begin(), depend_packages.end(), 32, 00);
+
+      // NEXT
+      // Output to PackageOption.
+      return "build-depends: " + depend_packages;
+      break;
+    } else {
+     continue;
+    }
+  }
+
+  // Output if no package.
+  if (inPkg == false)
+  {
+    return "build-depends: no";
+  }
+  return 0;
+}
diff --git a/build_depends.h b/build_depends.h
new file mode 100644
index 0000000..eec9921
--- /dev/null
+++ b/build_depends.h
@@ -0,0 +1,24 @@
+/*
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ */
+
+#ifndef USE_BUILD_DEPENDS_H
+#define USE_BUILD_DEPENDS_H
+
+#include "getopt++/StringOption.h"
+#include "resource.h"
+
+// Create option class.
+StringOption BuildDependsOption ("", '\0', "build-depend",
IDS_HELPTEXT_BUILD_DEPENDS, false);
+
+// Forward declare function for use.
+std::string build_depend(std::string pkg_search, std::string stream);
+
+#endif /* USE_BUILD_DEPENDS_H */
diff --git a/main.cc b/main.cc
index 91d0eca..45e456f 100644
--- a/main.cc
+++ b/main.cc
@@ -42,6 +42,7 @@
 #include "mount.h"
 #include "LogFile.h"
 #include "setup_version.h"
+#include "build_depends.h"

 #include "proppage.h"
 #include "propsheet.h"
@@ -300,7 +301,12 @@ WinMain (HINSTANCE h,
     std::string elevate_extra_args;

     if (unattended_mode || output_only || !elevate)
-      set_cout ();
+    {
+      std::string build_depends_options = BuildDependsOption;
+       if (build_depends_options.length() > 1)
+           std::cout << build_depend(build_depends_options,
"setup.ini") << std::endl;
+      set_cout();
+    }

     /* Start logging only if we don't elevate.  Same for setting default
        security settings. */
diff --git a/res/en/res.rc b/res/en/res.rc
index 0bdd4c7..d8b2298 100644
--- a/res/en/res.rc
+++ b/res/en/res.rc
@@ -656,6 +656,7 @@ BEGIN
     IDS_HELPTEXT_ALLOW_UNSUPPORTED_WINDOWS "Allow old, unsupported
Windows versions"
     IDS_HELPTEXT_ARCH "Architecture to install (x86_64 or x86)"
     IDS_HELPTEXT_CATEGORIES "Specify categories to install"
+    IDS_HELPTEXT_BUILD_DEPENDS "Install the build requirements of a package"
     IDS_HELPTEXT_COMPACTOS "Compress installed files with Compact OS
(xpress4k, xpress8k, xpress16k, lzx)"
     IDS_HELPTEXT_DELETE_ORPHANS "Remove orphaned packages"
     IDS_HELPTEXT_DISABLE_ANTIVIRUS "Disable known or suspected buggy
anti virus software packages during execution"
diff --git a/resource.h b/resource.h
index a08489c..11fef73 100644
--- a/resource.h
+++ b/resource.h
@@ -158,6 +158,7 @@
 #define IDS_HELPTEXT_HEADER              1546
 #define IDS_HELPTEXT_FOOTER              1547
 #define IDS_HELPTEXT_NO_WRITE_REGISTRY   1548
+#define IDS_HELPTEXT_BUILD_DEPENDS       1549

 // Dialogs

-- 
2.49.0.windows.1


Take Care,

John Haugabook
add-build-depend-option.patch (application/octet-stream, 6 KB)
From 3ad9c8d346f90ce22408b97c2effb4cb5225e1bd Mon Sep 17 00:00:00 2001
From: John Haugabook <[email protected]>
Date: Wed, 16 Jul 2025 22:51:09 +0100
Subject: [PATCH setup] add --build-depend option

add --build-depend option initial debugging

add --build-depend option
---
 Makefile.am      |  2 ++
 build_depends.cc | 92 ++++++++++++++++++++++++++++++++++++++++++++++++
 build_depends.h  | 24 +++++++++++++
 main.cc          |  8 ++++-
 res/en/res.rc    |  1 +
 resource.h       |  1 +
 6 files changed, 127 insertions(+), 1 deletion(-)
 create mode 100644 build_depends.cc
 create mode 100644 build_depends.h

diff --git a/Makefile.am b/Makefile.am
index 4046d37..daf1609 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -136,6 +136,8 @@ endif
 	archive_tar.cc \
 	archive_tar.h \
 	archive_tar_file.cc \
+	build_depends.h \
+	build_depends.cc \
 	choose.cc \
 	choose.h \
 	compactos.cc \
diff --git a/build_depends.cc b/build_depends.cc
new file mode 100644
index 0000000..6829f2c
--- /dev/null
+++ b/build_depends.cc
@@ -0,0 +1,92 @@
+/*
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ */
+
+
+#include <fstream>
+#include <algorithm>
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <cstdio>
+
+#include "io_stream.h"
+#include "ini.h"
+#include "resource.h"
+
+
+std::string 
+build_depend(std::string pkg_search, std::string stream) 
+{
+  // Use option passed as argument.
+  std::string target_pkg = pkg_search;
+
+  // Mark and property for identifying package and extracting value.
+  std::string pkg_marker = "@";
+  std::string key = "build-depends:";
+
+  std::string depend_packages; // for final output
+  // NEXT
+  //std::ifstream infile("setup.ini");
+  std::ifstream infile(stream);
+  
+  // Ensure setup.ini was identified
+  if (!infile) {
+    depend_packages = "Error opening setup.ini";
+  }
+
+  // Start process of reading setup.
+  std::string line;
+  bool inPkg = false;
+  //io_stream *infile = stream;
+  while (std::getline(infile, line)) {
+    std::istringstream iss(line);
+    std::string first, second;
+    iss >> first >> second;
+
+    // For each pkg_marker check if name matches option.
+    if (first == pkg_marker) 
+    {
+      if (second == target_pkg) 
+      {
+        // Package found, handle next lines accordingly.
+        inPkg = true;
+        continue;
+      }
+      else 
+      {
+        inPkg = false;
+        continue;
+      }
+    }
+
+    // If package found and hsa property build-depends.
+    if (inPkg && line.find(key) == 0) {
+      /* Extract by property length, then remove space character 
+      using ASCII encoding. */
+      std::string depend_packages = line.substr(key.size());
+      replace(depend_packages.begin(), depend_packages.end(), 32, 00);
+      
+      // NEXT
+      // Output to PackageOption.
+      return "build-depends: " + depend_packages;
+      break;
+    } else {
+     continue;
+    }
+  }
+
+  // Output if no package.
+  if (inPkg == false) 
+  {
+    return "build-depends: no"; 
+  }
+  return 0;
+}
diff --git a/build_depends.h b/build_depends.h
new file mode 100644
index 0000000..eec9921
--- /dev/null
+++ b/build_depends.h
@@ -0,0 +1,24 @@
+/*
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ */
+
+#ifndef USE_BUILD_DEPENDS_H
+#define USE_BUILD_DEPENDS_H
+
+#include "getopt++/StringOption.h"
+#include "resource.h"
+
+// Create option class.
+StringOption BuildDependsOption ("", '\0', "build-depend", IDS_HELPTEXT_BUILD_DEPENDS, false);
+
+// Forward declare function for use.
+std::string build_depend(std::string pkg_search, std::string stream);
+
+#endif /* USE_BUILD_DEPENDS_H */
diff --git a/main.cc b/main.cc
index 91d0eca..45e456f 100644
--- a/main.cc
+++ b/main.cc
@@ -42,6 +42,7 @@
 #include "mount.h"
 #include "LogFile.h"
 #include "setup_version.h"
+#include "build_depends.h"
 
 #include "proppage.h"
 #include "propsheet.h"
@@ -300,7 +301,12 @@ WinMain (HINSTANCE h,
     std::string elevate_extra_args;
 
     if (unattended_mode || output_only || !elevate)
-      set_cout ();
+    {
+      std::string build_depends_options = BuildDependsOption;
+       if (build_depends_options.length() > 1)
+           std::cout << build_depend(build_depends_options, "setup.ini") << std::endl;
+      set_cout();
+    }
 
     /* Start logging only if we don't elevate.  Same for setting default
        security settings. */
diff --git a/res/en/res.rc b/res/en/res.rc
index 0bdd4c7..d8b2298 100644
--- a/res/en/res.rc
+++ b/res/en/res.rc
@@ -656,6 +656,7 @@ BEGIN
     IDS_HELPTEXT_ALLOW_UNSUPPORTED_WINDOWS "Allow old, unsupported Windows versions"
     IDS_HELPTEXT_ARCH "Architecture to install (x86_64 or x86)"
     IDS_HELPTEXT_CATEGORIES "Specify categories to install"
+    IDS_HELPTEXT_BUILD_DEPENDS "Install the build requirements of a package"
     IDS_HELPTEXT_COMPACTOS "Compress installed files with Compact OS (xpress4k, xpress8k, xpress16k, lzx)"
     IDS_HELPTEXT_DELETE_ORPHANS "Remove orphaned packages"
     IDS_HELPTEXT_DISABLE_ANTIVIRUS "Disable known or suspected buggy anti virus software packages during execution"
diff --git a/resource.h b/resource.h
index a08489c..11fef73 100644
--- a/resource.h
+++ b/resource.h
@@ -158,6 +158,7 @@
 #define IDS_HELPTEXT_HEADER              1546
 #define IDS_HELPTEXT_FOOTER              1547
 #define IDS_HELPTEXT_NO_WRITE_REGISTRY   1548
+#define IDS_HELPTEXT_BUILD_DEPENDS       1549
 
 // Dialogs
 
-- 
2.49.0.windows.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.