summaryrefslogtreecommitdiffstats
path: root/pkgs/development/compilers/scala/2.x.nix
blob: 5497b1909093072579a2ad0bf46c4ece8891eaae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
{
  stdenv,
  lib,
  fetchurl,
  makeWrapper,
  jre,
  gnugrep,
  coreutils,
  writeScript,
  common-updater-scripts,
  git,
  gnused,
  nix,
  majorVersion,
}:

let
  repo = "git@github.com:scala/scala.git";

  versionMap = {
    "2.12" = {
      version = "2.12.18";
      hash = "sha256-naIJCET+YPrbXln39F9aU3DBdnjcn7PYMmhDxETOA5g=";
      pname = "scala_2_12";
    };

    "2.13" = {
      version = "2.13.15";
      hash = "sha256-jXIZ0q2IHIHPdwmp5JU05s4S0Bft4Uc+r9Hpuyh8ObE=";
      pname = "scala_2_13";
    };
  };

in
with versionMap.${majorVersion};

stdenv.mkDerivation rec {
  inherit version;

  pname = "scala";

  src = fetchurl {
    inherit hash;
    url = "https://www.scala-lang.org/files/archive/scala-${version}.tgz";
  };

  propagatedBuildInputs = [ jre ];

  nativeBuildInputs = [ makeWrapper ];

  installPhase = ''
    runHook preInstall
    mkdir -p $out
    rm bin/*.bat
    mv * $out
    # put docs in correct subdirectory
    mkdir -p $out/share/doc
    mv $out/doc $out/share/doc/${pname}-${version}
    mv $out/man $out/share/man
    for p in $(ls $out/bin/) ; do
        wrapProgram $out/bin/$p \
          --prefix PATH ":" ${coreutils}/bin \
          --prefix PATH ":" ${gnugrep}/bin \
          --prefix PATH ":" ${jre}/bin \
          --set JAVA_HOME ${jre}
    done
    runHook postInstall
  '';

  doInstallCheck = true;
  installCheckPhase = ''
    $out/bin/scalac -version 2>&1 | grep '^Scala compiler version ${version}'

    echo 'println("foo"*3)' | $out/bin/scala 2>/dev/null | grep "foofoofoo"
  '';

  passthru = {
    updateScript = writeScript "update.sh" ''
      #!${stdenv.shell}
      set -o errexit
      PATH=${
        lib.makeBinPath [
          common-updater-scripts
          coreutils
          git
          gnused
          nix
        ]
      }
      versionSelect='v${lib.versions.major version}.${lib.versions.minor version}.*'
      oldVersion="$(nix-instantiate --eval -E "with import ./. {}; lib.getVersion ${pname}" | tr -d '"')"
      latestTag="$(git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags ${repo} "$versionSelect" | tail --lines=1 | cut --delimiter='/' --fields=3 | sed 's|^v||g')"
      if [ "$oldVersion" != "$latestTag" ]; then
        update-source-version ${pname} "$latestTag" --version-key=version --print-changes
      else
        echo "${pname} is already up-to-date"
      fi
    '';
  };

  meta = {
    description = "General purpose programming language";
    longDescription = ''
      Scala is a general purpose programming language designed to express
      common programming patterns in a concise, elegant, and type-safe way.
      It smoothly integrates features of object-oriented and functional
      languages, enabling Java and other programmers to be more productive.
      Code sizes are typically reduced by a factor of two to three when
      compared to an equivalent Java application.
    '';
    homepage = "https://www.scala-lang.org/";
    license = lib.licenses.bsd3;
    platforms = lib.platforms.all;
    branch = lib.versions.majorMinor version;
    maintainers = with lib.maintainers; [
      kashw2
    ];
  };
}