예제 #1
0
 /**
  * Returns array of additional compiler commands to look for
  *
  * @return String[]
  */
 private String[] computeCompilerCommands() {
   if (project != null) {
     SCProfileInstance profileInstance =
         ScannerConfigProfileManager.getInstance()
             .getSCProfileInstance(project, ScannerConfigProfileManager.NULL_PROFILE_ID);
     BuildOutputProvider boProvider = profileInstance.getProfile().getBuildOutputProviderElement();
     if (boProvider != null) {
       String compilerCommandsString =
           boProvider.getScannerInfoConsoleParser().getCompilerCommands();
       if (compilerCommandsString != null && compilerCommandsString.length() > 0) {
         String[] compilerCommands = compilerCommandsString.split(",\\s*"); // $NON-NLS-1$
         if (compilerCommands.length > 0) {
           String[] compilerInvocation =
               new String[COMPILER_INVOCATION.length + compilerCommands.length];
           System.arraycopy(
               COMPILER_INVOCATION, 0, compilerInvocation, 0, COMPILER_INVOCATION.length);
           System.arraycopy(
               compilerCommands,
               0,
               compilerInvocation,
               COMPILER_INVOCATION.length,
               compilerCommands.length);
           return compilerInvocation;
         }
       }
     }
   }
   return COMPILER_INVOCATION;
 }
예제 #2
0
  @Override
  public void process(
      TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor)
      throws ProcessFailureException {
    String projectName = args[0].getSimpleValue();
    String prefix = args[1].getSimpleValue();
    String path = args[2].getSimpleValue();

    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (!project.exists()) return;

    IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(project);
    if (buildInfo == null) return;

    IConfiguration[] configs = buildInfo.getManagedProject().getConfigurations();
    for (IConfiguration config : configs) {
      IToolChain toolchain = config.getToolChain();
      IOption option =
          toolchain.getOptionBySuperClassId("cdt.managedbuild.option.gnu.cross.prefix");
      ManagedBuildManager.setOption(config, toolchain, option, prefix);
      option = toolchain.getOptionBySuperClassId("cdt.managedbuild.option.gnu.cross.path");
      ManagedBuildManager.setOption(config, toolchain, option, path);

      ICfgScannerConfigBuilderInfo2Set cbi =
          CfgScannerConfigProfileManager.getCfgScannerConfigBuildInfo(config);
      Map<CfgInfoContext, IScannerConfigBuilderInfo2> map = cbi.getInfoMap();
      for (CfgInfoContext cfgInfoContext : map.keySet()) {
        IScannerConfigBuilderInfo2 bi = map.get(cfgInfoContext);
        String providerId = "specsFile";
        String runCommand = bi.getProviderRunCommand(providerId);
        bi.setProviderRunCommand(providerId, prefix + runCommand);
        try {
          bi.save();
        } catch (CoreException e) {
          throw new ProcessFailureException(e);
        }

        // Clear the path info that was captured at project creation time
        // TODO we need an API to do this to avoid the discouraged access warnings.

        DiscoveredPathInfo pathInfo = new DiscoveredPathInfo(project);
        InfoContext infoContext = cfgInfoContext.toInfoContext();

        // 1. Remove scanner info from .metadata/.plugins/org.eclipse.cdt.make.core/Project.sc
        DiscoveredScannerInfoStore dsiStore = DiscoveredScannerInfoStore.getInstance();
        try {
          dsiStore.saveDiscoveredScannerInfoToState(project, infoContext, pathInfo);
        } catch (CoreException e) {
          e.printStackTrace();
        }

        // 2. Remove scanner info from CfgDiscoveredPathManager cache and from the Tool
        CfgDiscoveredPathManager cdpManager = CfgDiscoveredPathManager.getInstance();
        cdpManager.removeDiscoveredInfo(project, cfgInfoContext);

        // 3. Remove scanner info from SI collector
        IScannerConfigBuilderInfo2 buildInfo2 = map.get(cfgInfoContext);
        if (buildInfo2 != null) {
          ScannerConfigProfileManager scpManager = ScannerConfigProfileManager.getInstance();
          String selectedProfileId = buildInfo2.getSelectedProfileId();
          SCProfileInstance profileInstance =
              scpManager.getSCProfileInstance(project, infoContext, selectedProfileId);

          IScannerInfoCollector collector = profileInstance.getScannerInfoCollector();
          if (collector instanceof IScannerInfoCollectorCleaner) {
            ((IScannerInfoCollectorCleaner) collector).deleteAll(project);
          }
          buildInfo2 = null;
        }
      }
    }

    ManagedBuildManager.saveBuildInfo(project, true);
  }