简体   繁体   中英

Having issue defining go_remote_library declaration for 3rdparty/go/golang.org/x/text:*

I'm trying to used github.com/spf13/viper which requires github.com/spf13/afero and that requires some of the 3rdparty/go/golang.org/x/text: packages. Till afero works, and when defining 3rdparty BUILD for text:* packages I get the following errors,

3rdparty/go/github.com/spf13/afero has remote dependencies which require local declaration:
        --> golang.org/x/text/unicode/norm (expected go_remote_library declaration at 3rdparty/go/golang.org/x/text:unicode/norm)
        --> golang.org/x/text/transform (expected go_remote_library declaration at 3rdparty/go/golang.org/x/text:transform)

I tried to define it like this in 3rdparty/go/golang.org/x/text/BUILD,

go_remote_library(
    rev='342b2e1fbaa52c93f31447ad2c6abc048c63e475',
    packages=[
        'unicode/norm',
        'transform',
    ]
)

And it still shows the same error. Plus now running buildgen.go fails with the following error,

Exception caught: (pants.build_graph.target.UnknownArgumentError) (backtrace omitted)
Exception message: Invalid target 3rdparty/go/golang.org/x/text:text: GoRemoteLibrary received unknown arguments:
    packages = ['unicode/norm', 'transform']

Some more info, - Pants version: 1.13.0 - pantsbuild.pants.contrib.go: 1.13.0 - Tried using 1.14.0 & 1.15.0 as well and got the same results

Simple example to recreate it,

package main

import (
    "fmt"

    "github.com/spf13/viper"
)

func main() {
    viper.AutomaticEnv()
    fmt.Printf("%s", viper.GetString("HOME"))
}

Also you can simply do pants resolve on the package to get the error,

pants resolve 3rdparty/go/github.com/spf13/viper

Thanks to the pants team, got the issue resolved.

buildgen.go does turn go_remote_library(pkg='foo') takes into go_remote_libraries targets. We need to use go_remote_libraries (not go_remote_library) to specify multiple packages.

Using this works fine,

go_remote_libraries(
  rev='342b2e1fbaa52c93f31447ad2c6abc048c63e475',
  packages=[
    'transform',
    'unicode/norm',
  ]
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM