AZO234 / NP2kai

Neko Project II kai
http://domisan.sakura.ne.jp/article/np2kai/np2kai.html
MIT License
246 stars 61 forks source link

(CMake) Make Git (and commit id?) optional #108

Open OPNA2608 opened 3 years ago

OPNA2608 commented 3 years ago

I'm maintaining the NP2kai packages (stand-alone & RetroArch core) for Nixpkgs. Our fetching method strips the repository of its .git directory - the contents of which may change without any new commits, which is at odds with our increased focus on reproducibility & input hashing.

For 0.86rev22, I was able to patch the Makefiles to make it possible to define the GIT_VERSION variable via environment variables simply by changing them from GIT_VERSION := to GIT_VERSION ?=. This was enough to get rid of any dependencies on git and the .git directory. For the new CMake system, this seems less trivial.

For a start, would it be possible to make the dependency on the Git package and the existence of a .git directory for getting tag and version information optional depending on whether or not the tag/commit was manually specified? I would be able of passing the git tag from the package definition as an environment variable or a CMake option.

Ideally, it would be great to get rid of the absolutely necessary commit ID as well, maybe displaying

in the "About" window instead? Just wishful thinking on my part though.

AZO234 commented 3 years ago

Wow, Awesome! How great dist it is! Thanks for supporting.

NP2kai's code is very dirty... GIT_VERSION maybe used in "About" dialog, and Caption?? I'll search and try to your saying.

AZO234 commented 3 years ago

We use Tag and Hash is separately to emulation dump data for debug.

Would we can define NP2KAI_HASH to 8c96339? In stead of modify from NP2KAI_COMMIT(rev.22 - dev 8c96339)?

AZO234 commented 3 years ago

We changed CMakeList.txt and Makefile. You can set env various when pre building.

1) NP2KAI_COMMIT = rev.22 - dev 8c96339

2) NP2KAI_VERSION = rev.22 NP2KAI_HASH = 8c96339

Best Regard.

OPNA2608 commented 3 years ago

(That's what I meant, yes. The rev.22 - dev 8c96339 was an idea for what the "About" dialogue could display instead, how to combine VERSION and COMMIT to give some useful build information. I think the current version identification exclusively via commit hash is very non-telling about the actual age and state of the build. Sorry for the confusion.)

I can pass a full-length git hash (e.g. 8c96339397dba27500051586c875aa2223f11b40) without any repository information present by querying the GitHub API, but I can't shorten it guarenteed-unambiguously without git rev-parse --short, which needs a proper Git repository to determine the shortest unique version of that hash. :confused:

I currently do a simple 7-character substring extraction, but that really isn't the proper way of shortening a Git hash.

{
  pname = "np2kai";
  version = "0.86rev22"; #update src.rev to commit rev accordingly

  src = fetchFromGitHub rec {
    owner = "AZO234";
    repo = "NP2kai";
    rev = "4a317747724669343e4c33ebdd34783fb7043221";
    sha256 = "0kxysxhx6jyk82mx30ni0ydzmwdcbnlxlnarrlq018rsnwb4md72";
  };

  configurePhase = ''
    export GIT_VERSION=${builtins.substring 0 7 src.rev}
    # ...
  '';
}

I think it's be wonderful if we could upgrade to something like this.

{
  pname = "np2kai";
  rev = "rev.23";
  version = "0.86-${rev}";

  src = fetchFromGitHub rec {
    owner = "AZO234";
    repo = "NP2kai";
    inherit rev;
    sha256 = "0dfh46afdhg4dh272732df6g7dfh6fg6h54984dfsg56d6h7dfh7";
  };

  configurePhase = ''
    export NP2KAI_VERSION=${rev}
    # ...
  '';
}

Then I could do version updates entirely by querying the GitHub API to tag updates instead of needing to track the current release tag name & commit separately.


We use Tag and Hash is separately to emulation dump data for debug.

If those values are used just for display & logging, have you considered having just a single VERSION defaulting to git describe --tags? That would give you rev.22-86-g09e3426 (exact composition is explained here) for the current commit and just rev.22 for the tagged rev.22 release. Since we plan to build only releases anyway, I could pass just the Git tag and it'd result in the same output as if I was building the tagged release from a Git repository.

AZO234 commented 3 years ago

Anyway I remove 'example value' function.

We want 'Tag' and 'Shorten hash'. Shorten hash is use not usable dump on different build. (To reoccurs bug other environment.)

'Tag'=rev.** is we'll use.

Your writing after manifest is good. I think. Method of shorten hash is it isn't better.

You could get full hash, could we some implement it for you?

AZO234 commented 3 years ago

I'm sorry to slow progress! I added 'NP2KAI_BUILDER' environment value.

To all you want to show info, I need to calc dialog sizes etc. I added one sentence.

Regard.

OPNA2608 commented 3 years ago

No problem, I'm currently busy with work anyway.

I can set "Tag" and "Shortened hash" environment variables, if you want. The manually-shortened hash might have a different length than how git itself would shorten the hash. If that's acceptable with you for representing the version of your project, that's all I really needed from this issue. :slightly_smiling_face:

I don't know what NP2KAI_BUILDER could be used for. Do you expect me to pass something specific there to identify our build? Something like "Nixpkgs build"? You're "upstream" here, let me know what you'd like me to do.

(I'm having some trouble understanding what you're trying to tell me sometimes, apologies for any confusion that's causing)

Shorten hash is use not usable dump on different build.

You could get full hash, could we some implement it for you?

AZO234 commented 3 years ago

I am confusing yes, because I am not good to English... Sorry and thank you!

I thought 'Inputting string manually when build by removing .git'. And I saw .nix script. It is wonderful if work it. I understood you want to do (maybe). 😅

Version '0.86' will be constant forever. This is original NP2 version. I sometime count-up tag 'rev.22' to my progress. (Just for me.) You set NP2KAI_VERSION. If you can use shorten hash (It is need to unique, even if not correctly. Substr is OK.), You set NP2KAI_HASH.

Shorten hash is use not usable dump on different build.

I think shorten hash is not need strictly same string. It is substr enough to use.

You could get full hash, could we some implement it for you?

I don't use full hash. 😃

But .git directory removing is inconvenience. Using GitHub API is too?

I had think confuse, 'Showing on About dialog some original string' etc. Then I thought NP2KAI_BUILDER like value is useful for you... (It will be removed.)

There is other request to build sequence, please tell me! Thanks!

Edit: NP2KAI_BUILDER variable is removed.