void findFiles(const String& searchDir, const StringVec& filePatterns, int fileType, bool recursive, StringList& results)
{
  struct dirent *entry;
  DIR *dir = opendir(searchDir.c_str());
  
  if (!dir) {
    SBLog::warning() << "Failed to open \"" << searchDir << "\" directory for file search." << std::endl;
    return;
  }
  
  while ((entry = readdir(dir))) {
    // Ignore . and .. so we dont accidentally recurse on them
    if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
      continue;
      
    // Get full path to entry
    String path = joinPaths(searchDir, entry->d_name);
    
    // Check if the file matches our search criteria
    if (entry->d_type == fileType && matchWildcardList(entry->d_name, filePatterns)) {
      results.push_back(path);
      continue;
    }
    
    // Possibly recurse
    if (entry->d_type == DT_DIR && recursive) {
      findFiles(path, filePatterns, fileType, recursive, results);
    }
  }

  closedir(dir);
}
void getRecursiveDirList(const String& baseDir, StringVec& dirVec, const StringVec& ignoreList)
{ 
  DIR* dir = opendir(baseDir.c_str());
  if (!dir)
    return;
    
  dirVec.push_back(baseDir);

  struct dirent* entry;
  while ((entry = readdir(dir))) {
    if (entry->d_type == DT_DIR) {
      String path = joinPaths(baseDir, entry->d_name);
         
      if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
        continue;
        
      if (matchWildcardList(entry->d_name, ignoreList))
        continue;
      
      getRecursiveDirList(path, dirVec, ignoreList);
    }
  }

  closedir(dir);
}
Esempio n. 3
0
SBTarget* SBTarget::getPossibleTarget(const PBXBuildFile* buildFile)
{
  static const char* const _productWildcards[] = {"lib*.a", "*.app", "*.framework"};
  static StringVec productWildcards(_productWildcards, _productWildcards + sizeof(_productWildcards) / sizeof(char*));

  sbAssert(buildFile);
  const PBXFile* file = buildFile->getFile();
  
  String filePath, fileName;
  if (file) {
    filePath = file->getFullPath();
    fileName = sb_basename(filePath);
  }

  SBTarget* depTarget = NULL;
  const PBXReferenceProxy* proxyFile = NULL;

  // We are interested in any potential Xcode build products
  if (!matchWildcardList(fileName, productWildcards)) {
    // Do nothing
  } else if ((proxyFile = dynamic_cast<const PBXReferenceProxy*>(file))) {
    // Construct base error string, to hopefully never be used
    String errStr = "Failed to process PBXBuildFile (" + buildFile->getId() + ") for " + getName() + " target. ";

    // Get remote proxy container
    const PBXContainerItemProxy* container = proxyFile->getContainer();

    // Ignore build file, if necessary
    if (!container) {
      SBLog::warning() << errStr << "Unable to get the PBXContainerItemProxy.";
      return NULL;
    }

    // Get remote project and target identifier from the proxy
    const String& remoteId = container->getRemoteId();
    String projectPath = container->getPortalPath();

    // Expand the project path
    const BuildSettings& projBS = m_parentProject.getBuildSettings();
    String absProjectPath = projBS.expand(projectPath, PathValue);
      
    // Try to open the remote project
    SBProject* remoteProject = SBWorkspace::get()->openProject(absProjectPath);

    // Try to queue up the target with the given product reference
    if (remoteProject) {
      depTarget = remoteProject->queueTargetWithProductReference(remoteId);
      if (!depTarget)
        SBLog::warning() << errStr << "Unable to create proxy target " << remoteId << " from the \"" << remoteProject->getName() << "\" project." << std::endl;
    } else {
      SBLog::warning() << errStr << "Unable to open referenced project path: " << projectPath << std::endl;
    }
  } else {
    // Look for target in current project first
    depTarget = m_parentProject.queueTargetWithProductName(fileName);

    // Look for target in workspace, if it hasn't been found already
    if (!depTarget)
      depTarget = SBWorkspace::get()->queueTargetWithProductName(fileName);
  }

  // Add the target to the dependency set
  addDependency(depTarget);

  // Indicate whether this was a dependency or not
  return depTarget;
}