Function: bazel--bazelignore-patterns

bazel--bazelignore-patterns is a natively compiled function defined in bazel.el.

Signature

(bazel--bazelignore-patterns REPOSITORY-ROOT)

Documentation

Parse a .bazelignore file in REPOSITORY-ROOT.

Return a list of glob patterns for ‘project-ignores’. Return nil if no .bazelignore file exists.

Source Code

;; Defined in /nix/store/ws8pkszjvcad1rgzqw6wja7qxacylfhn-emacs-packages-deps/share/emacs/site-lisp/elpa/bazel-20261002.1510/bazel.el
(defun bazel--bazelignore-patterns (repository-root)
  "Parse a .bazelignore file in REPOSITORY-ROOT.
Return a list of glob patterns for ‘project-ignores’.
Return nil if no .bazelignore file exists."
  (declare (ftype (function (string) list)))
  (cl-check-type repository-root string)
  (with-temp-buffer
    ;; Bazel always treats .bazelignore files as UTF-8,
    ;; cf. https://github.com/bazelbuild/bazel/blob/09c621e4cf5b968f4c6cdf905ab142d5961f9ddc/src/main/java/com/google/devtools/build/lib/skyframe/IgnoredPackagePrefixesFunction.java#L52.
    (let ((coding-system-for-read 'utf-8)
          (format-alist nil)
          (after-insert-file-functions nil)
          (bazelignore-file (expand-file-name ".bazelignore" repository-root))
          (patterns ()))
      ;; It’s not a critical error if the .bazelignore file doesn’t exist or we
      ;; can’t read it.
      (when (ignore-error file-error (insert-file-contents bazelignore-file))
        ;; Replicate behavior of
        ;; https://github.com/bazelbuild/bazel/blob/09c621e4cf5b968f4c6cdf905ab142d5961f9ddc/src/main/java/com/google/devtools/build/lib/skyframe/IgnoredPackagePrefixesFunction.java#L122-L127.
        (while (not (eobp))
          (unless (or (eolp) (eq (following-char) ?#))
            ;; This glob pattern isn’t quite correct if the line contains
            ;; wildcard characters, but we have no way to escape them.
            (push (concat "./" (file-name-as-directory
                                (buffer-substring-no-properties
                                 (point) (line-end-position))))
                  patterns))
          (forward-line))
        (nreverse patterns)))))