static sanitizeCommand(
    sourceFile: string,
    args_: Array<string>,
    basePath: string,
  ): Array<string> {
    // Make a mutable copy.
    let args = [...args_];
    // For safety, create a new copy of the array. We exclude the path to the file to compile from
    // compilation database generated by Buck. It must be removed from the list of command-line
    // arguments passed to libclang.
    const normalizedSourceFile = nuclideUri.normalize(sourceFile);
    args = args.filter(
      arg =>
        normalizedSourceFile !== arg &&
        normalizedSourceFile !== nuclideUri.resolve(basePath, arg),
    );

    // Resolve relative path arguments against the Buck project root.
    args = mapPathsInFlags(args, path_ => {
      let path = overrideIncludePath(path_);
      if (!nuclideUri.isAbsolute(path)) {
        path = nuclideUri.join(basePath, path);
      }
      return path;
    });

    // If an output file is specified, remove that argument.
    const index = args.indexOf('-o');
    if (index !== -1) {
      args.splice(index, 2);
    }

    return args;
  }
Beispiel #2
0
function processGrepResult(
  result: string,
  headerFile: string,
  includeRegex: RegExp,
): ?string {
  const splitIndex = result.indexOf('\0');
  if (splitIndex === -1) {
    return null;
  }
  const filename = result.substr(0, splitIndex);
  if (!isSourceFile(filename)) {
    return null;
  }
  const match = includeRegex.exec(result.substr(splitIndex + 1));
  if (match == null) {
    return null;
  }
  // Source-relative includes have to be verified.
  // Relative paths will match the (../)* rule (at index 2).
  if (match[2] != null) {
    const includePath = nuclideUri.normalize(
      nuclideUri.join(nuclideUri.dirname(filename), match[1]),
    );
    if (includePath !== headerFile) {
      return null;
    }
  }
  return filename;
}
Beispiel #3
0
 createDirectory(
   uri: NuclideUri,
   hgRepositoryDescription: ?HgRepositoryDescription,
   symlink: boolean = false,
 ): RemoteDirectory {
   let {path} = nuclideUri.parse(uri);
   path = nuclideUri.normalize(path);
   return new RemoteDirectory(this, this.getUriOfRemotePath(path), symlink, {
     hgRepositoryDescription,
   });
 }
Beispiel #4
0
 createFile(uri: NuclideUri, symlink: boolean = false): RemoteFile {
   let {path} = nuclideUri.parse(uri);
   path = nuclideUri.normalize(path);
   return new RemoteFile(this, this.getUriOfRemotePath(path), symlink);
 }
Beispiel #5
0
 _isRoot(filePath_: string): boolean {
   let filePath = filePath_;
   filePath = nuclideUri.normalize(filePath);
   const parts = nuclideUri.parsePath(filePath);
   return parts.root === filePath;
 }