Commit graph

63 commits

Author SHA1 Message Date
Martin Baillie
d9ea49c898
Parameterise tools.go
Signed-off-by: Martin Baillie <martin@baillie.id>
2022-09-13 10:17:46 +10:00
adisbladis
3b4076283d builder: Use rsync for copying vendor environment
cp will fail on dangling symlinks and it's errors can't be ignored.
rsync gives us a greater degree of control so let's use that.
2022-09-07 09:44:36 +12:00
adisbladis
01426762a5 Litter go.mod parser with comments 2022-09-02 17:02:56 +12:00
adisbladis
82718bac0b Don't needlessly copy internal sources in builder 2022-09-02 16:46:05 +12:00
adisbladis
32ba72372b Follow symlinks when copying vendor environment 2022-09-02 16:46:05 +12:00
adisbladis
36f0c54655 Use the highest compatible Go version whenever possible
It should be generally safe to compile any older Go project with a
newer compiler and in the few cases where it isn't it could be
manually passed.
2022-09-02 16:38:03 +12:00
adisbladis
6c4e4b7f57 Change stripVersion comment to indicate that it's not rubbish
But just extra data that Nix can't handle in version attributes.
2022-09-02 16:35:58 +12:00
adisbladis
a5fabc015d builder: Don't use a default go argument internally 2022-09-02 16:18:41 +12:00
adisbladis
a02a4ea0b2 builder: Remove unused removeExpr variable 2022-09-02 16:11:43 +12:00
adisbladis
9b360feaf2 builder/symlink: Factor out into separate functions to make indents more readable
Implement suggestion from https://github.com/NixOS/nixpkgs/pull/188272#discussion_r958608686.
2022-09-02 15:59:32 +12:00
adisbladis
fc2d392494 Remove usage of deprecated ioutil package 2022-09-02 15:59:32 +12:00
adisbladis
fe398402f4 Add passthru.updateScript when package is fully auto generated
Meaning when both src and modules comes from the same call to `gomod2nix generate` like so:
``` bash
$ gomod2nix generate github.com/simeji/jid/cmd/jid
```
2022-08-24 16:25:42 +08:00
adisbladis
94dc447f5c Allow passing null as modules for packages that don't have dependencies or that vendor them 2022-08-24 15:01:08 +08:00
adisbladis
5149c67e6e Enable Cgo by default
To be in line with the behaviour of buildGoModule since https://github.com/NixOS/nixpkgs/pull/177594.
2022-08-24 11:57:43 +08:00
adisbladis
ac99f239a5 don't run vet linter
This is a port of 5b76f42372.
2022-08-24 11:34:30 +08:00
adisbladis
4141b461c4 builder/symlink.go: Remove commented code 2022-08-24 09:51:55 +08:00
adisbladis
f3314213be Add ldflags to buildGoApplication function signature
This is not strictly required but is good for discoverability.
2022-08-24 09:51:55 +08:00
adisbladis
564d1edc26 Set SSL_CERT_FILE by setup hook rather than explicit 2022-08-24 09:51:55 +08:00
adisbladis
b40e660f51 don't set trimpath for tests
This is a port of 64e6cc1a1d.
2022-08-24 09:41:59 +08:00
adisbladis
ab5ec79935 Run unit tests under subdirs
Bug:
Due to the way `buildGoDir` function was repurposed to also run `go
test`, if `checkFlags` was defined, `go test` was ran only at the top
level directory. Only the first element of `checkFlags` array would get
passed to the `go test` command as arguments.

Fix:
Now the first parameter to `buildGoDir` is handled as the command.  If
the command is "test" `checkFlags` get passed as arguments along with
other build flags like ldflags, tags, etc.

Readability:
- Iteratively build a flag array in `buildGoDir` instead of single long
  variable expansion command line.
- Bash style: Single line local assignment of positional parameters.

This is a port of 89864413b2.
2022-08-24 09:00:33 +08:00
adisbladis
4d9ea46f79 Copy vendor directory instead of symlinking to it
As pointed out in
https://github.com/NixOS/nixpkgs/pull/188035#discussion_r953044264
this can be a source of errors when builders do things they shouldn't.

I'm not really happy about this change as it causes quite a bit more
IO for larger dependency graphs.
2022-08-24 08:05:37 +08:00
adisbladis
bca2a1231e Fix Go compiler missing from mkGoEnv created environments
Closes #68
2022-08-23 21:11:28 +08:00
adisbladis
b8c2216317 builder/install.go: Make build failures more apparent by attaching stdout/stderr 2022-08-17 15:36:21 +08:00
HuangYi
71fd703317
Invalid regex on macOS
- fix the regex
2022-07-29 19:38:34 +08:00
adisbladis
0ea20c514a refactor: inherit lib/builtins in top level scope in builder 2022-06-15 06:14:59 +08:00
adisbladis
85eaf382e6 refactor: Move replace commands computation to mkVendorEnv
It should be shared between shell envs and packages.
2022-06-15 06:14:59 +08:00
adisbladis
74a2950c64 buildGoApplication: Remove package from let binding
It's the thing we return so no point in binding it to a temporary variable.
2022-06-14 19:27:24 +08:00
adisbladis
5a8afd711e builder: Reformat with nixpkgs-fmt
After porting builder changes from nixpkgs the structure has changed somewhat.
2022-06-14 19:14:19 +08:00
adisbladis
2028c2f3ff go: Apply package exclusion equally
The exclusion logic was moved out of getGoDirs but only buildPhase was updated
causing checkPhase to possibly fail. This happened in golint as it has go
files in testdata that are meant as testdata files and not go packages to
test which caused the checkPhase to fail.

This is a port of ddcc7c67d2
2022-06-14 19:14:19 +08:00
adisbladis
df791b8057 go: Drop unnecessary backslash-escape
There's no backslash interpretation going on within single-quote strings
which means there's no need to escape the backslash. Since this was going
on within single-quote strings the $exclude variable ended up having 2
backslashes (`\\`) instead of the intended single backslash. This meant
that the regex that was built up was incorrect. For example prometheus'
exclude contents before and after this change are:

✕: \(/_\|examples\|Godeps\|testdata\\|documentation/prometheus-mixin\)
✓: \(/_\|examples\|Godeps\|testdata\|documentation/prometheus-mixin\)

This is a port of 60543c4f9e
2022-06-14 19:14:19 +08:00
adisbladis
31102e0753 go: Bunch of fixes when using excludedPackages and other bits
Few things going on in this commit:

Do not print "Building subPakage $pkg" message if actually going to skip the
package. This was confusing to me when I was trying to figure out how to set
excludedPackages and seeing the "Building subpackage $pkg" messages for
packages I wanted to skip. Turns out this messages was being printed before
checking if we actually wanted to build the package and not necessarily that my
excludedPackages was wrong.

This commit also does some setup outside the buildGoDir function so that we
avoid checking `excludedPackages` for every package and cut down the number
of grep calls by half since we always want at least one grep for the default
excludedPackages, might as well just add to the patterns being checked.

Finally, adds documentation for usage of excludedPackages and subPackages. I
had to read the implementation to figure out how to correctly use these
function arguments since there was no documentation and different uses in the
code base. So this commit documents usage of the arguments.

This is a port of 8b5a7940b0
2022-06-14 19:14:19 +08:00
adisbladis
359449a284 buildGoApplication: warn if buildFlagsArray is used
This is a port of 3360a376cb
2022-06-14 19:14:19 +08:00
adisbladis
8aa44afb7e buildGoApplication: warn if buildFlags is used
This is a port of cb7d80dcaf
2022-06-14 19:14:19 +08:00
adisbladis
f42a0cddb4 buildGoApplication: add tags argument
Simpler method of setting tags rather than using some combination of buildFlags, buildFlagsArray, preBuild, etc

Using `lib.concatStringsSep ","` as space separated tags are deprecated in go.

This is a port of b60dde0c1e
2022-06-14 19:14:19 +08:00
adisbladis
5913cf95d5 buildGoApplication: add support for checkFlags
This is a port of dc973241a9
2022-06-14 19:14:19 +08:00
adisbladis
24c5e41124 buildGoApplication: Introduce ldflags argument
Previously it was not possible to define multiple ldflags, since only
the last definition applies, and there's some quoting issues with
`buildFlagsArray`. With the new `ldflags` argument it's possible to do
this, e.g.

    ldflags = drv.ldflags or [] ++ [
      "-X main.Version=1.0"
    ]

can now properly append a flag without clearing all previous ldflags.

This is a port of 155ae682a5
2022-06-14 19:14:19 +08:00
adisbladis
366c0e5a17 mkGoEnv: Pass attrs on to mkDerivation 2022-06-14 18:26:50 +08:00
adisbladis
509b97c288 Build non-development packages in the same way as development packages
The difference in behaviour was unfortunate.

The only downside I can see is that this doesn't allow for mixed
origins in the same package, which probably shouldn't be done anyway.
2022-06-14 08:19:42 +08:00
adisbladis
d404767bec builder: Build internal packages for host plattform 2022-06-14 05:27:43 +08:00
adisbladis
1ffea526a0 Add package generation for non development packages
This makes it possible to generate packages that you do not have a
local checkout for, e.g. running:
`gomod2nix generate --outdir example/ golang.org/x/tools/cmd/stringer`

This will be useful for packaging dependencies that you are not
developing, but just simply packaging.
2022-06-14 05:15:43 +08:00
adisbladis
aae59a6851 Don't set CGO_ENABLED by default
Instead let the compiler decide.
This will result in less cryptic errors.
2022-06-13 20:53:45 +08:00
adisbladis
ade4c20234 Factor out Go version selection from mkGoEnv and add it to buildGoApplication too 2022-06-13 20:53:45 +08:00
adisbladis
908ab2bb87 Precompile internal packages instead of using go run
It shaves off a second or so of wait time per environment.
2022-06-13 20:37:42 +08:00
adisbladis
973b050adf fetcher: Make sure sources are writable before filtering .ds_store 2022-06-13 20:37:42 +08:00
adisbladis
1eb70073c4 Bump dependencies 2022-06-13 20:37:42 +08:00
adisbladis
a4bed25a86 Add mkGoEnv function
This creates an `mkGoEnv` function which takes care of adding the
correct Go package to your development environment and installs
development dependencies from tools.go in a Nix derivation.

The "normal" workflow around Go with tools.go just sticks development
dependencies in $GOBIN which isn't ideal since you have no separation
between projects.
2022-06-13 20:37:42 +08:00
adisbladis
d7830bd5b2 Filter MacOS .DS_Store directories
Now that we're hashing files directly from the Go sources on the host
system we need to avoid these files.

Closes #49.
2022-06-01 01:46:29 +08:00
HuangYi
36bc9ef864
support impure env GOPROXY
which is by go mod download
2022-05-30 11:13:30 +08:00
adisbladis
79d737ec6e Fix passing of Go to buildGoApplication 2022-05-29 16:24:58 +08:00
adisbladis
d831b947fc Fix go.mod parser for repeated replace directives
Constructs such as
```
replace google.golang.org/grpc => google.golang.org/grpc v1.33.2
replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
```

Are perfectly valid and we previously discarded every one but the last of them.
2022-05-29 16:23:37 +08:00