go: remove renameImports and use goPackageAliases

This commit is contained in:
Luca Bruno 2015-05-15 11:02:01 +02:00
parent f66cd5dbe9
commit 58b865cfc6
4 changed files with 36 additions and 27 deletions

View file

@ -662,18 +662,16 @@ standard Go packages.
<programlisting> <programlisting>
net = buildGoPackage rec { net = buildGoPackage rec {
name = "go.net-${rev}"; name = "go.net-${rev}";
goPackagePath = "code.google.com/p/go.net"; <co xml:id='ex-buildGoPackage-1' /> goPackagePath = "golang.org/x/net"; <co xml:id='ex-buildGoPackage-1' />
subPackages = [ "ipv4" "ipv6" ]; <co xml:id='ex-buildGoPackage-2' /> subPackages = [ "ipv4" "ipv6" ]; <co xml:id='ex-buildGoPackage-2' />
rev = "28ff664507e4"; rev = "e0403b4e005";
src = fetchhg { src = fetchFromGitHub {
inherit rev; inherit rev;
url = "https://${goPackagePath}"; owner = "golang";
sha256 = "1lkz4c9pyz3yz2yz18hiycvlfhgy3jxp68bs7mv7bcfpaj729qav"; repo = "net";
sha256 = "1g7cjzw4g4301a3yqpbk8n1d4s97sfby2aysl275x04g0zh8jxqp";
}; };
renameImports = [ <co xml:id='ex-buildGoPackage-3' /> goPackageAliases = [ "code.google.com/p/go.net" ]; <co xml:id='ex-buildGoPackage-3' />
"code.google.com/p/go.crypto golang.org/x/crypto"
"code.google.com/p/goprotobuf github.com/golang/protobuf"
];
propagatedBuildInputs = [ goPackages.text ]; <co xml:id='ex-buildGoPackage-4' /> propagatedBuildInputs = [ goPackages.text ]; <co xml:id='ex-buildGoPackage-4' />
buildFlags = "--tags release"; <co xml:id='ex-buildGoPackage-5' /> buildFlags = "--tags release"; <co xml:id='ex-buildGoPackage-5' />
}; };
@ -703,17 +701,18 @@ the following arguments are of special significance to the function:
</para> </para>
</callout> </callout>
<callout arearefs='ex-buildGoPackage-4'> <callout arearefs='ex-buildGoPackage-3'>
<para> <para>
<varname>renameImports</varname> is a list of import paths to be renamed before <varname>goPackageAliases</varname> is a list of alternative import paths
building the package. The path to be renamed can be a regular expression. that are valid for this library.
Packages that depend on this library will automatically rename
import paths that match any of the aliases to <literal>goPackagePath</literal>.
</para> </para>
<para> <para>
In this example imports will be renamed from In this example imports will be renamed from
<literal>code.google.com/p/go.crypto</literal> to <literal>code.google.com/p/go.net</literal> to
<literal>golang.org/x/crypto</literal> and from <literal>golang.org/x/net</literal> in every package that depend on the
<literal>code.google.com/p/goprotobuf</literal> to <literal>go.net</literal> library.
<literal>github.com/golang/protobuf</literal>.
</para> </para>
</callout> </callout>

View file

@ -14,11 +14,6 @@ buildGoPackage rec {
subPackages = [ "client" ]; subPackages = [ "client" ];
renameImports = [
"code.google.com/p/go.crypto golang.org/x/crypto"
"code.google.com/p/goprotobuf github.com/golang/protobuf"
];
buildInputs = [ trousers net crypto protobuf ed25519 govers ]; buildInputs = [ trousers net crypto protobuf ed25519 govers ];
buildFlags = "--tags nogui"; buildFlags = "--tags nogui";

View file

@ -5,18 +5,25 @@
# Go import path of the package # Go import path of the package
, goPackagePath , goPackagePath
# Go package aliases
, goPackageAliases ? [ ]
# Extra sources to include in the gopath # Extra sources to include in the gopath
, extraSrcs ? [ ] , extraSrcs ? [ ]
, dontRenameImports ? false
, meta ? {}, ... } @ args': , meta ? {}, ... } @ args':
let let
args = lib.filterAttrs (name: _: name != "extraSrcs") args'; args = lib.filterAttrs (name: _: name != "extraSrcs") args';
in in
go.stdenv.mkDerivation ( args // { go.stdenv.mkDerivation (
(builtins.removeAttrs args [ "goPackageAliases" ]) // {
name = "go${go.meta.branch}-${name}"; name = "go${go.meta.branch}-${name}";
buildInputs = [ go ] ++ buildInputs ++ (lib.optional (args ? renameImports) govers) ; buildInputs = [ go ] ++ buildInputs ++ (lib.optional (!dontRenameImports) govers) ;
configurePhase = args.configurePhase or '' configurePhase = args.configurePhase or ''
runHook preConfigure runHook preConfigure
@ -40,10 +47,12 @@ go.stdenv.mkDerivation ( args // {
runHook postConfigure runHook postConfigure
''; '';
renameImports = lib.optionalString (args ? renameImports) renameImports = args.renameImports or (
(lib.concatMapStringsSep "\n" let
(cmdargs: "govers -m ${cmdargs}") inputsWithAliases = lib.filter (x: x ? goPackageAliases) buildInputs;
args.renameImports); rename = to: from: "echo Renaming '${from}' to '${to}'; govers -m ${from} ${to}";
renames = p: lib.concatMapStringsSep "\n" (rename p.goPackagePath) p.goPackageAliases;
in lib.concatMapStringsSep "\n" renames inputsWithAliases);
buildPhase = args.buildPhase or '' buildPhase = args.buildPhase or ''
runHook preBuild runHook preBuild
@ -107,6 +116,8 @@ go.stdenv.mkDerivation ( args // {
runHook postInstall runHook postInstall
''; '';
passthru = lib.optionalAttrs (goPackageAliases != []) { inherit goPackageAliases; };
meta = meta // { meta = meta // {
# add an extra maintainer to every package # add an extra maintainer to every package
maintainers = (meta.maintainers or []) ++ maintainers = (meta.maintainers or []) ++

View file

@ -13,6 +13,7 @@ let self = _self // overrides; _self = with self; {
rev = "4d48e5fa3d62b5e6e71260571bf76c767198ca02"; rev = "4d48e5fa3d62b5e6e71260571bf76c767198ca02";
name = "go-crypto-${rev}"; name = "go-crypto-${rev}";
goPackagePath = "golang.org/x/crypto"; goPackagePath = "golang.org/x/crypto";
goPackageAliases = [ "code.google.com/p/go.crypto" ];
src = fetchFromGitHub { src = fetchFromGitHub {
inherit rev; inherit rev;
@ -49,6 +50,7 @@ let self = _self // overrides; _self = with self; {
rev = "e0403b4e005737430c05a57aac078479844f919c"; rev = "e0403b4e005737430c05a57aac078479844f919c";
name = "net-${stdenv.lib.strings.substring 0 7 rev}"; name = "net-${stdenv.lib.strings.substring 0 7 rev}";
goPackagePath = "golang.org/x/net"; goPackagePath = "golang.org/x/net";
goPackageAliases = [ "code.google.com/p/go.net" ];
src = fetchFromGitHub { src = fetchFromGitHub {
inherit rev; inherit rev;
@ -84,6 +86,7 @@ let self = _self // overrides; _self = with self; {
rev = "efd7476481382c195beb33acd8ec2f1527167fb4"; rev = "efd7476481382c195beb33acd8ec2f1527167fb4";
name = "goprotobuf-${stdenv.lib.strings.substring 0 7 rev}"; name = "goprotobuf-${stdenv.lib.strings.substring 0 7 rev}";
goPackagePath = "github.com/golang/protobuf"; goPackagePath = "github.com/golang/protobuf";
goPackageAliases = [ "code.google.com/p/goprotobuf" ];
src = fetchFromGitHub { src = fetchFromGitHub {
inherit rev; inherit rev;
@ -409,6 +412,7 @@ let self = _self // overrides; _self = with self; {
rev = "3b5f175f65d601d06f48d78fcbdb0add633565b9"; rev = "3b5f175f65d601d06f48d78fcbdb0add633565b9";
name = "govers-${stdenv.lib.strings.substring 0 7 rev}"; name = "govers-${stdenv.lib.strings.substring 0 7 rev}";
goPackagePath = "github.com/rogpeppe/govers"; goPackagePath = "github.com/rogpeppe/govers";
dontRenameImports = true;
src = fetchFromGitHub { src = fetchFromGitHub {
inherit rev; inherit rev;
owner = "rogpeppe"; owner = "rogpeppe";