From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id mBouFR11SGZO7AAAqHPOHw:P1 (envelope-from ) for ; Sat, 18 May 2024 11:30:05 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id mBouFR11SGZO7AAAqHPOHw (envelope-from ) for ; Sat, 18 May 2024 11:30:05 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=p9VN89nj; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1716024605; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=PsuuDeZUs/PvqzuJB6D5wtT38lZnPtmF0lVEn4wwdtE=; b=J1xXRGS2ttn8YAXGTvdFBTybEHx6IOd0AsI0ICXu9dQM4bKEqDJouGuGHp7kRUBozUBmsy frcH7KQmpb1jJ6lHcnaXcPbDMMy+HFAZ0O6tNBO/4TF0D8kwJt3XO9Bhxk2gUhIWTg/+xr HOiF1vycShAUHS2Ea7jusu5hjSK7sXDwcOpWsIEcjQ+ZxlWa8w5e96t3tVf3EZuNHE6vwv sBJwbLJStGyGiU79ep3TQ4EVu6NDiZf5h1wCMzndpqJAe4DSic1v6PgAabL2dJdcB01T5B anoMn4HLoTnt03Jc2DinwWNfbX2EIb6JLeq/GpCQZ0oHbU+IXn+vFs4ME1LQ3g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1716024605; a=rsa-sha256; cv=none; b=FyyxqHw9H/CxAaXKs9T6aaxsfr66Z5U8xJkZqTHBQHMNawpyhQL8AC2QsANrOeRDBS00dV 0L7UCSbPwH9DHfhbiRQZdABzkyrGV9zjsRjTXCPN4PcZdC8Jh9p94nj/VJjcP8RUAMYyuz jxq3xpZ8oCUdQk4WIobtUeEddAOuv/Tc1nMLFM6J+xQbp7klcgzZecmZOh8cf/GOHNWFxh POfRHBDBbRSk5JAZ++EGmJ5m7Zjte/8TwSMnT0Y/eXybezZCN2V4swNK8LXHf/POKvUGnd 0VEk0PTu30cglAfr5zQeU1xt9Fm7bLrqYf8pDjbZX/hTCH89bdKgDC6HwojuYA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=p9VN89nj; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id AFE69FB51 for ; Sat, 18 May 2024 11:30:04 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s8GNI-0005Fs-F9; Sat, 18 May 2024 05:29:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s8GNF-0005Fh-Ou for emacs-orgmode@gnu.org; Sat, 18 May 2024 05:29:05 -0400 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s8GN5-0004wg-VL for emacs-orgmode@gnu.org; Sat, 18 May 2024 05:29:05 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 4D019240103 for ; Sat, 18 May 2024 11:28:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1716024531; bh=kslOzoDKJRgy3njgsv/8grs07MAtM0L8BFhsU0e171c=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=p9VN89njs7uAcwnosuicZWh8esf84v5JZbWis08To8qUoZxh3XAR5qk9lyRMiGbym 7+k6I7FbymvXeOyCVCxv5GDScmgUKwgYMn8G2oFWGsLIH+d0Wd4XjQcR0HjZDH8M31 KYE0d0qY5pSNw/71dm64HG+sB1uolnJjJ5KV/ypncqh8Hz1QIJzALb87cQU/Fz8GF5 L0osKtp1Xp8tobIwnNtZ9vzz5E7oZYoaCtaUiDuEaNKOg1QMGKXi3nHDiJLf2dy7rP CLQhcUhS23Y6iyjhvEkIYWIFCosPuDg6vrdgcH04G34hAw4A2K8hY2IT6VbFlz8dgH aTvnDGZD9c+sw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4VhJRk4Z5qz9rxD; Sat, 18 May 2024 11:28:50 +0200 (CEST) From: Ihor Radchenko To: Francesc Rocher Cc: emacs-orgmode@gnu.org Subject: Re: Testing issues for Ada/SPARK support in Babel In-Reply-To: References: <87le9szzev.fsf@localhost> <87le7at17k.fsf@bzg.fr> <87cyskn7xa.fsf@localhost> <87plvzek3f.fsf@localhost> <87y18ef7yt.fsf@localhost> Date: Sat, 18 May 2024 09:30:27 +0000 Message-ID: <87ttivtqks.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -6.58 X-Spam-Score: -6.58 X-Migadu-Queue-Id: AFE69FB51 X-Migadu-Scanner: mx11.migadu.com X-TUID: hhrqup1kg4P8 Francesc Rocher writes: > If you don't mind, I attach here the patch in its current state for > reviewing purposes. Sure. See my comments inline. > +;; Author: Francesc Rocher > +;; Maintainer: Francesc Rocher If you can, please provide a contact email here. > + > +(require 'ob) > +(require 'time-stamp) > + > +(org-assert-version) Need (require 'org-macs) - it is where `org-assert-version' is defined. > +(defvar org-babel-tangle-lang-exts) > +(add-to-list 'org-babel-tangle-lang-exts '("ada" . "adb")) Why not (require 'ob-tangle)? Or, better (eval-after-load 'ob-tangle ...) > +(defvar org-babel-temporary-directory) You don't need it after (require 'ob) - org-babel-temporary-directory is defined in ob-core, loaded by ob, and is thus available. > +(defvar org-babel-default-header-args:ada '((:args . nil) > + (:cflags . nil) > + (:pflags . nil) > + (:prove . nil) > + (:template . nil) > + (:unit . nil) > + (:with . nil)) > + "Ada/SPARK default header arguments.") > + > +(defconst org-babel-header-args:ada '((args . any) > + (cflags . any) > + (pflags . any) > + (prove . ((nil t))) > + (template . :any) > + (unit . :any) > + (with . nil)) What does (with . nil) is supposed to mean? AFAIK, this does not follow the format we describe in `org-babel-common-header-args-w-values'. > +(defconst ob-ada-spark-template-var-name-format "ob-ada-spark-template:%s" > + "Format of the name of the template variables. > +All templates must be defined in a variable with a name > +compatible with this format. The template name is only the '%s' > +part. From the source block, templates can be used in the > +':template' header with the template name. By convention, Elisp docstrings use double space to separate sentences. Also, ' should be used with care as they may be interpreted specially. You may have to protect them with \=' escape or use some other formatting. Try M-x checkdoc and check out "D.6 Tips for Documentation Strings" section of Elisp manual. > +(defcustom org-babel-ada-spark-compile-command "gnatmake" > + "Command used to compile Ada/SPARK code into an executable. > +May be either a command in the path, like gnatmake, or an > +absolute path name. > + > +If using Alire 2.x, install the default native toolchain, with > +`alr install gnat_native', and write here the path to gnatmake or I think `...' is used incorrectly here - it is not a Elisp symbol. > + :safe #'stringp) I very much doubt that setting this variable in buffer-locals is safe - a file downloaded from internet may set this to something like "rm -f /home;" and unsuspecting users may evaluate the code... > +(defcustom org-babel-ada-spark-prove-command "gnatprove" > .... > + :safe #'stringp) Same here. > +(defcustom org-babel-ada-spark-default-compile-flags > ... > + :safe #'stringp) And here. > +(defcustom org-babel-ada-spark-default-prove-flags > ... > + :safe #'stringp) And here. > +(defcustom org-babel-ada-spark-default-file-header > + (lambda () Why not making the value a named function? > +(defun ob-ada-spark-replace-params-from-template (params) > + "Replace headers in PARAMS with headers defined in the template. > +If a template defines a set of params, replace the values in > +PARAMS with the values defined in the template, overwriting > +parameters already defined in the source code block. > +Return the new list of PARAMS, or the original list if the > +template does not define any header or no template is used." It is important to note that PARAMS is modified by side effect. > + (let* ((template-name (cdr (assq :template params))) > + (template (eval > + (intern-soft > + (format ob-ada-spark-template-var-name-format > + template-name))))) > + (if template > + (progn > + (message "-- replacing params from template %s" template-name) Any reason to display a message here? It is not a big deal when running code interactively, but it may become annoying for users when code blocks are evaluated in batches. For example during export. > + (mapc (lambda (p) > + (assq-delete-all (car p) params)) > + (cdr (assq :params template))) > + (append params (cdr (assq :params template)))) > + params))) Why not simply (append params ...)? When a plist has (:foo bar :foo baz), the first value is used. Also, while your approach works for your current value of `org-babel-header-args:ada' that does not have any compound parameters, it should be more future-compatible to use `org-babel-merge-params' that knows about multi-class parameters. > +(defun org-babel-expand-body:ada (body params) > ... > + (message "-- expanding body from template %s" template-name) Same question about message. > ... > + (setq body (string-replace (format "%s" key) (format "%s" val) body)))) `string-replace' is not yet available in Emacs 27 that Org mode still supports. Also, do I understand correctly, that ob-ada does not support passing lists or tables as variable values? And it would be nice to support :prologue and :epilogue header arguments. > +(defun org-babel-execute:ada (body params) > + "Execute or prove a block of Ada/SPARK code with org-babel. > +BODY contains the Ada/SPARK source code to evaluate. PARAMS is > +the list of source code block parameters. > + > +This function is called by `org-babel-execute-src-block'" > + (let* ((processed-params (org-babel-process-params params)) This is redundant. `org-babel-execute-src-block' calls `org-babel-process-params' as a part of pre-processing. > +(defun ob-ada-spark-execute (body params) > + "Execute or prove a block of Ada/SPARK code with org-babel. "or prove"? Then, how is it different from `ob-ada-spark-prove'? > +(defvar ada-skel-initial-string--backup "") > + > +(defun ob-ada-spark-pre-tangle-hook () > + ... > +(defun ob-ada-spark-post-tangle-hook () > + "This function is called just after `org-babel-tangle'. > +Once the file has been generated, this function restores the > +value of the header inserted into Ada/SPARK files." > + ;; if ada-skel-initial-string has not been inserted by ada-mode, then > + ;; insert the default header > + (if (boundp 'ada-skel-initial-string) > + (setq ada-skel-initial-string ada-skel-initial-string--backup) > + (save-excursion > + (goto-char (point-min)) > + (insert (funcall org-babel-ada-spark-default-file-header))))) > + > +(add-hook 'org-babel-pre-tangle-hook #'ob-ada-spark-pre-tangle-hook) > +(add-hook 'org-babel-post-tangle-hook #'ob-ada-spark-post-tangle-hook) This is all awkward: (1) you are setting tangle hooks globally, not just for ada source blocks; (2) moving around global variables can be fragile. Maybe we can instead extend ob-core to handle your needs? For example, we can add abnormal hooks executed before `org-babel-tangle' populates the target buffer? Or introduce a backend-specific hook like org-babel-post-tangle-hook:ada? > --- /dev/null > +++ b/testing/lisp/test-ob-ada-spark.el > ... > + > +;;; Code: > +(require 'ob-core) > +(require 'ob-ada-spark) No need to put requires here. The test design for babel backends is that tests are to be evaluated _only_ when the corresponding babel backend is loaded. This is what > +(unless (featurep 'ob-ada-spark) > + (signal 'missing-test-dependency "Support for Ada and SPARK code blocks")) is for - when feature is not available, mark tests to be skipped. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at