DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Git (975a35c0f5)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
'use strict';
/**
 * This script scans the app directories and output them to GAIA_APPDIRS in
 * Makefile. Please note that we use utils.stdout to pass the result over.
 */

const utils = require('./utils');

var ScanAppdir = function() {
  var GAIA_APP_CONFIG = utils.getEnv('GAIA_APP_CONFIG');
  var GAIA_DIR = utils.getEnv('GAIA_DIR');
  var GAIA_DISTRIBUTION_DIR = utils.getEnv('GAIA_DISTRIBUTION_DIR');
  var GAIA_APP_SRCDIRS = utils.getEnv('GAIA_APP_SRCDIRS');
  var appListFile = utils.getFile(GAIA_APP_CONFIG);
  this.appList = utils.getFileContent(appListFile.exists() ?
    appListFile : utils.getFile(GAIA_APP_SRCDIRS));

  this.gaiaDirPath = GAIA_DIR;
  this.gaiaDistributionPath = GAIA_DISTRIBUTION_DIR;
  this.allAppList = [];
};

ScanAppdir.prototype.scanAppAndDistributionFolder = function(src, recursive) {
  var gaiaAppFolder = utils.getFile(this.gaiaDirPath, src);
  var distributionAppFolder;
  try {
    distributionAppFolder = utils.getFile(this.gaiaDistributionPath, src);
  } catch (e) {
    distributionAppFolder = null;
  }
  if (recursive) {
    utils.ls(distributionAppFolder, false, true).forEach(function(subFolder) {
      this.pushPathSrc(subFolder);
    }, this);
    utils.ls(gaiaAppFolder, false, true).forEach(function(subFolder) {
      this.pushPathSrc(subFolder);
    }, this);
  } else {
    if (!this.pushPathSrc(distributionAppFolder)) {
      if (!this.pushPathSrc(gaiaAppFolder)) {
        this.pushPathSrc(src);
      }
    }
  }
};

ScanAppdir.prototype.pushPathSrc = function(srcFolder, path) {
  try {
    if (!srcFolder.exists() || !srcFolder.isDirectory()) {
      return false;
    }
    var appFolder = path ? utils.getFile(srcFolder.path, path) : srcFolder;
    if (appFolder.exists() && appFolder.isDirectory()) {
      this.allAppList.push(appFolder.path);
      return true;
    }
    return false;
  } catch (e) {
    return false;
  }
};

ScanAppdir.prototype.execute = function() {
  var baseSrc;
  this.appList.split('\n').forEach(function(src) {
    src = src.trim();
    if (!src || src === '') {
      return;
    }
    if (src[src.length - 1] === '*') {
      baseSrc = src.slice(0, src.length - 2);
      this.scanAppAndDistributionFolder(baseSrc, true);
    } else {
      this.scanAppAndDistributionFolder(src, false);
    }
  }, this);
};

function execute() {
  var appList;
  var scanAppDir = new ScanAppdir();
  scanAppDir.execute();
  appList = scanAppDir.allAppList.join(' ');
  utils.stdout((utils.getOsType().indexOf('WIN') !== -1) ?
    appList.replace(/\\/g, '\\\\') : appList);
}

exports.execute = execute;