emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/beardbolt 5e389a88d9 152/323: Add rmsbolt splitter for


From: ELPA Syncer
Subject: [elpa] externals/beardbolt 5e389a88d9 152/323: Add rmsbolt splitter for splitting and mutating commands
Date: Thu, 9 Mar 2023 10:58:26 -0500 (EST)

branch: externals/beardbolt
commit 5e389a88d9f4f0a8d0d409160a0ddaa791625aec
Author: Jay Kamat <jaygkamat@gmail.com>
Commit: Jay Kamat <jaygkamat@gmail.com>

    Add rmsbolt splitter for splitting and mutating commands
    
    Very far from being foolproof, doesn't even handle quotes yet, but we
    shouldn't spend time on stuff no one will use (probably), since
    generated output is pretty predictable.
    
    See #4
---
 .ert-runner                |  2 +-
 Cask                       |  3 +-
 rmsbolt-split.el           | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 test/rmsbolt-split-test.el | 63 +++++++++++++++++++++++++++++++++++++++++
 test/rmsbolt-test.el       |  1 +
 5 files changed, 137 insertions(+), 2 deletions(-)

diff --git a/.ert-runner b/.ert-runner
index fbc31e4b07..b5f5e2ff74 100644
--- a/.ert-runner
+++ b/.ert-runner
@@ -1 +1 @@
--l rmsbolt-java.el rmsbolt.el
+-l rmsbolt-java.el rmsbolt.el rmsbolt-split.el
diff --git a/Cask b/Cask
index 0827a85ac2..8059cb55ef 100644
--- a/Cask
+++ b/Cask
@@ -4,7 +4,8 @@
 (package-file "rmsbolt.el")
 
 (files "rmsbolt.el"
-          "rmsbolt-java.el")
+          "rmsbolt-java.el"
+          "rmsbolt-split.el")
 
 (development
  (depends-on "ert-runner")
diff --git a/rmsbolt-split.el b/rmsbolt-split.el
new file mode 100644
index 0000000000..2e7e5bf1ea
--- /dev/null
+++ b/rmsbolt-split.el
@@ -0,0 +1,70 @@
+;;; rmsbolt-split.el --- An Elisp library to edit command lines -*- 
lexical-binding: t; -*-
+
+;; Copyright (C) 2018 Jay Kamat
+;; Author: Jay Kamat <jaygkamat@gmail.com>
+;; Version: 0.1.0
+;; Keywords: compilation, tools
+;; URL: http://gitlab.com/jgkamat/rmsbolt
+;; Package-Requires: ((emacs "25.1"))
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU Affero General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU Affero General Public License for more details.
+
+;; You should have received a copy of the GNU Affero General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This is a small library for editing command line parameters, passed as
+;; a string. For example, given:
+;; gcc -o one two -c -S
+;; This library tries to make it possible to remove '-o one' '-c' and '-S'.
+;;
+;; This is not easy to do without bugs, and therefore this is mostly 
incomplete.
+;; Hopefully we will never see more complicated formats (such as quoted 
arguments)
+;; in generated commands, or we will need to write a parser.
+
+;;; Requires:
+
+(require 'cl-lib)
+
+;;; Variables
+
+(defvar rmsbolt-split--regexp (rx (1+ blank)))
+
+;;; Code:
+
+(defun rmsbolt-split-rm-single (cmd flag)
+  "Remove a single FLAG from CMD."
+  (let ((cmd (split-string cmd rmsbolt-split--regexp)))
+    (mapconcat
+     #'identity
+     (cl-remove-if (apply-partially #'string= flag) cmd)
+     " ")))
+
+(defun rmsbolt-split-rm-double (cmd flag)
+  "Remove a single FLAG and arg from CMD."
+  (let ((cmd (split-string cmd rmsbolt-split--regexp))
+        (removed nil))
+    (mapconcat
+     #'identity
+     (cl-remove-if (lambda (f)
+                     (cond
+                      ((string= f flag)
+                       (setq removed t))
+                      (removed
+                       (setq removed nil)
+                       t)
+                      (t nil)))
+                   cmd)
+     " ")))
+
+;;; rmsbolt-split.el ends here
+(provide 'rmsbolt-split)
diff --git a/test/rmsbolt-split-test.el b/test/rmsbolt-split-test.el
new file mode 100644
index 0000000000..c8e15afcb2
--- /dev/null
+++ b/test/rmsbolt-split-test.el
@@ -0,0 +1,63 @@
+;;; rmsbolt-split-test.el --- Tests for rmsbolt-split -*- lexical-binding: t; 
-*-
+
+;;; Commentary:
+;; Tests for rmsbolt
+
+;;; Code:
+
+(require 'rmsbolt-split)
+
+(ert-deftest test-split-single ()
+  "Test split single function"
+  (should (equal
+           (rmsbolt-split-rm-single "/usr/bin/c++ -a -R -c" "-R")
+           "/usr/bin/c++ -a -c"))
+
+  (should (equal
+           (rmsbolt-split-rm-single "/usr/bin/c++              -a -R -c" "-R")
+           "/usr/bin/c++ -a -c"))
+
+  (should (equal
+           (rmsbolt-split-rm-single "/usr/bin/c++ -a -R -c" "-a")
+           "/usr/bin/c++ -R -c"))
+
+  (should (equal
+           (rmsbolt-split-rm-single "/usr/bin/c++ -a -R -c" "-c")
+           "/usr/bin/c++ -a -R"))
+
+  (should (equal
+           (rmsbolt-split-rm-single "/usr/bin/c++ -a -R -c" "-z")
+           "/usr/bin/c++ -a -R -c"))
+
+  (should (equal
+           (rmsbolt-split-rm-single "/usr/bin/c++ -a -R -a" "-a")
+           "/usr/bin/c++ -R"))
+
+  (should (equal
+           (rmsbolt-split-rm-single
+            "/usr/bin/c++   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB 
-DQT_NO_KEYWORDS -DQT_WIDGETS_LIB -Isrc/googletest/include -I../common -Icommon 
-Icommon/protobuf -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtCore -isystem 
/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtNetwork -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtGui   -Werror=retu [...]
+           "/usr/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB 
-DQT_NO_KEYWORDS -DQT_WIDGETS_LIB -Isrc/googletest/include -I../common -Icommon 
-Icommon/protobuf -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtCore -isystem 
/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtNetwork -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtGui -Werror=return-lo [...]
+
+
+(ert-deftest test-split-double ()
+  "Test split single function"
+  (should (equal
+           (rmsbolt-split-rm-double "/usr/bin/c++ -a -R -c" "-R")
+           "/usr/bin/c++ -a"))
+
+  (should (equal
+           (rmsbolt-split-rm-double "/usr/bin/c++              -a -R -c" "-c")
+           "/usr/bin/c++ -a -R"))
+
+  (should (equal
+           (rmsbolt-split-rm-double "/usr/bin/c++ -a -R -c" "-a")
+           "/usr/bin/c++ -c"))
+
+  (should (equal
+           (rmsbolt-split-rm-double
+            "/usr/bin/c++   -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB 
-DQT_NO_KEYWORDS -DQT_WIDGETS_LIB -Isrc/googletest/include -I../common -Icommon 
-Icommon/protobuf -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtCore -isystem 
/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtNetwork -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtGui   -Werror=retu [...]
+           "/usr/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB 
-DQT_NO_KEYWORDS -DQT_WIDGETS_LIB -Isrc/googletest/include -I../common -Icommon 
-Icommon/protobuf -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtCore -isystem 
/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtNetwork -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem 
/usr/include/x86_64-linux-gnu/qt5/QtGui -Werror=return-lo [...]
+
+(provide 'rmsbolt-split-test)
+
+;;; rmsbolt-split-test.el ends here
diff --git a/test/rmsbolt-test.el b/test/rmsbolt-test.el
index 8880b1caeb..79258ca9a6 100644
--- a/test/rmsbolt-test.el
+++ b/test/rmsbolt-test.el
@@ -108,3 +108,4 @@
 
 
 ;;; rmsbolt-test.el ends here
+(provide 'rmsbolt-test)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]