Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Add kotlin rules support to buck project
Browse files Browse the repository at this point in the history
Summary: Closes #1200

Reviewed By: krschultz, dsyang

fbshipit-source-id: 14f9282
  • Loading branch information
Gautam Korlam authored and facebook-github-bot committed Mar 2, 2017
1 parent e6c81cb commit 6fdc2ce
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/com/facebook/buck/cxx/BUCK.autodeps
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"//src/com/facebook/buck/util:process_executor",
"//src/com/facebook/buck/versions:types",
"//third-party/java/immutables:immutables",
"//third-party/java/jackson:jackson-databind"
"//third-party/java/jackson:jackson-databind",
"//third-party/java/jsr:jsr305"
],
"exported_deps" : [
"//src/com/facebook/buck/android:packageable",
Expand Down Expand Up @@ -87,8 +88,7 @@
"//src/com/facebook/buck/versions:translator",
"//src/com/facebook/buck/versions:versions",
"//third-party/java/guava:guava",
"//third-party/java/infer-annotations:infer-annotations",
"//third-party/java/jsr:jsr305"
"//third-party/java/infer-annotations:infer-annotations"
]
}
}
1 change: 0 additions & 1 deletion src/com/facebook/buck/file/BUCK.autodeps
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"//src/com/facebook/buck/event:event",
"//src/com/facebook/buck/model:model",
"//src/com/facebook/buck/rules:command_tool",
"//src/com/facebook/buck/rules/args:args",
"//src/com/facebook/buck/step/fs:fs",
"//src/com/facebook/buck/util:exceptions",
"//src/com/facebook/buck/zip:steps"
Expand Down
1 change: 0 additions & 1 deletion src/com/facebook/buck/go/BUCK.autodeps
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"//src/com/facebook/buck/io:executable-finder",
"//src/com/facebook/buck/log:api",
"//src/com/facebook/buck/rules:command_tool",
"//src/com/facebook/buck/rules/args:args",
"//src/com/facebook/buck/step/fs:fs",
"//src/com/facebook/buck/test/result/type:type",
"//src/com/facebook/buck/util:exceptions",
Expand Down
6 changes: 3 additions & 3 deletions src/com/facebook/buck/js/BUCK.autodeps
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"//src/com/facebook/buck/shell:worker_pool_factory",
"//src/com/facebook/buck/step/fs:fs",
"//src/com/facebook/buck/util:exceptions",
"//src/com/facebook/buck/util:util"
"//src/com/facebook/buck/util:util",
"//third-party/java/jsr:jsr305"
],
"exported_deps" : [
"//src/com/facebook/buck/android:packageable",
Expand All @@ -22,8 +23,7 @@
"//src/com/facebook/buck/shell:worker_tool",
"//src/com/facebook/buck/step:step",
"//third-party/java/guava:guava",
"//third-party/java/infer-annotations:infer-annotations",
"//third-party/java/jsr:jsr305"
"//third-party/java/infer-annotations:infer-annotations"
]
}
}
1 change: 0 additions & 1 deletion src/com/facebook/buck/jvm/java/BUCK.autodeps
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"//src/com/facebook/buck/maven:util",
"//src/com/facebook/buck/model:build_id",
"//src/com/facebook/buck/rules:command_tool",
"//src/com/facebook/buck/rules/args:args",
"//src/com/facebook/buck/shell:steps",
"//src/com/facebook/buck/step/fs:fs",
"//src/com/facebook/buck/test/result/type:type",
Expand Down
1 change: 1 addition & 0 deletions src/com/facebook/buck/jvm/java/intellij/BUCK.autodeps
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"//src/com/facebook/buck/jvm/java:packagefinder",
"//src/com/facebook/buck/jvm/java:rules",
"//src/com/facebook/buck/jvm/java:support",
"//src/com/facebook/buck/jvm/kotlin:kotlin",
"//src/com/facebook/buck/log:api",
"//src/com/facebook/buck/shell:steps",
"//src/com/facebook/buck/util:exceptions",
Expand Down
44 changes: 43 additions & 1 deletion src/com/facebook/buck/jvm/java/intellij/IjModuleFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.facebook.buck.jvm.java.JavaTestDescription;
import com.facebook.buck.jvm.java.JavacOptions;
import com.facebook.buck.jvm.java.JvmLibraryArg;
import com.facebook.buck.jvm.kotlin.KotlinLibraryDescription;
import com.facebook.buck.jvm.kotlin.KotlinTestDescription;
import com.facebook.buck.model.BuildTarget;
import com.facebook.buck.model.BuildTargets;
import com.facebook.buck.rules.Description;
Expand Down Expand Up @@ -72,7 +74,9 @@ public class IjModuleFactory {
JavaTestDescription.class,
RobolectricTestDescription.class,
GroovyLibraryDescription.class,
GroovyTestDescription.class);
GroovyTestDescription.class,
KotlinLibraryDescription.class,
KotlinTestDescription.class);

/**
* Rule describing which aspects of the supplied {@link TargetNode} to transfer to the
Expand Down Expand Up @@ -125,6 +129,8 @@ public IjModuleFactory(
addToIndex(new RobolectricTestModuleRule());
addToIndex(new GroovyLibraryModuleRule());
addToIndex(new GroovyTestModuleRule());
addToIndex(new KotlinLibraryModuleRule());
addToIndex(new KotlinTestModuleRule());

this.moduleFactoryResolver = moduleFactoryResolver;

Expand Down Expand Up @@ -677,6 +683,42 @@ public void apply(TargetNode<JavaTestDescription.Arg, ?> target, ModuleBuildCont
}
}

private class KotlinLibraryModuleRule implements IjModuleRule<KotlinLibraryDescription.Arg> {

@Override
public Class<? extends Description<?>> getDescriptionClass() {
return KotlinLibraryDescription.class;
}

@Override
public void apply(
TargetNode<KotlinLibraryDescription.Arg, ?> target,
ModuleBuildContext context) {
addDepsAndSources(
target,
false /* wantsPackagePrefix */,
context);
}
}

private class KotlinTestModuleRule implements IjModuleRule<KotlinTestDescription.Arg> {

@Override
public Class<? extends Description<?>> getDescriptionClass() {
return KotlinTestDescription.class;
}

@Override
public void apply(
TargetNode<KotlinTestDescription.Arg, ?> target,
ModuleBuildContext context) {
addDepsAndTestSources(
target,
false /* wantsPackagePrefix */,
context);
}
}

private class RobolectricTestModuleRule extends JavaTestModuleRule {

@Override
Expand Down
1 change: 0 additions & 1 deletion test/com/facebook/buck/android/BUCK.autodeps
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@
"//src/com/facebook/buck/rules:build_rule",
"//src/com/facebook/buck/rules:rule_key",
"//src/com/facebook/buck/rules:rules",
"//src/com/facebook/buck/rules/args:args",
"//src/com/facebook/buck/rules/coercer:coercer",
"//src/com/facebook/buck/rules/keys:keys",
"//src/com/facebook/buck/rules/query:types",
Expand Down
1 change: 1 addition & 0 deletions test/com/facebook/buck/cxx/BUCK.autodeps
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"//src/com/facebook/buck/util:util",
"//src/com/facebook/buck/util/cache:cache",
"//src/com/facebook/buck/util/environment:platform",
"//src/com/facebook/buck/util/sha1:sha1",
"//src/com/facebook/buck/versions:translator",
"//src/com/facebook/buck/versions:types",
"//src/com/facebook/buck/versions:versions",
Expand Down
2 changes: 1 addition & 1 deletion test/com/facebook/buck/eden/cli/BUCK.autodeps
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"cli" : {
"deps" : [
"//src/com/facebook/buck/eden:eden",
"//src/com/facebook/buck/util/sha1:sha1",
"//third-party/java/guava:guava"
],
"exported_deps" : [
"//src/com/facebook/buck/eden:eden",
"//third-party/java/args4j:args4j",
"//third-party/java/infer-annotations:infer-annotations"
]
Expand Down
1 change: 1 addition & 0 deletions test/com/facebook/buck/jvm/java/intellij/BUCK.autodeps
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"//test/com/facebook/buck/jvm/java:fakepackagefinder",
"//test/com/facebook/buck/jvm/java:javac-env",
"//test/com/facebook/buck/jvm/java:testutil",
"//test/com/facebook/buck/jvm/kotlin:testutil",
"//test/com/facebook/buck/model:testutil",
"//test/com/facebook/buck/rules:testutil",
"//test/com/facebook/buck/shell:testutil",
Expand Down
26 changes: 26 additions & 0 deletions test/com/facebook/buck/jvm/java/intellij/IjModuleFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.facebook.buck.jvm.java.JavaLibraryBuilder;
import com.facebook.buck.jvm.java.JavaTestBuilder;
import com.facebook.buck.jvm.java.JvmLibraryArg;
import com.facebook.buck.jvm.kotlin.KotlinLibraryBuilder;
import com.facebook.buck.model.BuildTarget;
import com.facebook.buck.model.BuildTargetFactory;
import com.facebook.buck.rules.BuildRuleResolver;
Expand Down Expand Up @@ -337,6 +338,31 @@ public void testGroovyLibrary() {
assertFalse(folder.getWantsPackagePrefix());
}

@Test
public void testKotlinLibrary() {
IjModuleFactory factory = createIjModuleFactory();

TargetNode<?, ?> kotlinLib = KotlinLibraryBuilder
.createBuilder(BuildTargetFactory.newInstance("//kotlin/com/example/base:base"))
.addSrc(Paths.get("kotlin/com/example/base/File.kt"))
.build();

Path moduleBasePath = Paths.get("kotlin/com/example/base");
IjModule module = factory.createModule(
moduleBasePath,
ImmutableSet.<TargetNode<?, ?>>of(kotlinLib));

assertEquals(moduleBasePath, module.getModuleBasePath());
assertFalse(module.getAndroidFacet().isPresent());
assertEquals(1, module.getFolders().size());
assertEquals(ImmutableSet.of(kotlinLib), module.getTargets());

IjFolder folder = module.getFolders().iterator().next();
assertEquals(Paths.get("kotlin/com/example/base"), folder.getPath());
assertFalse(folder instanceof TestFolder);
assertFalse(folder.getWantsPackagePrefix());
}

@Test
public void testJavaLibraryInRoot() {
IjModuleFactory factory = createIjModuleFactory();
Expand Down
11 changes: 9 additions & 2 deletions test/com/facebook/buck/jvm/kotlin/BUCK.autodeps
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@
},
"testutil" : {
"deps" : [
"//src/com/facebook/buck/jvm/kotlin:kotlin",
"//src/com/facebook/buck/util:exceptions",
"//src/com/facebook/buck/util/environment:platform",
"//test/com/facebook/buck/cli:FakeBuckConfig",
"//test/com/facebook/buck/testutil:testutil",
"//third-party/java/junit:junit"
],
"exported_deps" : [ ]
"exported_deps" : [
"//src/com/facebook/buck/io:io",
"//src/com/facebook/buck/jvm/kotlin:kotlin",
"//src/com/facebook/buck/model:model",
"//src/com/facebook/buck/rules:build_rule",
"//test/com/facebook/buck/rules:testutil",
"//third-party/java/guava:guava"
]
}
}
60 changes: 60 additions & 0 deletions test/com/facebook/buck/jvm/kotlin/KotlinLibraryBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.jvm.kotlin;

import com.facebook.buck.io.ProjectFilesystem;
import com.facebook.buck.model.BuildTarget;
import com.facebook.buck.rules.AbstractNodeBuilder;
import com.facebook.buck.rules.BuildRule;
import com.facebook.buck.rules.PathSourcePath;
import com.facebook.buck.rules.SourcePath;
import com.facebook.buck.testutil.FakeProjectFilesystem;
import com.google.common.hash.HashCode;

import java.nio.file.Path;

public class KotlinLibraryBuilder
extends AbstractNodeBuilder<KotlinLibraryDescription.Arg, KotlinLibraryDescription, BuildRule> {

private final ProjectFilesystem projectFilesystem;

protected KotlinLibraryBuilder(
BuildTarget target,
ProjectFilesystem projectFilesystem,
HashCode hashCode) {
super(
new KotlinLibraryDescription(null, null),
target,
projectFilesystem,
hashCode);
this.projectFilesystem = projectFilesystem;
}

public static KotlinLibraryBuilder createBuilder(BuildTarget target) {
return new KotlinLibraryBuilder(target, new FakeProjectFilesystem(), null);
}

public KotlinLibraryBuilder addSrc(SourcePath path) {
arg.srcs = amend(arg.srcs, path);
return this;
}

public KotlinLibraryBuilder addSrc(Path path) {
return addSrc(new PathSourcePath(projectFilesystem, path));
}

}
1 change: 0 additions & 1 deletion test/com/facebook/buck/rules/BUCK.autodeps
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"//src/com/facebook/buck/rules:rules",
"//src/com/facebook/buck/rules:target_graph_hashing",
"//src/com/facebook/buck/rules:types",
"//src/com/facebook/buck/rules/args:args",
"//src/com/facebook/buck/rules/coercer:coercer",
"//src/com/facebook/buck/rules/coercer:types",
"//src/com/facebook/buck/rules/keys:keys",
Expand Down

0 comments on commit 6fdc2ce

Please sign in to comment.