Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy binary files #44

Open
eternal-turtles opened this issue May 26, 2024 · 2 comments
Open

Copy binary files #44

eternal-turtles opened this issue May 26, 2024 · 2 comments

Comments

@eternal-turtles
Copy link

It would be convenient to be able to specify some files from the skeleton to copy over without being processed by cl-emb.

I'd like to include favicon.ico or a png, or some other file that is not text-based, but currently an error like the following is signaled:

debugger invoked on a SB-INT:STREAM-DECODING-ERROR in thread
#<THREAD tid=162769 "main thread" RUNNING {10044E8113}>:
  :UTF-8 stream decoding error on
  #<SB-SYS:FD-STREAM for "file /home/jnewton/quicklisp/local-projects/foo.lisp.vinland/skeleton/web/static/favicon.ico" {100423E973}>:

    the octet sequence #(158) cannot be decoded.

Perhaps there could be a second special variable that would be bound to a regular expression representing files to copy directly, or else a list of file extensions or filenames.

As a workaround, I can keep these files in another directory and copy them over after calling CL-PROJECT:MAKE-PROJECT, but this seems like a feature that could be added to the library.

@kilianmh
Copy link
Collaborator

kilianmh commented Jun 7, 2024

  • You are writing about files that need not be loaded with asdf:load-system, right?
  • Should there be default folder such as /static/, or user supplied folder, such as /web/static/ in your example? If the user supplies custom folder we would need to make sure that the folder exists.
  • Should the file-name of the copied one be automatically be the same or changeable (e.g. source is favicon.ico and copied version favorite-icon.ico)? If yes, should the file type also be changeable?

So it could look like this, whereas the first value is the path to the file to be copied and the second is the path where to copy the file:
:copy-file (list (list (pathname "/home/jnewton/web/static/favicon.ico") (pathname "/web/static/favorite-icon.ico")))

@eternal-turtles
Copy link
Author

eternal-turtles commented Jun 15, 2024

I should have mentioned, but this feature request is for when a custom cl-project:*skeleton-directory* is provided before calling cl-project:make-project (which allows for custom project skeletons).

  • Yes, for the use-cases I'm thinking of, these files would not be loaded with asdf:load-system. The idea is to copy images or other binary files from the custom skeleton directory to the equivalent location in the target directory.
  • Perhaps an additional parameter to cl-project:make-project to specify a static directory, or a special variable that names a static directory, with or without a default, is the way to go - I hadn't considered this approach, and think a default "static/" directory could make sense.
  • I think the file-name should be copied as-is, except perhaps with "skeleton" in the file name replaced by the provided project name to keep behavior consistent:

    cl-project/src/file.lisp

    Lines 27 to 37 in 0df6de1

    (when (search "skeleton" (pathname-name target-path))
    (setf target-path
    (make-pathname :name
    (regex-replace-all "skeleton"
    (pathname-name target-path)
    (getf *skeleton-parameters* :name))
    :defaults target-path)))
    (copy-file-to-file (merge-pathnames (template-file-path file)
    *skeleton-directory*)
    target-path
    :verbose verbose)

I was imagining that there would be an additional special variable that might be checked around here

cl-project/src/io.lisp

Lines 15 to 18 in 0df6de1

(with-open-file (stream target-path :direction :output :if-exists :supersede)
(write-sequence
(cl-emb:execute-emb source-path :env *skeleton-parameters*)
stream)))
and if the file pathname has a file-type that indicates it is binary, then it would be copied without calling cl-emb:execute-emb. I do like the idea though of being able to specify a static directory or have a default static directory for which files would be copied without cl-emb processing. I'm not sure though about being able to specify different target filenames/locations for the copied static files, as I don't have a use-case for this and it wouldn't really be consistent with how cl-emb processed files are copied, always with the same name/relative location except with "skeleton" replaced with the project name.

@fukamachi Any thoughts on the right design for this feature if you agree with it and if you'd be open to a PR?

Edit: it now occurs to me that there might be JS or CSS files in the static directory that might be useful to process with cl-emb, so to me I think being able to specify binary file types, either with a special variable or an additional parameter to cl-project:make-project, still makes the most sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants