eList;
import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Streams;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Optional;
import java.util.SortedSet;

/** A build rule which compiles one or more Swift sources into a Swift module. */
public class SwiftCompile extends AbstractBuildRule implements SupportsInputBasedRuleKey {

  private static final String INCLUDE_FLAG = "-I";

  @AddToRuleKey private final Tool swiftCompiler;

  @AddToRuleKey private final String moduleName;

  @AddToRuleKey(stringify = true)
  private final Path outputPath;

  @AddToRuleKey(stringify = true)
  private final Path objectFilePath;
  @AddToRuleKey(stringify = true)
  private final Path modulePath;
  @AddToRuleKey(stringify = true)
  private final Path moduleObjectPath;
  @AddToRuleKey(stringify = true)
  private final ImmutableList<Path> objectPaths;
  private final Optional<AbsPath> swiftFileListPath;

  @AddToRuleKey private final boolean shouldEmitSwiftdocs;
  @AddToRuleKey private final boolean useModulewrap;
  @AddToRuleKey private final boolean compileForceCache;
  @AddToRuleKey(stringify = true)
  private final Path swiftdocPath;

  @AddToRuleKey private final ImmutableSortedSet<SourcePath> srcs;
  @AddToRuleKey private final SwiftTargetTriple swiftTarget;
  @AddToRuleKey private final Optional<String> version;
  @AddToRuleKey private final ImmutableList<? extends Arg> compilerFlags;

  @AddToRuleKey(stringify = true)
  private final Path headerPath;
  @AddToRuleKey private final ImmutableSet<FrameworkPath> frameworks;
  @AddToRuleKey private final AddsToRuleKeyFunction<FrameworkPath, Path> frameworkPathToSearchPath;
  @AddToRuleKey(stringify = true)
  private final Flavor flavor;

  @AddToRuleKey private final boolean enable