Skip to content

use :include in install stanza #256

Closed
ocaml/opam-repository
#22317

Description

@timbertson

I have a package which installs a server program, but also a bunch of resource files (fonts, images, CSS styles etc). I can happily use jbuilder to install the server binary, but I can't figure out how to install the resources without listing them explicitly (not much fun since this includes a large number of files that I didn't write, copied from twitter-bootstrap).

My first thought was that maybe I could write a rule to generate resource-files.sexp and then (:include resource-files.sexp) that in my (files ...) stanza, but that isn't allowed. Is it possible to add this?

Activity

  1. timbertson commented on Sep 22, 2017

    @timbertson
    ContributorAuthor

    I don't think so - in this case I'd like to:

    • include everything under res/ (recursively)
    • follow symlinks in this traversal
    • drop the res from the destination path (e.g. res/images/foo becomes images/foo)

    I could work around any of those being missing (particularly the third, it's just a cosmetic thing), but it doesn't seem like a great fit given that none of them are currently supported by globs.

    Aside: it would be pretty neat from an extensibility point of view if pretty much everything supported (:include) - giving an escape hatch which is less severe than generating the whole file. Are you trying to keep the interface simple by not allowing that, or is it difficult / costly to add support each place it's allowed?

  2. timbertson commented on Oct 2, 2017

    @timbertson
    ContributorAuthor

    Ahh, I see. That does make it tricky.

    Couldn't you assume that if someone references ${lib:foo:bar} then foo needs to be located, but not go any further than that? In particular, I guess it would mean that any requested file for an external library is assumed to be buildable (and you know its path because you know where foo is to be installed), and it's a runtime error if it fails to exist after installation (since I assume installation is atomic; you wouldn't just install specific files which were needed from external libraries).

    To rephrase, I guess what I'm suggesting is to terminate the "is X buildable" at the library layer, not the file layer, since jbuilder can't look inside non-jbuilder libraries anyway. But I have no idea if that would work, so it's up to you whether that's a useful suggestion :)

    To come back to your use case, are files under res generated?

    Not individually, and not by jbuilder - they're externally-built (npm packages, multiple size variants of input images)

    Otherwise, I think something equivalent to (files_recursively_in X) would work well.

    Yeah, that would work well for my use case, as long as it followed symlinks (or could be made to). Would it have src and dest prefixes (i.e. "install files from res/ into share/www")? That would be useful, to prevent the source code layout restricting the installed layout.

  3. timbertson commented on Mar 8, 2018

    @timbertson
    ContributorAuthor

    Thanks for the idea and the diff action! I've (finally ;)) tried this out now, and hit a couple of snags:

    Firstly, when I pass --auto-promote the command still exits with 1 when the generated file differs. So I end up having to run:

    jbuilder build @src/www/jbuild-res.inc --auto-promote || jbuilder build @src/www/jbuild-res.inc --auto-promote
    

    Which is awkward, but I'm assuming this should be an easy fix.

    (I also chose to name the alias the same as the file in question, not sure if that's more or less confusing ;))

    But secondly, I can't get my .gen file to be regenerated. If I change some file which affects the list of generated resources (but which isn't ./gen-list-of-files-to-install.exe itself), I can't get jbuilder to ever regenerate the file, even if I ask for it explicitly (with jbuilder build @src/www/jbuild-res.inc.gen). It just doesn't bother running, because none of its known dependencies are out of date. I think this is essentially another case of #255 (but maybe slightly easier, since I'm explicitly requesting it be built).

    Since the whole point of this is to include files which were built outside jbuilder, having jbuilder refuse to regenerate the file makes it difficult. I can at least use an external build tool to just build jbuild-res.inc.gen myself explicitly, but it's quite a dance to get right and make sure the file actually gets regenerated.

  4. timbertson commented on Mar 8, 2018

    @timbertson
    ContributorAuthor

    For the exit code, the idea is that because the file has changed, you might need to build again to get a fix point.

    Hmm, fair enough. I still think it should be 0 on --auto-promote though, since if you need to distinguish that case couldn't you just not use --auto-promote? i.e.:

    if ! jbuilder build @diff-target; then
      jbuilder build @diff-target --auto-promote
      jbuilder build all-the-other-things
    fi
    

    The current workaround is fine though 🤷‍♂️

    Maybe the generator could generate the dependencies?

    Maybe. This particular target would be affected by:

    • updating my bootstrap dependency version (this is effectively depending on package.json)
    • me manually adding another image into the source location where res/images is generated from (i.e. depend on all files in images/)
    • me modifying any of the build scripts which control what paths are created in res/, which currently is:
    gup/_build/bootstrap.gup
    gup/src/www/res/all.gup
    gup/src/www/res/fonts.gup
    gup/src/www/res/images.gup
    

    ...but if I add to that set or any of these scripts start sourcing other scripts, I'd need to manually add those to the list of dependencies which should cause a rebuild (I have no automated way to get this list).

    So it could be done, but it's quite a lot of effort to maintain an accurate dependency list. And if I miss something, the result is an incorrect build which I can't force jbuilder to rebuild. For me, the time wasted by running the command on every build would be well worth the reduced effort in accurately tracking dependencies, since it takes ~0.03s.

  5. mseri commented on Sep 24, 2018

    @mseri
    Member

    I was discussing with @rgrinberg the possibility to use :include or a glob in the install stanza. For me glob would be enough, I'd be happy to give a shot to the feature if you point me to the right direction

  6. rgrinberg commented on Sep 24, 2018

    @rgrinberg
    Member

    Actually, I think that we should just finish off #962 first. Let's support static variables first before considering (:include ..). @mseri would you like to finish off that PR, I believe the original author likely abandoned it anyway. Note that (:include ..) is incompatible with the current model of the install dir so it wouldn't be so easy to support

  7. self-assigned this
    on Jul 28, 2022
  8. added a commit that references this issue on Oct 19, 2022
    2996546
  9. added this to the 3.5.0 milestone on Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions