Skip to content

Commit 723c2e3

Browse files
authored
Add .okbuck.buckconfig to .buckconfig (#929)
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
1 parent e0bfe82 commit 723c2e3

File tree

10 files changed

+70
-65
lines changed

10 files changed

+70
-65
lines changed

.buckconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<file:.okbuck/config/okbuck.buckconfig>
2+
13
[project]
24
allow_symlinks = forbid
35
ide = intellij
@@ -48,5 +50,3 @@
4850

4951
[scala]
5052
target_level = jvm-1.8
51-
52-
<file:.okbuck/config/okbuck.buckconfig>

buckw

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,6 @@ setupBuckRun ( ) {
225225
fi
226226
}
227227
228-
setupBuckFlags ( ) {
229-
EXTRA_BUCK_CONFIG="$EXTRA_BUCK_CONFIG --config-file .okbuck/config/okbuck.buckconfig"
230-
}
231-
232228
# Handle parameters and flags
233229
handleParams ( ) {
234230
SKIP_FLAGS=""
@@ -239,11 +235,6 @@ handleParams ( ) {
239235
--version) export SKIP_FLAGS=1;;
240236
esac;
241237
done
242-
243-
if [[ -z "$SKIP_FLAGS" ]]; then
244-
# --help|-h|help|kill|--version do not support --config-file
245-
setupBuckFlags
246-
fi
247238
}
248239
249240
handleParams "$@"

buildSrc/src/main/java/com/uber/okbuck/core/model/jvm/JvmTarget.java

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.util.List;
3434
import java.util.Map;
3535
import java.util.Optional;
36-
import java.util.ServiceLoader;
3736
import java.util.Set;
3837
import java.util.concurrent.ConcurrentHashMap;
3938
import java.util.function.Function;
@@ -42,7 +41,6 @@
4241
import javax.annotation.Nullable;
4342
import org.gradle.api.JavaVersion;
4443
import org.gradle.api.Project;
45-
import org.gradle.api.Task;
4644
import org.gradle.api.UnknownDomainObjectException;
4745
import org.gradle.api.UnknownTaskException;
4846
import org.gradle.api.artifacts.Configuration;
@@ -55,15 +53,16 @@
5553
import org.gradle.api.plugins.JavaPluginConvention;
5654
import org.gradle.api.tasks.SourceSet;
5755
import org.gradle.api.tasks.SourceSetContainer;
58-
import org.gradle.api.tasks.compile.AbstractCompile;
5956
import org.gradle.api.tasks.compile.JavaCompile;
6057
import org.gradle.api.tasks.testing.Test;
6158
import org.gradle.jvm.tasks.Jar;
62-
import org.jetbrains.kotlin.allopen.gradle.AllOpenKotlinGradleSubplugin;
59+
import org.jetbrains.kotlin.allopen.gradle.AllOpenGradleSubplugin;
6360
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions;
61+
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension;
6462
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePluginWrapper;
65-
import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin;
63+
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation;
6664
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption;
65+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation;
6766
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile;
6867

6968
public class JvmTarget extends Target {
@@ -91,8 +90,6 @@ public class JvmTarget extends Target {
9190
private final SourceSetContainer sourceSets;
9291
protected final boolean isKotlin;
9392

94-
@Nullable private final AbstractCompile fakeCompile;
95-
9693
public JvmTarget(Project project, String name) {
9794
this(
9895
project,
@@ -115,10 +112,6 @@ public JvmTarget(
115112
sourceSets = getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
116113
isKotlin =
117114
project.getPlugins().stream().anyMatch(plugin -> plugin instanceof KotlinBasePluginWrapper);
118-
119-
Optional<Task> compileTask =
120-
project.getTasks().stream().filter(it -> it instanceof AbstractCompile).findFirst();
121-
fakeCompile = (AbstractCompile) compileTask.orElse(null);
122115
}
123116

124117
/**
@@ -477,15 +470,13 @@ public Map<String, List<String>> getKotlinFriendPaths(boolean isTest) {
477470
}
478471

479472
protected List<String> getKotlinCompilerPlugins() {
480-
ImmutableList.Builder<String> pluginBuilder = ImmutableList.builder();
481-
if (getProject().getPlugins().hasPlugin(KotlinManager.KOTLIN_ALLOPEN_MODULE)) {
482-
AllOpenKotlinGradleSubplugin subPlugin = getAllOpenKotlinGradleSubplugin();
473+
List<SubpluginOption> subpluginOptions = getAllOpenSubpluginOptions();
483474

484-
if (subPlugin != null && fakeCompile != null) {
485-
pluginBuilder.add(KotlinManager.KOTLIN_AO_PLUGIN_TARGET);
486-
}
475+
if (subpluginOptions.size() > 0) {
476+
return ImmutableList.of(KotlinManager.KOTLIN_AO_PLUGIN_TARGET);
477+
} else {
478+
return ImmutableList.of();
487479
}
488-
return pluginBuilder.build();
489480
}
490481

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

496487
ImmutableList.Builder<String> optionBuilder = ImmutableList.builder();
497488
optionBuilder.addAll(readKotlinCompilerArguments());
498-
if (getProject().getPlugins().hasPlugin(KotlinManager.KOTLIN_ALLOPEN_MODULE)) {
499-
AllOpenKotlinGradleSubplugin subPlugin = getAllOpenKotlinGradleSubplugin();
500-
501-
if (subPlugin != null && fakeCompile != null) {
502-
List<SubpluginOption> options =
503-
subPlugin.apply(getProject(), fakeCompile, fakeCompile, null, null, null);
504-
505-
for (SubpluginOption option : options) {
506-
optionBuilder.add("-P");
507-
optionBuilder.add(
508-
"plugin:org.jetbrains.kotlin.allopen:" + option.getKey() + "=" + option.getValue());
509-
}
510-
}
489+
490+
for (SubpluginOption option : getAllOpenSubpluginOptions()) {
491+
optionBuilder.add("-P");
492+
optionBuilder.add(
493+
"plugin:org.jetbrains.kotlin.allopen:" + option.getKey() + "=" + option.getValue());
511494
}
495+
512496
return optionBuilder.build();
513497
}
514498

@@ -587,15 +571,25 @@ private List<String> readKotlinCompilerArguments() {
587571
}
588572
}
589573

590-
@Nullable
591-
private AllOpenKotlinGradleSubplugin getAllOpenKotlinGradleSubplugin() {
592-
for (KotlinGradleSubplugin subplugin :
593-
ServiceLoader.load(KotlinGradleSubplugin.class, getClass().getClassLoader())) {
594-
if (subplugin instanceof AllOpenKotlinGradleSubplugin) {
595-
return (AllOpenKotlinGradleSubplugin) subplugin;
596-
}
574+
private ImmutableList<SubpluginOption> getAllOpenSubpluginOptions() {
575+
if (!getProject().getPlugins().hasPlugin(KotlinManager.KOTLIN_ALLOPEN_MODULE)) {
576+
return ImmutableList.of();
597577
}
598-
return null;
578+
579+
KotlinSingleTargetExtension extension =
580+
getProject().getExtensions().findByType(KotlinSingleTargetExtension.class);
581+
if (extension == null) {
582+
return ImmutableList.of();
583+
}
584+
585+
AllOpenGradleSubplugin subPlugin =
586+
(AllOpenGradleSubplugin)
587+
getProject().getPlugins().getPlugin(KotlinManager.KOTLIN_ALLOPEN_MODULE);
588+
KotlinCompilation fakeCompilation =
589+
new KotlinCommonCompilation(extension.getTarget(), "fakeCompilation");
590+
return new ImmutableList.Builder<SubpluginOption>()
591+
.addAll(subPlugin.applyToCompilation(fakeCompilation).get())
592+
.build();
599593
}
600594

601595
@SuppressWarnings("NoFunctionalReturnType")

buildSrc/src/main/java/com/uber/okbuck/core/task/OkBuckTask.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.google.common.collect.ImmutableList;
88
import com.google.common.collect.Multimap;
99
import com.google.common.collect.TreeMultimap;
10+
import com.google.errorprone.annotations.Var;
1011
import com.uber.okbuck.OkBuckGradlePlugin;
1112
import com.uber.okbuck.composer.base.BuckRuleComposer;
1213
import com.uber.okbuck.core.dependency.OExternalDependency;
@@ -16,6 +17,7 @@
1617
import com.uber.okbuck.core.manager.ScalaManager;
1718
import com.uber.okbuck.core.model.base.ProjectType;
1819
import com.uber.okbuck.core.model.base.RuleType;
20+
import com.uber.okbuck.core.util.FileUtil;
1921
import com.uber.okbuck.core.util.ProguardUtil;
2022
import com.uber.okbuck.core.util.ProjectUtil;
2123
import com.uber.okbuck.extension.ExternalDependenciesExtension;
@@ -258,6 +260,17 @@ private void generate(
258260
.getExternalDependenciesExtension()
259261
.getGenerateMavenRepositories()))
260262
.render(okbuckBuckConfig());
263+
264+
// Add entry of OkBuckBuckConfig to DotBuckConfig
265+
String entry =
266+
String.format(
267+
"<file:%s>", FileUtil.getRelativePath(getProject().getRootDir(), okbuckBuckConfig()));
268+
269+
@Var String dotBuckContent = FileUtil.readString(dotBuckConfig());
270+
if (!dotBuckContent.contains(entry)) {
271+
dotBuckContent = entry + "\n\n" + dotBuckContent;
272+
FileUtil.writeString(dotBuckConfig(), dotBuckContent);
273+
}
261274
}
262275

263276
private LinkedHashMap<String, String> repositoryMap(boolean downloadInBuck) {

buildSrc/src/main/java/com/uber/okbuck/core/util/FileUtil.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ public static String getRelativePath(File root, File f) {
4545
}
4646
}
4747

48+
public static String readString(File f) {
49+
try {
50+
return new String(Files.readAllBytes(f.toPath()), UTF_8);
51+
} catch (IOException e) {
52+
throw new IllegalStateException("Failed to read from file " + f + " due to exception: " + e);
53+
}
54+
}
55+
56+
public static void writeString(File f, String content) {
57+
try {
58+
Files.write(f.toPath(), content.getBytes(UTF_8));
59+
} catch (IOException e) {
60+
throw new IllegalStateException("Failed to write to file " + f + " due to exception: " + e);
61+
}
62+
}
63+
4864
public static void copyResourceToProject(String resource, File destination) {
4965
try {
5066
FileUtils.copyURLToFile(FileUtil.class.getResource(resource), destination);

buildSrc/src/main/java/com/uber/okbuck/extension/OkBuckExtension.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@SuppressWarnings("unused")
1616
public class OkBuckExtension {
1717

18-
private static final String DEFAULT_BUCK_BINARY_SHA = "0299f0ff54201b700c06f8892862e1109d9739eb";
18+
private static final String DEFAULT_BUCK_BINARY_SHA = "a68ef0d834eec5fe381cb3e8e8612ba9fa42a09d";
1919

2020
/** Build Tools Version */
2121
@Input public String buildToolVersion = "28.0.2";
@@ -83,9 +83,7 @@ public class OkBuckExtension {
8383
@Input public boolean legacyAnnotationProcessorSupport = true;
8484

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

9088
/** The prebuilt buck binary to use with java 11 */
9189
@Input

buildSrc/src/main/rocker/com/uber/okbuck/template/config/BuckWrapper.rocker.raw

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,6 @@ setupBuckRun ( ) {
222222
fi
223223
}
224224

225-
setupBuckFlags ( ) {
226-
EXTRA_BUCK_CONFIG="$EXTRA_BUCK_CONFIG --config-file .okbuck/config/okbuck.buckconfig"
227-
}
228-
229225
# Handle parameters and flags
230226
handleParams ( ) {
231227
SKIP_FLAGS=""
@@ -236,11 +232,6 @@ handleParams ( ) {
236232
--version) export SKIP_FLAGS=1;;
237233
esac;
238234
done
239-
240-
if [[ -z "$SKIP_FLAGS" ]]; then
241-
# --help|-h|help|kill|--version do not support --config-file
242-
setupBuckFlags
243-
fi
244235
}
245236

246237
handleParams "$@@"

dependencies.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// CI keeps gradle home cached based on the SHA of this file.
22
// Update below to invalidate the cache.
3-
// Gradle Cache Version 3
3+
// Gradle Cache Version 4
44

55
def exclude = { dep, String... excludes ->
66
return dependencies.create(dep) {
@@ -24,7 +24,7 @@ def versions = [
2424
butterKnife : "10.2.1",
2525
dagger : "2.28.3",
2626
jna : "5.6.0",
27-
kotlin : "1.3.72",
27+
kotlin : "1.4.10",
2828
leakCanary : "1.5.4",
2929
rocker : "1.3.0",
3030
support : "28.0.0",

kotlin-app/src/test/java/com/uber/okbuck/example/Coffee.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ interface CoffeeShop {
8383
fun main(args: Array<String>) {
8484
val coffee = DaggerCoffeeShop.builder().build()
8585
coffee.maker().brew()
86+
println(args)
8687
}

libraries/kotlinlibrary/src/main/java/demo/helloWorld.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fun getGreeting(): String {
1111
}
1212

1313
fun main(args: Array<String>) {
14+
println(args)
1415
println(getGreeting())
1516
println(JavaClass().foo)
1617
}

0 commit comments

Comments
 (0)