/*
* Copyright 2014-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.model.BuildTarget;
import com.facebook.buck.rules.AbstractBuildRule;
import com.facebook.buck.rules.BinaryBuildRule;
import com.facebook.buck.rules.BuildContext;
import com.facebook.buck.rules.BuildRule;
import com.facebook.buck.rules.BuildRuleParams;
import com.facebook.buck.rules.BuildableContext;
import com.facebook.buck.rules.CommandTool;
import com.facebook.buck.rules.ForwardingBuildTargetSourcePath;
import com.facebook.buck.rules.HasRuntimeDeps;
import com.facebook.buck.rules.SourcePath;
import com.facebook.buck.rules.Tool;
import com.facebook.buck.rules.args.SourcePathArg;
import com.facebook.buck.step.Step;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.stream.Stream;
public class OcamlBinary extends AbstractBuildRule implements BinaryBuildRule, HasRuntimeDeps {
private final BuildRule binary;
public OcamlBinary(BuildRuleParams params, BuildRule binary) {
super(params);
this.binary = binary;
}
@Override
public Tool getExecutableCommand() {
return new CommandTool.Builder()
.addArg(SourcePathArg.of(Preconditions.checkNotNull(binary.getSourcePathToOutput())))
.build();
}
@Override
public ImmutableList<Step> getBuildSteps(
BuildContext context, BuildableContext buildableContext) {
return ImmutableList.of();
}
@Override
public SourcePath getSourcePathToOutput() {
return new ForwardingBuildTargetSourcePath(
getBuildTarget(), Preconditions.checkNotNull(binary.getSourcePathToOutput()));
}
// Since this rule doesn't actual generate the binary it references, and is just a wrapper for
// the real binary rule, mark that rule as a runtime dep.
@Override
public Stream<BuildTarget> getRuntimeDeps() {
return Stream.of(binary.getBuildTarget());
}
}