a-scie / jump

A Self Contained Interpreted Executable Launcher
Apache License 2.0
50 stars 7 forks source link

Add support for `${scie.env.X}`. #8

Closed jsirois closed 1 year ago

jsirois commented 1 year ago

Although node support currently works, it looks like this for cowsay installed via npx cowsay and then the resulting node_modules directory zipped up and used as the scie trailer zip:

{
  "scie": {
    "root": "~/.nce",
    "size": 2164160,
    "version": "0.1.0"
  },
  "files": [
    {
      "type": "archive",
      "name": "node",
      "size": 23692504,
      "fingerprint": {
        "algorithm": "sha256",
        "hash": "9429e26d9a35cb079897f0a22622fe89ff597976259a8fcb38b7d08b154789dc"
      },
      "archive_type": "tar.xz"
    },
    {
      "type": "archive",
      "name": "node_modules",
      "size": 406840,
      "fingerprint": {
        "algorithm": "sha256",
        "hash": "d7fa4e96a282573a763173902955d1f77bde176b58cba3abae5bd3bb6129c183"
      },
      "archive_type": "zip"
    }
  ],
  "command": {
      "env": {
          "NODE_PATH": "${node_modules}"
      },
      "exe": "${node}/node-v18.12.0-linux-x64/bin/node",
      "args": [
        "${node_modules}/node_modules/cowsay/cli.js"
      ]
  }
}

Here the command has to bind to the underlying js entry point file that implements cowsay. This is because the js console script equivalent is a #!/usr/bin/env node shebang script. The current env var handling is to always only use env vars defined in the config as defaults and let presence in the env go undisturbed. There probably needs to be a way to specify fallback vs trump and then trumping could do this:

{
  "command": {
    "env": {
      "NODE_PATH": "${node_modules}",
      "=PATH": "${node}/node-v18.12.0-linux-x64/bin:${scie.env.PATH}"
    },
    "exe": "${node}/node-v18.12.0-linux-x64/bin/npx",
    "args": [
      "cowsay"
    ]
  }
}

Here I've used the straw man = prefix on PATH to indicate it should override. This sort of reads like it does and is safe since "These strings have the form name=value; names shall not contain the character '='.": https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap08.html.

jsirois commented 1 year ago

The working cowsay.js executable:

{
  "scie": {
    "root": "~/.nce",
    "size": 1185192,
    "version": "0.1.0"
  },
  "files": [
    {
      "type": "archive",
      "name": "node",
      "size": 23692504,
      "fingerprint": {
        "algorithm": "sha256",
        "hash": "9429e26d9a35cb079897f0a22622fe89ff597976259a8fcb38b7d08b154789dc"
      },
      "archive_type": "tar.xz"
    },
    {
      "type": "archive",
      "name": "cowsay",
      "size": 406840,
      "fingerprint": {
        "algorithm": "sha256",
        "hash": "d7fa4e96a282573a763173902955d1f77bde176b58cba3abae5bd3bb6129c183"
      },
      "archive_type": "zip"
    }
  ],
  "command": {
      "env": {
          "NODE_PATH": "{cowsay}",
          "=PATH": "{node}/node-v18.12.0-linux-x64/bin:{scie.env.PATH}"
      },
      "exe": "{node}/node-v18.12.0-linux-x64/bin/npx",
      "args": [
        "cowsay"
      ]
  }
}

And the working cowsay PEX executable, but with no explicit configuration of the PEX zip trailer:

{
  "scie": {
    "version": "0.1.0",
    "size": 1185192,
    "root": "~/.nce"
  },
  "files": [
    {
      "type": "archive",
      "name": "python",
      "size": 42111958,
      "fingerprint": {
        "algorithm": "sha256",
        "hash": "032da47cd2d8f73fa677ac8f3b172d743a13cc044d457f1871e73b528d547ea1"
      },
      "archive_type": "tar.zst"
    }
  ],
  "command": {
      "exe": "{python}/python/install/bin/python3.10",
      "args": [
        "{scie}"
      ]
  }
}