How to get the swift toolchain to print its *entire* git hash?

when you dump the toolchain version with swift --version on a nightly, you get something like:

$ swift --version
Swift version 5.9-dev (LLVM 08f7fecaf6cedb8, Swift a0b3f802c2ce715)
Target: x86_64-unknown-linux-gnu

the toolchain git hash is truncated. is there a way to get all 40 characters of the toolchain‘s git hash?

git show a0b3f802c2ce715 gets me a0b3f802c2ce715b3e4c709ea7817bc89736d915.

that’s if you clone the apple/swift repository for the compiler, but i’m trying to get the hash from a downloaded toolchain.

That's the question: why do you want to get it from the trunk toolchain? The git hash is a compile-time constant that is sliced to 15 hexadecimal chars and printed only when checking the version, presumably since that's enough to identify the full hash most of the time.

If you want it directly from the toolchain, you'd have to modify that line in your compiler source to print out the full 160-bit hash.

If you really want it for some reason, I think this GitHub API could help.

$ curl https://api.github.com/repos/apple/swift/commits/a0b3f802c2ce715
{
  "sha": "a0b3f802c2ce715b3e4c709ea7817bc89736d915",
  "node_id": "C_kwDOAqwwJdoAKGEwYjNmODAyYzJjZTcxNWIzZTRjNzA5ZWE3ODE3YmM4OTczNmQ5MTU",
  "commit": {
    "author": {
      "name": "Joe Groff",
      "email": "jgroff@apple.com",
      "date": "2023-01-09T17:02:50Z"
    },
    "committer": {
      "name": "GitHub",
      "email": "noreply@github.com",
      "date": "2023-01-09T17:02:50Z"
    },
    "message": "Merge pull request #62847 from jckarter/mangler-structural-opaque-type-issues-5.8\n\n[5.8] Mangler: Fix substitution ordering when mangling opaque return types.",
    "tree": {
      "sha": "b79b645b7e1f9b31c01365eee1b06ce726cfa896",
      "url": "https://api.github.com/repos/apple/swift/git/trees/b79b645b7e1f9b31c01365eee1b06ce726cfa896"
    },
    "url": "https://api.github.com/repos/apple/swift/git/commits/a0b3f802c2ce715b3e4c709ea7817bc89736d915",
    "comment_count": 0,
    "verification": {
      "verified": true,
      "reason": "valid",
      "signature": "-----BEGIN PGP SIGNATURE-----\n\nwsBcBAABCAAQBQJjvEi6CRBK7hj4Ov3rIwAAW5gIAEkd1r1lQ0ZutDO5t0UTv2lW\nvn42cMDIDz/g8zdhJsc8XcdXx0DEMXviB8NPSkwJTW41DVdQu8D1pW9ukNfVR18O\nEiNGXPZCIDRb1sip0qJsiuBBb2LPfqdtYcPWTt/yXV5fE+FGiD2K5uZ58WxD708V\nzs++jB7d6LEVx3g54WVY22GzSbNJke4G+nO/384wRzUeQDOgEcUDoGPpK6BcGWtq\naD71Eft8wa2/oP1vVaKg1tERz4tGGc80Z88CQMrfptVdwRqyhxFXOWFWGtuks/Q5\nBq3GVkY0clP+gJQgBN8KRlS474+h0LOTfOBPWZRngBeGrc08pkbC5qmU/idZY/A=\n=R2qq\n-----END PGP SIGNATURE-----\n",
      "payload": "tree b79b645b7e1f9b31c01365eee1b06ce726cfa896\nparent 21dfdaf67eefe776b47479a3ba185a6b2315ad18\nparent 9e08b40c63d87b974465cec6a40dd2714c5fc0bd\nauthor Joe Groff <jgroff@apple.com> 1673283770 -0800\ncommitter GitHub <noreply@github.com> 1673283770 -0800\n\nMerge pull request #62847 from jckarter/mangler-structural-opaque-type-issues-5.8\n\n[5.8] Mangler: Fix substitution ordering when mangling opaque return types."
    }
  },
  "url": "https://api.github.com/repos/apple/swift/commits/a0b3f802c2ce715b3e4c709ea7817bc89736d915",
  "html_url": "https://github.com/apple/swift/commit/a0b3f802c2ce715b3e4c709ea7817bc89736d915",
  "comments_url": "https://api.github.com/repos/apple/swift/commits/a0b3f802c2ce715b3e4c709ea7817bc89736d915/comments",
  // truncated
}
1 Like