mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-26 17:03:01 +00:00
go: remove renameImports and use goPackageAliases
This commit is contained in:
parent
f66cd5dbe9
commit
58b865cfc6
@ -662,18 +662,16 @@ standard Go packages.
|
||||
<programlisting>
|
||||
net = buildGoPackage rec {
|
||||
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' />
|
||||
rev = "28ff664507e4";
|
||||
src = fetchhg {
|
||||
rev = "e0403b4e005";
|
||||
src = fetchFromGitHub {
|
||||
inherit rev;
|
||||
url = "https://${goPackagePath}";
|
||||
sha256 = "1lkz4c9pyz3yz2yz18hiycvlfhgy3jxp68bs7mv7bcfpaj729qav";
|
||||
owner = "golang";
|
||||
repo = "net";
|
||||
sha256 = "1g7cjzw4g4301a3yqpbk8n1d4s97sfby2aysl275x04g0zh8jxqp";
|
||||
};
|
||||
renameImports = [ <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"
|
||||
];
|
||||
goPackageAliases = [ "code.google.com/p/go.net" ]; <co xml:id='ex-buildGoPackage-3' />
|
||||
propagatedBuildInputs = [ goPackages.text ]; <co xml:id='ex-buildGoPackage-4' />
|
||||
buildFlags = "--tags release"; <co xml:id='ex-buildGoPackage-5' />
|
||||
};
|
||||
@ -703,17 +701,18 @@ the following arguments are of special significance to the function:
|
||||
</para>
|
||||
</callout>
|
||||
|
||||
<callout arearefs='ex-buildGoPackage-4'>
|
||||
<callout arearefs='ex-buildGoPackage-3'>
|
||||
<para>
|
||||
<varname>renameImports</varname> is a list of import paths to be renamed before
|
||||
building the package. The path to be renamed can be a regular expression.
|
||||
<varname>goPackageAliases</varname> is a list of alternative import paths
|
||||
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>
|
||||
In this example imports will be renamed from
|
||||
<literal>code.google.com/p/go.crypto</literal> to
|
||||
<literal>golang.org/x/crypto</literal> and from
|
||||
<literal>code.google.com/p/goprotobuf</literal> to
|
||||
<literal>github.com/golang/protobuf</literal>.
|
||||
<literal>code.google.com/p/go.net</literal> to
|
||||
<literal>golang.org/x/net</literal> in every package that depend on the
|
||||
<literal>go.net</literal> library.
|
||||
</para>
|
||||
</callout>
|
||||
|
||||
|
@ -14,11 +14,6 @@ buildGoPackage rec {
|
||||
|
||||
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 ];
|
||||
|
||||
buildFlags = "--tags nogui";
|
||||
|
@ -5,18 +5,25 @@
|
||||
# Go import path of the package
|
||||
, goPackagePath
|
||||
|
||||
# Go package aliases
|
||||
, goPackageAliases ? [ ]
|
||||
|
||||
# Extra sources to include in the gopath
|
||||
, extraSrcs ? [ ]
|
||||
|
||||
, dontRenameImports ? false
|
||||
|
||||
, meta ? {}, ... } @ args':
|
||||
|
||||
let
|
||||
args = lib.filterAttrs (name: _: name != "extraSrcs") args';
|
||||
in
|
||||
|
||||
go.stdenv.mkDerivation ( args // {
|
||||
go.stdenv.mkDerivation (
|
||||
(builtins.removeAttrs args [ "goPackageAliases" ]) // {
|
||||
|
||||
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 ''
|
||||
runHook preConfigure
|
||||
@ -40,10 +47,12 @@ go.stdenv.mkDerivation ( args // {
|
||||
runHook postConfigure
|
||||
'';
|
||||
|
||||
renameImports = lib.optionalString (args ? renameImports)
|
||||
(lib.concatMapStringsSep "\n"
|
||||
(cmdargs: "govers -m ${cmdargs}")
|
||||
args.renameImports);
|
||||
renameImports = args.renameImports or (
|
||||
let
|
||||
inputsWithAliases = lib.filter (x: x ? goPackageAliases) buildInputs;
|
||||
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 ''
|
||||
runHook preBuild
|
||||
@ -107,6 +116,8 @@ go.stdenv.mkDerivation ( args // {
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
passthru = lib.optionalAttrs (goPackageAliases != []) { inherit goPackageAliases; };
|
||||
|
||||
meta = meta // {
|
||||
# add an extra maintainer to every package
|
||||
maintainers = (meta.maintainers or []) ++
|
||||
|
@ -13,6 +13,7 @@ let self = _self // overrides; _self = with self; {
|
||||
rev = "4d48e5fa3d62b5e6e71260571bf76c767198ca02";
|
||||
name = "go-crypto-${rev}";
|
||||
goPackagePath = "golang.org/x/crypto";
|
||||
goPackageAliases = [ "code.google.com/p/go.crypto" ];
|
||||
|
||||
src = fetchFromGitHub {
|
||||
inherit rev;
|
||||
@ -49,6 +50,7 @@ let self = _self // overrides; _self = with self; {
|
||||
rev = "e0403b4e005737430c05a57aac078479844f919c";
|
||||
name = "net-${stdenv.lib.strings.substring 0 7 rev}";
|
||||
goPackagePath = "golang.org/x/net";
|
||||
goPackageAliases = [ "code.google.com/p/go.net" ];
|
||||
|
||||
src = fetchFromGitHub {
|
||||
inherit rev;
|
||||
@ -84,6 +86,7 @@ let self = _self // overrides; _self = with self; {
|
||||
rev = "efd7476481382c195beb33acd8ec2f1527167fb4";
|
||||
name = "goprotobuf-${stdenv.lib.strings.substring 0 7 rev}";
|
||||
goPackagePath = "github.com/golang/protobuf";
|
||||
goPackageAliases = [ "code.google.com/p/goprotobuf" ];
|
||||
|
||||
src = fetchFromGitHub {
|
||||
inherit rev;
|
||||
@ -409,6 +412,7 @@ let self = _self // overrides; _self = with self; {
|
||||
rev = "3b5f175f65d601d06f48d78fcbdb0add633565b9";
|
||||
name = "govers-${stdenv.lib.strings.substring 0 7 rev}";
|
||||
goPackagePath = "github.com/rogpeppe/govers";
|
||||
dontRenameImports = true;
|
||||
src = fetchFromGitHub {
|
||||
inherit rev;
|
||||
owner = "rogpeppe";
|
||||
|
Loading…
Reference in New Issue
Block a user