Search in sources :

Example 26 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class BlazeRenderErrorContributorTest method createTargetMapWithNonStandardAndroidManifestNameInDependency.

private void createTargetMapWithNonStandardAndroidManifestNameInDependency() {
    Label mainResourceTarget = Label.create("//com/google/example:main");
    Label dependencyResourceTarget = Label.create("//com/google/example:dependency");
    ArtifactLocation mainManifest = artifact("com/google/example/main/AndroidManifest.xml", true);
    ArtifactLocation mainResource = artifact("com/google/example/main/res", true);
    ArtifactLocation mainBuildFile = artifact("com/google/example/main/BUILD", true);
    ArtifactLocation dependencyManifest = artifact("com/google/example/dependency/MyManifest.xml", true);
    ArtifactLocation dependencyResource = artifact("com/google/example/dependency/res", true);
    ArtifactLocation dependencyBuildFile = artifact("com/google/example/dependency/BUILD", true);
    AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
    registry.put(module, AndroidResourceModule.builder(TargetKey.forPlainTarget(mainResourceTarget)).addResource(mainResource).addTransitiveResourceDependency(dependencyResourceTarget).addTransitiveResource(dependencyResource).build());
    registry.put(mock(Module.class), AndroidResourceModule.builder(TargetKey.forPlainTarget(dependencyResourceTarget)).addResource(dependencyResource).build());
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel(mainResourceTarget).setBuildFile(mainBuildFile).setAndroidInfo(AndroidIdeInfo.builder().setGenerateResourceClass(true).setManifestFile(mainManifest).addResource(mainResource))).addTarget(TargetIdeInfo.builder().setLabel(dependencyResourceTarget).setBuildFile(dependencyBuildFile).setAndroidInfo(AndroidIdeInfo.builder().setGenerateResourceClass(true).setManifestFile(dependencyManifest).addResource(dependencyResource))).build();
    projectDataManager.setTargetMap(targetMap);
}
Also used : Label(com.google.idea.blaze.base.model.primitives.Label) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) AndroidResourceModuleRegistry(com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry) MockModule(com.intellij.mock.MockModule) Module(com.intellij.openapi.module.Module) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) SourceToTargetMap(com.google.idea.blaze.base.targetmaps.SourceToTargetMap) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Example 27 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class BlazeIntellijPluginConfiguration method checkConfiguration.

@Override
public void checkConfiguration() throws RuntimeConfigurationException {
    super.checkConfiguration();
    Label label = getTarget();
    if (label == null) {
        throw new RuntimeConfigurationError("Select a target to run");
    }
    TargetInfo target = TargetFinder.findTargetInfo(getProject(), label);
    if (target == null) {
        throw new RuntimeConfigurationError("The selected target does not exist.");
    }
    if (!IntellijPluginRule.isPluginTarget(target)) {
        throw new RuntimeConfigurationError("The selected target is not an intellij_plugin");
    }
    if (!IdeaJdkHelper.isIdeaJdk(pluginSdk)) {
        throw new RuntimeConfigurationError("Select an IntelliJ Platform Plugin SDK");
    }
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) Label(com.google.idea.blaze.base.model.primitives.Label) JLabel(javax.swing.JLabel) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

Example 28 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class BlazePyRunConfigurationRunner method getExecutableToDebug.

/**
 * Builds blaze python target and returns the output build artifact.
 *
 * @throws ExecutionException if the target cannot be debugged.
 */
private static File getExecutableToDebug(ExecutionEnvironment env) throws ExecutionException {
    BlazeCommandRunConfiguration configuration = getConfiguration(env);
    Project project = configuration.getProject();
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        throw new ExecutionException("Not synced yet, please sync project");
    }
    String validationError = BlazePyDebugHelper.validateDebugTarget(env.getProject(), configuration.getTarget());
    if (validationError != null) {
        throw new WithBrowserHyperlinkExecutionException(validationError);
    }
    try (BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> true)) {
        ListenableFuture<BuildResult> buildOperation = BlazeBeforeRunCommandHelper.runBlazeBuild(configuration, buildResultHelper, BlazePyDebugHelper.getAllBlazeDebugFlags(Blaze.getBuildSystem(project)), ImmutableList.of(), "Building debug binary");
        try {
            SaveUtil.saveAllFiles();
            BuildResult result = buildOperation.get();
            if (result.status != BuildResult.Status.SUCCESS) {
                throw new ExecutionException("Blaze failure building debug binary");
            }
        } catch (InterruptedException | CancellationException e) {
            buildOperation.cancel(true);
            throw new RunCanceledByUserException();
        } catch (java.util.concurrent.ExecutionException e) {
            throw new ExecutionException(e);
        }
        List<File> candidateFiles = buildResultHelper.getBuildArtifactsForTarget((Label) configuration.getTarget()).stream().filter(File::canExecute).collect(Collectors.toList());
        if (candidateFiles.isEmpty()) {
            throw new ExecutionException(String.format("No output artifacts found when building %s", configuration.getTarget()));
        }
        File file = findExecutable((Label) configuration.getTarget(), candidateFiles);
        if (file == null) {
            throw new ExecutionException(String.format("More than 1 executable was produced when building %s; " + "don't know which one to debug", configuration.getTarget()));
        }
        LocalFileSystem.getInstance().refreshIoFiles(ImmutableList.of(file));
        return file;
    }
}
Also used : WithBrowserHyperlinkExecutionException(com.google.idea.blaze.base.run.WithBrowserHyperlinkExecutionException) Label(com.google.idea.blaze.base.model.primitives.Label) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) Project(com.intellij.openapi.project.Project) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) CancellationException(java.util.concurrent.CancellationException) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ExecutionException(com.intellij.execution.ExecutionException) WithBrowserHyperlinkExecutionException(com.google.idea.blaze.base.run.WithBrowserHyperlinkExecutionException) File(java.io.File) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)

Example 29 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class FileLookupData method packageLocalFileLookup.

@Nullable
public static FileLookupData packageLocalFileLookup(String originalLabel, StringLiteral element, @Nullable BuildFile basePackage, @Nullable VirtualFileFilter fileFilter) {
    if (basePackage == null) {
        return null;
    }
    Label packageLabel = basePackage.getPackageLabel();
    if (packageLabel == null) {
        return null;
    }
    String basePackagePath = packageLabel.blazePackage().relativePath();
    String filePath = basePackagePath + "/" + LabelUtils.getRuleComponent(originalLabel);
    return new FileLookupData(originalLabel, basePackage, basePackagePath, filePath, PathFormat.PackageLocal, element.getQuoteType(), fileFilter);
}
Also used : Label(com.google.idea.blaze.base.model.primitives.Label) Nullable(javax.annotation.Nullable)

Example 30 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class PackageReferenceFragment method bindToElement.

@Override
public PsiElement bindToElement(PsiElement element) throws IncorrectOperationException {
    if (!(element instanceof BuildFile)) {
        return super.bindToElement(element);
    }
    if (element.equals(resolve())) {
        return myElement;
    }
    Label newPackageLabel = ((BuildFile) element).getPackageLabel();
    if (newPackageLabel == null) {
        return myElement;
    }
    String newPath = newPackageLabel.blazePackage().toString();
    String labelString = myElement.getStringContents();
    int colonIndex = labelString.indexOf(':');
    if (colonIndex != -1) {
        return handleRename("//" + newPath + labelString.substring(colonIndex));
    }
    // need to assume there's an implicit rule name
    return handleRename("//" + newPath + ":" + PathUtil.getFileName(labelString));
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) Label(com.google.idea.blaze.base.model.primitives.Label)

Aggregations

Label (com.google.idea.blaze.base.model.primitives.Label)48 File (java.io.File)15 Test (org.junit.Test)11 Nullable (javax.annotation.Nullable)8 BlazeTestResults (com.google.idea.blaze.base.run.testlogs.BlazeTestResults)7 BuildEventStreamProtos (com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos)6 BlazeTestResult (com.google.idea.blaze.base.run.testlogs.BlazeTestResult)6 AndroidResourceModuleRegistry (com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry)5 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)5 Kind (com.google.idea.blaze.base.model.primitives.Kind)5 TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)5 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)4 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)4 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)4 BuildEvent (com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEvent)3 AndroidResourceModule (com.google.idea.blaze.android.sync.model.AndroidResourceModule)3 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)3 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)3 StatusOutput (com.google.idea.blaze.base.scope.output.StatusOutput)3 SourceToTargetMap (com.google.idea.blaze.base.targetmaps.SourceToTargetMap)3