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

Pass path associations as special compiler flags #5301

Closed
wants to merge 2 commits into from

Conversation

yvvan
Copy link
Contributor

@yvvan yvvan commented Sep 1, 2023

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: #5300

Description of this change

Pass all headers in targets with include_prefix with special "-ibazel" flag like so that they could be handled by CLion.

@google-cla
Copy link

google-cla bot commented Sep 1, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added product: CLion CLion plugin awaiting-review Awaiting review from Bazel team on PRs labels Sep 1, 2023
@sgowroji sgowroji added awaiting-user-response Awaiting response from author on PRs and removed awaiting-review Awaiting review from Bazel team on PRs labels Sep 1, 2023
@sgowroji
Copy link
Member

sgowroji commented Sep 1, 2023

Hi @yvvan, Could you please sign the CLA?

@yvvan
Copy link
Contributor Author

yvvan commented Sep 1, 2023

Hi @yvvan, Could you please sign the CLA?

I was added to our JetBrains list. My commit also has my JetBrains email.

@sgowroji sgowroji added awaiting-review Awaiting review from Bazel team on PRs and removed awaiting-user-response Awaiting response from author on PRs labels Sep 1, 2023
Copy link
Contributor

@tpasternak tpasternak left a comment

Choose a reason for hiding this comment

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

So when I tried to use this code on the example below, and try to jump to lib_header.h from app.cpp, I still got "This file does not belong to any project target" error.

The other comments are stylistic, so feel free to ignore them.

     File: app/app.cpp
   1 #include "lib/lib_header.h"
   2 
   3 int main () {
   4     f();
   5 }

     File: app/BUILD
   1 cc_binary(
   2     name = "app",
   3     srcs = ["app.cpp"],
   4     deps = ["//lib:lib"],
   5 )

     File: lib/BUILD
   1 cc_library(
   2     name = "lib",
   3     srcs = ["lib.cpp"],
   4     hdrs = ["include/lib_header.h"],
   5     strip_include_prefix = "include",
   6     include_prefix = "lib",
   7     visibility = ["//visibility:public"],
   8 )

     File: lib/include/lib_header.h
   1 #pragma once
   2 
   3 int f();

     File: lib/lib.cpp
   1 #include "lib/lib_header.h"
   2 
   3 int f() {
   4     return 0;
   5 }

@@ -22,8 +22,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.errorprone.annotations.Keep;
import com.google.idea.blaze.base.ideinfo.TargetIdeInfo;
import com.google.idea.blaze.base.ideinfo.TargetKey;
import com.google.idea.blaze.base.ideinfo.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

iirc we try to avoid asterisk imports cc @mai93

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's right, we prefer specific imports for the classes you need.

// defines and include directories are the same for all sources in a given target, so lets
// collect them once and reuse for each source file's options

UnfilteredCompilerOptions coptsExtractor =
UnfilteredCompilerOptions.builder()
.registerSingleOrSplitOption("-I")
.build(targetIdeInfo.getcIdeInfo().getLocalCopts());
.build(cIdeInfo.getLocalCopts());
Copy link
Contributor

Choose a reason for hiding this comment

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

We still have two release branches - google and master. We regularly cherry pick commits from google to master. For this reason we try to keep the changes as small as possible. If it's refactoring-only, I'd prefer to keep the targetIdeInfo.getcIdeInfo calls

Copy link
Contributor Author

@yvvan yvvan Sep 6, 2023

Choose a reason for hiding this comment

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

@tpasternak The changes are not supported by any public CLion version. It will be in the closest CLion 2023.3 EAP or in the next 2023.2.x release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tpasternak Ok, I will remove my small refactoring which is not really necessary.

 - take library path into account for path transformation
 - don't use imports with `*`
 - revert small refactoring
}
if (includePrefix != null && !includePrefix.isEmpty()) {
pathUsedInSourceCode = includePrefix + "/" + pathUsedInSourceCode;
System.out.println("updated path 2 = " + pathUsedInSourceCode);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove these print statements or change to logger calls

Comment on lines +179 to +181
String realPath = rootPath + "/" + header.getExecutionRootRelativePath();
String libPath = targetKey.getLabel().blazePackage().asPath().toString();
String pathUsedInSourceCode = header.getRelativePath();
Copy link
Contributor

Choose a reason for hiding this comment

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

How about using Path instead of String in many places here? It could be much safer imo, particularly when we call .startsWith().

For example "libA/header.h".startsWith("lib") would return true for Strings, but false for Paths.

We also wouldn't have to call things like (stripPrefix.endsWith("/") ? 0 : 1)

@@ -247,6 +292,9 @@ private OCWorkspaceImpl.ModifiableModel calculateConfigurations(
.map(file -> "-I" + file.getAbsolutePath())
.collect(toImmutableList());

String rootPath = workspaceRoot.directory().getAbsolutePath();
ImmutableList<String> includes = ImmutableList.copyOf(collectIncludes(rootPath, targetKey, blazeProjectData));
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO collectIncludes method might be quite heavy, because it traverses whole dependency graph. I'd prefer to

  1. Add a registry key that allows users to disable it at all in case it's too heavy for them and they don't use include_prefix
  2. Measure time and print it to the user or (maybe even better) to run it with Progress Indicator so the users could observe that this particular step significantly impacts them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you like to take over this pull request? I'm not working on bazel currently and have less knowledge on the plugin source code.
Also I don't think this step is long - it may take time only if enough entries are specified so if one doesn't use this feature at all than it wouldn't cost time. But if you are still worried we may make a progress indicator here.

LeFrosch pushed a commit to LeFrosch/intellij-bazel that referenced this pull request Jan 29, 2024
 - take library path into account for path transformation
 - don't use imports with `*`
 - revert small refactoring
LeFrosch added a commit to LeFrosch/intellij-bazel that referenced this pull request Feb 1, 2024
- added registry key
- added progress indicator
- using path instead of string transformations
LeFrosch pushed a commit to LeFrosch/intellij-bazel that referenced this pull request Feb 19, 2024
 - take library path into account for path transformation
 - don't use imports with `*`
 - revert small refactoring
LeFrosch added a commit to LeFrosch/intellij-bazel that referenced this pull request Feb 19, 2024
- added registry key
- added progress indicator
- using path instead of string transformations
@ujohnny ujohnny closed this Mar 7, 2024
@github-actions github-actions bot removed the awaiting-review Awaiting review from Bazel team on PRs label Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product: CLion CLion plugin
Projects
Development

Successfully merging this pull request may close these issues.

5 participants