emacs-tree-sitter / elisp-tree-sitter

Emacs Lisp bindings for tree-sitter
https://emacs-tree-sitter.github.io
MIT License
822 stars 74 forks source link

json.dylib is not GPL compatible #100

Closed jhenahan closed 3 years ago

jhenahan commented 3 years ago

Not sure if this is right repo to report this since I'm not really certain where the dylib actually originates.

Config:

  (use-package tree-sitter
    :commands global-tree-sitter-mode
    :init
    (global-tree-sitter-mode))
  (use-package tree-sitter-langs)

This causes Emacs to fail to run with the message

Module is not GPL compatible: "/nix/store/s734psnf1qlnhrgi0c70gs33655hps4l-emacs-packages-deps/share/emacs/site-lisp/elpa/tree-sitter-langs-20210113.1755/bin/json.dylib"

I manage my package installation with Nix, though no other module is currently throwing the error so it seems to be an issue of just this module. If I forcibly move the dylib so that Emacs doesn't try to load it, I don't get the error.

ubolonton commented 3 years ago

It seems like there is some code in your config that tries to load json.dylib, which is not a dynamic module. Please check if your load-path includes that directory, and turn on debug-on-error to see which code tries to load the file.

jhenahan commented 3 years ago

It appears that (use-package tree-sitter-langs) is what's trying to load the dylib, as removing that line allows Emacs to load again. I can run emacs -Q with that line in place and then load my init file, but then I get a nonsensical trace.

Debugger entered--Lisp error: (module-not-gpl-compatible "/nix/store/s734psnf1qlnhrgi0c70gs33655hps4l-emacs-...")
  require(json)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\305\306\307\"\210\305\310\307\"\210\305\311\307\"\210\305\312\307\"\210\305\313\307\"\210\305\314\307\"\210\305\315\307\"..." [require json password-cache cl-lib eieio autoload secrets-create-item "secrets" secrets-delete-item secrets-get-alias secrets-get-attributes secrets-get-secret secrets-list-collections secrets-search-items rfc2104-hash "rfc2104" plstore-open "plstore" plstore-find plstore-put plstore-delete plstore-save plstore-get-file epg-make-context "epg" epg-context-set-passphrase-callback epg-decrypt-string epg-encrypt-string help-mode "help-mode" nil t custom-declare-group auth-source "Authentication sources." :version "23.1" :group gnus custom-declare-variable auth-source-cache-expiry funcall function #f(compiled-function () #<bytecode 0x1f400017dfb1>) "How many seconds passwords are cached, or nil to d..." "24.1" :type (choice (const :tag "Never" nil) (const :tag "All Day" 86400) (const :tag "2 Hours" 7200) (const :tag "30 Minutes" 1800) (integer :tag "Seconds")) defalias auth-source-backend-p ...] 8)
  require(auth-source)
  byte-code("\300\301!\210\300\302!\210\303\304\305\"\207" [require url-vars auth-source autoload url-scheme-get-property "url-methods"] 3)
  require(url-parse)
  require(url-handlers)
  byte-code("\301\302!\210\301\303!\210\301\304!\210\301\305!\210\301\306!\210\301\307!\210\310\311\312\313\314\315\316\317&\7\210\320\321\322\323\324DD\325\326\327\316\317&\7\210..." [package-user-dir require cl-lib seq tabulated-list macroexp url-handlers browse-url custom-declare-group package nil "Manager for Emacs Lisp packages." :group applications :version "24.1" custom-declare-variable package-enable-at-startup funcall function #f(compiled-function () #<bytecode 0x1f4000153e5d>) "Whether to make installed packages available when ..." :type boolean package-load-list #f(compiled-function () #<bytecode 0x1f400b02864d>) "List of packages for `package-initialize' to make ..." (repeat (choice (const all) (list :tag "Specific package" (symbol :tag "Package name") (choice :tag "Version" (const :tag "disable" nil) (const :tag "most recent" t) (string :tag "specific version"))))) :risky t package-archives #f(compiled-function () #<bytecode -0x75a5cc784ebdbc5>) "An alist of archives from which to fetch.\nThe defa..." (alist :key-type (string :tag "Archive name") :value-type (string :tag "URL or directory name")) "26.1" package-menu-hide-low-priority #f(compiled-function () #<bytecode 0x1ffad57c21a99>) "If non-nil, hide low priority packages from the pa..." (choice (const :tag "Don't hide anything" nil) (const :tag "Hide per package-archive-priorities" archive) (const :tag "Hide per archive and version number" t)) "25.1" package-archive-priorities #f(compiled-function () #<bytecode 0x1f4000153e91>) "An alist of priorities for packages.\n\nEach element..." (alist :key-type (string :tag "Archive name") :value-type (integer :tag "Priority (default is 0)")) package-pinned-packages #f(compiled-function () #<bytecode 0x1f4000153e91>) "An alist of packages that are pinned to specific a..." (alist :key-type (symbol :tag "Package") :value-type (string :tag "Archive name")) "24.4" #f(compiled-function () #<bytecode 0x1f40947b174e>) ...] 12)
  require(package)
  use-package-ensure-elpa(org (org-plus-contrib) nil)
  use-package-handler/:ensure(org :ensure (org-plus-contrib) (:preface ((eval-when-compile (with-demoted-errors "Cannot load org: %S" nil (unless (featurep 'org) (load "org" nil t))))) :catch t :init nil :load (org) :config (t)) nil)
  use-package-process-keywords(org (:ensure (org-plus-contrib) :preface ((eval-when-compile (with-demoted-errors "Cannot load org: %S" nil (unless (featurep 'org) (load "org" nil t))))) :catch t :init nil :load (org) :config (t)) nil)
  #f(compiled-function (name &rest args) "Declare an Emacs package by specifying a group of configuration options.\n\nFor full documentation, please see the README file that came with\nthis file.  Usage:\n\n  (use-package package-name\n     [:keyword [option]]...)\n\n:init            Code to run before PACKAGE-NAME has been loaded.\n:config          Code to run after PACKAGE-NAME has been loaded.  Note that\n                 if loading is deferred for any reason, this code does not\n                 execute until the lazy load has occurred.\n:preface         Code to be run before everything except `:disabled'; this\n                 can be used to define functions for use in `:if', or that\n                 should be seen by the byte-compiler.\n\n:mode            Form to be added to `auto-mode-alist'.\n:magic           Form to be added to `magic-mode-alist'.\n:magic-fallback  Form to be added to `magic-fallback-mode-alist'.\n:interpreter     Form to be added to `interpreter-mode-alist'.\n\n:commands        Define autoloads for commands that will be defined by the\n                 package.  This is useful if the package is being lazily\n                 loaded, and you wish to conditionally call functions in your\n                 `:init' block that are defined in the package.\n:hook            Specify hook(s) to attach this package to.\n\n:bind            Bind keys, and define autoloads for the bound commands.\n:bind*           Bind keys, and define autoloads for the bound commands,\n                 *overriding all minor mode bindings*.\n:bind-keymap     Bind a key prefix to an auto-loaded keymap defined in the\n                 package.  This is like `:bind', but for keymaps.\n:bind-keymap*    Like `:bind-keymap', but overrides all minor mode bindings\n\n:defer           Defer loading of a package -- this is implied when using\n                 `:commands', `:bind', `:bind*', `:mode', `:magic', `:hook',\n                 `:magic-fallback', or `:interpreter'.  This can be an integer,\n                 to force loading after N seconds of idle time, if the package\n                 has not already been loaded.\n:after           Delay the use-package declaration until after the named modules\n                 have loaded. Once load, it will be as though the use-package\n                 declaration (without `:after') had been seen at that moment.\n:demand          Prevent the automatic deferred loading introduced by constructs\n                 such as `:bind' (see `:defer' for the complete list).\n\n:if EXPR         Initialize and load only if EXPR evaluates to a non-nil value.\n:disabled        The package is ignored completely if this keyword is present.\n:defines         Declare certain variables to silence the byte-compiler.\n:functions       Declare certain functions to silence the byte-compiler.\n:load-path       Add to the `load-path' before attempting to load the package.\n:diminish        Support for diminish.el (if installed).\n:delight         Support for delight.el (if installed).\n:custom          Call `custom-set' or `set-default' with each variable\n                 definition without modifying the Emacs `custom-file'.\n                 (compare with `custom-set-variables').\n:custom-face     Call `customize-set-faces' with each face definition.\n:ensure          Loads the package using package.el if necessary.\n:pin             Pin the package to an archive." #<bytecode -0x17b98b2cd21d87ac>)(org :ensure org-plus-contrib)
  macroexpand((use-package org :ensure org-plus-contrib) ((the-with-operating-system . #f(compiled-function (os &rest body) #<bytecode 0x1361100e08ecdc24>)) (the-operating-system-p . #f(compiled-function (os) #<bytecode 0x1e182058d52dfffc>)) (the-defhook . #f(compiled-function (name arglist hooks docstring &rest body) #<bytecode -0x10e62e2e1d603d51>)) (declare-function . byte-compile-macroexpand-declare-function) (eval-when-compile . #f(compiled-function (&rest body) #<bytecode -0x1e4cce36188253c3>)) (eval-and-compile . #f(compiled-function (&rest body) #<bytecode 0x92240a5e701e498>)) (with-suppressed-warnings . #f(compiled-function (warnings &rest body) #<bytecode 0xde46421673df16e>))))
  macroexp-macroexpand((use-package org :ensure org-plus-contrib) ((the-with-operating-system . #f(compiled-function (os &rest body) #<bytecode 0x1361100e08ecdc24>)) (the-operating-system-p . #f(compiled-function (os) #<bytecode 0x1e182058d52dfffc>)) (the-defhook . #f(compiled-function (name arglist hooks docstring &rest body) #<bytecode -0x10e62e2e1d603d51>)) (declare-function . byte-compile-macroexpand-declare-function) (eval-when-compile . #f(compiled-function (&rest body) #<bytecode -0x1e4cce36188253c3>)) (eval-and-compile . #f(compiled-function (&rest body) #<bytecode 0x92240a5e701e498>)) (with-suppressed-warnings . #f(compiled-function (warnings &rest body) #<bytecode 0xde46421673df16e>))))
  byte-compile-recurse-toplevel((use-package org :ensure org-plus-contrib) #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_45>)
  byte-compile-toplevel-file-form((use-package org :ensure org-plus-contrib))
  #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_43>(#<buffer  *Compiler Input*>)
  byte-compile-from-buffer(#<buffer  *Compiler Input*>)
  byte-compile-file("~/.emacs.d/the.el")
  org-babel-load-file("~/.emacs.d/the.org" t)
  (if (version< emacs-version the-minimum-emacs-version) (error (concat "THE Emacs requires at least Emacs %s, " "but you are running Emacs %s") the-minimum-emacs-version emacs-version) (defvar the-lib-file (concat user-emacs-directory "the.org") "File containing main THE configuration. This file ...") (if (file-exists-p the-lib-file) nil (error "Library file %S does not exist" the-lib-file)) (org-babel-load-file the-lib-file t) (run-hooks 'the-after-init-hook))
  load-with-code-conversion("/Users/jack.henahan/.emacs.d/init.el" "/Users/jack.henahan/.emacs.d/init.el" nil nil)
  load-file("~/.emacs.d/init.el")
  funcall-interactively(load-file "~/.emacs.d/init.el")
  command-execute(load-file record)
  execute-extended-command(nil "load-file" "load-fi")
  funcall-interactively(execute-extended-command nil "load-file" "load-fi")
  command-execute(execute-extended-command)

It looks like something in use-package's call stack is requiring json, which might be doing the wrong thing?

jhenahan commented 3 years ago

It occurs to me that this might be something wonky going on in the site-start.el that Nix packages, so I'm going to look into that, as well. I'll try to load just tree-sitter-langs from an emacs -q and emacs -Q with use-package and plain require to see if that makes the stack trace less horrific.

jhenahan commented 3 years ago

Okay, I ruled out the site-start.el, so from emacs -q, I can M-x load-library RET tree-sitter-langs RET for the following trace:

Debugger entered--Lisp error: (module-not-gpl-compatible "/nix/store/5ym430p2ry8dpa6rnahjydsd1fs88ll4-emacs-...")
  require(json)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\305\306\307\"\210\305\310\307\"\210\305\311\307\"\210\305\312\307\"\210\305\313\307\"\210\305\314\307\"\210\305\315\307\"..." [require json password-cache cl-lib eieio autoload secrets-create-item "secrets" secrets-delete-item secrets-get-alias secrets-get-attributes secrets-get-secret secrets-list-collections secrets-search-items rfc2104-hash "rfc2104" plstore-open "plstore" plstore-find plstore-put plstore-delete plstore-save plstore-get-file epg-make-context "epg" epg-context-set-passphrase-callback epg-decrypt-string epg-encrypt-string help-mode "help-mode" nil t custom-declare-group auth-source "Authentication sources." :version "23.1" :group gnus custom-declare-variable auth-source-cache-expiry funcall function #f(compiled-function () #<bytecode 0x1f400017dfb1>) "How many seconds passwords are cached, or nil to d..." "24.1" :type (choice (const :tag "Never" nil) (const :tag "All Day" 86400) (const :tag "2 Hours" 7200) (const :tag "30 Minutes" 1800) (integer :tag "Seconds")) defalias auth-source-backend-p ...] 8)
  require(auth-source)
  byte-code("\300\301!\210\300\302!\210\303\304\305\"\207" [require url-vars auth-source autoload url-scheme-get-property "url-methods"] 3)
  require(url-parse)
  byte-code("\300\301!\210\300\302!\210\303\304\305\"\210\303\306\305\"\210\303\307\310\"\207" [require url-parse url-vars autoload timezone-parse-date "timezone" timezone-make-date-arpa-standard mail-header-extract "mailheader"] 3)
  require(url-util)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\304\305\306\307\310\311\310\312\313\314&\11\207" [require url-util url-parse url-domsuf custom-declare-group url-cookie nil "URL cookies." :prefix "url-" "url-cookie-" :group url] 10)
  require(url-cookie)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\300\306!\210\300\307!\210\300\310!\210\300\311!\210\300\312!\210\313\314\315\316\317DD\320\321\322..." [require mailcap url-vars url-cookie url-history url-expand url-privacy url-methods url-proxy url-parse url-util custom-declare-variable url-configuration-directory funcall function #f(compiled-function () #<bytecode 0x1f4942900ad7>) "Directory used by the URL package for cookies, his..." :type directory :group url] 8)
  require(url)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\207" [require seq pp url tar-mode] 2)
  require(tree-sitter-langs-build)
  byte-code("\301\302!\210\301\303!\210\301\304!\210\301\305!\210\301\306!\210\307\310\311\312\313\303%\210\314\300!\203&\0\10\204*\0\315\316!\210\311\207" [tree-sitter-langs--testing require cl-lib tree-sitter tree-sitter-load tree-sitter-hl tree-sitter-langs-build custom-declare-group tree-sitter-langs nil "Grammar bundle for `tree-sitter'." :group boundp tree-sitter-langs-install-grammars :skip-if-installed] 6)
  load-library("tree-sitter-langs")
  funcall-interactively(load-library "tree-sitter-langs")
  command-execute(load-library record)
  execute-extended-command(nil "load-library" "load-lib")
  funcall-interactively(execute-extended-command nil "load-library" "load-lib")
  command-execute(execute-extended-command)
jhenahan commented 3 years ago

Okay, so it looks like https://github.com/NixOS/nixpkgs/issues/108089 references a similar situation and has some hacky suggestions, so it looks like this is probably a Nix problem more than a you problem.

junyi-hou commented 3 years ago

I also encounter this issue. I think this is because in nix the .so in the tree-sitter-langs-grammar-dir are symlinks. This error will arise if tree-sitter-lang does not support symlinked .so file.

So my question is whether this is the case. If so, is there a way to use the target .so files rather than the symlinks? Thanks!

jhenahan commented 3 years ago

@junyi-hou I just patch the library in my overlay.

Snippets from my config:

Getting the object files (change as necessary for your platform):

  tree-sitter-grammars = super.stdenv.mkDerivation rec {
    name = "tree-sitter-grammars";
    version = "0.10.0";
    src = super.fetchzip {
      url = "https://github.com/ubolonton/tree-sitter-langs/releases/download/${version}/tree-sitter-grammars-macos-${version}.tar.gz";
      stripRoot = false;
      sha256 = "sha256-m5WH9TYIn+ldMM/6bWpSYPMAGmPgCZhgiUCVIUb+Fd0=";
    };
    installPhase = ''
      install -d $out/langs/bin
      install -m444 * $out/langs/bin
      echo -n $version > $out/langs/bin/BUNDLE-VERSION
    '';
  };

Overriding the package (modify however to match your setup):

    tree-sitter-langs = epkgs.tree-sitter-langs.overrideAttrs (oldAttrs: {
        postPatch = oldAttrs.postPatch or "" + ''
          substituteInPlace ./tree-sitter-langs-build.el \
          --replace "tree-sitter-langs-grammar-dir tree-sitter-langs--dir"  "tree-sitter-langs-grammar-dir \"${self.tree-sitter-grammars}/langs\""
        '';
      });
junyi-hou commented 3 years ago

Yes, I have done something similar to this. Just wondering if enabling symlink-following would be a nice addition to the package.

On Thu, Jun 3, 2021, 3:18 PM Jack Henahan @.***> wrote:

@junyi-hou https://github.com/junyi-hou I just patch the library in my overlay.

Snippets from my config:

Getting the object files (change as necessary for your platform):

tree-sitter-grammars = super.stdenv.mkDerivation rec { name = "tree-sitter-grammars"; version = "0.10.0"; src = super.fetchzip { url = "https://github.com/ubolonton/tree-sitter-langs/releases/download/${version}/tree-sitter-grammars-macos-${version}.tar.gz"; stripRoot = false; sha256 = "sha256-m5WH9TYIn+ldMM/6bWpSYPMAGmPgCZhgiUCVIUb+Fd0="; }; installPhase = '' install -d $out/langs/bin install -m444 * $out/langs/bin echo -n $version > $out/langs/bin/BUNDLE-VERSION ''; };

Overriding the package (modify however to match your setup):

tree-sitter-langs = epkgs.tree-sitter-langs.overrideAttrs (oldAttrs: {
    postPatch = oldAttrs.postPatch or "" + ''          substituteInPlace ./tree-sitter-langs-build.el \          --replace "tree-sitter-langs-grammar-dir tree-sitter-langs--dir"  "tree-sitter-langs-grammar-dir \"${self.tree-sitter-grammars}/langs\""        '';
  });

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ubolonton/emacs-tree-sitter/issues/100#issuecomment-854222060, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJT3YA5IIBXGBZ5H2HIVDGTTQ75RVANCNFSM4WP5BPRQ .