summary refs log tree commit diff
path: root/pkgs/development/misc/resholve/oildev.nix
blob: 3e7dbc8e0108cca6ad38b70b8b88d595f6aa2efd (plain) (blame)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
{ lib
, stdenv
, python27
, callPackage
, fetchFromGitHub
, makeWrapper
, # re2c deps
  autoreconfHook
, # py-yajl deps
  git
, # oil deps
  file
, glibcLocales
, six
, typing
}:

rec {
  re2c = stdenv.mkDerivation rec {
    pname = "re2c";
    version = "1.0.3";
    sourceRoot = "${src.name}/re2c";
    src = fetchFromGitHub {
      owner = "skvadrik";
      repo = "re2c";
      rev = version;
      sha256 = "0grx7nl9fwcn880v5ssjljhcb9c5p2a6xpwil7zxpmv0rwnr3yqi";
    };
    nativeBuildInputs = [ autoreconfHook ];
    preCheck = ''
      patchShebangs run_tests.sh
    '';
  };

  py-yajl = python27.pkgs.buildPythonPackage rec {
    pname = "oil-pyyajl-unstable";
    version = "2022-09-01";
    src = fetchFromGitHub {
      owner = "oilshell";
      repo = "py-yajl";
      rev = "72686b0e2e9d13d3ce5fefe47ecd607c540c90a3";
      hash = "sha256-H3GKN0Pq1VFD5+SWxm8CXUVO7zAyj/ngKVmDaG/aRT4=";
      fetchSubmodules = true;
    };
    # just for submodule IIRC
    nativeBuildInputs = [ git ];
  };

  /*
    Upstream isn't interested in packaging this as a library
    (or accepting all of the patches we need to do so).
    This creates one without disturbing upstream too much.
  */
  oildev = python27.pkgs.buildPythonPackage rec {
    pname = "oildev-unstable";
    version = "2021-07-14";

    src = fetchFromGitHub {
      owner = "oilshell";
      repo = "oil";
      # rev == present HEAD of release/0.14.0
      rev = "3d0427e222f7e42ae7be90c706d7fde555efca2e";
      hash = "sha256-XMoNkBEEmD6AwNSu1uSh3OcWLfy4/ADtRckn/Pj2cP4=";

      /*
        It's not critical to drop most of these; the primary target is
        the vendored fork of Python-2.7.13, which is ~ 55M and over 3200
        files, dozens of which get interpreter script patches in fixup.

        Note: -f is necessary to keep it from being a pain to update
        hash on rev updates. Command will fail w/o and not print hash.
      */
      postFetch = ''
        rm -rf $out/{Python-2.7.13,metrics,py-yajl,rfc,gold,web,testdata,services,demo,devtools}
      '';
    };

    # patch to support a python package, pass tests on macOS, drop deps, etc.
    patchSrc = fetchFromGitHub {
      owner = "abathur";
      repo = "nix-py-dev-oil";
      rev = "v0.14.0.1";
      hash = "sha256-47+986+SohdtoNzTYAgF2vPPWgakyg0VCmR+MgxMzTk=";
    };
    patches = [
      "${patchSrc}/0001-add_setup_py.patch"
      "${patchSrc}/0002-add_MANIFEST_in.patch"
      "${patchSrc}/0004-disable-internal-py-yajl-for-nix-built.patch"
      "${patchSrc}/0006-disable_failing_libc_tests.patch"
      "${patchSrc}/0007-namespace_via_init.patch"
      "${patchSrc}/0009-avoid_nix_arch64_darwin_toolchain_bug.patch"
      "${patchSrc}/0010-disable-line-input.patch"
      "${patchSrc}/0011-disable-fanos.patch"
      "${patchSrc}/0012-disable-doc-cmark.patch"
      "${patchSrc}/0013-fix-pyverify.patch"
    ];

    configureFlags = [
      "--without-readline"
    ];

    nativeBuildInputs = [ re2c file makeWrapper ];

    propagatedBuildInputs = [ six typing py-yajl ];

    doCheck = true;

    preBuild = ''
      build/dev.sh all
    '';

    postPatch = ''
      patchShebangs asdl build core doctools frontend pyext oil_lang
      substituteInPlace pyext/fastlex.c --replace '_gen/frontend' '../_gen/frontend'
      substituteInPlace core/main_loop.py --replace 'import fanos' '# import fanos'
      rm cpp/stdlib.h # keep modules from finding the wrong stdlib?
      # work around hard parse failure documented in oilshell/oil#1468
      substituteInPlace osh/cmd_parse.py --replace 'elif self.c_id == Id.Op_LParen' 'elif False'
    '';

    # See earlier note on glibcLocales TODO: verify needed?
    LOCALE_ARCHIVE = lib.optionalString (stdenv.buildPlatform.libc == "glibc") "${glibcLocales}/lib/locale/locale-archive";

    # not exhaustive; sample what resholve uses as a sanity check
    pythonImportsCheck = [
      "oil"
      "oil.asdl"
      "oil.core"
      "oil.frontend"
      "oil._devbuild"
      "oil._devbuild.gen.id_kind_asdl"
      "oil._devbuild.gen.syntax_asdl"
      "oil.tools.osh2oil"
    ];

    meta = {
      license = with lib.licenses; [
        psfl # Includes a portion of the python interpreter and standard library
        asl20 # Licence for Oil itself
      ];
    };
  };
}