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

perf: avoid scanning convenience symlink directories during initial import #6094

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,20 @@

import com.google.idea.blaze.base.projectview.ProjectView;
import com.google.idea.blaze.base.projectview.ProjectViewSet;
import com.google.idea.blaze.base.projectview.parser.ParseContext;
import com.google.idea.blaze.base.projectview.parser.ProjectViewParser;
import com.google.idea.blaze.base.projectview.section.ProjectViewDefaultValueProvider;
import com.google.idea.blaze.base.projectview.section.ScalarSection;
import com.google.idea.blaze.base.projectview.section.ScalarSectionParser;
import com.google.idea.blaze.base.projectview.section.SectionKey;
import com.google.idea.blaze.base.projectview.section.SectionParser;
import com.google.idea.blaze.base.settings.BuildSystemName;
import javax.annotation.Nullable;

/** If set to true, automatically derives targets from the project directories. */
public class AutomaticallyDeriveTargetsSection {
public static final SectionKey<Boolean, ScalarSection<Boolean>> KEY =
SectionKey.of("derive_targets_from_directories");
public static final SectionParser PARSER = new AutomaticallyDeriveTargetsSectionParser();

private static class AutomaticallyDeriveTargetsSectionParser
extends ScalarSectionParser<Boolean> {
AutomaticallyDeriveTargetsSectionParser() {
super(KEY, ':');
}

@Override
@Nullable
protected Boolean parseItem(ProjectViewParser parser, ParseContext parseContext, String text) {
if (text.equals("true")) {
return true;
}
if (text.equals("false")) {
return false;
}
parseContext.addError(
"'derive_targets_from_directories' must be set to 'true' or 'false' (e.g."
+ " 'derive_targets_from_directories: true')");
return null;
}

@Override
protected void printItem(StringBuilder sb, Boolean item) {
sb.append(item);
}

@Override
public ItemType getItemType() {
return ItemType.Other;
}

@Override
public String quickDocs() {
return "If set to true, project targets will be derived from the directories.";
}
}
public static final SectionParser PARSER = new BooleanSectionParser(
KEY,
"If set to true, project targets will be derived from the directories."
);

static class DefaultValueProvider implements ProjectViewDefaultValueProvider {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2024 The Bazel Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.idea.blaze.base.projectview.section.sections;

import com.google.idea.blaze.base.projectview.parser.ParseContext;
import com.google.idea.blaze.base.projectview.parser.ProjectViewParser;
import com.google.idea.blaze.base.projectview.section.ScalarSection;
import com.google.idea.blaze.base.projectview.section.ScalarSectionParser;
import com.google.idea.blaze.base.projectview.section.SectionKey;

import javax.annotation.Nullable;

class BooleanSectionParser
extends ScalarSectionParser<Boolean> {
private final String quickDocs;

BooleanSectionParser(SectionKey<Boolean, ScalarSection<Boolean>> key, String quickDocs) {
super(key, ':');
this.quickDocs = quickDocs;
}

@Override
@Nullable
protected Boolean parseItem(ProjectViewParser parser, ParseContext parseContext, String text) {
if (text.equals("true")) {
return true;
}
if (text.equals("false")) {
return false;
}
String key = super.getSectionKey().getName();
parseContext.addError(
"'" + key + "' must be set to 'true' or 'false' (e.g."
+ " '" + key + ": true')");
return null;
}

@Override
protected void printItem(StringBuilder sb, Boolean item) {
sb.append(item);
}

@Override
public ItemType getItemType() {
return ItemType.Other;
}

@Override
public String quickDocs() {
return quickDocs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public class Sections {
ShardBlazeBuildsSection.PARSER,
TargetShardSizeSection.PARSER,
BazelBinarySection.PARSER,
BuildConfigSection.PARSER);
BuildConfigSection.PARSER,
UseExclusionPatternsSection.PARSER);

public static List<SectionParser> getParsers() {
List<SectionParser> parsers = Lists.newArrayList(PARSERS);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2024 The Bazel Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.idea.blaze.base.projectview.section.sections;

import com.google.idea.blaze.base.projectview.section.ScalarSection;
import com.google.idea.blaze.base.projectview.section.SectionKey;
import com.google.idea.blaze.base.projectview.section.SectionParser;

/** 'use_exclusion_pattern' section. */
public class UseExclusionPatternsSection {
public static final SectionKey<Boolean, ScalarSection<Boolean>> KEY =
SectionKey.of("use_exclusion_patterns");

public static final SectionParser PARSER = new BooleanSectionParser(
KEY,
"""
Add an exclusion pattern for all directories that are supposed to be excluded from the project.
It might significantly improve first import performance, but if your project contains files
that are typically ignored (`bazel-bin`, `bazel-out`, `.ijwb` etc.) they will be excluded, even
if they do noy lay in the root directory. In these cases, please disable exclusion patterns (set
to false). By default the exclusion patterns are enabled. For more info please check
https://www.jetbrains.com/help/idea/content-roots.html#exclude_folders
""");


}


Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.idea.blaze.base.model.primitives.WorkspacePath;
import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
import com.google.idea.blaze.base.projectview.ProjectViewSet;
import com.google.idea.blaze.base.projectview.section.sections.UseExclusionPatternsSection;
import com.google.idea.blaze.base.settings.Blaze;
import com.google.idea.blaze.base.sync.SourceFolderProvider;
import com.google.idea.blaze.base.sync.data.BlazeDataStorage;
Expand Down Expand Up @@ -68,8 +69,14 @@ public static void createContentEntries(
modifiableRootModel.addContentEntry(UrlUtil.pathToUrl(rootFile.getPath()));

for (WorkspacePath exclude : excludesByRootDirectory.get(rootDirectory)) {
File excludeFolder = workspaceRoot.fileForPath(exclude);
contentEntry.addExcludeFolder(UrlUtil.fileToIdeaUrl(excludeFolder));
if (projectViewSet.getScalarValue(UseExclusionPatternsSection.KEY).orElse(true)
&& !exclude.asPath().isAbsolute()
&& exclude.asPath().getNameCount() == 1) {
contentEntry.addExcludePattern(exclude.relativePath());
} else {
File excludeFolder = workspaceRoot.fileForPath(exclude);
contentEntry.addExcludeFolder(UrlUtil.fileToIdeaUrl(excludeFolder));
}
}

File directory = new File(workspaceRoot.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.google.idea.blaze.base.projectview.section.sections.TextBlock;
import com.google.idea.blaze.base.projectview.section.sections.TextBlockSection;
import com.google.idea.blaze.base.projectview.section.sections.TryImportSection;
import com.google.idea.blaze.base.projectview.section.sections.UseExclusionPatternsSection;
import com.google.idea.blaze.base.projectview.section.sections.WorkspaceTypeSection;
import com.google.idea.blaze.base.sync.BlazeSyncPlugin;
import com.google.idea.common.experiments.ExperimentService;
Expand Down Expand Up @@ -115,6 +116,7 @@ public void testProjectViewSetSerializable() {
.add(
ScalarSection.builder(BuildConfigSection.KEY)
.set(new WorkspacePath("test")))
.add(ScalarSection.builder(UseExclusionPatternsSection.KEY).set(false))
.build())
.build();

Expand Down
Loading