Skip to content

Commit

Permalink
Add .okbuck.buckconfig to .buckconfig (#929)
Browse files Browse the repository at this point in the history
Don't pass okbuck.buckconfig explicity to buck in the
buckwrapper to allow overriding configs in .okbuck.buckconfig

Bump Kotlin to 1.4.10 and incorporate Subplugin changes

Bump buck to a68ef0d834eec5fe381cb3e8e8612ba9fa42a09d. The latest version
has changes to kotlin params which will require further changes when updating.

Resolves #927
  • Loading branch information
raviagarwal7 authored Nov 10, 2020
1 parent e0bfe82 commit 723c2e3
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .buckconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<file:.okbuck/config/okbuck.buckconfig>

[project]
allow_symlinks = forbid
ide = intellij
Expand Down Expand Up @@ -48,5 +50,3 @@

[scala]
target_level = jvm-1.8

<file:.okbuck/config/okbuck.buckconfig>
9 changes: 0 additions & 9 deletions buckw
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,6 @@ setupBuckRun ( ) {
fi
}
setupBuckFlags ( ) {
EXTRA_BUCK_CONFIG="$EXTRA_BUCK_CONFIG --config-file .okbuck/config/okbuck.buckconfig"
}
# Handle parameters and flags
handleParams ( ) {
SKIP_FLAGS=""
Expand All @@ -239,11 +235,6 @@ handleParams ( ) {
--version) export SKIP_FLAGS=1;;
esac;
done
if [[ -z "$SKIP_FLAGS" ]]; then
# --help|-h|help|kill|--version do not support --config-file
setupBuckFlags
fi
}
handleParams "$@"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
Expand All @@ -42,7 +41,6 @@
import javax.annotation.Nullable;
import org.gradle.api.JavaVersion;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.UnknownDomainObjectException;
import org.gradle.api.UnknownTaskException;
import org.gradle.api.artifacts.Configuration;
Expand All @@ -55,15 +53,16 @@
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.compile.AbstractCompile;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.api.tasks.testing.Test;
import org.gradle.jvm.tasks.Jar;
import org.jetbrains.kotlin.allopen.gradle.AllOpenKotlinGradleSubplugin;
import org.jetbrains.kotlin.allopen.gradle.AllOpenGradleSubplugin;
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions;
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension;
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper;
import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin;
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation;
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption;
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation;
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile;

public class JvmTarget extends Target {
Expand Down Expand Up @@ -91,8 +90,6 @@ public class JvmTarget extends Target {
private final SourceSetContainer sourceSets;
protected final boolean isKotlin;

@Nullable private final AbstractCompile fakeCompile;

public JvmTarget(Project project, String name) {
this(
project,
Expand All @@ -115,10 +112,6 @@ public JvmTarget(
sourceSets = getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
isKotlin =
project.getPlugins().stream().anyMatch(plugin -> plugin instanceof KotlinBasePluginWrapper);

Optional<Task> compileTask =
project.getTasks().stream().filter(it -> it instanceof AbstractCompile).findFirst();
fakeCompile = (AbstractCompile) compileTask.orElse(null);
}

/**
Expand Down Expand Up @@ -477,15 +470,13 @@ public Map<String, List<String>> getKotlinFriendPaths(boolean isTest) {
}

protected List<String> getKotlinCompilerPlugins() {
ImmutableList.Builder<String> pluginBuilder = ImmutableList.builder();
if (getProject().getPlugins().hasPlugin(KotlinManager.KOTLIN_ALLOPEN_MODULE)) {
AllOpenKotlinGradleSubplugin subPlugin = getAllOpenKotlinGradleSubplugin();
List<SubpluginOption> subpluginOptions = getAllOpenSubpluginOptions();

if (subPlugin != null && fakeCompile != null) {
pluginBuilder.add(KotlinManager.KOTLIN_AO_PLUGIN_TARGET);
}
if (subpluginOptions.size() > 0) {
return ImmutableList.of(KotlinManager.KOTLIN_AO_PLUGIN_TARGET);
} else {
return ImmutableList.of();
}
return pluginBuilder.build();
}

protected List<String> getKotlinCompilerOptions() {
Expand All @@ -495,20 +486,13 @@ protected List<String> getKotlinCompilerOptions() {

ImmutableList.Builder<String> optionBuilder = ImmutableList.builder();
optionBuilder.addAll(readKotlinCompilerArguments());
if (getProject().getPlugins().hasPlugin(KotlinManager.KOTLIN_ALLOPEN_MODULE)) {
AllOpenKotlinGradleSubplugin subPlugin = getAllOpenKotlinGradleSubplugin();

if (subPlugin != null && fakeCompile != null) {
List<SubpluginOption> options =
subPlugin.apply(getProject(), fakeCompile, fakeCompile, null, null, null);

for (SubpluginOption option : options) {
optionBuilder.add("-P");
optionBuilder.add(
"plugin:org.jetbrains.kotlin.allopen:" + option.getKey() + "=" + option.getValue());
}
}

for (SubpluginOption option : getAllOpenSubpluginOptions()) {
optionBuilder.add("-P");
optionBuilder.add(
"plugin:org.jetbrains.kotlin.allopen:" + option.getKey() + "=" + option.getValue());
}

return optionBuilder.build();
}

Expand Down Expand Up @@ -587,15 +571,25 @@ private List<String> readKotlinCompilerArguments() {
}
}

@Nullable
private AllOpenKotlinGradleSubplugin getAllOpenKotlinGradleSubplugin() {
for (KotlinGradleSubplugin subplugin :
ServiceLoader.load(KotlinGradleSubplugin.class, getClass().getClassLoader())) {
if (subplugin instanceof AllOpenKotlinGradleSubplugin) {
return (AllOpenKotlinGradleSubplugin) subplugin;
}
private ImmutableList<SubpluginOption> getAllOpenSubpluginOptions() {
if (!getProject().getPlugins().hasPlugin(KotlinManager.KOTLIN_ALLOPEN_MODULE)) {
return ImmutableList.of();
}
return null;

KotlinSingleTargetExtension extension =
getProject().getExtensions().findByType(KotlinSingleTargetExtension.class);
if (extension == null) {
return ImmutableList.of();
}

AllOpenGradleSubplugin subPlugin =
(AllOpenGradleSubplugin)
getProject().getPlugins().getPlugin(KotlinManager.KOTLIN_ALLOPEN_MODULE);
KotlinCompilation fakeCompilation =
new KotlinCommonCompilation(extension.getTarget(), "fakeCompilation");
return new ImmutableList.Builder<SubpluginOption>()
.addAll(subPlugin.applyToCompilation(fakeCompilation).get())
.build();
}

@SuppressWarnings("NoFunctionalReturnType")
Expand Down
13 changes: 13 additions & 0 deletions buildSrc/src/main/java/com/uber/okbuck/core/task/OkBuckTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
import com.google.errorprone.annotations.Var;
import com.uber.okbuck.OkBuckGradlePlugin;
import com.uber.okbuck.composer.base.BuckRuleComposer;
import com.uber.okbuck.core.dependency.OExternalDependency;
Expand All @@ -16,6 +17,7 @@
import com.uber.okbuck.core.manager.ScalaManager;
import com.uber.okbuck.core.model.base.ProjectType;
import com.uber.okbuck.core.model.base.RuleType;
import com.uber.okbuck.core.util.FileUtil;
import com.uber.okbuck.core.util.ProguardUtil;
import com.uber.okbuck.core.util.ProjectUtil;
import com.uber.okbuck.extension.ExternalDependenciesExtension;
Expand Down Expand Up @@ -258,6 +260,17 @@ private void generate(
.getExternalDependenciesExtension()
.getGenerateMavenRepositories()))
.render(okbuckBuckConfig());

// Add entry of OkBuckBuckConfig to DotBuckConfig
String entry =
String.format(
"<file:%s>", FileUtil.getRelativePath(getProject().getRootDir(), okbuckBuckConfig()));

@Var String dotBuckContent = FileUtil.readString(dotBuckConfig());
if (!dotBuckContent.contains(entry)) {
dotBuckContent = entry + "\n\n" + dotBuckContent;
FileUtil.writeString(dotBuckConfig(), dotBuckContent);
}
}

private LinkedHashMap<String, String> repositoryMap(boolean downloadInBuck) {
Expand Down
16 changes: 16 additions & 0 deletions buildSrc/src/main/java/com/uber/okbuck/core/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ public static String getRelativePath(File root, File f) {
}
}

public static String readString(File f) {
try {
return new String(Files.readAllBytes(f.toPath()), UTF_8);
} catch (IOException e) {
throw new IllegalStateException("Failed to read from file " + f + " due to exception: " + e);
}
}

public static void writeString(File f, String content) {
try {
Files.write(f.toPath(), content.getBytes(UTF_8));
} catch (IOException e) {
throw new IllegalStateException("Failed to write to file " + f + " due to exception: " + e);
}
}

public static void copyResourceToProject(String resource, File destination) {
try {
FileUtils.copyURLToFile(FileUtil.class.getResource(resource), destination);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@SuppressWarnings("unused")
public class OkBuckExtension {

private static final String DEFAULT_BUCK_BINARY_SHA = "0299f0ff54201b700c06f8892862e1109d9739eb";
private static final String DEFAULT_BUCK_BINARY_SHA = "a68ef0d834eec5fe381cb3e8e8612ba9fa42a09d";

/** Build Tools Version */
@Input public String buildToolVersion = "28.0.2";
Expand Down Expand Up @@ -83,9 +83,7 @@ public class OkBuckExtension {
@Input public boolean legacyAnnotationProcessorSupport = true;

/** The prebuilt buck binary to use */
@Input
public String buckBinary =
"com.github.facebook:buck:" + DEFAULT_BUCK_BINARY_SHA + "@pex";
@Input public String buckBinary = "com.github.facebook:buck:" + DEFAULT_BUCK_BINARY_SHA + "@pex";

/** The prebuilt buck binary to use with java 11 */
@Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ setupBuckRun ( ) {
fi
}

setupBuckFlags ( ) {
EXTRA_BUCK_CONFIG="$EXTRA_BUCK_CONFIG --config-file .okbuck/config/okbuck.buckconfig"
}

# Handle parameters and flags
handleParams ( ) {
SKIP_FLAGS=""
Expand All @@ -236,11 +232,6 @@ handleParams ( ) {
--version) export SKIP_FLAGS=1;;
esac;
done

if [[ -z "$SKIP_FLAGS" ]]; then
# --help|-h|help|kill|--version do not support --config-file
setupBuckFlags
fi
}

handleParams "$@@"
Expand Down
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// CI keeps gradle home cached based on the SHA of this file.
// Update below to invalidate the cache.
// Gradle Cache Version 3
// Gradle Cache Version 4

def exclude = { dep, String... excludes ->
return dependencies.create(dep) {
Expand All @@ -24,7 +24,7 @@ def versions = [
butterKnife : "10.2.1",
dagger : "2.28.3",
jna : "5.6.0",
kotlin : "1.3.72",
kotlin : "1.4.10",
leakCanary : "1.5.4",
rocker : "1.3.0",
support : "28.0.0",
Expand Down
1 change: 1 addition & 0 deletions kotlin-app/src/test/java/com/uber/okbuck/example/Coffee.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,5 @@ interface CoffeeShop {
fun main(args: Array<String>) {
val coffee = DaggerCoffeeShop.builder().build()
coffee.maker().brew()
println(args)
}
1 change: 1 addition & 0 deletions libraries/kotlinlibrary/src/main/java/demo/helloWorld.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fun getGreeting(): String {
}

fun main(args: Array<String>) {
println(args)
println(getGreeting())
println(JavaClass().foo)
}

0 comments on commit 723c2e3

Please sign in to comment.