Skip to content

Commit

Permalink
cross-build for 2.13 (#287)
Browse files Browse the repository at this point in the history
* rebooting 213 port

* bijection-core: cross build 213

* bijection-json split 213

* bijection-util: use Future.apply instead of concurrent.future

* bijection-clojure: codegen updated for scalabug 11770

* bijection-json: re-unifiy shared code

* bijection-core: unify Bufferable
  • Loading branch information
Martijn Hoekstra authored and johnynek committed Jan 13, 2020
1 parent d8d37a4 commit f1aaa9d
Show file tree
Hide file tree
Showing 30 changed files with 1,810 additions and 190 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ matrix:
"++$TRAVIS_SCALA_VERSION clean"
"++$TRAVIS_SCALA_VERSION test"
- name: checks
- scala: 2.13.1
jdk: openjdk8
script:
- >
sbt
"++$TRAVIS_SCALA_VERSION clean"
"++$TRAVIS_SCALA_VERSION test"
- name: scalafmtCheck
scala: 2.12.10
jdk: openjdk8
script: sbt scalafmtCheckAll scalafmtSbtCheck
Expand Down
3 changes: 2 additions & 1 deletion bijection-clojure/codegen/Generator.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Run this generator like a script:
// scala Generator.scala > ../src/main/scala/com/twitter/bijection/clojure/GeneratedIFnBijections.scala
// scala Generator.scala > ../src/main/scala-2.12-/com/twitter/bijection/clojure/GeneratedIFnBijections.scala

/*
* Example of the code generated:
Expand Down Expand Up @@ -46,6 +46,7 @@ def implicitIFn(i: Int): String = {
}

println("// Autogenerated code DO NOT EDIT BY HAND")
println("// Generated by bijection-clojure/codegen/Generator.scala")
println("package com.twitter.bijection.clojure")
println("import clojure.lang.{ AFn, IFn }")
println("import com.twitter.bijection.{ AbstractBijection, Bijection, CastInjection }")
Expand Down
95 changes: 95 additions & 0 deletions bijection-clojure/codegen/GeneratorWorkaroundJava.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// This is a generator for java methods to forward to, as a workaround for
// scala bug#11770
//
// Run this generator like a script:
// scala GeneratorWorkaroundJava.scala > ../src/main/scala-2.13+/com/twitter/bijection/clojure/Workaround11770.java

def conversionN(n: Int) = {
val intypes = (1 to n).map(i => "I" + i.toString).toList
val invalues = intypes.map(_.toLowerCase)
val intv = intypes.zip(invalues).map{ case (t, v) => s"$t $v"}
val inobjv = invalues.map(v => s"Object $v")
val casts = intypes.zip(invalues).map{ case (t, v) => s"($t)$v"}
def render(args: List[String]) = args.mkString(", ")

s"""
public static final <O, ${render(intypes)}> Bijection<Function$n<${render(intypes)}, O>, IFn> function${n}ToIFn() {
return new AbstractBijection<Function$n<${render(intypes)}, O>, IFn>() {
public final AFn apply(Function${n}<${render(intypes)}, O> fna) {
final Function${n}<${render(intypes)}, O> fn = fna;
return new AFn() {
public final Object invoke(${render(inobjv)}) {
return (Object)fn.apply(${render(casts)});
}
};
}

public final Function${n}<${render(intypes)}, O> invert(IFn fna) {
final IFn fn = fna;
return new Function${n}<${render(intypes)}, O>(){
public final O apply(${render(intv)}) {
return (O)fn.invoke(${render(invalues)});
}
};
}
};
}
"""
}

val fileContents = s"""
/*
Copyright 2012 Twitter, 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.twitter.bijection.clojure;
import clojure.lang.AFn;
import clojure.lang.IFn;
import com.twitter.bijection.AbstractBijection;
import com.twitter.bijection.Bijection;

${(0 to 22).map(n => s"import scala.Function${n};").mkString("\n")}

public class Workaround11770 {

public static final <O> Bijection<Function0<O>, IFn> function0ToIFn() {
return new AbstractBijection<Function0<O>, IFn>() {
public final AFn apply(Function0<O> fna) {
final Function0<O> fn = fna;
return new AFn() {
public final Object invoke() {
return (Object)fn.apply();
}
};
}

public Function0<O> invert(IFn fna) {
final IFn fn = fna;
return new Function0<O>(){
public final O apply() {
return (O)fn.invoke();
}
};
}
};
}

${(1 to 22).map(conversionN).mkString("\n\n")}

}""";

println("// Autogenerated code DO NOT EDIT BY HAND")
println("// Generated by bijection-clojure/codegen/GeneratorWorkaroundJava.scala")
println(fileContents)
25 changes: 25 additions & 0 deletions bijection-clojure/codegen/GeneratorWorkaroundScala.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This is a generator to forward to the generated java methods
// as a workaround for scala bug#11770
//
// Run this generator like a script:
// scala GeneratorWorkaroundScala.scala > ../src/main/scala-2.13+/com/twitter/bijection/clojure/GenertedIFnBijections.scala

val letters = (('A' to 'Z').toList.inits.toList.reverse.tail).take(23)
def rot(l: List[Char]) = l.tail :+ l.head
val methods = letters.zipWithIndex.map { case (range, i) => s"""implicit def function${i}ToIFn[${range.mkString(", ")}]:
Bijection[Function${i}[${rot(range).mkString(", ")}], IFn] =
Workaround11770.function${i}ToIFn[${range.mkString(", ")}]
""" }

println("// Autogenerated code DO NOT EDIT BY HAND")
println("// Generated by bijection-clojure/codegen/GeneratorWorkaroundScala.scala")
println("package com.twitter.bijection.clojure")
println("import clojure.lang.{ AFn, IFn }")
println("import com.twitter.bijection.{ AbstractBijection, Bijection, CastInjection }")
println("\ntrait GeneratedIFnBijections {")

methods.foreach(method => {
println(method)
println
})
println("}")
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Autogenerated code DO NOT EDIT BY HAND
// Generated by bijection-clojure/codegen/Generator.scala
package com.twitter.bijection.clojure
import clojure.lang.{AFn, IFn}
import com.twitter.bijection.{AbstractBijection, Bijection}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Autogenerated code DO NOT EDIT BY HAND
// Generated by bijection-clojure/codegen/GeneratorWorkaroundScala.scala
package com.twitter.bijection.clojure
import clojure.lang.{AFn, IFn}
import com.twitter.bijection.{AbstractBijection, Bijection, CastInjection}

trait GeneratedIFnBijections {
implicit def function0ToIFn[A]: Bijection[Function0[A], IFn] =
Workaround11770.function0ToIFn[A]

implicit def function1ToIFn[A, B]: Bijection[Function1[B, A], IFn] =
Workaround11770.function1ToIFn[A, B]

implicit def function2ToIFn[A, B, C]: Bijection[Function2[B, C, A], IFn] =
Workaround11770.function2ToIFn[A, B, C]

implicit def function3ToIFn[A, B, C, D]: Bijection[Function3[B, C, D, A], IFn] =
Workaround11770.function3ToIFn[A, B, C, D]

implicit def function4ToIFn[A, B, C, D, E]: Bijection[Function4[B, C, D, E, A], IFn] =
Workaround11770.function4ToIFn[A, B, C, D, E]

implicit def function5ToIFn[A, B, C, D, E, F]: Bijection[Function5[B, C, D, E, F, A], IFn] =
Workaround11770.function5ToIFn[A, B, C, D, E, F]

implicit def function6ToIFn[A, B, C, D, E, F, G]: Bijection[Function6[B, C, D, E, F, G, A], IFn] =
Workaround11770.function6ToIFn[A, B, C, D, E, F, G]

implicit def function7ToIFn[A, B, C, D, E, F, G, H]
: Bijection[Function7[B, C, D, E, F, G, H, A], IFn] =
Workaround11770.function7ToIFn[A, B, C, D, E, F, G, H]

implicit def function8ToIFn[A, B, C, D, E, F, G, H, I]
: Bijection[Function8[B, C, D, E, F, G, H, I, A], IFn] =
Workaround11770.function8ToIFn[A, B, C, D, E, F, G, H, I]

implicit def function9ToIFn[A, B, C, D, E, F, G, H, I, J]
: Bijection[Function9[B, C, D, E, F, G, H, I, J, A], IFn] =
Workaround11770.function9ToIFn[A, B, C, D, E, F, G, H, I, J]

implicit def function10ToIFn[A, B, C, D, E, F, G, H, I, J, K]
: Bijection[Function10[B, C, D, E, F, G, H, I, J, K, A], IFn] =
Workaround11770.function10ToIFn[A, B, C, D, E, F, G, H, I, J, K]

implicit def function11ToIFn[A, B, C, D, E, F, G, H, I, J, K, L]
: Bijection[Function11[B, C, D, E, F, G, H, I, J, K, L, A], IFn] =
Workaround11770.function11ToIFn[A, B, C, D, E, F, G, H, I, J, K, L]

implicit def function12ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M]
: Bijection[Function12[B, C, D, E, F, G, H, I, J, K, L, M, A], IFn] =
Workaround11770.function12ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M]

implicit def function13ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N]
: Bijection[Function13[B, C, D, E, F, G, H, I, J, K, L, M, N, A], IFn] =
Workaround11770.function13ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N]

implicit def function14ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]
: Bijection[Function14[B, C, D, E, F, G, H, I, J, K, L, M, N, O, A], IFn] =
Workaround11770.function14ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]

implicit def function15ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]
: Bijection[Function15[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, A], IFn] =
Workaround11770.function15ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]

implicit def function16ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]
: Bijection[Function16[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, A], IFn] =
Workaround11770.function16ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]

implicit def function17ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R]
: Bijection[Function17[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, A], IFn] =
Workaround11770.function17ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R]

implicit def function18ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S]
: Bijection[Function18[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, A], IFn] =
Workaround11770.function18ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S]

implicit def function19ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T]
: Bijection[Function19[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, A], IFn] =
Workaround11770.function19ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T]

implicit def function20ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U]
: Bijection[Function20[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, A], IFn] =
Workaround11770.function20ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U]

implicit def function21ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V]
: Bijection[
Function21[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, A],
IFn
] =
Workaround11770
.function21ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V]

implicit def function22ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W]
: Bijection[
Function22[B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, A],
IFn
] =
Workaround11770
.function22ToIFn[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W]

}
Loading

0 comments on commit f1aaa9d

Please sign in to comment.