Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Add version output #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
filegroup(
name = "git_files",
srcs = glob([".git/**"]),
)

genrule(
name = "gen_version",
srcs = [
":git_files",
"version.sh"
],
outs = ["version.txt"],
cmd = "./version.sh $@",
)

cc_library(
name = "butteraugli_lib",
srcs = [
Expand All @@ -21,4 +36,5 @@ cc_binary(
"@jpeg_archive//:jpeg",
"@png_archive//:png",
],
data = [":gen_version"],
)
28 changes: 24 additions & 4 deletions butteraugli/butteraugli_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,33 @@ void CreateHeatMapImage(const ImageF& distmap, double good_threshold,
}
}

char* ReadVersion(char* argv) {
FILE* file = fopen("version.txt", "r");
char* buffer = new char[100];
fread(buffer, 1, 100, file);
fclose(file);
return buffer;
}

// main() function, within butteraugli namespace for convenience.
int Run(int argc, char* argv[]) {
if (argc != 3 && argc != 4) {
bool valid_syntax = false;

if (argc == 2) {
if (strcmp(argv[1], "--version") == 0) {
fprintf(stdout, "%s version %s\n", argv[0], ReadVersion(argv[0]));
return 0;
}
} else if (argc == 3 || argc == 4) {
valid_syntax = true;
}

if (!valid_syntax) {
fprintf(stderr,
"Usage: %s {image1.(png|jpg|jpeg)} {image2.(png|jpg|jpeg)} "
"[heatmap.ppm]\n",
argv[0]);
"Usage:\n"
"%s {image1.(png|jpg|jpeg)} {image2.(png|jpg|jpeg)} [heatmap.ppm]\n"
"%s --version\n",
argv[0], argv[0]);
return 1;
}

Expand Down
11 changes: 11 additions & 0 deletions version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# .git must not be a symlink
mv .git .git2
cp -Lr .git2 .git

(
git rev-list --count HEAD
echo ' ('; git rev-parse HEAD
echo ')'
) | tr -d '\n' > $@