public function buildAll()

in src/build/APISourcesBuildStep.php [44:105]


  public function buildAll(): void {
    Log::i("\nFetching API sources...");
    if (HHAPIDocBuildStep::shouldSkip()) {
      Log::i("\n  ...not needed because the dependent step is being skipped.");
      return;
    }

    foreach (self::REPOSITORIES as $product => $spec) {
      $repo = $spec['name'];
      $local = C\lastx(Str\split($repo, '/'));
      $tag = PRODUCT_TAGS[$product];
      Log::i("\n  Fetching %s@%s...", $repo, $tag);
      $local_abs = Str\format('%s/api-sources/%s', LocalConfig::ROOT, $local);
      $tag_file = $local_abs.'/.tag';
      if (
        \file_exists($tag_file) &&
        \file_get_contents($tag_file) === self::getTagFileContent($product)
      ) {
        Log::i("\n  ...already present.");
        continue;
      }
      \shell_exec('rm -rf -- '.\escapeshellarg($local_abs));
      $gzipped = \file_get_contents(
        Str\format('https://github.com/%s/archive/%s.tar.gz', $repo, $tag),
      );
      Log::i("\n  Extracting tarball...");
      $tar = \gzdecode($gzipped);
      if ($tar === false) {
        Log::e("\ngzdecode failed.");
        exit(1);
      }
      Util\parse_tar(
        (string)$tar,
        ($metadata, $content) ==> {
          $path = Str\split($metadata['path'], '/')
            |> Vec\drop($$, 1)
            |> Str\join($$, '/');
          if (!C\any($spec['prefixes'], $p ==> Str\starts_with($path, $p))) {
            return;
          }
          $path = $local_abs.'/'.$path;
          $parent = \dirname($path);
          if (!\is_dir($parent)) {
            \mkdir($parent, /* mode = */ 0755, /* recursive = */ true);
          }
          switch ($metadata['type']) {
            case Util\TarEntryType::FILE:
              \file_put_contents($path, $content);
              break;
            case Util\TarEntryType::SYMLINK:
              \symlink($content as nonnull, $path);
              break;
            case Util\TarEntryType::DIRECTORY:
              \mkdir($path, 0755);
              break;
          }
          \chmod($path, $metadata['mode']);
        },
      );
      \file_put_contents($tag_file, self::getTagFileContent($product));
    }
  }