Fix bug that recognized "C" as a remote package.

Review Request #3170 - Created Nov. 24, 2015 and submitted

Information
John Sirois
pants
jsirois/issues/2616
2616, 2619
Reviewers
pants-reviews
kwlzn, mateor, stuhood
The `import "C"` statement has special semantics and imports of this
form are satisfied by the Go distribution with links to local libraries
using the C calling convention.  Pants did not recognize this and would
attempt to fetch "C" and fail since "C" is not part of the stdlib and is
also not a remote package.

This change fixes import scanning code to know about "C" and also
centralizes the import logic in `ImportOracle`.

 contrib/go/examples/src/go/cgo/BUILD                                               |  4 +++
 contrib/go/examples/src/go/cgo/main.go                                             | 12 +++++++
 contrib/go/src/python/pants/contrib/go/tasks/go_buildgen.py                        | 52 ++++++++---------------------
 contrib/go/src/python/pants/contrib/go/tasks/go_fetch.py                           | 33 ++++--------------
 contrib/go/src/python/pants/contrib/go/tasks/go_task.py                            | 90 ++++++++++++++++++++++++++++++++++++++++++++++++--
 contrib/go/tests/python/pants_test/contrib/go/tasks/BUILD                          |  9 +++++
 contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_buildgen.py            | 36 ++++++++++++++++++++
 contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_compile_integration.py |  5 +++
 contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_fetch.py               | 31 +++++++++++++++++
 contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_run_integration.py     |  8 +++++
 contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_task.py                | 58 ++++++++++++++++++++++++++++++++
 11 files changed, 271 insertions(+), 67 deletions(-)

Added a new failing test_issues_2616 to GoFetchTest that this change
fixes as well compile and run integration tests for Cgo that aren't
directly related to this change but do exercise the full pipeline of
interest for Cgo code.

Also did not check in the motivating example since it requires ImageMagick
libs, but adding
contrib/go/examples/3rdparty/go/github.com/gographics/imagick/BUILD:

# Auto-generated by pants!
# To re-generate run: `pants buildgen.go --materialize --remote`

go_remote_libraries(
  rev='02d20b370cf9bac9d1d8297397c7e4b20a92add4',
  packages=[
    'imagick',
  ]
)

Demonstrates a successful resolve and compile for remote Cgo code (the
scary output below is just 3 compile warnings in ImageMagick):

./pants compile contrib/go/examples/3rdparty/go/github.com/gographics/imagick
...
09:43:02 00:00   [resolve]
...
09:43:02 00:00     [go]
                   Invalidated 1 target.INFO] Downloading https://github.com/gographics/imagick/archive/02d20b370cf9bac9d1d8297397c7e4b20a92add4.tar.gz...

09:43:04 00:02       [github.com/gographics/imagick/imagick]
...
09:43:04 00:02   [compile]
...
09:43:04 00:02     [go]
                   Invalidated 1 target.
09:43:04 00:02       [install]
                     # github.com/gographics/imagick/imagick
                     .pants.d/compile/go/contrib.go.examples.3rdparty.go.github.com.gographics.imagick.imagick/src/github.com/gographics/imagick/imagick/magick_core_env.go: In function ‘_cgo_85b92643e208_Cfunc_IsMagickInstantiated’:
                     .pants.d/compile/go/contrib.go.examples.3rdparty.go.github.com.gographics.imagick.imagick/src/github.com/gographics/imagick/imagick/magick_core_env.go:54:2: warning: ‘IsMagickInstantiated’ is deprecated [-Wdeprecated-declarations]
                     In file included from /usr/include/ImageMagick-6/magick/MagickCore.h:95:0,
                                      from /usr/include/ImageMagick-6/wand/MagickWand.h:72,
                                      from .pants.d/compile/go/contrib.go.examples.3rdparty.go.github.com.gographics.imagick.imagick/src/github.com/gographics/imagick/imagick/magick_core_env.go:8:
                     /usr/include/ImageMagick-6/magick/deprecate.h:205:3: note: declared here
                        IsMagickInstantiated(void) magick_attribute((deprecated)),
                        ^
                     # github.com/gographics/imagick/imagick
                     .pants.d/compile/go/contrib.go.examples.3rdparty.go.github.com.gographics.imagick.imagick/src/github.com/gographics/imagick/imagick/magick_wand_image.go: In function ‘_cgo_85b92643e208_Cfunc_MagickRadialBlurImage’:
                     .pants.d/compile/go/contrib.go.examples.3rdparty.go.github.com.gographics.imagick.imagick/src/github.com/gographics/imagick/imagick/magick_wand_image.go:3032:2: warning: ‘MagickRadialBlurImage’ is deprecated [-Wdeprecated-declarations]
                     In file included from /usr/include/ImageMagick-6/wand/MagickWand.h:78:0,
                                      from .pants.d/compile/go/contrib.go.examples.3rdparty.go.github.com.gographics.imagick.imagick/src/github.com/gographics/imagick/imagick/magick_wand_image.go:9:
                     /usr/include/ImageMagick-6/wand/deprecate.h:109:3: note: declared here
                        MagickRadialBlurImage(MagickWand *,const double)
                        ^
                     .pants.d/compile/go/contrib.go.examples.3rdparty.go.github.com.gographics.imagick.imagick/src/github.com/gographics/imagick/imagick/magick_wand_image.go: In function ‘_cgo_85b92643e208_Cfunc_MagickRadialBlurImageChannel’:
                     .pants.d/compile/go/contrib.go.examples.3rdparty.go.github.com.gographics.imagick.imagick/src/github.com/gographics/imagick/imagick/magick_wand_image.go:3049:2: warning: ‘MagickRadialBlurImageChannel’ is deprecated [-Wdeprecated-declarations]
                      // image that is added back into the original.
                       ^
                     In file included from /usr/include/ImageMagick-6/wand/MagickWand.h:78:0,
                                      from .pants.d/compile/go/contrib.go.examples.3rdparty.go.github.com.gographics.imagick.imagick/src/github.com/gographics/imagick/imagick/magick_wand_image.go:9:
                     /usr/include/ImageMagick-6/wand/deprecate.h:111:3: note: declared here
                        MagickRadialBlurImageChannel(MagickWand *,const ChannelType,const double)
                        ^

...
09:43:14 00:12   [complete]
               SUCCESS

CI went green here:
https://travis-ci.org/pantsbuild/pants/builds/93049583

John Sirois
Stu Hood
Chad Rhyner
John Sirois
John Sirois
John Sirois
Review request changed

Status: Closed (submitted)

Loading...