#!/usr/bin/make -f
include /usr/share/dpkg/pkg-info.mk
# Upstream version without the +ds repack suffix, and its series (3).
VERSION = $(firstword $(subst +, ,$(DEB_VERSION_UPSTREAM)))
SERIES = $(word 1,$(subst ., ,$(VERSION)))
# Version string of the intermediate compilers. The compiler that builds the
# shipped jars writes its version into every TASTy file; upstream builds its
# published jars with its non-bootstrapped compiler, so their TASTy files say
# "3.9.0-bin-nonbootstrapped". Using the same string keeps ours identical.
# The shipped jars themselves say $(VERSION).
INTERVERSION = $(VERSION)-bin-nonbootstrapped
# Abbreviated commit of the upstream tag, which upstream writes into
# compiler.properties (update it with the upstream version).
GITHASH = 777528f
YEAR := $(shell sed -n 's/^Copyright 2012-\([0-9]*\) EPFL$$/\1/p' NOTICE.md)
export JAVA_HOME = /usr/lib/jvm/default-java
export PATH := $(JAVA_HOME)/bin:$(PATH)
J = /usr/share/java
# Version-independent aliases of the build dependencies.
export ASM = /usr/share/maven-repo/org/scala-lang/modules/scala-asm/debian/scala-asm-debian.jar
export DEPS = $(ASM):$(J)/sbt-compiler-interface.jar:$(J)/sbt-util-interface.jar
# JLine 4, for the REPL (libjline4-java)
export JLINE = $(J)/jline4-reader.jar:$(J)/jline4-terminal.jar:$(J)/jline4-terminal-jni.jar:$(J)/jline4-native.jar
# scaladoc's dependencies and theirs (no jar names them in a Class-Path),
# in the scaladoc command and the build-time test (SDRT); for compiling
# also the JetBrains annotations, whose @NotNull marks in flexmark keep its
# types non-nullable under -Yexplicit-nulls, as on upstream's class path.
SDJARS = flexmark flexmark-ext-anchorlink flexmark-ext-autolink flexmark-ext-emoji \
flexmark-ext-gfm-strikethrough flexmark-ext-gfm-tasklist flexmark-ext-ins \
flexmark-ext-superscript flexmark-ext-tables flexmark-ext-wikilink \
flexmark-ext-yaml-front-matter flexmark-jira-converter flexmark-util flexmark-util-ast \
flexmark-util-builder flexmark-util-collection flexmark-util-data flexmark-util-dependency \
flexmark-util-format flexmark-util-html flexmark-util-misc flexmark-util-options \
flexmark-util-sequence flexmark-util-visitor autolink \
liqp strftime4j antlr4-runtime jackson-core jackson-databind jackson-datatype-jsr310 \
jsoup jackson3-core jackson3-databind jackson3-dataformat-yaml jackson-annotations \
snakeyaml-engine fastdoubleparser
empty :=
space := $(empty) $(empty)
SDRT = $(subst $(space),:,$(patsubst %,$(J)/%.jar,$(SDJARS)))
export SDCP = $(SDRT):$(J)/org.jetbrains.annotations-java8.jar
# highlight.js for scaladoc's pages (libjs-highlight.js)
export HLJS = /usr/share/javascript/highlight.js/highlight.min.js
# Browser bundles for the type hierarchy graph (node-d3, node-graphlib-dot,
# node-dagre-d3-renderer)
export D3JS = /usr/share/nodejs/d3/dist/d3.min.js
export GRAPHLIBDOTJS = /usr/share/nodejs/graphlib-dot/dist/graphlib-dot.min.js
export DAGRED3JS = /usr/share/nodejs/dagre-d3/dist/dagre-d3.min.js
GRAPHPKGS = node-d3 node-graphlib-dot node-dagre-d3-renderer
# Scala.js IR libraries for scaladoc's front end (scala-js-library); the
# linker is the scalajs-link command (scala-js)
export SJSLIB = $(J)/scalajs-library.jar:$(J)/scalajs-javalib.jar
export SJS_SCALALIB213 = $(J)/scalajs-scalalib.jar
# Two-pass self-host build (no sbt):
# pass 1 compiler = scala3 from the archive (Build-Depends)
# pass 2 compiler = the pass-1 output; only pass-2 jars are shipped
# For the one-time bootstrap (build profile pkg.scala.stage0) the first
# compiler is upstream's pinned reference compiler, from $(SCALA3_STAGE0),
# and an extra pass 0 comes first: a compiler built by that seed is not yet
# a fixed point (see debian/README.source), the next generation is.
SCALA3_STAGE0 ?= /usr/share/scala3-stage0
ifneq ($(filter pkg.scala.stage0,$(DEB_BUILD_PROFILES)),)
STAGE0 = yes
SEED_CP = $(SCALA3_STAGE0)/scala3-compiler_3.jar:$(SCALA3_STAGE0)/scala3-interfaces.jar:$(SCALA3_STAGE0)/tasty-core_3.jar:$(SCALA3_STAGE0)/scala-library.jar
else
SEED_CP = $(J)/scala3-compiler-$(SERIES).jar:$(J)/scala3-interfaces-$(SERIES).jar:$(J)/tasty-core-$(SERIES).jar:$(J)/scala-library-$(SERIES).jar
endif
# class path of the compiler built in a pass
ccp = $(1)/jars/scala3-compiler_3.jar:$(1)/jars/scala3-interfaces.jar:$(1)/jars/tasty-core_3.jar:$(1)/jars/scala-library.jar
export SRC = $(CURDIR)
export VERSION GITHASH YEAR
export S2LIB = $(CURDIR)/debian/s2lib
export FILES_TO_COPY = $(CURDIR)/debian/files-to-copy.txt
OUT0 = $(CURDIR)/debian/buildout0
OUT1 = $(CURDIR)/debian/buildout1
OUT2 = $(CURDIR)/debian/buildout2
DRV = debian/build-driver.sh
D = debian/scala3
DLIB = debian/scala3-library
SD = /usr/share/scala3
# POMs, and the jar names in /usr/share/java (no underscore; see debian/*.poms)
POMS = scala3-interfaces tasty-core_3 scala3-compiler_3 scala3-staging_3 scala3-tasty-inspector_3 \
scala3-directives-parser_3 scala3-repl_3 scala3-sbt-bridge scala-library scala3-library_3 scaladoc_3
JARS3 = scala3-interfaces tasty-core scala3-compiler scala3-staging scala3-tasty-inspector \
scala3-directives-parser scala3-repl scala3-sbt-bridge
JARSLIB = scala-library
%:
dh $@
override_dh_auto_build:
# The classes that replace part of the Scala 3 standard library:
# Scala 2.13 library sources compiled by scalac 2.13.
debian/build-scala2-library.sh $(CURDIR)/scala213-library/src/library $(S2LIB)
# Their list, from upstream's sbt build definition.
sed -n 's/^ *"\([^"]*\)",$$/\1/p' project/ScalaLibraryFilesToCopy.scala > $(FILES_TO_COPY)
test -s $(FILES_TO_COPY)
ifeq ($(STAGE0),yes)
# Pass 0 (stage0 only): build from the seed.
$(DRV) nonbootstrapped $(OUT0) $(SEED_CP) $(INTERVERSION)
$(DRV) bootstrapped $(OUT1) $(call ccp,$(OUT0)) $(INTERVERSION)
else
$(DRV) bootstrapped $(OUT1) $(SEED_CP) $(INTERVERSION)
endif
# The shipped pass also builds scaladoc.
SCALADOC=yes $(DRV) bootstrapped $(OUT2) $(call ccp,$(OUT1)) $(VERSION)
# The scaladoc command, with the class path of its dependencies.
sed 's|@SDRT@|$(SDRT)|' debian/scaladoc.in > debian/scaladoc
# POMs for the Maven repository (installed by maven-repo-helper).
set -e; for p in $(POMS); do \
sed "s/@VERSION@/$(VERSION)/g" debian/poms/$$p.pom.xml.in > debian/poms/$$p.pom.xml; \
done
override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
# Compile and run a small program with the pass-2 jars.
rm -rf debian/testout && mkdir -p debian/testout/classes
printf '%s\n' '@main def hello(): Unit =' \
' println("Hello from Scala " + scala.util.Properties.versionNumberString)' \
> debian/testout/Hello.scala
java -cp $(call ccp,$(OUT2)):$(DEPS) dotty.tools.dotc.Main \
-classpath $(OUT2)/jars/scala-library.jar -d debian/testout/classes debian/testout/Hello.scala
java -cp debian/testout/classes:$(OUT2)/jars/scala-library.jar hello \
| grep -qx 'Hello from Scala $(VERSION)'
# Evaluate one line in the REPL (dumb terminal, input from a pipe).
# (The REPL writes its history to user.home, which must be writable.)
printf 'println(6 * 7)\n' | TERM=dumb java --enable-native-access=ALL-UNNAMED \
-Duser.home=$(CURDIR)/debian/testout -Dscala.usejavacp=true -cp $(call ccp,$(OUT2)):$(DEPS):$(JLINE):$(OUT2)/jars/scala3-repl_3.jar:$(OUT2)/jars/scala3-directives-parser_3.jar \
dotty.tools.repl.Main -usejavacp -color:never > debian/testout/repl.txt 2>&1
cat -A debian/testout/repl.txt
tr -d '\r' < debian/testout/repl.txt | grep -qx 'scala> 42'
# Document a small library with the pass-2 scaladoc: the page and its
# doc comment are there, and no page loads anything from other sites.
printf '%s\n' 'package demo' '/** Greets people. */' 'object Greeter:' \
' /** The greeting for `name`. */' ' def greet(name: String): String = s"Hello, $$name"' \
> debian/testout/Greeter.scala
mkdir -p debian/testout/lib debian/testout/doc
java -cp $(call ccp,$(OUT2)):$(DEPS) dotty.tools.dotc.Main \
-classpath $(OUT2)/jars/scala-library.jar -d debian/testout/lib debian/testout/Greeter.scala
# (Run from debian/testout: scaladoc's default -siteroot is ./docs, and
# here that would be the Scala 3 reference documentation.)
cd debian/testout && java -cp $(OUT2)/jars/scaladoc_3.jar:$(OUT2)/jars/scala3-tasty-inspector_3.jar:$(call ccp,$(OUT2)):$(DEPS):$(SDRT) \
dotty.tools.scaladoc.Main -d doc -project demo -classpath $(OUT2)/jars/scala-library.jar lib
test ! -d debian/testout/doc/docs
grep -q 'Greets people.' 'debian/testout/doc/demo/Greeter$$.html'
grep -q 'The greeting for' 'debian/testout/doc/demo/Greeter$$.html'
! grep -rlE '<(script|img|iframe)[^>]* src="(https?:)?//|]* href="(https?:)?//' \
debian/testout/doc --include='*.html'
# The Scala.js front end is there, and the search data it reads.
test -s debian/testout/doc/scripts/scaladoc-scalajs.js
test -s debian/testout/doc/scripts/contributors.js
grep -q 'scaladoc-scalajs.js' 'debian/testout/doc/demo/Greeter$$.html'
grep -q 'Greeter' debian/testout/doc/scripts/searchData.js
# The type hierarchy graph: its DOT source in the page, its scripts
# local (the same files as the Debian packages').
grep -q 'id="dot"' 'debian/testout/doc/demo/Greeter$$.html'
cmp $(D3JS) debian/testout/doc/scripts/d3.min.js
cmp $(GRAPHLIBDOTJS) debian/testout/doc/scripts/graphlib-dot.min.js
cmp $(DAGRED3JS) debian/testout/doc/scripts/dagre-d3.min.js
grep -q 'src="../scripts/dagre-d3.min.js"' 'debian/testout/doc/demo/Greeter$$.html'
endif
override_dh_auto_install:
# The jars are installed by maven-repo-helper (debian/*.poms) as
# /usr/share/java/-$(VERSION).jar and in /usr/share/maven-repo;
# no unversioned names, scala-library.jar belongs to the default Scala.
install -d $(D)$(SD)/bin $(D)$(SD)/man/man1
install -m755 debian/scalac $(D)$(SD)/bin/scalac
install -m755 debian/scala-runner $(D)$(SD)/bin/scala
install -m644 debian/scalac.1 $(D)$(SD)/man/man1/scalac.1
install -m644 debian/scala.1 $(D)$(SD)/man/man1/scala.1
# The scaladoc command is in scala3 too, so that every slave of the
# scala alternative always has its target; without scala3-scaladoc it
# says which package to install.
install -m755 debian/scaladoc $(D)$(SD)/bin/scaladoc
install -m644 debian/scaladoc.1 $(D)$(SD)/man/man1/scaladoc.1
gzip -9n $(D)$(SD)/man/man1/*.1
execute_before_dh_gencontrol:
# highlight.js, the graph's scripts and the Scala.js library are built
# into the scaladoc jar (Static-Built-Using names their source packages).
echo "scaladoc:Static-Built-Using=$$(for p in libjs-highlight.js scala-js-library $(GRAPHPKGS); do \
dpkg-query -W -f '$${source:Package} (= $${source:Version}), ' $$p; done | sed 's/, $$//')" \
>> debian/scala3-scaladoc.substvars
execute_after_dh_installdocs:
# NOTICE files of the two other upstream projects whose code is built
# into the jars (Apache-2.0, section 4(d)).
install -D -m644 scalajs-ir/NOTICE $(D)/usr/share/doc/scala3/Scala.js/NOTICE
install -D -m644 scala213-library/NOTICE $(DLIB)/usr/share/doc/scala3-library/Scala-2/NOTICE
execute_after_dh_link:
# Series links (-3.jar), and the commands as -3.
set -e; for j in $(JARSLIB); do \
dh_link -pscala3-library usr/share/java/$$j-$(VERSION).jar usr/share/java/$$j-$(SERIES).jar; \
done
set -e; for j in $(JARS3); do \
dh_link -pscala3 usr/share/java/$$j-$(VERSION).jar usr/share/java/$$j-$(SERIES).jar; \
done
set -e; for c in scala scalac scaladoc; do \
dh_link -pscala3 $(SD)/bin/$$c usr/bin/$$c-$(SERIES); \
dh_link -pscala3 $(SD)/man/man1/$$c.1.gz usr/share/man/man1/$$c-$(SERIES).1.gz; \
done
dh_link -pscala3-scaladoc usr/share/java/scaladoc-$(VERSION).jar usr/share/java/scaladoc-$(SERIES).jar
override_dh_auto_clean:
rm -rf debian/buildout0 debian/buildout1 debian/buildout2 debian/s2lib \
debian/testout debian/files-to-copy.txt debian/poms/*.pom.xml debian/scaladoc