git-time-metric / gtm

Simple, seamless, lightweight time tracking for Git
MIT License
973 stars 52 forks source link

FreeBSD 13.0-RELEASE compatibility #112

Open realnedsanders opened 2 years ago

realnedsanders commented 2 years ago

working on FreeBSD compatibility.

Currently testing using 13.0-RELEASE-p6.

uname -r
13.0-RELEASE-p6

First issue was git2go.

13.0-RELEASE-p6 uses libgit2 version 1.3.0.

pkg-config --modversion libgit2
1.3.0

This corresponds to git2go V33 per the documentation.

I updated the imports to "github.com/libgit2/git2go/v33", updated the Makefile to use GIT2GO_VERSION = v33.0.7, and added SHELL = /usr/local/bin/bash to the top of the Makefile.

Then, I encountered an issue with scm/git.go on line 301. git2go v27 -> v33 changed type TreeWalkCallback : func(string, *TreeEntry) int -> func(string, *TreeEntry) error

Since the anonymous func just returns 0 anyways, I just changed the return type to error and the return to nil and called it a day.

go vet ran successfully :+1:

  300     err := childTree.Walk(
~ 301       func(s string, entry *git.TreeEntry) error {
  302         switch entry.Filemode {
  303         case git.FilemodeTree:
  304           // directory where file entry is located
  305           path = filepath.ToSlash(entry.Name)
  306         default:
  307           files = append(files, filepath.Join(path, entry.Name))
  308           fileCnt++
  309         }
~ 310         return nil
  311       })
@@ -298,7 +298,7 @@ func DiffParentCommit(childCommit *git.Commit) (CommitStats, error) {
                files := []string{}

                err := childTree.Walk(
-                       func(s string, entry *git.TreeEntry) int {
+                       func(s string, entry *git.TreeEntry) error {
                                switch entry.Filemode {
                                case git.FilemodeTree:
                                        // directory where file entry is located
@@ -307,7 +307,7 @@ func DiffParentCommit(childCommit *git.Commit) (CommitStats, error) {
                                        files = append(files, filepath.Join(path, entry.Name))
                                        fileCnt++
                                }
-                               return 0
+                               return nil
                        })

Now it builds, but not with --tags 'static'.

gmake build                                                                            Mon Jan 31 04:35:36 2022
go build --tags 'static' -ldflags "-X main.Version=0.0.0-dev-019de99" -o bin/gtm
# pkg-config --cflags --static -- /usr/home/aescaler/code/dev-tools/gtm/vendor/github.com/libgit2/git2go/v33/static-build/install/lib/pkgconfig/libgit2.pc
Package vendor/github.com/libgit2/git2go/v33/static-build/install/lib/pkgconfig/libgit2.pc was not found in the pkg-config search path.
Perhaps you should add the directory containing `/usr/home/aescaler/code/dev-tools/gtm/vendor/github.com/libgit2/git2go/v33/static-build/install/lib/pkgconfig/libgit2.pc.pc'
to the PKG_CONFIG_PATH environment variable
Package '/usr/home/aescaler/code/dev-tools/gtm/vendor/github.com/libgit2/git2go/v33/static-build/install/lib/pkgconfig/libgit2.pc', required by 'virtual:world', not found
pkg-config: exit status 1
gmake: *** [Makefile:13: build] Error 2

Looks like an issue with some libgit2 stuff so I checked out the git2go readme and it has info on static builds. I changed the Makefile, which now only needs to use gmake install-static after cding in the git2go target. It also wasn't pointing to the right directories, so I changed GIT2GO_PATH to vendor/github.com/libgit2/git2go.

With a few more edits to the Makefile paths and the git commands, I was able to get it to compile statically linked.

gmake build                                              
go build --tags 'static' -ldflags "-X main.Version=0.0.0-dev-019de99" -o bin/gtm

I'll have a PR submitted, probably tomorrow as it is already late for me.

realnedsanders commented 2 years ago

I have the relevant changes included in #113.

I have more to do to not break the existing supported platforms, but that's effectively the meat of what needs to be changed.

realnedsanders commented 2 years ago

@mschenk42 can you provide a high level overview of how the vendor directory is generated?

I notice you aren't using modules. I use them fairly religiously, so I have no clue how this is supposed to work.