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

Allow to have non-existent import entries in projectview that pointing to … #5689

Merged
merged 8 commits into from
Dec 11, 2023

Conversation

dkashyn-sfdc
Copy link
Contributor

@dkashyn-sfdc dkashyn-sfdc commented Nov 14, 2023

…files that are optional and can be missing for some of the users.

Checklist

  • I have filed an issue about this change and discussed potential changes with the maintainers.
  • I have received the approval from the maintainers to make this change.
  • This is not a stylistic, refactoring, or cleanup change.

Please note that the maintainers will not be reviewing this change until all checkboxes are ticked. See
the Contributions section in the README for more
details.

Discussion thread for this change

Issue number: 5688

Description of this change

…files that are optional and can be missing for some of the users.
@github-actions github-actions bot added product: CLion CLion plugin product: IntelliJ IntelliJ plugin product: GoLand GoLand plugin awaiting-review Awaiting review from Bazel team on PRs labels Nov 14, 2023
@@ -303,11 +306,26 @@ public void testCanParseWithMissingCarriageReturnAtEndOfSection() {

@Test
public void testImportMissingFileResultsInIssue() {
Registry.get("bazel.projectview.optional.imports").setValue(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was unable to make it work with Registry.is('bla', false) for tests.

@@ -55,6 +55,10 @@ public void assertHasErrors() {
assertThat(issues.stream().anyMatch(i -> i.getCategory() == Category.ERROR)).isTrue();
}

public void assertHasNoErrors() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

in some cases there are issues but those are not errors.

@ujohnny
Copy link
Collaborator

ujohnny commented Nov 14, 2023

codewise lgtm, haven't checked how it works IRL. @tpasternak could you please check this?

related though: I'd be happy to see warnings (primarily highlighting) in editor on unresolved imports when feature is enabled, though I believe it falls outside of the scope of proposed change.

@dkashyn-sfdc
Copy link
Contributor Author

sigh...

Copy link
Collaborator

@ujohnny ujohnny left a comment

Choose a reason for hiding this comment

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

We had a discussion about this feature and the common point was that primarily in all programming languages imports require imported entity to exist. Though for example python allows to handle import errors, so can we keep import statement as is and just introduce try_import which will allow imported entity to be absent?

@dkashyn-sfdc
Copy link
Contributor Author

I don't think that .projectview is a programing language to be that strict :)

@dkashyn-sfdc
Copy link
Contributor Author

@ujohnny please note that this is protected by registry value and not default behavior.

Our use case is following:

  1. we do have templates
  2. customers use those templates to create their projects
  3. template changes over time and we delete/remove imports
  4. files not there anymore and projects generated as part of 2 and oblivious to 3 still expecting files to be there when they are physically not

In our case we want to have freedom to remove any imported file without much deprecation process.
Every import that we have should be try-import based on what you are suggesting.

If we go via try-import way then we don't need that registry key.

Could you please consider approving this PR and if someone needs try-import they can add it in the future.

@dkashyn-sfdc
Copy link
Contributor Author

With your suggestion we need to ask EVERY engineer to replace import in their existing projects with try-import and this is what we wanted to avoid by enabling optional imports with warning without involvement of EVERY engineer who have their project already configured.

@mai93 mai93 removed their assignment Nov 22, 2023
@ujohnny
Copy link
Collaborator

ujohnny commented Nov 29, 2023

@dkashyn-sfdc you could leave implicit optional import support under the flag, but please then make try_import statement available for everyone.

@dkashyn-sfdc
Copy link
Contributor Author

@ujohnny could you please check now? I'll think of other tests if the approach is correct.

@@ -52,10 +52,12 @@ public <T> List<T> listItems(SectionKey<T, ListSection<T>> key) {
}

/** Returns all values from all scalar sections in the project views, in order */
public <T> List<T> listScalarItems(SectionKey<T, ScalarSection<T>> key) {
public <T> List<T> listScalarItems(SectionKey<T, ScalarSection<T>>... keys) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure whether this is a good idea so can redo if someone have strong opinions against this way

@dkashyn-sfdc
Copy link
Contributor Author

Added as try_import as requested but bazelrc has it as try-import https://bazel.build/run/bazelrc

Copy link
Collaborator

@ujohnny ujohnny left a comment

Choose a reason for hiding this comment

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

LGTM. @tpasternak would you like to check this?

@ujohnny ujohnny merged commit fec469b into bazelbuild:master Dec 11, 2023
6 checks passed
@github-actions github-actions bot removed the awaiting-review Awaiting review from Bazel team on PRs label Dec 11, 2023
@@ -599,6 +600,9 @@ public void updateBuilder(BlazeNewProjectBuilder builder) {
.add(
ScalarSection.builder(ImportSection.KEY)
.set(selectProjectViewOption.getSharedProjectView()))
.add(
Copy link
Collaborator

@mai93 mai93 Dec 21, 2023

Choose a reason for hiding this comment

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

why is this needed? It results in having both import and try_import sections in the generated local projectview file even with the flag disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is ok to use both import and try_import. It might be not ok to have some duplication or excessive defaults...

Could you please share more context for your inquiry?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not know why it is needed to add a try_import in this function? If I understand correctly, this function creates a project view that imports the shared project view file selected in the import process. So import section should be enough and there is no need to try_import the same project view.

Copy link
Contributor Author

@dkashyn-sfdc dkashyn-sfdc Dec 27, 2023

Choose a reason for hiding this comment

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

@mai93 there might be "mandatory" and "optional" imports in any project view. One example of optional would be

try_import:
  ~/.some.local.projectview

(let's assume ~ is resolved to user home dir ;) )

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, I'm still not sure what the effect of having something like:

import hello/hello.bazelproject
try_import hello/hello.bazelproject

will this provide a different result from only

import hello/hello.bazelproject

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is rather for

import hello/fail.if.not.present.bazelproject
try_import hello/ok.if.not.present.bazelproject

That can result in:

  1. both imported
  2. only hello/fail.if.not.present.bazelproject imported and accepting the fact that that try_import hello/ok.if.not.present.bazelproject is not there
  3. failing if hello/fail.if.not.present.bazelproject is missing

Optional imports will allow engineers to have pre-defined custom import files both present or missing.

Now it is possible for some of the users to benefit from custom contents while other users not affected even if they have no local customizations. For both groups of users the same .bazelproject can be stored in VCS now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

so there is no additional value for having:

import hello/hello.bazelproject
try_import hello/hello.bazelproject

right? If so, then the change in this line can be reverted because it adds try_import section for the same project view file: selectProjectViewOption.getSharedProjectView() that already was added with import in line 600.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverting here #5958 @mai93

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product: CLion CLion plugin product: GoLand GoLand plugin product: IntelliJ IntelliJ plugin
Projects
Development

Successfully merging this pull request may close these issues.

5 participants