/*
 * Copyright 2018-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.cxx;

import com.facebook.buck.core.rulekey.AddToRuleKey;
import com.facebook.buck.core.sourcepath.PathSourcePath;
import com.facebook.buck.core.sourcepath.SourcePath;
import com.facebook.buck.core.sourcepath.resolver.SourcePathResolver;
import com.facebook.buck.core.util.immutables.BuckStyleImmutable;
import com.facebook.buck.cxx.HeaderPathNormalizer.Builder;
import com.google.common.base.Preconditions;
import java.nio.file.Path;
import java.util.Optional;
import javax.annotation.Nullable;
import org.immutables.value.Value;

/** To support private_include_directories and public_include_directories */
@Value.Immutable
@BuckStyleImmutable
abstract class AbstractCxxIncludes extends CxxHeaders {

  @Override
  @Value.Parameter
  @AddToRuleKey
  public abstract CxxPreprocessables.IncludeType getIncludeType();

  @Nullable
  @Override
  public SourcePath getRoot() {
    return null;
  }

  @Override
  public Optional<SourcePath> getHeaderMap() {
    return Optional.empty();
  }

  @Override
  public void addToHeaderPathNormalizer(Builder builder) {}

  @Override
  public Optional<Path> getResolvedIncludeRoot(SourcePathResolver resolver) {
    return Optional.of(
        resolver.getAbsolutePath(Preconditions.checkNotNull(getIncludeDir())).normalize());
  }

  @Value.Parameter
  abstract PathSourcePath getIncludeDir();

  @AddToRuleKey
  @Value.Derived
  public String getIncludeDirPath() {
    return getIncludeDir().getRelativePath().toString();
  }
}

@@ -684,16 +684,197 @@
 uleKey;%0A
+import com.facebook.buck.core.rulekey.DefaultFieldSerialization;%0Aimport com.facebook.buck.core.rulekey.ExcludeFromRuleKey;%0Aimport com.facebook.buck.core.rulekey.IgnoredFieldInputs;%0A
 import c
@@ -914,32 +914,32 @@
 PathSourcePath;%0A
-
 import com.faceb
@@ -1509,17 +1509,16 @@
 aders %7B%0A
-%0A
   @Overr
@@ -1624,16 +1624,567 @@
 ype();%0A%0A
+  // TODO(cjhopman): The connection between this path and the corresponding headers and how the%0A  // rulekey is correctly handled shouldn't be so implicit, they should be next to each other.%0A  @Value.Parameter%0A  @ExcludeFromRuleKey(%0A      reason =%0A          %22This includeDir is used for constructing an include arg that likely points into the repo. The corresponding headers are added to rulekeys separately.%22,%0A      serialization = DefaultFieldSerialization.class,%0A      inputs = IgnoredFieldInputs.class)%0A  abstract PathSourcePath getIncludeDir();%0A%0A
   @Nulla
@@ -2629,76 +2629,13 @@
 ));%0A
+
   %7D%0A%0A
-  @Value.Parameter%0A  abstract PathSourcePath getIncludeDir();%0A%0A
   @A

Fix AbstractCxxIncludes rulekey/serialization/inputs