go-modules: Add useVend flag to go-modules

This commit is contained in:
Colin L Rice 2020-06-03 22:54:39 -04:00
parent 148138e9de
commit 95be7b25be
3 changed files with 20 additions and 2 deletions

View file

@ -64,6 +64,11 @@ pet = buildGoModule rec {
<varname>subPackages</varname> limits the builder from building child packages that have not been listed. If <varname>subPackages</varname> is not specified, all child packages will be built. <varname>subPackages</varname> limits the builder from building child packages that have not been listed. If <varname>subPackages</varname> is not specified, all child packages will be built.
</para> </para>
</callout> </callout>
<callout arearefs='ex-buildGoModule-3'>
<para>
<varname>runVend</varname> runs the vend command to generate the vendor directory. This is useful if your code depends on c code and go mod tidy does not include the needed sources to build.
</para>
</callout>
</calloutlist> </calloutlist>
</para> </para>

View file

@ -1,4 +1,4 @@
{ go, cacert, git, lib, removeReferencesTo, stdenv }: { go, cacert, git, lib, removeReferencesTo, stdenv, vend }:
{ name ? "${args'.pname}-${args'.version}" { name ? "${args'.pname}-${args'.version}"
, src , src
@ -20,6 +20,9 @@
, vendorSha256 , vendorSha256
# Whether to delete the vendor folder supplied with the source. # Whether to delete the vendor folder supplied with the source.
, deleteVendor ? false , deleteVendor ? false
# Whether to run the vend tool to regenerate the vendor directory.
# This is useful if any dependency contain C files.
, runVend ? false
, modSha256 ? null , modSha256 ? null
@ -48,6 +51,8 @@ let
deleteFlag = if deleteVendor then "true" else "false"; deleteFlag = if deleteVendor then "true" else "false";
vendCommand = if runVend then "${vend}/bin/vend" else "false";
go-modules = if vendorSha256 != null then go.stdenv.mkDerivation (let modArgs = { go-modules = if vendorSha256 != null then go.stdenv.mkDerivation (let modArgs = {
name = "${name}-go-modules"; name = "${name}-go-modules";
@ -87,7 +92,13 @@ let
echo "vendor folder exists, please set 'vendorSha256=null;' or 'deleteVendor=true;' in your expression" echo "vendor folder exists, please set 'vendorSha256=null;' or 'deleteVendor=true;' in your expression"
exit 10 exit 10
fi fi
go mod vendor
if [ ${vendCommand} != "false" ]; then
echo running vend to rewrite vendor folder
${vendCommand}
else
go mod vendor
fi
mkdir -p vendor mkdir -p vendor
runHook postBuild runHook postBuild

View file

@ -7419,6 +7419,8 @@ in
vcstool = callPackage ../development/tools/vcstool { }; vcstool = callPackage ../development/tools/vcstool { };
vend = callPackage ../development/tools/vend { };
verilator = callPackage ../applications/science/electronics/verilator {}; verilator = callPackage ../applications/science/electronics/verilator {};
verilog = callPackage ../applications/science/electronics/verilog {}; verilog = callPackage ../applications/science/electronics/verilog {};