Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -known_import flag #667

Merged
merged 1 commit into from
Jul 31, 2017
Merged

Conversation

pmcalpine
Copy link
Contributor

Private repositories can take a long time to resolve, and if the repo
host does not properly support go-import meta tags then gazelle may not
be able to resolve them at all.

This change allows the author of WORKSPACE files to add specially
crafted comments which instruct gazelle to update the external
resolver's repo cache. As a result, gazelle can be instructed to skip
resolution of certain imports.

@bazel-io
Copy link

Can one of the admins verify this patch?

@pmcalpine
Copy link
Contributor Author

Hi. I have been keeping this functionality on my own fork for a while and have rewritten it enough times while rebasing that I'm wondering if you'd consider for the mainline.

This is a quick-and-dirty solution that I've been using for the past few months. My overarching objective is to be able to update the externalResolver's cache. If this implementation doesn't suit do you think there's another one that would?

@pmcalpine
Copy link
Contributor Author

Thinking over lunch: this is actually two changes

  1. ability to add to the external resolver cache. This could be done with a new command line flag.
  2. ability to configure gazelle via magic comments in the WORKSPACE file.

Please consider these independently. I'm happy to take on #1 asap.

Copy link
Contributor

@jayconrod jayconrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sending this! I like this change, but I'd prefer it as a repeatable command line option instead of a directive in WORKSPACE, at least for now. We may move toward having more directives in the root BUILD file in the future, but that's not designed yet.

See go/tools/builders/flags.go for how we're handling repeated flags elsewhere. That can be copied into Gazelle's main package.

It would be good to have a test for this. TestSpecialCases in resolve_external_test.go is probably the right place.

@@ -77,6 +77,12 @@ func NewLabelResolver(c *config.Config) LabelResolver {
switch c.DepMode {
case config.ExternalMode:
e = newExternalResolver()
case config.KnownMode:
er := newExternalResolver()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to pass additional imports to newExternalResolver instead of modifying the cache directly here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm adding KnownImports to config.Config{...} should I move the default known imports from resolve_external.go to config.go?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question. Let's keep them in resolve_external.go for now. Config is created in a lot of places for tests, so that would make this change more complicated. I may refactor it later.

@@ -107,6 +144,12 @@ const (
// (declared in WORKSPACE).
ExternalMode DependencyMode = iota

// KnownMode indicates imports should be resolved via ExternalMode unless
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't need to be an extra mode of this. KnownImports can just be empty if there aren't any.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM.

@pmcalpine
Copy link
Contributor Author

Ok. I'll turn this into a repeatable command line option.

Thanks!

@pmcalpine pmcalpine changed the title Add "known" external resolution strategy Add -known_import flag Jul 29, 2017
Private repositories can take a long time to resolve, and if the repo
host does not properly support go-import meta tags then gazelle may not
be able to resolve them at all.

This change adds a flag that can be specified multiple times to append
arbitrary import paths to the cache of known imports when using the
external import resolver.
@pmcalpine
Copy link
Contributor Author

PTAL.

@jayconrod
Copy link
Contributor

Thanks, looks good!

Jenkins test this please.

@jayconrod jayconrod merged commit 3ea5bff into bazel-contrib:master Jul 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants