-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbazel.lisp
63 lines (52 loc) · 2.02 KB
/
bazel.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
;; Shell aliases for working with bazel...
(uiop:define-package :fare-scripts/bazel
(:use :cl :fare-utils :uiop :inferior-shell :optima :optima.ppcre :cl-scripting)
(:export #:*bazel-dir* #:*bazel* #:bazel #:ss #:ngr #:make-bazel
#:*java-home*))
(in-package :fare-scripts/bazel)
(exporting-definitions
(defparameter *java-home* "/usr/lib/jvm/java-8-openjdk-amd64")
(defparameter *bazel-dir* (subpathname (user-homedir-pathname) "src/google/bazel/"))
(defparameter *bazel* (subpathname *bazel-dir* "output/bazel"))
(defun make-bazel ()
(with-current-directory (*bazel-dir*)
(run/i `(env ("JAVA_HOME=" ,*java-home*) "./compile.sh"))
(values)))
(defun bazel (&rest args)
(with-current-directory (*bazel-dir*)
(run/i `(env ("JAVA_HOME=" ,*java-home*) ,*bazel* ,@args)))
(success))
(defun ss (&optional nobuild)
(with-current-directory (*bazel-dir*)
(unless nobuild
(bazel 'build "src/test/java:skylarkshell"))
(run/i '("bazel-bin/src/test/java/skylarkshell")))
(success))
(progn
(defun directory-last-name (path)
(let ((n (last (pathname-directory path))))
(and (consp n) (stringp (car n)) (car n))))
(defun repo-char-p (char)
(ascii-alphanumeric-or-underscore-p char)))
(defun ngr (&optional path)
(with-current-directory ((and path (ensure-directory-pathname path)))
(let* ((url
(match (run/ss '(git config --get remote.origin.url))
((ppcre "^(ssh:|git:)?(//)?(git@)?(github.com|gitlab.common-lisp.net)[:/](.*)$"
_ _ _ h p)
(strcat "https://" h "/" p))
(url url)))
(commit (run/ss '(git log -1 "--format=%H")))
(dirname (directory-last-name (getcwd)))
(repo (strcat "lisp__" (substitute-if-not #\_ #'repo-char-p
(string-downcase dirname)))))
(format t " native.new_git_repository(
name = \"~A\",
commit = \"~A\",
remote = \"~A\",
build_file = base_dir + \"/build_defs/~A.BUILD\"
)~%~%"
repo commit url repo)
(values))))
);exporting-definitions
(register-commands :fare-scripts/bazel)