/*
 * Copyright 2017-present Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.facebook.buck.ocaml;

import com.facebook.buck.cxx.toolchain.CompilerProvider;
import com.facebook.buck.cxx.toolchain.CxxPlatform;
import com.facebook.buck.cxx.toolchain.PreprocessorProvider;
import com.facebook.buck.rules.Tool;
import com.facebook.buck.toolchain.Toolchain;
import com.facebook.buck.util.immutables.BuckStyleImmutable;
import com.google.common.collect.ImmutableList;
import java.util.Optional;
import org.immutables.value.Value;

/** Abstracting the tooling/flags/libraries used to build OCaml rules. */
@Value.Immutable
@BuckStyleImmutable
interface AbstractOcamlPlatform extends Toolchain {

  Optional<Tool> getOcamlCompiler();

  Optional<Tool> getOcamlDepTool();

  Optional<Tool> getYaccCompiler();

  Optional<Tool> getLexCompiler();

  Optional<String> getOcamlInteropIncludesDir();

  Optional<String> getWarningsFlags();

  Optional<Tool> getOcamlBytecodeCompiler();

  Optional<Tool> getOcamlDebug();

  CompilerProvider getCCompiler();

  PreprocessorProvider getCPreprocessor();

  CompilerProvider getCxxCompiler();

  /** @return all C/C++ platform flags used to preprocess, compiler, and assemble C sources. */
  ImmutableList<String> getCFlags();

  ImmutableList<String> getLdFlags();

  /** @return the {@link CxxPlatform} to use for C/C++ dependencies. */
  CxxPlatform getCxxPlatform();
}

@@ -796,32 +796,121 @@
 cessorProvider;%0A
+import com.facebook.buck.model.Flavor;%0Aimport com.facebook.buck.model.FlavorConvertible;%0A
 import com.faceb
@@ -930,16 +930,16 @@
 s.Tool;%0A
-
 import c
@@ -1308,18 +1308,388 @@
 oolchain
- %7B
+, FlavorConvertible %7B%0A%0A  // TODO: For now, we rely on OCaml platforms having the same %22name%22 as the C/C++ platforms they%0A  // wrap, due to having to lookup the OCaml platform in the C/C++ interfaces that OCaml rules%0A  // implement, into which only C/C++ platform objects are threaded.%0A  @Override%0A  default Flavor getFlavor() %7B%0A    return getCxxPlatform().getFlavor();%0A  %7D
 %0A%0A  Opti

make `OcamlPlatform` a flavor convertible