Skip to content

Commit

Permalink
Support blazerc section in project view
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 553927607
  • Loading branch information
Googler authored and copybara-github committed Aug 4, 2023
1 parent 21581b5 commit 59f10f2
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2023 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.model.primitives.WorkspacePath;
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 com.google.idea.blaze.base.projectview.section.SectionParser;
import java.io.File;
import javax.annotation.Nullable;

/** A section to specify build-system's configuration file. */
public final class BuildConfigSection {
public static final SectionKey<WorkspacePath, ScalarSection<WorkspacePath>> KEY =
SectionKey.of("build_config_file");
public static final SectionParser PARSER = new BuildConfigSectionParser();

private static class BuildConfigSectionParser extends ScalarSectionParser<WorkspacePath> {
public BuildConfigSectionParser() {
super(KEY, ':');
}

@Nullable
@Override
protected WorkspacePath parseItem(
ProjectViewParser parser, ParseContext parseContext, String text) {
String error = WorkspacePath.validate(text);
if (error != null) {
parseContext.addError(error);
return null;
}

WorkspacePath workspacePath = new WorkspacePath(text);
if (parser.isRecursive()) {
File rcFile = parseContext.getWorkspacePathResolver().resolveToFile(workspacePath);
if (rcFile == null || !rcFile.exists()) {
parseContext.addError(
String.format(
"Could not resolve the build configuration file: %s",
workspacePath.relativePath()));
}
}
return workspacePath;
}

@Override
protected void printItem(StringBuilder sb, WorkspacePath section) {
sb.append(section);
}

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

@Override
public String quickDocs() {
return "Specifies build configuration file for the remote build services";
}
}

private BuildConfigSection() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class Sections {
RunConfigurationsSection.PARSER,
ShardBlazeBuildsSection.PARSER,
TargetShardSizeSection.PARSER,
BazelBinarySection.PARSER);
BazelBinarySection.PARSER,
BuildConfigSection.PARSER);

public static List<SectionParser> getParsers() {
List<SectionParser> parsers = Lists.newArrayList(PARSERS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.idea.blaze.base.projectview.section.sections.AdditionalLanguagesSection;
import com.google.idea.blaze.base.projectview.section.sections.AutomaticallyDeriveTargetsSection;
import com.google.idea.blaze.base.projectview.section.sections.BazelBinarySection;
import com.google.idea.blaze.base.projectview.section.sections.BuildConfigSection;
import com.google.idea.blaze.base.projectview.section.sections.BuildFlagsSection;
import com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry;
import com.google.idea.blaze.base.projectview.section.sections.DirectorySection;
Expand Down Expand Up @@ -107,6 +108,9 @@ public void testProjectViewSetSerializable() {
.add(
ScalarSection.builder(BazelBinarySection.KEY)
.set(new File("/bazel/path/override")))
.add(
ScalarSection.builder(BuildConfigSection.KEY)
.set(new WorkspacePath("test")))
.build())
.build();

Expand Down

0 comments on commit 59f10f2

Please sign in to comment.