/*
 * 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.rules.modern;

import com.facebook.buck.core.model.BuildTarget;
import com.facebook.buck.io.filesystem.ProjectFilesystem;
import com.facebook.buck.model.BuildTargets;
import java.nio.file.Path;

class DefaultOutputPathResolver implements OutputPathResolver {
  private final ProjectFilesystem filesystem;
  private final BuildTarget buildTarget;

  DefaultOutputPathResolver(ProjectFilesystem projectFilesystem, BuildTarget buildTarget) {
    this.filesystem = projectFilesystem;
    this.buildTarget = buildTarget;
  }

  @Override
  public Path getTempPath() {
    return BuildTargets.getScratchPath(filesystem, buildTarget, "%s");
  }

  @Override
  public Path resolvePath(OutputPath outputPath) {
    if (outputPath instanceof PublicOutputPath) {
      return outputPath.getPath();
    }
    return getRootPath().resolve(outputPath.getPath());
  }

  @Override
  public Path getRootPath() {
    return BuildTargets.getGenPath(filesystem, buildTarget, "%s");
  }
}

@@ -906,75 +906,52 @@
 al P
-rojectFilesystem filesystem;%0A  private final BuildTarget buildTarge
+ath scratchRoot;%0A  private final Path genRoo
 t;%0A%0A
@@ -1050,67 +1050,219 @@
     
-this.filesystem = projectFilesystem;%0A    this.buildTarget =
+String format = buildTarget.isFlavored() ? %22%25s%22 : %22%25s__%22;%0A    this.scratchRoot = BuildTargets.getScratchPath(projectFilesystem, buildTarget, format);%0A    this.genRoot = BuildTargets.getGenPath(projectFilesystem,
  bui
@@ -1269,16 +1269,25 @@
 ldTarget
+, format)
 ;%0A  %7D%0A%0A 
@@ -1342,66 +1342,19 @@
 urn 
-BuildTargets.getScratchPath(filesystem, buildTarget, %22%25s%22)
+scratchRoot
 ;%0A  
@@ -1628,62 +1628,15 @@
 urn 
-BuildTargets.getGenPath(filesystem, buildTarget, %22%25s%22)
+genRoot
 ;%0A  

Append "__" to gen/scratch root path for unflavored targets