-
Notifications
You must be signed in to change notification settings - Fork 316
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
Conversation
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. |
Hi @yvvan, Could you please sign the CLA? |
I was added to our JetBrains list. My commit also has my JetBrains email. |
There was a problem hiding this 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.*; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
String realPath = rootPath + "/" + header.getExecutionRootRelativePath(); | ||
String libPath = targetKey.getLabel().blazePackage().asPath().toString(); | ||
String pathUsedInSourceCode = header.getRelativePath(); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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
- 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
- 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
There was a problem hiding this comment.
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.
- take library path into account for path transformation - don't use imports with `*` - revert small refactoring
- added registry key - added progress indicator - using path instead of string transformations
- take library path into account for path transformation - don't use imports with `*` - revert small refactoring
- added registry key - added progress indicator - using path instead of string transformations
Checklist
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.