Search in sources :

Example 16 with TargetExpression

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

the class BlazeRunConfigurationSyncListener method onSyncComplete.

@Override
public void onSyncComplete(Project project, BlazeContext context, BlazeImportSettings importSettings, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, SyncMode syncMode, SyncResult syncResult) {
    updateExistingRunConfigurations(project);
    if (syncMode == SyncMode.STARTUP) {
        return;
    }
    Set<File> xmlFiles = getImportedRunConfigurations(projectViewSet, blazeProjectData.workspacePathResolver);
    Transactions.submitTransactionAndWait(() -> {
        // First, import from specified XML files. Then auto-generate from targets.
        xmlFiles.forEach((file) -> RunConfigurationSerializer.loadFromXmlIgnoreExisting(project, file));
        Set<Label> labelsWithConfigs = labelsWithConfigs(project);
        Set<TargetExpression> targetExpressions = Sets.newLinkedHashSet(projectViewSet.listItems(TargetSection.KEY));
        // We only auto-generate configurations for rules listed in the project view.
        for (TargetExpression target : targetExpressions) {
            if (!(target instanceof Label) || labelsWithConfigs.contains(target)) {
                continue;
            }
            Label label = (Label) target;
            labelsWithConfigs.add(label);
            maybeAddRunConfiguration(project, blazeProjectData, label);
        }
    });
}
Also used : Label(com.google.idea.blaze.base.model.primitives.Label) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) File(java.io.File)

Example 17 with TargetExpression

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

the class BlazeCidrLauncher method createDebugProcess.

@Override
public CidrDebugProcess createDebugProcess(CommandLineState state, XDebugSession session) throws ExecutionException {
    TargetExpression target = configuration.getTarget();
    if (target == null) {
        throw new ExecutionException("Cannot parse run configuration target.");
    }
    if (runner.executableToDebug == null) {
        throw new ExecutionException("No debug binary found.");
    }
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    GeneralCommandLine commandLine = new GeneralCommandLine(runner.executableToDebug.getPath());
    File workingDir = workspaceRoot.directory();
    commandLine.setWorkDirectory(workingDir);
    commandLine.addParameters(handlerState.getExeFlagsState().getExpandedFlags());
    EnvironmentVariablesData envState = handlerState.getEnvVarsState().getData();
    commandLine.withParentEnvironmentType(envState.isPassParentEnvs() ? ParentEnvironmentType.SYSTEM : ParentEnvironmentType.NONE);
    commandLine.getEnvironment().putAll(envState.getEnvs());
    if (Kind.CC_TEST.equals(configuration.getTargetKind())) {
        convertBlazeTestFilterToExecutableFlag().ifPresent(commandLine::addParameters);
    }
    TrivialInstaller installer = new TrivialInstaller(commandLine);
    ImmutableList<String> startupCommands = getGdbStartupCommands(workingDir);
    CLionRunParameters parameters = new CLionRunParameters(new BlazeGDBDriverConfiguration(project, startupCommands, workspaceRoot), installer);
    state.setConsoleBuilder(createConsoleBuilder(null));
    state.addConsoleFilters(getConsoleFilters().toArray(new Filter[0]));
    return new CidrLocalDebugProcess(parameters, session, state.getConsoleBuilder());
}
Also used : CLionRunParameters(com.jetbrains.cidr.cpp.execution.CLionRunParameters) CidrLocalDebugProcess(com.jetbrains.cidr.execution.debugger.CidrLocalDebugProcess) TrivialInstaller(com.jetbrains.cidr.execution.TrivialInstaller) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) EnvironmentVariablesData(com.intellij.execution.configuration.EnvironmentVariablesData) UrlFilter(com.intellij.execution.filters.UrlFilter) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) Filter(com.intellij.execution.filters.Filter) BlazeTargetFilter(com.google.idea.blaze.base.run.filter.BlazeTargetFilter) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File)

Example 18 with TargetExpression

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

the class BlazeCommandRunConfigurationGenericHandlerIntegrationTest method testEditorApplyToAndResetFromHandlesNulls.

@Test
public void testEditorApplyToAndResetFromHandlesNulls() throws ConfigurationException {
    BlazeCommandRunConfigurationSettingsEditor editor = new BlazeCommandRunConfigurationSettingsEditor(configuration);
    // Call setTarget to initialize a generic handler, or this won't apply anything.
    configuration.setTarget(null);
    assertThat(configuration.getTarget()).isNull();
    assertThat(configuration.getHandler()).isInstanceOf(BlazeCommandGenericRunConfigurationHandler.class);
    BlazeCommandRunConfigurationCommonState state = (BlazeCommandRunConfigurationCommonState) configuration.getHandler().getState();
    editor.resetFrom(configuration);
    BlazeCommandRunConfiguration readConfiguration = type.getFactory().createTemplateConfiguration(getProject());
    TargetExpression targetExpression = TargetExpression.fromStringSafe("//...");
    readConfiguration.setTarget(targetExpression);
    BlazeCommandRunConfigurationCommonState readState = (BlazeCommandRunConfigurationCommonState) readConfiguration.getHandler().getState();
    readState.getCommandState().setCommand(COMMAND);
    readState.getBlazeFlagsState().setRawFlags(ImmutableList.of("--flag1", "--flag2"));
    readState.getExeFlagsState().setRawFlags(ImmutableList.of("--exeFlag1"));
    readState.getBlazeBinaryState().setBlazeBinary("/usr/bin/blaze");
    editor.applyEditorTo(readConfiguration);
    assertThat(readConfiguration.getTarget()).isNull();
    assertThat(configuration.getHandler()).isInstanceOf(BlazeCommandGenericRunConfigurationHandler.class);
    readState = (BlazeCommandRunConfigurationCommonState) readConfiguration.getHandler().getState();
    assertThat(readState.getCommandState().getCommand()).isEqualTo(state.getCommandState().getCommand());
    assertThat(readState.getBlazeFlagsState().getRawFlags()).isEqualTo(state.getBlazeFlagsState().getRawFlags());
    assertThat(readState.getExeFlagsState().getRawFlags()).isEqualTo(state.getExeFlagsState().getRawFlags());
    assertThat(readState.getBlazeBinaryState().getBlazeBinary()).isEqualTo(state.getBlazeBinaryState().getBlazeBinary());
    Disposer.dispose(editor);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) BlazeCommandRunConfigurationSettingsEditor(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration.BlazeCommandRunConfigurationSettingsEditor) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) Test(org.junit.Test)

Example 19 with TargetExpression

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

the class BlazeCommandRunConfigurationGenericHandlerIntegrationTest method testEditorApplyToAndResetFromMatches.

@Test
public void testEditorApplyToAndResetFromMatches() throws ConfigurationException {
    BlazeCommandRunConfigurationSettingsEditor editor = new BlazeCommandRunConfigurationSettingsEditor(configuration);
    TargetExpression targetExpression = TargetExpression.fromStringSafe("//...");
    configuration.setTarget(targetExpression);
    BlazeCommandRunConfigurationCommonState state = (BlazeCommandRunConfigurationCommonState) configuration.getHandler().getState();
    state.getCommandState().setCommand(COMMAND);
    state.getBlazeFlagsState().setRawFlags(ImmutableList.of("--flag1", "--flag2"));
    state.getExeFlagsState().setRawFlags(ImmutableList.of("--exeFlag1"));
    state.getBlazeBinaryState().setBlazeBinary("/usr/bin/blaze");
    editor.resetFrom(configuration);
    BlazeCommandRunConfiguration readConfiguration = type.getFactory().createTemplateConfiguration(getProject());
    editor.applyEditorTo(readConfiguration);
    assertThat(readConfiguration.getTarget()).isEqualTo(targetExpression);
    assertThat(readConfiguration.getHandler()).isInstanceOf(BlazeCommandGenericRunConfigurationHandler.class);
    BlazeCommandRunConfigurationCommonState readState = (BlazeCommandRunConfigurationCommonState) readConfiguration.getHandler().getState();
    assertThat(readState.getCommandState().getCommand()).isEqualTo(state.getCommandState().getCommand());
    assertThat(readState.getBlazeFlagsState().getRawFlags()).isEqualTo(state.getBlazeFlagsState().getRawFlags());
    assertThat(readState.getExeFlagsState().getRawFlags()).isEqualTo(state.getExeFlagsState().getRawFlags());
    assertThat(readState.getBlazeBinaryState().getBlazeBinary()).isEqualTo(state.getBlazeBinaryState().getBlazeBinary());
    Disposer.dispose(editor);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) BlazeCommandRunConfigurationSettingsEditor(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration.BlazeCommandRunConfigurationSettingsEditor) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) Test(org.junit.Test)

Example 20 with TargetExpression

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

the class BlazeCommandRunConfigurationGenericHandlerIntegrationTest method testReadAndWriteMatches.

@Test
public void testReadAndWriteMatches() throws Exception {
    TargetExpression targetExpression = TargetExpression.fromStringSafe("//...");
    configuration.setTarget(targetExpression);
    BlazeCommandRunConfigurationCommonState state = (BlazeCommandRunConfigurationCommonState) configuration.getHandler().getState();
    state.getCommandState().setCommand(COMMAND);
    state.getBlazeFlagsState().setRawFlags(ImmutableList.of("--flag1", "--flag2"));
    state.getExeFlagsState().setRawFlags(ImmutableList.of("--exeFlag1"));
    state.getBlazeBinaryState().setBlazeBinary("/usr/bin/blaze");
    Element element = new Element("test");
    configuration.writeExternal(element);
    BlazeCommandRunConfiguration readConfiguration = type.getFactory().createTemplateConfiguration(getProject());
    readConfiguration.readExternal(element);
    assertThat(readConfiguration.getTarget()).isEqualTo(targetExpression);
    assertThat(readConfiguration.getHandler()).isInstanceOf(BlazeCommandGenericRunConfigurationHandler.class);
    BlazeCommandRunConfigurationCommonState readState = (BlazeCommandRunConfigurationCommonState) readConfiguration.getHandler().getState();
    assertThat(readState.getCommandState().getCommand()).isEqualTo(COMMAND);
    assertThat(readState.getBlazeFlagsState().getRawFlags()).containsExactly("--flag1", "--flag2").inOrder();
    assertThat(readState.getExeFlagsState().getRawFlags()).containsExactly("--exeFlag1");
    assertThat(readState.getBlazeBinaryState().getBlazeBinary()).isEqualTo("/usr/bin/blaze");
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) Element(org.jdom.Element) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) Test(org.junit.Test)

Aggregations

TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)31 Test (org.junit.Test)11 WildcardTargetPattern (com.google.idea.blaze.base.model.primitives.WildcardTargetPattern)10 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)8 File (java.io.File)6 Label (com.google.idea.blaze.base.model.primitives.Label)5 ImmutableList (com.google.common.collect.ImmutableList)3 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)3 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 FutureUtil (com.google.idea.blaze.base.async.FutureUtil)2 BuildSystemProvider (com.google.idea.blaze.base.bazel.BuildSystemProvider)2 BlazeCommand (com.google.idea.blaze.base.command.BlazeCommand)2 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)2 Kind (com.google.idea.blaze.base.model.primitives.Kind)2