diff --git a/.direnv/bin/nix-direnv-reload b/.direnv/bin/nix-direnv-reload new file mode 100755 index 0000000..74fcf7c --- /dev/null +++ b/.direnv/bin/nix-direnv-reload @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -e +if [[ ! -d "/home/nickorlow/programming/septastic/api" ]]; then + echo "Cannot find source directory; Did you move it?" + echo "(Looking for "/home/nickorlow/programming/septastic/api")" + echo 'Cannot force reload with this script - use "direnv reload" manually and then try again' + exit 1 +fi + +# rebuild the cache forcefully +_nix_direnv_force_reload=1 direnv exec "/home/nickorlow/programming/septastic/api" true + +# Update the mtime for .envrc. +# This will cause direnv to reload again - but without re-building. +touch "/home/nickorlow/programming/septastic/api/.envrc" + +# Also update the timestamp of whatever profile_rc we have. +# This makes sure that we know we are up to date. +touch -r "/home/nickorlow/programming/septastic/api/.envrc" "/home/nickorlow/programming/septastic/api/.direnv"/*.rc diff --git a/.direnv/nix-profile-25.11-sizirny50f893gx0 b/.direnv/nix-profile-25.11-sizirny50f893gx0 new file mode 120000 index 0000000..458ba8c --- /dev/null +++ b/.direnv/nix-profile-25.11-sizirny50f893gx0 @@ -0,0 +1 @@ +/nix/store/jyg5pzxlxkbvzy1wb808kc5idmbij4r6-env-env \ No newline at end of file diff --git a/.direnv/nix-profile-25.11-sizirny50f893gx0.rc b/.direnv/nix-profile-25.11-sizirny50f893gx0.rc new file mode 100644 index 0000000..99f4d9f --- /dev/null +++ b/.direnv/nix-profile-25.11-sizirny50f893gx0.rc @@ -0,0 +1,2127 @@ +unset shellHook +PATH=${PATH:-} +nix_saved_PATH="$PATH" +XDG_DATA_DIRS=${XDG_DATA_DIRS:-} +nix_saved_XDG_DATA_DIRS="$XDG_DATA_DIRS" +AR='ar' +export AR +AS='as' +export AS +BASH='/nix/store/rlq03x4cwf8zn73hxaxnx0zn5q9kifls-bash-5.3p3/bin/bash' +CC='gcc' +export CC +CONFIG_SHELL='/nix/store/rlq03x4cwf8zn73hxaxnx0zn5q9kifls-bash-5.3p3/bin/bash' +export CONFIG_SHELL +CXX='g++' +export CXX +HOSTTYPE='x86_64' +HOST_PATH='/nix/store/y2ngdv5xdfy5m6jrdgjn1r81rkqy41rh-lvm2-2.03.35-bin/bin:/nix/store/k0gl1zc7f5hk87lylxwbipb0b870bcmk-openssl-3.6.0-bin/bin:/nix/store/rf0crwiz4z45li0n31pqwczi49jg2kwj-util-linux-minimal-2.41.2-bin/bin:/nix/store/f03spphbp2fyq35pcbwxkivxr3av6874-libargon2-20190702/bin:/nix/store/1h477y97ws0m7qdyqdc6s2gj6flba3ha-cryptsetup-2.8.1-bin/bin:/nix/store/vpjk1z71ga010lyzn7f5abbjm4pnr7qn-protobuf-32.1/bin:/nix/store/imad8dvhp77h0pjbckp6wvmnyhp8dpgg-coreutils-9.8/bin:/nix/store/av4xw9f56xlx5pgv862wabfif6m1yc0a-findutils-4.10.0/bin:/nix/store/20axvl7mgj15m23jgmnq97hx37fgz7bk-diffutils-3.12/bin:/nix/store/drc7kang929jaza6cy9zdx10s4gw1z5p-gnused-4.9/bin:/nix/store/x3zjxxz8m4ki88axp0gn8q8m6bldybba-gnugrep-3.12/bin:/nix/store/y2wdhdcrffp9hnkzk06d178hq3g98jay-gawk-5.3.2/bin:/nix/store/yi3c5karhx764ham5rfwk7iynr8mjf6q-gnutar-1.35/bin:/nix/store/d471xb7sfbah076s8rx02i68zpxc2r5n-gzip-1.14/bin:/nix/store/qm9rxn2sc1vrz91i443rr6f0vxm0zd82-bzip2-1.0.8-bin/bin:/nix/store/3fmzbq9y4m9nk235il7scmvwn8j9zy3p-gnumake-4.4.1/bin:/nix/store/rlq03x4cwf8zn73hxaxnx0zn5q9kifls-bash-5.3p3/bin:/nix/store/qrwznp1ikdf0qw05wia2haiwi32ik5n0-patch-2.8/bin:/nix/store/v0rfdwhg6w6i0yb6dbry4srk6pnj3xp0-xz-5.8.1-bin/bin:/nix/store/paj6a1lpzp57hz1djm5bs86b7ci221r0-file-5.45/bin' +export HOST_PATH +IFS=' +' +IN_NIX_SHELL='impure' +export IN_NIX_SHELL +LD='ld' +export LD +LINENO='76' +MACHTYPE='x86_64-pc-linux-gnu' +NIX_BINTOOLS='/nix/store/xwydcyvlsa3cvssk0y5llgdhlhjvmqdm-binutils-wrapper-2.44' +export NIX_BINTOOLS +NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu='1' +export NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_BUILD_CORES='12' +export NIX_BUILD_CORES +NIX_CC='/nix/store/vr15iyyykg9zai6fpgvhcgyw7gckl78w-gcc-wrapper-14.3.0' +export NIX_CC +NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu='1' +export NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_CFLAGS_COMPILE=' -frandom-seed=jyg5pzxlxk -isystem /nix/store/f9qvdl02ckaiawxaqmb3w738g2j395p4-postgresql-14.20-dev/include -isystem /nix/store/9071ak7icm08rqjgw7raybxmhhp086wc-cryptsetup-2.8.1-dev/include -isystem /nix/store/fxxaan0lgr5yqs299sjfw0klwwd53313-lvm2-2.03.35-dev/include -isystem /nix/store/pzxlqc84603x27hibv6zq6giyar0rz0m-json-c-0.18-dev/include -isystem /nix/store/ydrckgnllgg8nmhdwni81h7xhcpnrlhd-openssl-3.6.0-dev/include -isystem /nix/store/57nxr75jbgqnxgbjsp4f6r9shyqzylm2-util-linux-minimal-2.41.2-dev/include -isystem /nix/store/g3prh2g2vsnfwrqp19cf1wnpchn5p00b-popt-1.19/include -isystem /nix/store/f03spphbp2fyq35pcbwxkivxr3av6874-libargon2-20190702/include -isystem /nix/store/vpjk1z71ga010lyzn7f5abbjm4pnr7qn-protobuf-32.1/include -isystem /nix/store/7qfvcajvjs89fxqk4379zhbdmlmxjaxb-abseil-cpp-20250814.1/include -isystem /nix/store/f9qvdl02ckaiawxaqmb3w738g2j395p4-postgresql-14.20-dev/include -isystem /nix/store/9071ak7icm08rqjgw7raybxmhhp086wc-cryptsetup-2.8.1-dev/include -isystem /nix/store/fxxaan0lgr5yqs299sjfw0klwwd53313-lvm2-2.03.35-dev/include -isystem /nix/store/pzxlqc84603x27hibv6zq6giyar0rz0m-json-c-0.18-dev/include -isystem /nix/store/ydrckgnllgg8nmhdwni81h7xhcpnrlhd-openssl-3.6.0-dev/include -isystem /nix/store/57nxr75jbgqnxgbjsp4f6r9shyqzylm2-util-linux-minimal-2.41.2-dev/include -isystem /nix/store/g3prh2g2vsnfwrqp19cf1wnpchn5p00b-popt-1.19/include -isystem /nix/store/f03spphbp2fyq35pcbwxkivxr3av6874-libargon2-20190702/include -isystem /nix/store/vpjk1z71ga010lyzn7f5abbjm4pnr7qn-protobuf-32.1/include -isystem /nix/store/7qfvcajvjs89fxqk4379zhbdmlmxjaxb-abseil-cpp-20250814.1/include' +export NIX_CFLAGS_COMPILE +NIX_ENFORCE_NO_NATIVE='1' +export NIX_ENFORCE_NO_NATIVE +NIX_HARDENING_ENABLE='bindnow format fortify fortify3 libcxxhardeningextensive libcxxhardeningfast pic relro stackclashprotection stackprotector strictoverflow zerocallusedregs' +export NIX_HARDENING_ENABLE +NIX_LDFLAGS='-rpath /home/nickorlow/programming/septastic/api/outputs/out/lib -L/nix/store/f9qvdl02ckaiawxaqmb3w738g2j395p4-postgresql-14.20-dev/lib -L/nix/store/9l82bx0yp6q4rk2sdkjr3r8zvyghz0mh-postgresql-14.20-lib/lib -L/nix/store/p48k53gf4mskvxrfahajaczk6m3isfrm-postgresql-14.20/lib -L/nix/store/0s06zawwhmqq3vdf39bi94lxwdyvg705-lvm2-2.03.35-lib/lib -L/nix/store/64q3424klqaq5bq409nrmjmiyrs04k2a-json-c-0.18/lib -L/nix/store/61i74yjkj9p1qphfl7018ja4sdwkipx0-openssl-3.6.0/lib -L/nix/store/z4wx1a8n24fxfl4rjpf0jg8cmp5b76b5-util-linux-minimal-2.41.2-lib/lib -L/nix/store/g3prh2g2vsnfwrqp19cf1wnpchn5p00b-popt-1.19/lib -L/nix/store/f03spphbp2fyq35pcbwxkivxr3av6874-libargon2-20190702/lib -L/nix/store/c7rsnyvdb0zwhj8fb9hnxpfw7nfshfxb-cryptsetup-2.8.1/lib -L/nix/store/vpjk1z71ga010lyzn7f5abbjm4pnr7qn-protobuf-32.1/lib -L/nix/store/7qfvcajvjs89fxqk4379zhbdmlmxjaxb-abseil-cpp-20250814.1/lib -L/nix/store/f9qvdl02ckaiawxaqmb3w738g2j395p4-postgresql-14.20-dev/lib -L/nix/store/9l82bx0yp6q4rk2sdkjr3r8zvyghz0mh-postgresql-14.20-lib/lib -L/nix/store/p48k53gf4mskvxrfahajaczk6m3isfrm-postgresql-14.20/lib -L/nix/store/0s06zawwhmqq3vdf39bi94lxwdyvg705-lvm2-2.03.35-lib/lib -L/nix/store/64q3424klqaq5bq409nrmjmiyrs04k2a-json-c-0.18/lib -L/nix/store/61i74yjkj9p1qphfl7018ja4sdwkipx0-openssl-3.6.0/lib -L/nix/store/z4wx1a8n24fxfl4rjpf0jg8cmp5b76b5-util-linux-minimal-2.41.2-lib/lib -L/nix/store/g3prh2g2vsnfwrqp19cf1wnpchn5p00b-popt-1.19/lib -L/nix/store/f03spphbp2fyq35pcbwxkivxr3av6874-libargon2-20190702/lib -L/nix/store/c7rsnyvdb0zwhj8fb9hnxpfw7nfshfxb-cryptsetup-2.8.1/lib -L/nix/store/vpjk1z71ga010lyzn7f5abbjm4pnr7qn-protobuf-32.1/lib -L/nix/store/7qfvcajvjs89fxqk4379zhbdmlmxjaxb-abseil-cpp-20250814.1/lib' +export NIX_LDFLAGS +NIX_NO_SELF_RPATH='1' +NIX_PKG_CONFIG_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu='1' +export NIX_PKG_CONFIG_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_STORE='/nix/store' +export NIX_STORE +NM='nm' +export NM +OBJCOPY='objcopy' +export OBJCOPY +OBJDUMP='objdump' +export OBJDUMP +OLDPWD='' +export OLDPWD +OPTERR='1' +OSTYPE='linux-gnu' +PATH='/nix/store/8vdiwpbh0g4avsd6x5v4s0di32vcl3dp-pkg-config-wrapper-0.29.2/bin:/nix/store/f9qvdl02ckaiawxaqmb3w738g2j395p4-postgresql-14.20-dev/bin:/nix/store/p48k53gf4mskvxrfahajaczk6m3isfrm-postgresql-14.20/bin:/nix/store/8q2582rd22xp8jlcg1xn1w219q5lx5xa-patchelf-0.15.2/bin:/nix/store/vr15iyyykg9zai6fpgvhcgyw7gckl78w-gcc-wrapper-14.3.0/bin:/nix/store/kzq78n13l8w24jn8bx4djj79k5j717f1-gcc-14.3.0/bin:/nix/store/q6wgv06q39bfhx2xl8ysc05wi6m2zdss-glibc-2.40-66-bin/bin:/nix/store/imad8dvhp77h0pjbckp6wvmnyhp8dpgg-coreutils-9.8/bin:/nix/store/xwydcyvlsa3cvssk0y5llgdhlhjvmqdm-binutils-wrapper-2.44/bin:/nix/store/dc9vaz50jg7mibk9xvqw5dqv89cxzla3-binutils-2.44/bin:/nix/store/y2ngdv5xdfy5m6jrdgjn1r81rkqy41rh-lvm2-2.03.35-bin/bin:/nix/store/k0gl1zc7f5hk87lylxwbipb0b870bcmk-openssl-3.6.0-bin/bin:/nix/store/rf0crwiz4z45li0n31pqwczi49jg2kwj-util-linux-minimal-2.41.2-bin/bin:/nix/store/f03spphbp2fyq35pcbwxkivxr3av6874-libargon2-20190702/bin:/nix/store/1h477y97ws0m7qdyqdc6s2gj6flba3ha-cryptsetup-2.8.1-bin/bin:/nix/store/vpjk1z71ga010lyzn7f5abbjm4pnr7qn-protobuf-32.1/bin:/nix/store/imad8dvhp77h0pjbckp6wvmnyhp8dpgg-coreutils-9.8/bin:/nix/store/av4xw9f56xlx5pgv862wabfif6m1yc0a-findutils-4.10.0/bin:/nix/store/20axvl7mgj15m23jgmnq97hx37fgz7bk-diffutils-3.12/bin:/nix/store/drc7kang929jaza6cy9zdx10s4gw1z5p-gnused-4.9/bin:/nix/store/x3zjxxz8m4ki88axp0gn8q8m6bldybba-gnugrep-3.12/bin:/nix/store/y2wdhdcrffp9hnkzk06d178hq3g98jay-gawk-5.3.2/bin:/nix/store/yi3c5karhx764ham5rfwk7iynr8mjf6q-gnutar-1.35/bin:/nix/store/d471xb7sfbah076s8rx02i68zpxc2r5n-gzip-1.14/bin:/nix/store/qm9rxn2sc1vrz91i443rr6f0vxm0zd82-bzip2-1.0.8-bin/bin:/nix/store/3fmzbq9y4m9nk235il7scmvwn8j9zy3p-gnumake-4.4.1/bin:/nix/store/rlq03x4cwf8zn73hxaxnx0zn5q9kifls-bash-5.3p3/bin:/nix/store/qrwznp1ikdf0qw05wia2haiwi32ik5n0-patch-2.8/bin:/nix/store/v0rfdwhg6w6i0yb6dbry4srk6pnj3xp0-xz-5.8.1-bin/bin:/nix/store/paj6a1lpzp57hz1djm5bs86b7ci221r0-file-5.45/bin' +export PATH +PKG_CONFIG='pkg-config' +export PKG_CONFIG +PKG_CONFIG_PATH='/nix/store/f9qvdl02ckaiawxaqmb3w738g2j395p4-postgresql-14.20-dev/lib/pkgconfig:/nix/store/9071ak7icm08rqjgw7raybxmhhp086wc-cryptsetup-2.8.1-dev/lib/pkgconfig:/nix/store/fxxaan0lgr5yqs299sjfw0klwwd53313-lvm2-2.03.35-dev/lib/pkgconfig:/nix/store/pzxlqc84603x27hibv6zq6giyar0rz0m-json-c-0.18-dev/lib/pkgconfig:/nix/store/ydrckgnllgg8nmhdwni81h7xhcpnrlhd-openssl-3.6.0-dev/lib/pkgconfig:/nix/store/57nxr75jbgqnxgbjsp4f6r9shyqzylm2-util-linux-minimal-2.41.2-dev/lib/pkgconfig:/nix/store/g3prh2g2vsnfwrqp19cf1wnpchn5p00b-popt-1.19/lib/pkgconfig:/nix/store/f03spphbp2fyq35pcbwxkivxr3av6874-libargon2-20190702/lib/pkgconfig:/nix/store/vpjk1z71ga010lyzn7f5abbjm4pnr7qn-protobuf-32.1/lib/pkgconfig:/nix/store/7qfvcajvjs89fxqk4379zhbdmlmxjaxb-abseil-cpp-20250814.1/lib/pkgconfig' +export PKG_CONFIG_PATH +PS4='+ ' +RANLIB='ranlib' +export RANLIB +READELF='readelf' +export READELF +SHELL='/nix/store/rlq03x4cwf8zn73hxaxnx0zn5q9kifls-bash-5.3p3/bin/bash' +export SHELL +SIZE='size' +export SIZE +SOURCE_DATE_EPOCH='315532800' +export SOURCE_DATE_EPOCH +STRINGS='strings' +export STRINGS +STRIP='strip' +export STRIP +XDG_DATA_DIRS='/nix/store/8vdiwpbh0g4avsd6x5v4s0di32vcl3dp-pkg-config-wrapper-0.29.2/share:/nix/store/p48k53gf4mskvxrfahajaczk6m3isfrm-postgresql-14.20/share:/nix/store/8q2582rd22xp8jlcg1xn1w219q5lx5xa-patchelf-0.15.2/share' +export XDG_DATA_DIRS +__structuredAttrs='' +export __structuredAttrs +_substituteStream_has_warned_replace_deprecation='false' +buildInputs='/nix/store/9071ak7icm08rqjgw7raybxmhhp086wc-cryptsetup-2.8.1-dev /nix/store/vpjk1z71ga010lyzn7f5abbjm4pnr7qn-protobuf-32.1' +export buildInputs +builder='/nix/store/rlq03x4cwf8zn73hxaxnx0zn5q9kifls-bash-5.3p3/bin/bash' +export builder +cmakeFlags='' +export cmakeFlags +configureFlags='' +export configureFlags +defaultBuildInputs='' +defaultNativeBuildInputs='/nix/store/8q2582rd22xp8jlcg1xn1w219q5lx5xa-patchelf-0.15.2 /nix/store/l2xk4ac1wx9c95kpp8vymv9r9yn57fvh-update-autotools-gnu-config-scripts-hook /nix/store/0y5xmdb7qfvimjwbq7ibg1xdgkgjwqng-no-broken-symlinks.sh /nix/store/cv1d7p48379km6a85h4zp6kr86brh32q-audit-tmpdir.sh /nix/store/85clx3b0xkdf58jn161iy80y5223ilbi-compress-man-pages.sh /nix/store/wgrbkkaldkrlrni33ccvm3b6vbxzb656-make-symlinks-relative.sh /nix/store/5yzw0vhkyszf2d179m0qfkgxmp5wjjx4-move-docs.sh /nix/store/fyaryjvghbkpfnsyw97hb3lyb37s1pd6-move-lib64.sh /nix/store/kd4xwxjpjxi71jkm6ka0np72if9rm3y0-move-sbin.sh /nix/store/pag6l61paj1dc9sv15l7bm5c17xn5kyk-move-systemd-user-units.sh /nix/store/cmzya9irvxzlkh7lfy6i82gbp0saxqj3-multiple-outputs.sh /nix/store/x8c40nfigps493a07sdr2pm5s9j1cdc0-patch-shebangs.sh /nix/store/cickvswrvann041nqxb0rxilc46svw1n-prune-libtool-files.sh /nix/store/xyff06pkhki3qy1ls77w10s0v79c9il0-reproducible-builds.sh /nix/store/z7k98578dfzi6l3hsvbivzm7hfqlk0zc-set-source-date-epoch-to-latest.sh /nix/store/pilsssjjdxvdphlg2h19p0bfx5q0jzkn-strip.sh /nix/store/vr15iyyykg9zai6fpgvhcgyw7gckl78w-gcc-wrapper-14.3.0' +depsBuildBuild='' +export depsBuildBuild +depsBuildBuildPropagated='' +export depsBuildBuildPropagated +depsBuildTarget='' +export depsBuildTarget +depsBuildTargetPropagated='' +export depsBuildTargetPropagated +depsHostHost='' +export depsHostHost +depsHostHostPropagated='' +export depsHostHostPropagated +depsTargetTarget='' +export depsTargetTarget +depsTargetTargetPropagated='' +export depsTargetTargetPropagated +doCheck='' +export doCheck +doInstallCheck='' +export doInstallCheck +dontAddDisableDepTrack='1' +export dontAddDisableDepTrack +declare -a envBuildBuildHooks=() +declare -a envBuildHostHooks=() +declare -a envBuildTargetHooks=() +declare -a envHostHostHooks=('pkgConfigWrapper_addPkgConfigPath' 'ccWrapper_addCVars' 'bintoolsWrapper_addLDVars' ) +declare -a envHostTargetHooks=('pkgConfigWrapper_addPkgConfigPath' 'ccWrapper_addCVars' 'bintoolsWrapper_addLDVars' ) +declare -a envTargetTargetHooks=() +declare -a fixupOutputHooks=('if [ -z "${dontPatchELF-}" ]; then patchELF "$prefix"; fi' 'if [[ -z "${noAuditTmpdir-}" && -e "$prefix" ]]; then auditTmpdir "$prefix"; fi' 'if [ -z "${dontGzipMan-}" ]; then compressManPages "$prefix"; fi' '_moveLib64' '_moveSbin' '_moveSystemdUserUnits' 'patchShebangsAuto' '_pruneLibtoolFiles' '_doStrip' ) +initialPath='/nix/store/imad8dvhp77h0pjbckp6wvmnyhp8dpgg-coreutils-9.8 /nix/store/av4xw9f56xlx5pgv862wabfif6m1yc0a-findutils-4.10.0 /nix/store/20axvl7mgj15m23jgmnq97hx37fgz7bk-diffutils-3.12 /nix/store/drc7kang929jaza6cy9zdx10s4gw1z5p-gnused-4.9 /nix/store/x3zjxxz8m4ki88axp0gn8q8m6bldybba-gnugrep-3.12 /nix/store/y2wdhdcrffp9hnkzk06d178hq3g98jay-gawk-5.3.2 /nix/store/yi3c5karhx764ham5rfwk7iynr8mjf6q-gnutar-1.35 /nix/store/d471xb7sfbah076s8rx02i68zpxc2r5n-gzip-1.14 /nix/store/qm9rxn2sc1vrz91i443rr6f0vxm0zd82-bzip2-1.0.8-bin /nix/store/3fmzbq9y4m9nk235il7scmvwn8j9zy3p-gnumake-4.4.1 /nix/store/rlq03x4cwf8zn73hxaxnx0zn5q9kifls-bash-5.3p3 /nix/store/qrwznp1ikdf0qw05wia2haiwi32ik5n0-patch-2.8 /nix/store/v0rfdwhg6w6i0yb6dbry4srk6pnj3xp0-xz-5.8.1-bin /nix/store/paj6a1lpzp57hz1djm5bs86b7ci221r0-file-5.45' +mesonFlags='' +export mesonFlags +name='env-env' +export name +nativeBuildInputs='/nix/store/8vdiwpbh0g4avsd6x5v4s0di32vcl3dp-pkg-config-wrapper-0.29.2 /nix/store/f9qvdl02ckaiawxaqmb3w738g2j395p4-postgresql-14.20-dev' +export nativeBuildInputs +out='/home/nickorlow/programming/septastic/api/outputs/out' +export out +outputBin='out' +outputDev='out' +outputDevdoc='REMOVE' +outputDevman='out' +outputDoc='out' +outputInclude='out' +outputInfo='out' +outputLib='out' +outputMan='out' +outputs='out' +export outputs +patches='' +export patches +pkg='/nix/store/vr15iyyykg9zai6fpgvhcgyw7gckl78w-gcc-wrapper-14.3.0' +declare -a pkgsBuildBuild=() +declare -a pkgsBuildHost=('/nix/store/8vdiwpbh0g4avsd6x5v4s0di32vcl3dp-pkg-config-wrapper-0.29.2' '/nix/store/f9qvdl02ckaiawxaqmb3w738g2j395p4-postgresql-14.20-dev' '/nix/store/9l82bx0yp6q4rk2sdkjr3r8zvyghz0mh-postgresql-14.20-lib' '/nix/store/p48k53gf4mskvxrfahajaczk6m3isfrm-postgresql-14.20' '/nix/store/8q2582rd22xp8jlcg1xn1w219q5lx5xa-patchelf-0.15.2' '/nix/store/l2xk4ac1wx9c95kpp8vymv9r9yn57fvh-update-autotools-gnu-config-scripts-hook' '/nix/store/0y5xmdb7qfvimjwbq7ibg1xdgkgjwqng-no-broken-symlinks.sh' '/nix/store/cv1d7p48379km6a85h4zp6kr86brh32q-audit-tmpdir.sh' '/nix/store/85clx3b0xkdf58jn161iy80y5223ilbi-compress-man-pages.sh' '/nix/store/wgrbkkaldkrlrni33ccvm3b6vbxzb656-make-symlinks-relative.sh' '/nix/store/5yzw0vhkyszf2d179m0qfkgxmp5wjjx4-move-docs.sh' '/nix/store/fyaryjvghbkpfnsyw97hb3lyb37s1pd6-move-lib64.sh' '/nix/store/kd4xwxjpjxi71jkm6ka0np72if9rm3y0-move-sbin.sh' '/nix/store/pag6l61paj1dc9sv15l7bm5c17xn5kyk-move-systemd-user-units.sh' '/nix/store/cmzya9irvxzlkh7lfy6i82gbp0saxqj3-multiple-outputs.sh' '/nix/store/x8c40nfigps493a07sdr2pm5s9j1cdc0-patch-shebangs.sh' '/nix/store/cickvswrvann041nqxb0rxilc46svw1n-prune-libtool-files.sh' '/nix/store/xyff06pkhki3qy1ls77w10s0v79c9il0-reproducible-builds.sh' '/nix/store/z7k98578dfzi6l3hsvbivzm7hfqlk0zc-set-source-date-epoch-to-latest.sh' '/nix/store/pilsssjjdxvdphlg2h19p0bfx5q0jzkn-strip.sh' '/nix/store/vr15iyyykg9zai6fpgvhcgyw7gckl78w-gcc-wrapper-14.3.0' '/nix/store/xwydcyvlsa3cvssk0y5llgdhlhjvmqdm-binutils-wrapper-2.44' ) +declare -a pkgsBuildTarget=() +declare -a pkgsHostHost=() +declare -a pkgsHostTarget=('/nix/store/9071ak7icm08rqjgw7raybxmhhp086wc-cryptsetup-2.8.1-dev' '/nix/store/fxxaan0lgr5yqs299sjfw0klwwd53313-lvm2-2.03.35-dev' '/nix/store/y2ngdv5xdfy5m6jrdgjn1r81rkqy41rh-lvm2-2.03.35-bin' '/nix/store/0s06zawwhmqq3vdf39bi94lxwdyvg705-lvm2-2.03.35-lib' '/nix/store/pzxlqc84603x27hibv6zq6giyar0rz0m-json-c-0.18-dev' '/nix/store/64q3424klqaq5bq409nrmjmiyrs04k2a-json-c-0.18' '/nix/store/ydrckgnllgg8nmhdwni81h7xhcpnrlhd-openssl-3.6.0-dev' '/nix/store/k0gl1zc7f5hk87lylxwbipb0b870bcmk-openssl-3.6.0-bin' '/nix/store/61i74yjkj9p1qphfl7018ja4sdwkipx0-openssl-3.6.0' '/nix/store/57nxr75jbgqnxgbjsp4f6r9shyqzylm2-util-linux-minimal-2.41.2-dev' '/nix/store/rf0crwiz4z45li0n31pqwczi49jg2kwj-util-linux-minimal-2.41.2-bin' '/nix/store/z4wx1a8n24fxfl4rjpf0jg8cmp5b76b5-util-linux-minimal-2.41.2-lib' '/nix/store/g3prh2g2vsnfwrqp19cf1wnpchn5p00b-popt-1.19' '/nix/store/f03spphbp2fyq35pcbwxkivxr3av6874-libargon2-20190702' '/nix/store/1h477y97ws0m7qdyqdc6s2gj6flba3ha-cryptsetup-2.8.1-bin' '/nix/store/c7rsnyvdb0zwhj8fb9hnxpfw7nfshfxb-cryptsetup-2.8.1' '/nix/store/vpjk1z71ga010lyzn7f5abbjm4pnr7qn-protobuf-32.1' '/nix/store/7qfvcajvjs89fxqk4379zhbdmlmxjaxb-abseil-cpp-20250814.1' ) +declare -a pkgsTargetTarget=() +declare -a postFixupHooks=('noBrokenSymlinksInAllOutputs' '_makeSymlinksRelativeInAllOutputs' '_multioutPropagateDev' ) +declare -a postUnpackHooks=('_updateSourceDateEpochFromSourceRoot' ) +declare -a preConfigureHooks=('_multioutConfig' 'ProtobufCMakeFlags' ) +preConfigurePhases=' updateAutotoolsGnuConfigScriptsPhase' +declare -a preFixupHooks=('_moveToShare' '_multioutDocs' '_multioutDevs' ) +prefix='/home/nickorlow/programming/septastic/api/outputs/out' +declare -a propagatedBuildDepFiles=('propagated-build-build-deps' 'propagated-native-build-inputs' 'propagated-build-target-deps' ) +propagatedBuildInputs='' +export propagatedBuildInputs +declare -a propagatedHostDepFiles=('propagated-host-host-deps' 'propagated-build-inputs' ) +propagatedNativeBuildInputs='' +export propagatedNativeBuildInputs +declare -a propagatedTargetDepFiles=('propagated-target-target-deps' ) +shell='/nix/store/rlq03x4cwf8zn73hxaxnx0zn5q9kifls-bash-5.3p3/bin/bash' +export shell +stdenv='/nix/store/s3w5m3spa1g71hx0yb82lvk6394j3w5j-stdenv-linux' +export stdenv +strictDeps='' +export strictDeps +system='x86_64-linux' +export system +declare -a unpackCmdHooks=('_defaultUnpack' ) +ProtobufCMakeFlags () +{ + + cmakeFlagsArray+=(-DPROTOC_EXE="/nix/store/vpjk1z71ga010lyzn7f5abbjm4pnr7qn-protobuf-32.1/bin/protoc" -DProtobuf_PROTOC_EXE="/nix/store/vpjk1z71ga010lyzn7f5abbjm4pnr7qn-protobuf-32.1/bin/protoc" -DProtobuf_PROTOC_EXECUTABLE="/nix/store/vpjk1z71ga010lyzn7f5abbjm4pnr7qn-protobuf-32.1/bin/protoc") +} +_activatePkgs () +{ + + local hostOffset targetOffset; + local pkg; + for hostOffset in "${allPlatOffsets[@]}"; + do + local pkgsVar="${pkgAccumVarVars[hostOffset + 1]}"; + for targetOffset in "${allPlatOffsets[@]}"; + do + (( hostOffset <= targetOffset )) || continue; + local pkgsRef="${pkgsVar}[$targetOffset - $hostOffset]"; + local pkgsSlice="${!pkgsRef}[@]"; + for pkg in ${!pkgsSlice+"${!pkgsSlice}"}; + do + activatePackage "$pkg" "$hostOffset" "$targetOffset"; + done; + done; + done +} +_addRpathPrefix () +{ + + if [ "${NIX_NO_SELF_RPATH:-0}" != 1 ]; then + export NIX_LDFLAGS="-rpath $1/lib ${NIX_LDFLAGS-}"; + fi +} +_addToEnv () +{ + + local depHostOffset depTargetOffset; + local pkg; + for depHostOffset in "${allPlatOffsets[@]}"; + do + local hookVar="${pkgHookVarVars[depHostOffset + 1]}"; + local pkgsVar="${pkgAccumVarVars[depHostOffset + 1]}"; + for depTargetOffset in "${allPlatOffsets[@]}"; + do + (( depHostOffset <= depTargetOffset )) || continue; + local hookRef="${hookVar}[$depTargetOffset - $depHostOffset]"; + if [[ -z "${strictDeps-}" ]]; then + local visitedPkgs=""; + for pkg in "${pkgsBuildBuild[@]}" "${pkgsBuildHost[@]}" "${pkgsBuildTarget[@]}" "${pkgsHostHost[@]}" "${pkgsHostTarget[@]}" "${pkgsTargetTarget[@]}"; + do + if [[ "$visitedPkgs" = *"$pkg"* ]]; then + continue; + fi; + runHook "${!hookRef}" "$pkg"; + visitedPkgs+=" $pkg"; + done; + else + local pkgsRef="${pkgsVar}[$depTargetOffset - $depHostOffset]"; + local pkgsSlice="${!pkgsRef}[@]"; + for pkg in ${!pkgsSlice+"${!pkgsSlice}"}; + do + runHook "${!hookRef}" "$pkg"; + done; + fi; + done; + done +} +_allFlags () +{ + + export system pname name version; + while IFS='' read -r varName; do + nixTalkativeLog "@${varName}@ -> ${!varName}"; + args+=("--subst-var" "$varName"); + done < <(awk 'BEGIN { for (v in ENVIRON) if (v ~ /^[a-z][a-zA-Z0-9_]*$/) print v }') +} +_assignFirst () +{ + + local varName="$1"; + local _var; + local REMOVE=REMOVE; + shift; + for _var in "$@"; + do + if [ -n "${!_var-}" ]; then + eval "${varName}"="${_var}"; + return; + fi; + done; + echo; + echo "error: _assignFirst: could not find a non-empty variable whose name to assign to ${varName}."; + echo " The following variables were all unset or empty:"; + echo " $*"; + if [ -z "${out:-}" ]; then + echo ' If you do not want an "out" output in your derivation, make sure to define'; + echo ' the other specific required outputs. This can be achieved by picking one'; + echo " of the above as an output."; + echo ' You do not have to remove "out" if you want to have a different default'; + echo ' output, because the first output is taken as a default.'; + echo; + fi; + return 1 +} +_callImplicitHook () +{ + + local def="$1"; + local hookName="$2"; + if declare -F "$hookName" > /dev/null; then + nixTalkativeLog "calling implicit '$hookName' function hook"; + "$hookName"; + else + if type -p "$hookName" > /dev/null; then + nixTalkativeLog "sourcing implicit '$hookName' script hook"; + source "$hookName"; + else + if [ -n "${!hookName:-}" ]; then + nixTalkativeLog "evaling implicit '$hookName' string hook"; + eval "${!hookName}"; + else + return "$def"; + fi; + fi; + fi +} +_defaultUnpack () +{ + + local fn="$1"; + local destination; + if [ -d "$fn" ]; then + destination="$(stripHash "$fn")"; + if [ -e "$destination" ]; then + echo "Cannot copy $fn to $destination: destination already exists!"; + echo "Did you specify two \"srcs\" with the same \"name\"?"; + return 1; + fi; + cp -r --preserve=timestamps --reflink=auto -- "$fn" "$destination"; + else + case "$fn" in + *.tar.xz | *.tar.lzma | *.txz) + ( XZ_OPT="--threads=$NIX_BUILD_CORES" xz -d < "$fn"; + true ) | tar xf - --mode=+w --warning=no-timestamp + ;; + *.tar | *.tar.* | *.tgz | *.tbz2 | *.tbz) + tar xf "$fn" --mode=+w --warning=no-timestamp + ;; + *) + return 1 + ;; + esac; + fi +} +_doStrip () +{ + + local -ra flags=(dontStripHost dontStripTarget); + local -ra debugDirs=(stripDebugList stripDebugListTarget); + local -ra allDirs=(stripAllList stripAllListTarget); + local -ra stripCmds=(STRIP STRIP_FOR_TARGET); + local -ra ranlibCmds=(RANLIB RANLIB_FOR_TARGET); + stripDebugList=${stripDebugList[*]:-lib lib32 lib64 libexec bin sbin Applications Library/Frameworks}; + stripDebugListTarget=${stripDebugListTarget[*]:-}; + stripAllList=${stripAllList[*]:-}; + stripAllListTarget=${stripAllListTarget[*]:-}; + local i; + for i in ${!stripCmds[@]}; + do + local -n flag="${flags[$i]}"; + local -n debugDirList="${debugDirs[$i]}"; + local -n allDirList="${allDirs[$i]}"; + local -n stripCmd="${stripCmds[$i]}"; + local -n ranlibCmd="${ranlibCmds[$i]}"; + if [[ -n "${dontStrip-}" || -n "${flag-}" ]] || ! type -f "${stripCmd-}" 2> /dev/null 1>&2; then + continue; + fi; + stripDirs "$stripCmd" "$ranlibCmd" "$debugDirList" "${stripDebugFlags[*]:--S -p}"; + stripDirs "$stripCmd" "$ranlibCmd" "$allDirList" "${stripAllFlags[*]:--s -p}"; + done +} +_eval () +{ + + if declare -F "$1" > /dev/null 2>&1; then + "$@"; + else + eval "$1"; + fi +} +_logHook () +{ + + if [[ -z ${NIX_LOG_FD-} ]]; then + return; + fi; + local hookKind="$1"; + local hookExpr="$2"; + shift 2; + if declare -F "$hookExpr" > /dev/null 2>&1; then + nixTalkativeLog "calling '$hookKind' function hook '$hookExpr'" "$@"; + else + if type -p "$hookExpr" > /dev/null; then + nixTalkativeLog "sourcing '$hookKind' script hook '$hookExpr'"; + else + if [[ "$hookExpr" != "_callImplicitHook"* ]]; then + local exprToOutput; + if [[ ${NIX_DEBUG:-0} -ge 5 ]]; then + exprToOutput="$hookExpr"; + else + local hookExprLine; + while IFS= read -r hookExprLine; do + hookExprLine="${hookExprLine#"${hookExprLine%%[![:space:]]*}"}"; + if [[ -n "$hookExprLine" ]]; then + exprToOutput+="$hookExprLine\\n "; + fi; + done <<< "$hookExpr"; + exprToOutput="${exprToOutput%%\\n }"; + fi; + nixTalkativeLog "evaling '$hookKind' string hook '$exprToOutput'"; + fi; + fi; + fi +} +_makeSymlinksRelative () +{ + + local symlinkTarget; + if [ "${dontRewriteSymlinks-}" ] || [ ! -e "$prefix" ]; then + return; + fi; + while IFS= read -r -d '' f; do + symlinkTarget=$(readlink "$f"); + if [[ "$symlinkTarget"/ != "$prefix"/* ]]; then + continue; + fi; + if [ ! -e "$symlinkTarget" ]; then + echo "the symlink $f is broken, it points to $symlinkTarget (which is missing)"; + fi; + echo "rewriting symlink $f to be relative to $prefix"; + ln -snrf "$symlinkTarget" "$f"; + done < <(find $prefix -type l -print0) +} +_makeSymlinksRelativeInAllOutputs () +{ + + local output; + for output in $(getAllOutputNames); + do + prefix="${!output}" _makeSymlinksRelative; + done +} +_moveLib64 () +{ + + if [ "${dontMoveLib64-}" = 1 ]; then + return; + fi; + if [ ! -e "$prefix/lib64" -o -L "$prefix/lib64" ]; then + return; + fi; + echo "moving $prefix/lib64/* to $prefix/lib"; + mkdir -p $prefix/lib; + shopt -s dotglob; + for i in $prefix/lib64/*; + do + mv --no-clobber "$i" $prefix/lib; + done; + shopt -u dotglob; + rmdir $prefix/lib64; + ln -s lib $prefix/lib64 +} +_moveSbin () +{ + + if [ "${dontMoveSbin-}" = 1 ]; then + return; + fi; + if [ ! -e "$prefix/sbin" -o -L "$prefix/sbin" ]; then + return; + fi; + echo "moving $prefix/sbin/* to $prefix/bin"; + mkdir -p $prefix/bin; + shopt -s dotglob; + for i in $prefix/sbin/*; + do + mv "$i" $prefix/bin; + done; + shopt -u dotglob; + rmdir $prefix/sbin; + ln -s bin $prefix/sbin +} +_moveSystemdUserUnits () +{ + + if [ "${dontMoveSystemdUserUnits:-0}" = 1 ]; then + return; + fi; + if [ ! -e "${prefix:?}/lib/systemd/user" ]; then + return; + fi; + local source="$prefix/lib/systemd/user"; + local target="$prefix/share/systemd/user"; + echo "moving $source/* to $target"; + mkdir -p "$target"; + ( shopt -s dotglob; + for i in "$source"/*; + do + mv "$i" "$target"; + done ); + rmdir "$source"; + ln -s "$target" "$source" +} +_moveToShare () +{ + + if [ -n "$__structuredAttrs" ]; then + if [ -z "${forceShare-}" ]; then + forceShare=(man doc info); + fi; + else + forceShare=(${forceShare:-man doc info}); + fi; + if [[ -z "$out" ]]; then + return; + fi; + for d in "${forceShare[@]}"; + do + if [ -d "$out/$d" ]; then + if [ -d "$out/share/$d" ]; then + echo "both $d/ and share/$d/ exist!"; + else + echo "moving $out/$d to $out/share/$d"; + mkdir -p $out/share; + mv $out/$d $out/share/; + fi; + fi; + done +} +_multioutConfig () +{ + + if [ "$(getAllOutputNames)" = "out" ] || [ -z "${setOutputFlags-1}" ]; then + return; + fi; + if [ -z "${shareDocName:-}" ]; then + local confScript="${configureScript:-}"; + if [ -z "$confScript" ] && [ -x ./configure ]; then + confScript=./configure; + fi; + if [ -f "$confScript" ]; then + local shareDocName="$(sed -n "s/^PACKAGE_TARNAME='\(.*\)'$/\1/p" < "$confScript")"; + fi; + if [ -z "$shareDocName" ] || echo "$shareDocName" | grep -q '[^a-zA-Z0-9_-]'; then + shareDocName="$(echo "$name" | sed 's/-[^a-zA-Z].*//')"; + fi; + fi; + prependToVar configureFlags --bindir="${!outputBin}"/bin --sbindir="${!outputBin}"/sbin --includedir="${!outputInclude}"/include --mandir="${!outputMan}"/share/man --infodir="${!outputInfo}"/share/info --docdir="${!outputDoc}"/share/doc/"${shareDocName}" --libdir="${!outputLib}"/lib --libexecdir="${!outputLib}"/libexec --localedir="${!outputLib}"/share/locale; + prependToVar installFlags pkgconfigdir="${!outputDev}"/lib/pkgconfig m4datadir="${!outputDev}"/share/aclocal aclocaldir="${!outputDev}"/share/aclocal +} +_multioutDevs () +{ + + if [ "$(getAllOutputNames)" = "out" ] || [ -z "${moveToDev-1}" ]; then + return; + fi; + moveToOutput include "${!outputInclude}"; + moveToOutput lib/pkgconfig "${!outputDev}"; + moveToOutput share/pkgconfig "${!outputDev}"; + moveToOutput lib/cmake "${!outputDev}"; + moveToOutput share/aclocal "${!outputDev}"; + for f in "${!outputDev}"/{lib,share}/pkgconfig/*.pc; + do + echo "Patching '$f' includedir to output ${!outputInclude}"; + sed -i "/^includedir=/s,=\${prefix},=${!outputInclude}," "$f"; + done +} +_multioutDocs () +{ + + local REMOVE=REMOVE; + moveToOutput share/info "${!outputInfo}"; + moveToOutput share/doc "${!outputDoc}"; + moveToOutput share/gtk-doc "${!outputDevdoc}"; + moveToOutput share/devhelp/books "${!outputDevdoc}"; + moveToOutput share/man "${!outputMan}"; + moveToOutput share/man/man3 "${!outputDevman}" +} +_multioutPropagateDev () +{ + + if [ "$(getAllOutputNames)" = "out" ]; then + return; + fi; + local outputFirst; + for outputFirst in $(getAllOutputNames); + do + break; + done; + local propagaterOutput="$outputDev"; + if [ -z "$propagaterOutput" ]; then + propagaterOutput="$outputFirst"; + fi; + if [ -z "${propagatedBuildOutputs+1}" ]; then + local po_dirty="$outputBin $outputInclude $outputLib"; + set +o pipefail; + propagatedBuildOutputs=`echo "$po_dirty" | tr -s ' ' '\n' | grep -v -F "$propagaterOutput" | sort -u | tr '\n' ' ' `; + set -o pipefail; + fi; + if [ -z "$propagatedBuildOutputs" ]; then + return; + fi; + mkdir -p "${!propagaterOutput}"/nix-support; + for output in $propagatedBuildOutputs; + do + echo -n " ${!output}" >> "${!propagaterOutput}"/nix-support/propagated-build-inputs; + done +} +_nixLogWithLevel () +{ + + [[ -z ${NIX_LOG_FD-} || ${NIX_DEBUG:-0} -lt ${1:?} ]] && return 0; + local logLevel; + case "${1:?}" in + 0) + logLevel=ERROR + ;; + 1) + logLevel=WARN + ;; + 2) + logLevel=NOTICE + ;; + 3) + logLevel=INFO + ;; + 4) + logLevel=TALKATIVE + ;; + 5) + logLevel=CHATTY + ;; + 6) + logLevel=DEBUG + ;; + 7) + logLevel=VOMIT + ;; + *) + echo "_nixLogWithLevel: called with invalid log level: ${1:?}" >&"$NIX_LOG_FD"; + return 1 + ;; + esac; + local callerName="${FUNCNAME[2]}"; + if [[ $callerName == "_callImplicitHook" ]]; then + callerName="${hookName:?}"; + fi; + printf "%s: %s: %s\n" "$logLevel" "$callerName" "${2:?}" >&"$NIX_LOG_FD" +} +_overrideFirst () +{ + + if [ -z "${!1-}" ]; then + _assignFirst "$@"; + fi +} +_pruneLibtoolFiles () +{ + + if [ "${dontPruneLibtoolFiles-}" ] || [ ! -e "$prefix" ]; then + return; + fi; + find "$prefix" -type f -name '*.la' -exec grep -q '^# Generated by .*libtool' {} \; -exec grep -q "^old_library=''" {} \; -exec sed -i {} -e "/^dependency_libs='[^']/ c dependency_libs='' #pruned" \; +} +_updateSourceDateEpochFromSourceRoot () +{ + + if [ -n "$sourceRoot" ]; then + updateSourceDateEpoch "$sourceRoot"; + fi +} +activatePackage () +{ + + local pkg="$1"; + local -r hostOffset="$2"; + local -r targetOffset="$3"; + (( hostOffset <= targetOffset )) || exit 1; + if [ -f "$pkg" ]; then + nixTalkativeLog "sourcing setup hook '$pkg'"; + source "$pkg"; + fi; + if [[ -z "${strictDeps-}" || "$hostOffset" -le -1 ]]; then + addToSearchPath _PATH "$pkg/bin"; + fi; + if (( hostOffset <= -1 )); then + addToSearchPath _XDG_DATA_DIRS "$pkg/share"; + fi; + if [[ "$hostOffset" -eq 0 && -d "$pkg/bin" ]]; then + addToSearchPath _HOST_PATH "$pkg/bin"; + fi; + if [[ -f "$pkg/nix-support/setup-hook" ]]; then + nixTalkativeLog "sourcing setup hook '$pkg/nix-support/setup-hook'"; + source "$pkg/nix-support/setup-hook"; + fi +} +addEnvHooks () +{ + + local depHostOffset="$1"; + shift; + local pkgHookVarsSlice="${pkgHookVarVars[$depHostOffset + 1]}[@]"; + local pkgHookVar; + for pkgHookVar in "${!pkgHookVarsSlice}"; + do + eval "${pkgHookVar}s"'+=("$@")'; + done +} +addToSearchPath () +{ + + addToSearchPathWithCustomDelimiter ":" "$@" +} +addToSearchPathWithCustomDelimiter () +{ + + local delimiter="$1"; + local varName="$2"; + local dir="$3"; + if [[ -d "$dir" && "${!varName:+${delimiter}${!varName}${delimiter}}" != *"${delimiter}${dir}${delimiter}"* ]]; then + export "${varName}=${!varName:+${!varName}${delimiter}}${dir}"; + fi +} +appendToVar () +{ + + local -n nameref="$1"; + local useArray type; + if [ -n "$__structuredAttrs" ]; then + useArray=true; + else + useArray=false; + fi; + if type=$(declare -p "$1" 2> /dev/null); then + case "${type#* }" in + -A*) + echo "appendToVar(): ERROR: trying to use appendToVar on an associative array, use variable+=([\"X\"]=\"Y\") instead." 1>&2; + return 1 + ;; + -a*) + useArray=true + ;; + *) + useArray=false + ;; + esac; + fi; + shift; + if $useArray; then + nameref=(${nameref+"${nameref[@]}"} "$@"); + else + nameref="${nameref-} $*"; + fi +} +auditTmpdir () +{ + + local dir="$1"; + [ -e "$dir" ] || return 0; + echo "checking for references to $TMPDIR/ in $dir..."; + local tmpdir elf_fifo script_fifo; + tmpdir="$(mktemp -d)"; + elf_fifo="$tmpdir/elf"; + script_fifo="$tmpdir/script"; + mkfifo "$elf_fifo" "$script_fifo"; + ( find "$dir" -type f -not -path '*/.build-id/*' -print0 | while IFS= read -r -d '' file; do + if isELF "$file"; then + printf '%s\0' "$file" 1>&3; + else + if isScript "$file"; then + filename=${file##*/}; + dir=${file%/*}; + if [ -e "$dir/.$filename-wrapped" ]; then + printf '%s\0' "$file" 1>&4; + fi; + fi; + fi; + done; + exec 3>&- 4>&- ) 3> "$elf_fifo" 4> "$script_fifo" & ( xargs -0 -r -P "$NIX_BUILD_CORES" -n 1 sh -c ' + if { printf :; patchelf --print-rpath "$1"; } | grep -q -F ":$TMPDIR/"; then + echo "RPATH of binary $1 contains a forbidden reference to $TMPDIR/" + exit 1 + fi + ' _ < "$elf_fifo" ) & local pid_elf=$!; + local pid_script; + ( xargs -0 -r -P "$NIX_BUILD_CORES" -n 1 sh -c ' + if grep -q -F "$TMPDIR/" "$1"; then + echo "wrapper script $1 contains a forbidden reference to $TMPDIR/" + exit 1 + fi + ' _ < "$script_fifo" ) & local pid_script=$!; + wait "$pid_elf" || { + echo "Some binaries contain forbidden references to $TMPDIR/. Check the error above!"; + exit 1 + }; + wait "$pid_script" || { + echo "Some scripts contain forbidden references to $TMPDIR/. Check the error above!"; + exit 1 + }; + rm -r "$tmpdir" +} +bintoolsWrapper_addLDVars () +{ + + local role_post; + getHostRoleEnvHook; + if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then + export NIX_LDFLAGS${role_post}+=" -L$1/lib64"; + fi; + if [[ -d "$1/lib" ]]; then + local -a glob=($1/lib/lib*); + if [ "${#glob[*]}" -gt 0 ]; then + export NIX_LDFLAGS${role_post}+=" -L$1/lib"; + fi; + fi +} +buildPhase () +{ + + runHook preBuild; + if [[ -z "${makeFlags-}" && -z "${makefile:-}" && ! ( -e Makefile || -e makefile || -e GNUmakefile ) ]]; then + echo "no Makefile or custom buildPhase, doing nothing"; + else + foundMakefile=1; + local flagsArray=(${enableParallelBuilding:+-j${NIX_BUILD_CORES}} SHELL="$SHELL"); + concatTo flagsArray makeFlags makeFlagsArray buildFlags buildFlagsArray; + echoCmd 'build flags' "${flagsArray[@]}"; + make ${makefile:+-f $makefile} "${flagsArray[@]}"; + unset flagsArray; + fi; + runHook postBuild +} +ccWrapper_addCVars () +{ + + local role_post; + getHostRoleEnvHook; + local found=; + if [ -d "$1/include" ]; then + export NIX_CFLAGS_COMPILE${role_post}+=" -isystem $1/include"; + found=1; + fi; + if [ -d "$1/Library/Frameworks" ]; then + export NIX_CFLAGS_COMPILE${role_post}+=" -iframework $1/Library/Frameworks"; + found=1; + fi; + if [[ -n "" && -n ${NIX_STORE:-} && -n $found ]]; then + local scrubbed="$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-${1#"$NIX_STORE"/*-}"; + export NIX_CFLAGS_COMPILE${role_post}+=" -fmacro-prefix-map=$1=$scrubbed"; + fi +} +checkPhase () +{ + + runHook preCheck; + if [[ -z "${foundMakefile:-}" ]]; then + echo "no Makefile or custom checkPhase, doing nothing"; + runHook postCheck; + return; + fi; + if [[ -z "${checkTarget:-}" ]]; then + if make -n ${makefile:+-f $makefile} check > /dev/null 2>&1; then + checkTarget="check"; + else + if make -n ${makefile:+-f $makefile} test > /dev/null 2>&1; then + checkTarget="test"; + fi; + fi; + fi; + if [[ -z "${checkTarget:-}" ]]; then + echo "no check/test target in ${makefile:-Makefile}, doing nothing"; + else + local flagsArray=(${enableParallelChecking:+-j${NIX_BUILD_CORES}} SHELL="$SHELL"); + concatTo flagsArray makeFlags makeFlagsArray checkFlags=VERBOSE=y checkFlagsArray checkTarget; + echoCmd 'check flags' "${flagsArray[@]}"; + make ${makefile:+-f $makefile} "${flagsArray[@]}"; + unset flagsArray; + fi; + runHook postCheck +} +compressManPages () +{ + + local dir="$1"; + if [ -L "$dir"/share ] || [ -L "$dir"/share/man ] || [ ! -d "$dir/share/man" ]; then + return; + fi; + echo "gzipping man pages under $dir/share/man/"; + find "$dir"/share/man/ -type f -a '!' -regex '.*\.\(bz2\|gz\|xz\)$' -print0 | xargs -0 -n1 -P "$NIX_BUILD_CORES" gzip -n -f; + find "$dir"/share/man/ -type l -a '!' -regex '.*\.\(bz2\|gz\|xz\)$' -print0 | sort -z | while IFS= read -r -d '' f; do + local target; + target="$(readlink -f "$f")"; + if [ -f "$target".gz ]; then + ln -sf "$target".gz "$f".gz && rm "$f"; + fi; + done +} +concatStringsSep () +{ + + local sep="$1"; + local name="$2"; + local type oldifs; + if type=$(declare -p "$name" 2> /dev/null); then + local -n nameref="$name"; + case "${type#* }" in + -A*) + echo "concatStringsSep(): ERROR: trying to use concatStringsSep on an associative array." 1>&2; + return 1 + ;; + -a*) + local IFS="$(printf '\036')" + ;; + *) + local IFS=" " + ;; + esac; + local ifs_separated="${nameref[*]}"; + echo -n "${ifs_separated//"$IFS"/"$sep"}"; + fi +} +concatTo () +{ + + local -; + set -o noglob; + local -n targetref="$1"; + shift; + local arg default name type; + for arg in "$@"; + do + IFS="=" read -r name default <<< "$arg"; + local -n nameref="$name"; + if [[ -z "${nameref[*]}" && -n "$default" ]]; then + targetref+=("$default"); + else + if type=$(declare -p "$name" 2> /dev/null); then + case "${type#* }" in + -A*) + echo "concatTo(): ERROR: trying to use concatTo on an associative array." 1>&2; + return 1 + ;; + -a*) + targetref+=("${nameref[@]}") + ;; + *) + if [[ "$name" = *"Array" ]]; then + nixErrorLog "concatTo(): $name is not declared as array, treating as a singleton. This will become an error in future"; + targetref+=(${nameref+"${nameref[@]}"}); + else + targetref+=(${nameref-}); + fi + ;; + esac; + fi; + fi; + done +} +configurePhase () +{ + + runHook preConfigure; + : "${configureScript=}"; + if [[ -z "$configureScript" && -x ./configure ]]; then + configureScript=./configure; + fi; + if [ -z "${dontFixLibtool:-}" ]; then + export lt_cv_deplibs_check_method="${lt_cv_deplibs_check_method-pass_all}"; + local i; + find . -iname "ltmain.sh" -print0 | while IFS='' read -r -d '' i; do + echo "fixing libtool script $i"; + fixLibtool "$i"; + done; + CONFIGURE_MTIME_REFERENCE=$(mktemp configure.mtime.reference.XXXXXX); + find . -executable -type f -name configure -exec grep -l 'GNU Libtool is free software; you can redistribute it and/or modify' {} \; -exec touch -r {} "$CONFIGURE_MTIME_REFERENCE" \; -exec sed -i s_/usr/bin/file_file_g {} \; -exec touch -r "$CONFIGURE_MTIME_REFERENCE" {} \;; + rm -f "$CONFIGURE_MTIME_REFERENCE"; + fi; + if [[ -z "${dontAddPrefix:-}" && -n "$prefix" ]]; then + prependToVar configureFlags "${prefixKey:---prefix=}$prefix"; + fi; + if [[ -f "$configureScript" ]]; then + if [ -z "${dontAddDisableDepTrack:-}" ]; then + if grep -q dependency-tracking "$configureScript"; then + prependToVar configureFlags --disable-dependency-tracking; + fi; + fi; + if [ -z "${dontDisableStatic:-}" ]; then + if grep -q enable-static "$configureScript"; then + prependToVar configureFlags --disable-static; + fi; + fi; + if [ -z "${dontPatchShebangsInConfigure:-}" ]; then + patchShebangs --build "$configureScript"; + fi; + fi; + if [ -n "$configureScript" ]; then + local -a flagsArray; + concatTo flagsArray configureFlags configureFlagsArray; + echoCmd 'configure flags' "${flagsArray[@]}"; + $configureScript "${flagsArray[@]}"; + unset flagsArray; + else + echo "no configure script, doing nothing"; + fi; + runHook postConfigure +} +consumeEntire () +{ + + if IFS='' read -r -d '' "$1"; then + echo "consumeEntire(): ERROR: Input null bytes, won't process" 1>&2; + return 1; + fi +} +distPhase () +{ + + runHook preDist; + local flagsArray=(); + concatTo flagsArray distFlags distFlagsArray distTarget=dist; + echo 'dist flags: %q' "${flagsArray[@]}"; + make ${makefile:+-f $makefile} "${flagsArray[@]}"; + if [ "${dontCopyDist:-0}" != 1 ]; then + mkdir -p "$out/tarballs"; + cp -pvd ${tarballs[*]:-*.tar.gz} "$out/tarballs"; + fi; + runHook postDist +} +dumpVars () +{ + + if [[ "${noDumpEnvVars:-0}" != 1 && -d "$NIX_BUILD_TOP" ]]; then + local old_umask; + old_umask=$(umask); + umask 0077; + export 2> /dev/null > "$NIX_BUILD_TOP/env-vars"; + umask "$old_umask"; + fi +} +echoCmd () +{ + + printf "%s:" "$1"; + shift; + printf ' %q' "$@"; + echo +} +exitHandler () +{ + + exitCode="$?"; + set +e; + if [ -n "${showBuildStats:-}" ]; then + read -r -d '' -a buildTimes < <(times); + echo "build times:"; + echo "user time for the shell ${buildTimes[0]}"; + echo "system time for the shell ${buildTimes[1]}"; + echo "user time for all child processes ${buildTimes[2]}"; + echo "system time for all child processes ${buildTimes[3]}"; + fi; + if (( "$exitCode" != 0 )); then + runHook failureHook; + if [ -n "${succeedOnFailure:-}" ]; then + echo "build failed with exit code $exitCode (ignored)"; + mkdir -p "$out/nix-support"; + printf "%s" "$exitCode" > "$out/nix-support/failed"; + exit 0; + fi; + else + runHook exitHook; + fi; + return "$exitCode" +} +findInputs () +{ + + local -r pkg="$1"; + local -r hostOffset="$2"; + local -r targetOffset="$3"; + (( hostOffset <= targetOffset )) || exit 1; + local varVar="${pkgAccumVarVars[hostOffset + 1]}"; + local varRef="$varVar[$((targetOffset - hostOffset))]"; + local var="${!varRef}"; + unset -v varVar varRef; + local varSlice="$var[*]"; + case " ${!varSlice-} " in + *" $pkg "*) + return 0 + ;; + esac; + unset -v varSlice; + eval "$var"'+=("$pkg")'; + if ! [ -e "$pkg" ]; then + echo "build input $pkg does not exist" 1>&2; + exit 1; + fi; + function mapOffset () + { + local -r inputOffset="$1"; + local -n outputOffset="$2"; + if (( inputOffset <= 0 )); then + outputOffset=$((inputOffset + hostOffset)); + else + outputOffset=$((inputOffset - 1 + targetOffset)); + fi + }; + local relHostOffset; + for relHostOffset in "${allPlatOffsets[@]}"; + do + local files="${propagatedDepFilesVars[relHostOffset + 1]}"; + local hostOffsetNext; + mapOffset "$relHostOffset" hostOffsetNext; + (( -1 <= hostOffsetNext && hostOffsetNext <= 1 )) || continue; + local relTargetOffset; + for relTargetOffset in "${allPlatOffsets[@]}"; + do + (( "$relHostOffset" <= "$relTargetOffset" )) || continue; + local fileRef="${files}[$relTargetOffset - $relHostOffset]"; + local file="${!fileRef}"; + unset -v fileRef; + local targetOffsetNext; + mapOffset "$relTargetOffset" targetOffsetNext; + (( -1 <= hostOffsetNext && hostOffsetNext <= 1 )) || continue; + [[ -f "$pkg/nix-support/$file" ]] || continue; + local pkgNext; + read -r -d '' pkgNext < "$pkg/nix-support/$file" || true; + for pkgNext in $pkgNext; + do + findInputs "$pkgNext" "$hostOffsetNext" "$targetOffsetNext"; + done; + done; + done +} +fixLibtool () +{ + + local search_path; + for flag in $NIX_LDFLAGS; + do + case $flag in + -L*) + search_path+=" ${flag#-L}" + ;; + esac; + done; + sed -i "$1" -e "s^eval \(sys_lib_search_path=\).*^\1'${search_path:-}'^" -e 's^eval sys_lib_.+search_path=.*^^' +} +fixupPhase () +{ + + local output; + for output in $(getAllOutputNames); + do + if [ -e "${!output}" ]; then + chmod -R u+w,u-s,g-s "${!output}"; + fi; + done; + runHook preFixup; + local output; + for output in $(getAllOutputNames); + do + prefix="${!output}" runHook fixupOutput; + done; + recordPropagatedDependencies; + if [ -n "${setupHook:-}" ]; then + mkdir -p "${!outputDev}/nix-support"; + substituteAll "$setupHook" "${!outputDev}/nix-support/setup-hook"; + fi; + if [ -n "${setupHooks:-}" ]; then + mkdir -p "${!outputDev}/nix-support"; + local hook; + for hook in ${setupHooks[@]}; + do + local content; + consumeEntire content < "$hook"; + substituteAllStream content "file '$hook'" >> "${!outputDev}/nix-support/setup-hook"; + unset -v content; + done; + unset -v hook; + fi; + if [ -n "${propagatedUserEnvPkgs[*]:-}" ]; then + mkdir -p "${!outputBin}/nix-support"; + printWords "${propagatedUserEnvPkgs[@]}" > "${!outputBin}/nix-support/propagated-user-env-packages"; + fi; + runHook postFixup +} +genericBuild () +{ + + export GZIP_NO_TIMESTAMPS=1; + if [ -f "${buildCommandPath:-}" ]; then + source "$buildCommandPath"; + return; + fi; + if [ -n "${buildCommand:-}" ]; then + eval "$buildCommand"; + return; + fi; + if [ -z "${phases[*]:-}" ]; then + phases="${prePhases[*]:-} unpackPhase patchPhase ${preConfigurePhases[*]:-} configurePhase ${preBuildPhases[*]:-} buildPhase checkPhase ${preInstallPhases[*]:-} installPhase ${preFixupPhases[*]:-} fixupPhase installCheckPhase ${preDistPhases[*]:-} distPhase ${postPhases[*]:-}"; + fi; + for curPhase in ${phases[*]}; + do + runPhase "$curPhase"; + done +} +getAllOutputNames () +{ + + if [ -n "$__structuredAttrs" ]; then + echo "${!outputs[*]}"; + else + echo "$outputs"; + fi +} +getHostRole () +{ + + getRole "$hostOffset" +} +getHostRoleEnvHook () +{ + + getRole "$depHostOffset" +} +getRole () +{ + + case $1 in + -1) + role_post='_FOR_BUILD' + ;; + 0) + role_post='' + ;; + 1) + role_post='_FOR_TARGET' + ;; + *) + echo "binutils-wrapper-2.44: used as improper sort of dependency" 1>&2; + return 1 + ;; + esac +} +getTargetRole () +{ + + getRole "$targetOffset" +} +getTargetRoleEnvHook () +{ + + getRole "$depTargetOffset" +} +getTargetRoleWrapper () +{ + + case $targetOffset in + -1) + export NIX_BINTOOLS_WRAPPER_TARGET_BUILD_x86_64_unknown_linux_gnu=1 + ;; + 0) + export NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu=1 + ;; + 1) + export NIX_BINTOOLS_WRAPPER_TARGET_TARGET_x86_64_unknown_linux_gnu=1 + ;; + *) + echo "binutils-wrapper-2.44: used as improper sort of dependency" 1>&2; + return 1 + ;; + esac +} +installCheckPhase () +{ + + runHook preInstallCheck; + if [[ -z "${foundMakefile:-}" ]]; then + echo "no Makefile or custom installCheckPhase, doing nothing"; + else + if [[ -z "${installCheckTarget:-}" ]] && ! make -n ${makefile:+-f $makefile} "${installCheckTarget:-installcheck}" > /dev/null 2>&1; then + echo "no installcheck target in ${makefile:-Makefile}, doing nothing"; + else + local flagsArray=(${enableParallelChecking:+-j${NIX_BUILD_CORES}} SHELL="$SHELL"); + concatTo flagsArray makeFlags makeFlagsArray installCheckFlags installCheckFlagsArray installCheckTarget=installcheck; + echoCmd 'installcheck flags' "${flagsArray[@]}"; + make ${makefile:+-f $makefile} "${flagsArray[@]}"; + unset flagsArray; + fi; + fi; + runHook postInstallCheck +} +installPhase () +{ + + runHook preInstall; + if [[ -z "${makeFlags-}" && -z "${makefile:-}" && ! ( -e Makefile || -e makefile || -e GNUmakefile ) ]]; then + echo "no Makefile or custom installPhase, doing nothing"; + runHook postInstall; + return; + else + foundMakefile=1; + fi; + if [ -n "$prefix" ]; then + mkdir -p "$prefix"; + fi; + local flagsArray=(${enableParallelInstalling:+-j${NIX_BUILD_CORES}} SHELL="$SHELL"); + concatTo flagsArray makeFlags makeFlagsArray installFlags installFlagsArray installTargets=install; + echoCmd 'install flags' "${flagsArray[@]}"; + make ${makefile:+-f $makefile} "${flagsArray[@]}"; + unset flagsArray; + runHook postInstall +} +isELF () +{ + + local fn="$1"; + local fd; + local magic; + exec {fd}< "$fn"; + LANG=C read -r -n 4 -u "$fd" magic; + exec {fd}>&-; + if [ "$magic" = 'ELF' ]; then + return 0; + else + return 1; + fi +} +isMachO () +{ + + local fn="$1"; + local fd; + local magic; + exec {fd}< "$fn"; + LANG=C read -r -n 4 -u "$fd" magic; + exec {fd}>&-; + if [[ "$magic" = $(echo -ne "\xfe\xed\xfa\xcf") || "$magic" = $(echo -ne "\xcf\xfa\xed\xfe") ]]; then + return 0; + else + if [[ "$magic" = $(echo -ne "\xfe\xed\xfa\xce") || "$magic" = $(echo -ne "\xce\xfa\xed\xfe") ]]; then + return 0; + else + if [[ "$magic" = $(echo -ne "\xca\xfe\xba\xbe") || "$magic" = $(echo -ne "\xbe\xba\xfe\xca") ]]; then + return 0; + else + return 1; + fi; + fi; + fi +} +isScript () +{ + + local fn="$1"; + local fd; + local magic; + exec {fd}< "$fn"; + LANG=C read -r -n 2 -u "$fd" magic; + exec {fd}>&-; + if [[ "$magic" =~ \#! ]]; then + return 0; + else + return 1; + fi +} +mapOffset () +{ + + local -r inputOffset="$1"; + local -n outputOffset="$2"; + if (( inputOffset <= 0 )); then + outputOffset=$((inputOffset + hostOffset)); + else + outputOffset=$((inputOffset - 1 + targetOffset)); + fi +} +moveToOutput () +{ + + local patt="$1"; + local dstOut="$2"; + local output; + for output in $(getAllOutputNames); + do + if [ "${!output}" = "$dstOut" ]; then + continue; + fi; + local srcPath; + for srcPath in "${!output}"/$patt; + do + if [ ! -e "$srcPath" ] && [ ! -L "$srcPath" ]; then + continue; + fi; + if [ "$dstOut" = REMOVE ]; then + echo "Removing $srcPath"; + rm -r "$srcPath"; + else + local dstPath="$dstOut${srcPath#${!output}}"; + echo "Moving $srcPath to $dstPath"; + if [ -d "$dstPath" ] && [ -d "$srcPath" ]; then + rmdir "$srcPath" --ignore-fail-on-non-empty; + if [ -d "$srcPath" ]; then + mv -t "$dstPath" "$srcPath"/*; + rmdir "$srcPath"; + fi; + else + mkdir -p "$(readlink -m "$dstPath/..")"; + mv "$srcPath" "$dstPath"; + fi; + fi; + local srcParent="$(readlink -m "$srcPath/..")"; + if [ -n "$(find "$srcParent" -maxdepth 0 -type d -empty 2> /dev/null)" ]; then + echo "Removing empty $srcParent/ and (possibly) its parents"; + rmdir -p --ignore-fail-on-non-empty "$srcParent" 2> /dev/null || true; + fi; + done; + done +} +nixChattyLog () +{ + + _nixLogWithLevel 5 "$*" +} +nixDebugLog () +{ + + _nixLogWithLevel 6 "$*" +} +nixErrorLog () +{ + + _nixLogWithLevel 0 "$*" +} +nixInfoLog () +{ + + _nixLogWithLevel 3 "$*" +} +nixLog () +{ + + [[ -z ${NIX_LOG_FD-} ]] && return 0; + local callerName="${FUNCNAME[1]}"; + if [[ $callerName == "_callImplicitHook" ]]; then + callerName="${hookName:?}"; + fi; + printf "%s: %s\n" "$callerName" "$*" >&"$NIX_LOG_FD" +} +nixNoticeLog () +{ + + _nixLogWithLevel 2 "$*" +} +nixTalkativeLog () +{ + + _nixLogWithLevel 4 "$*" +} +nixVomitLog () +{ + + _nixLogWithLevel 7 "$*" +} +nixWarnLog () +{ + + _nixLogWithLevel 1 "$*" +} +noBrokenSymlinks () +{ + + local -r output="${1:?}"; + local path; + local pathParent; + local symlinkTarget; + local -i numDanglingSymlinks=0; + local -i numReflexiveSymlinks=0; + local -i numUnreadableSymlinks=0; + if [[ ! -e $output ]]; then + nixWarnLog "skipping non-existent output $output"; + return 0; + fi; + nixInfoLog "running on $output"; + while IFS= read -r -d '' path; do + pathParent="$(dirname "$path")"; + if ! symlinkTarget="$(readlink "$path")"; then + nixErrorLog "the symlink $path is unreadable"; + numUnreadableSymlinks+=1; + continue; + fi; + if [[ $symlinkTarget == /* ]]; then + nixInfoLog "symlink $path points to absolute target $symlinkTarget"; + else + nixInfoLog "symlink $path points to relative target $symlinkTarget"; + symlinkTarget="$(realpath --no-symlinks --canonicalize-missing "$pathParent/$symlinkTarget")"; + fi; + if [[ $symlinkTarget = "$TMPDIR"/* ]]; then + nixErrorLog "the symlink $path points to $TMPDIR directory: $symlinkTarget"; + numDanglingSymlinks+=1; + continue; + fi; + if [[ $symlinkTarget != "$NIX_STORE"/* ]]; then + nixInfoLog "symlink $path points outside the Nix store; ignoring"; + continue; + fi; + if [[ $path == "$symlinkTarget" ]]; then + nixErrorLog "the symlink $path is reflexive"; + numReflexiveSymlinks+=1; + else + if [[ ! -e $symlinkTarget ]]; then + nixErrorLog "the symlink $path points to a missing target: $symlinkTarget"; + numDanglingSymlinks+=1; + else + nixDebugLog "the symlink $path is irreflexive and points to a target which exists"; + fi; + fi; + done < <(find "$output" -type l -print0); + if ((numDanglingSymlinks > 0 || numReflexiveSymlinks > 0 || numUnreadableSymlinks > 0)); then + nixErrorLog "found $numDanglingSymlinks dangling symlinks, $numReflexiveSymlinks reflexive symlinks and $numUnreadableSymlinks unreadable symlinks"; + exit 1; + fi; + return 0 +} +noBrokenSymlinksInAllOutputs () +{ + + if [[ -z ${dontCheckForBrokenSymlinks-} ]]; then + for output in $(getAllOutputNames); + do + noBrokenSymlinks "${!output}"; + done; + fi +} +patchELF () +{ + + local dir="$1"; + [ -e "$dir" ] || return 0; + echo "shrinking RPATHs of ELF executables and libraries in $dir"; + local i; + while IFS= read -r -d '' i; do + if [[ "$i" =~ .build-id ]]; then + continue; + fi; + if ! isELF "$i"; then + continue; + fi; + echo "shrinking $i"; + patchelf --shrink-rpath "$i" || true; + done < <(find "$dir" -type f -print0) +} +patchPhase () +{ + + runHook prePatch; + local -a patchesArray; + concatTo patchesArray patches; + local -a flagsArray; + concatTo flagsArray patchFlags=-p1; + for i in "${patchesArray[@]}"; + do + echo "applying patch $i"; + local uncompress=cat; + case "$i" in + *.gz) + uncompress="gzip -d" + ;; + *.bz2) + uncompress="bzip2 -d" + ;; + *.xz) + uncompress="xz -d" + ;; + *.lzma) + uncompress="lzma -d" + ;; + esac; + $uncompress < "$i" 2>&1 | patch "${flagsArray[@]}"; + done; + runHook postPatch +} +patchShebangs () +{ + + local pathName; + local update=false; + while [[ $# -gt 0 ]]; do + case "$1" in + --host) + pathName=HOST_PATH; + shift + ;; + --build) + pathName=PATH; + shift + ;; + --update) + update=true; + shift + ;; + --) + shift; + break + ;; + -* | --*) + echo "Unknown option $1 supplied to patchShebangs" 1>&2; + return 1 + ;; + *) + break + ;; + esac; + done; + echo "patching script interpreter paths in $@"; + local f; + local oldPath; + local newPath; + local arg0; + local args; + local oldInterpreterLine; + local newInterpreterLine; + if [[ $# -eq 0 ]]; then + echo "No arguments supplied to patchShebangs" 1>&2; + return 0; + fi; + local f; + while IFS= read -r -d '' f; do + isScript "$f" || continue; + read -r oldInterpreterLine < "$f" || [ "$oldInterpreterLine" ]; + read -r oldPath arg0 args <<< "${oldInterpreterLine:2}"; + if [[ -z "${pathName:-}" ]]; then + if [[ -n $strictDeps && $f == "$NIX_STORE"* ]]; then + pathName=HOST_PATH; + else + pathName=PATH; + fi; + fi; + if [[ "$oldPath" == *"/bin/env" ]]; then + if [[ $arg0 == "-S" ]]; then + arg0=${args%% *}; + [[ "$args" == *" "* ]] && args=${args#* } || args=; + newPath="$(PATH="${!pathName}" type -P "env" || true)"; + args="-S $(PATH="${!pathName}" type -P "$arg0" || true) $args"; + else + if [[ $arg0 == "-"* || $arg0 == *"="* ]]; then + echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" 1>&2; + exit 1; + else + newPath="$(PATH="${!pathName}" type -P "$arg0" || true)"; + fi; + fi; + else + if [[ -z $oldPath ]]; then + oldPath="/bin/sh"; + fi; + newPath="$(PATH="${!pathName}" type -P "$(basename "$oldPath")" || true)"; + args="$arg0 $args"; + fi; + newInterpreterLine="$newPath $args"; + newInterpreterLine=${newInterpreterLine%${newInterpreterLine##*[![:space:]]}}; + if [[ -n "$oldPath" && ( "$update" == true || "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ) ]]; then + if [[ -n "$newPath" && "$newPath" != "$oldPath" ]]; then + echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""; + escapedInterpreterLine=${newInterpreterLine//\\/\\\\}; + timestamp=$(stat --printf "%y" "$f"); + tmpFile=$(mktemp -t patchShebangs.XXXXXXXXXX); + sed -e "1 s|.*|#\!$escapedInterpreterLine|" "$f" > "$tmpFile"; + local restoreReadOnly; + if [[ ! -w "$f" ]]; then + chmod +w "$f"; + restoreReadOnly=true; + fi; + cat "$tmpFile" > "$f"; + rm "$tmpFile"; + if [[ -n "${restoreReadOnly:-}" ]]; then + chmod -w "$f"; + fi; + touch --date "$timestamp" "$f"; + fi; + fi; + done < <(find "$@" -type f -perm -0100 -print0) +} +patchShebangsAuto () +{ + + if [[ -z "${dontPatchShebangs-}" && -e "$prefix" ]]; then + if [[ "$output" != out && "$output" = "$outputDev" ]]; then + patchShebangs --build "$prefix"; + else + patchShebangs --host "$prefix"; + fi; + fi +} +pkgConfigWrapper_addPkgConfigPath () +{ + + local role_post; + getHostRoleEnvHook; + addToSearchPath "PKG_CONFIG_PATH${role_post}" "$1/lib/pkgconfig"; + addToSearchPath "PKG_CONFIG_PATH${role_post}" "$1/share/pkgconfig" +} +prependToVar () +{ + + local -n nameref="$1"; + local useArray type; + if [ -n "$__structuredAttrs" ]; then + useArray=true; + else + useArray=false; + fi; + if type=$(declare -p "$1" 2> /dev/null); then + case "${type#* }" in + -A*) + echo "prependToVar(): ERROR: trying to use prependToVar on an associative array." 1>&2; + return 1 + ;; + -a*) + useArray=true + ;; + *) + useArray=false + ;; + esac; + fi; + shift; + if $useArray; then + nameref=("$@" ${nameref+"${nameref[@]}"}); + else + nameref="$* ${nameref-}"; + fi +} +printLines () +{ + + (( "$#" > 0 )) || return 0; + printf '%s\n' "$@" +} +printWords () +{ + + (( "$#" > 0 )) || return 0; + printf '%s ' "$@" +} +recordPropagatedDependencies () +{ + + declare -ra flatVars=(depsBuildBuildPropagated propagatedNativeBuildInputs depsBuildTargetPropagated depsHostHostPropagated propagatedBuildInputs depsTargetTargetPropagated); + declare -ra flatFiles=("${propagatedBuildDepFiles[@]}" "${propagatedHostDepFiles[@]}" "${propagatedTargetDepFiles[@]}"); + local propagatedInputsIndex; + for propagatedInputsIndex in "${!flatVars[@]}"; + do + local propagatedInputsSlice="${flatVars[$propagatedInputsIndex]}[@]"; + local propagatedInputsFile="${flatFiles[$propagatedInputsIndex]}"; + [[ -n "${!propagatedInputsSlice}" ]] || continue; + mkdir -p "${!outputDev}/nix-support"; + printWords ${!propagatedInputsSlice} > "${!outputDev}/nix-support/$propagatedInputsFile"; + done +} +runHook () +{ + + local hookName="$1"; + shift; + local hooksSlice="${hookName%Hook}Hooks[@]"; + local hook; + for hook in "_callImplicitHook 0 $hookName" ${!hooksSlice+"${!hooksSlice}"}; + do + _logHook "$hookName" "$hook" "$@"; + _eval "$hook" "$@"; + done; + return 0 +} +runOneHook () +{ + + local hookName="$1"; + shift; + local hooksSlice="${hookName%Hook}Hooks[@]"; + local hook ret=1; + for hook in "_callImplicitHook 1 $hookName" ${!hooksSlice+"${!hooksSlice}"}; + do + _logHook "$hookName" "$hook" "$@"; + if _eval "$hook" "$@"; then + ret=0; + break; + fi; + done; + return "$ret" +} +runPhase () +{ + + local curPhase="$*"; + if [[ "$curPhase" = unpackPhase && -n "${dontUnpack:-}" ]]; then + return; + fi; + if [[ "$curPhase" = patchPhase && -n "${dontPatch:-}" ]]; then + return; + fi; + if [[ "$curPhase" = configurePhase && -n "${dontConfigure:-}" ]]; then + return; + fi; + if [[ "$curPhase" = buildPhase && -n "${dontBuild:-}" ]]; then + return; + fi; + if [[ "$curPhase" = checkPhase && -z "${doCheck:-}" ]]; then + return; + fi; + if [[ "$curPhase" = installPhase && -n "${dontInstall:-}" ]]; then + return; + fi; + if [[ "$curPhase" = fixupPhase && -n "${dontFixup:-}" ]]; then + return; + fi; + if [[ "$curPhase" = installCheckPhase && -z "${doInstallCheck:-}" ]]; then + return; + fi; + if [[ "$curPhase" = distPhase && -z "${doDist:-}" ]]; then + return; + fi; + showPhaseHeader "$curPhase"; + dumpVars; + local startTime endTime; + startTime=$(date +"%s"); + eval "${!curPhase:-$curPhase}"; + endTime=$(date +"%s"); + showPhaseFooter "$curPhase" "$startTime" "$endTime"; + if [ "$curPhase" = unpackPhase ]; then + [ -n "${sourceRoot:-}" ] && chmod +x -- "${sourceRoot}"; + cd -- "${sourceRoot:-.}"; + fi +} +showPhaseFooter () +{ + + local phase="$1"; + local startTime="$2"; + local endTime="$3"; + local delta=$(( endTime - startTime )); + (( delta < 30 )) && return; + local H=$((delta/3600)); + local M=$((delta%3600/60)); + local S=$((delta%60)); + echo -n "$phase completed in "; + (( H > 0 )) && echo -n "$H hours "; + (( M > 0 )) && echo -n "$M minutes "; + echo "$S seconds" +} +showPhaseHeader () +{ + + local phase="$1"; + echo "Running phase: $phase"; + if [[ -z ${NIX_LOG_FD-} ]]; then + return; + fi; + printf "@nix { \"action\": \"setPhase\", \"phase\": \"%s\" }\n" "$phase" >&"$NIX_LOG_FD" +} +stripDirs () +{ + + local cmd="$1"; + local ranlibCmd="$2"; + local paths="$3"; + local stripFlags="$4"; + local excludeFlags=(); + local pathsNew=; + [ -z "$cmd" ] && echo "stripDirs: Strip command is empty" 1>&2 && exit 1; + [ -z "$ranlibCmd" ] && echo "stripDirs: Ranlib command is empty" 1>&2 && exit 1; + local pattern; + if [ -n "${stripExclude:-}" ]; then + for pattern in "${stripExclude[@]}"; + do + excludeFlags+=(-a '!' '(' -name "$pattern" -o -wholename "$prefix/$pattern" ')'); + done; + fi; + local p; + for p in ${paths}; + do + if [ -e "$prefix/$p" ]; then + pathsNew="${pathsNew} $prefix/$p"; + fi; + done; + paths=${pathsNew}; + if [ -n "${paths}" ]; then + echo "stripping (with command $cmd and flags $stripFlags) in $paths"; + local striperr; + striperr="$(mktemp --tmpdir="$TMPDIR" 'striperr.XXXXXX')"; + find $paths -type f "${excludeFlags[@]}" -a '!' -path "$prefix/lib/debug/*" -printf '%D-%i,%p\0' | sort -t, -k1,1 -u -z | cut -d, -f2- -z | xargs -r -0 -n1 -P "$NIX_BUILD_CORES" -- $cmd $stripFlags 2> "$striperr" || exit_code=$?; + [[ "$exit_code" = 123 || -z "$exit_code" ]] || ( cat "$striperr" 1>&2 && exit 1 ); + rm "$striperr"; + find $paths -name '*.a' -type f -exec $ranlibCmd '{}' \; 2> /dev/null; + fi +} +stripHash () +{ + + local strippedName casematchOpt=0; + strippedName="$(basename -- "$1")"; + shopt -q nocasematch && casematchOpt=1; + shopt -u nocasematch; + if [[ "$strippedName" =~ ^[a-z0-9]{32}- ]]; then + echo "${strippedName:33}"; + else + echo "$strippedName"; + fi; + if (( casematchOpt )); then + shopt -s nocasematch; + fi +} +substitute () +{ + + local input="$1"; + local output="$2"; + shift 2; + if [ ! -f "$input" ]; then + echo "substitute(): ERROR: file '$input' does not exist" 1>&2; + return 1; + fi; + local content; + consumeEntire content < "$input"; + if [ -e "$output" ]; then + chmod +w "$output"; + fi; + substituteStream content "file '$input'" "$@" > "$output" +} +substituteAll () +{ + + local input="$1"; + local output="$2"; + local -a args=(); + _allFlags; + substitute "$input" "$output" "${args[@]}" +} +substituteAllInPlace () +{ + + local fileName="$1"; + shift; + substituteAll "$fileName" "$fileName" "$@" +} +substituteAllStream () +{ + + local -a args=(); + _allFlags; + substituteStream "$1" "$2" "${args[@]}" +} +substituteInPlace () +{ + + local -a fileNames=(); + for arg in "$@"; + do + if [[ "$arg" = "--"* ]]; then + break; + fi; + fileNames+=("$arg"); + shift; + done; + if ! [[ "${#fileNames[@]}" -gt 0 ]]; then + echo "substituteInPlace called without any files to operate on (files must come before options!)" 1>&2; + return 1; + fi; + for file in "${fileNames[@]}"; + do + substitute "$file" "$file" "$@"; + done +} +substituteStream () +{ + + local var=$1; + local description=$2; + shift 2; + while (( "$#" )); do + local replace_mode="$1"; + case "$1" in + --replace) + if ! "$_substituteStream_has_warned_replace_deprecation"; then + echo "substituteStream() in derivation $name: WARNING: '--replace' is deprecated, use --replace-{fail,warn,quiet}. ($description)" 1>&2; + _substituteStream_has_warned_replace_deprecation=true; + fi; + replace_mode='--replace-warn' + ;& + --replace-quiet | --replace-warn | --replace-fail) + pattern="$2"; + replacement="$3"; + shift 3; + if ! [[ "${!var}" == *"$pattern"* ]]; then + if [ "$replace_mode" == --replace-warn ]; then + printf "substituteStream() in derivation $name: WARNING: pattern %q doesn't match anything in %s\n" "$pattern" "$description" 1>&2; + else + if [ "$replace_mode" == --replace-fail ]; then + printf "substituteStream() in derivation $name: ERROR: pattern %q doesn't match anything in %s\n" "$pattern" "$description" 1>&2; + return 1; + fi; + fi; + fi; + eval "$var"'=${'"$var"'//"$pattern"/"$replacement"}' + ;; + --subst-var) + local varName="$2"; + shift 2; + if ! [[ "$varName" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then + echo "substituteStream() in derivation $name: ERROR: substitution variables must be valid Bash names, \"$varName\" isn't." 1>&2; + return 1; + fi; + if [ -z ${!varName+x} ]; then + echo "substituteStream() in derivation $name: ERROR: variable \$$varName is unset" 1>&2; + return 1; + fi; + pattern="@$varName@"; + replacement="${!varName}"; + eval "$var"'=${'"$var"'//"$pattern"/"$replacement"}' + ;; + --subst-var-by) + pattern="@$2@"; + replacement="$3"; + eval "$var"'=${'"$var"'//"$pattern"/"$replacement"}'; + shift 3 + ;; + *) + echo "substituteStream() in derivation $name: ERROR: Invalid command line argument: $1" 1>&2; + return 1 + ;; + esac; + done; + printf "%s" "${!var}" +} +unpackFile () +{ + + curSrc="$1"; + echo "unpacking source archive $curSrc"; + if ! runOneHook unpackCmd "$curSrc"; then + echo "do not know how to unpack source archive $curSrc"; + exit 1; + fi +} +unpackPhase () +{ + + runHook preUnpack; + if [ -z "${srcs:-}" ]; then + if [ -z "${src:-}" ]; then + echo 'variable $src or $srcs should point to the source'; + exit 1; + fi; + srcs="$src"; + fi; + local -a srcsArray; + concatTo srcsArray srcs; + local dirsBefore=""; + for i in *; + do + if [ -d "$i" ]; then + dirsBefore="$dirsBefore $i "; + fi; + done; + for i in "${srcsArray[@]}"; + do + unpackFile "$i"; + done; + : "${sourceRoot=}"; + if [ -n "${setSourceRoot:-}" ]; then + runOneHook setSourceRoot; + else + if [ -z "$sourceRoot" ]; then + for i in *; + do + if [ -d "$i" ]; then + case $dirsBefore in + *\ $i\ *) + + ;; + *) + if [ -n "$sourceRoot" ]; then + echo "unpacker produced multiple directories"; + exit 1; + fi; + sourceRoot="$i" + ;; + esac; + fi; + done; + fi; + fi; + if [ -z "$sourceRoot" ]; then + echo "unpacker appears to have produced no directories"; + exit 1; + fi; + echo "source root is $sourceRoot"; + if [ "${dontMakeSourcesWritable:-0}" != 1 ]; then + chmod -R u+w -- "$sourceRoot"; + fi; + runHook postUnpack +} +updateAutotoolsGnuConfigScriptsPhase () +{ + + if [ -n "${dontUpdateAutotoolsGnuConfigScripts-}" ]; then + return; + fi; + for script in config.sub config.guess; + do + for f in $(find . -type f -name "$script"); + do + echo "Updating Autotools / GNU config script to a newer upstream version: $f"; + cp -f "/nix/store/1kzclixw4c13wxin0b6cij1zykvwp0wb-gnu-config-2024-01-01/$script" "$f"; + done; + done +} +updateSourceDateEpoch () +{ + + local path="$1"; + [[ $path == -* ]] && path="./$path"; + local -a res=($(find "$path" -type f -not -newer "$NIX_BUILD_TOP/.." -printf '%T@ "%p"\0' | sort -n --zero-terminated | tail -n1 --zero-terminated | head -c -1)); + local time="${res[0]//\.[0-9]*/}"; + local newestFile="${res[1]}"; + if [ "${time:-0}" -gt "$SOURCE_DATE_EPOCH" ]; then + echo "setting SOURCE_DATE_EPOCH to timestamp $time of file $newestFile"; + export SOURCE_DATE_EPOCH="$time"; + local now="$(date +%s)"; + if [ "$time" -gt $((now - 60)) ]; then + echo "warning: file $newestFile may be generated; SOURCE_DATE_EPOCH may be non-deterministic"; + fi; + fi +} +PATH="$PATH${nix_saved_PATH:+:$nix_saved_PATH}" +XDG_DATA_DIRS="$XDG_DATA_DIRS${nix_saved_XDG_DATA_DIRS:+:$nix_saved_XDG_DATA_DIRS}" +export NIX_BUILD_TOP="$(mktemp -d -t nix-shell.XXXXXX)" +export TMP="$NIX_BUILD_TOP" +export TMPDIR="$NIX_BUILD_TOP" +export TEMP="$NIX_BUILD_TOP" +export TEMPDIR="$NIX_BUILD_TOP" +eval "${shellHook:-}" diff --git a/api/Cargo.lock b/api/Cargo.lock index 8ec2a73..3b088e5 100644 --- a/api/Cargo.lock +++ b/api/Cargo.lock @@ -311,12 +311,6 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - [[package]] name = "android_system_properties" version = "0.1.5" @@ -646,16 +640,16 @@ checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "chrono" -version = "0.4.41" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" +checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" dependencies = [ - "android-tzdata", "iana-time-zone", "js-sys", "num-traits", + "serde", "wasm-bindgen", - "windows-link 0.1.3", + "windows-link 0.2.1", ] [[package]] @@ -1606,7 +1600,7 @@ dependencies = [ "libc", "percent-encoding", "pin-project-lite", - "socket2 0.5.10", + "socket2 0.6.1", "system-configuration", "tokio", "tower-service", @@ -1908,6 +1902,8 @@ dependencies = [ name = "libseptastic" version = "0.1.0" dependencies = [ + "chrono", + "chrono-tz", "serde", "serde_json", "sqlx", diff --git a/api/assets/style.css b/api/assets/style.css index 0cb61b6..c963a0f 100644 --- a/api/assets/style.css +++ b/api/assets/style.css @@ -70,7 +70,7 @@ img { .rr-container { background-color: #4c748c; color: #ffffff; - font-size: 1.5em; + font-size: 1.2em; padding: 0.3em; font-weight: bold; display: flex; @@ -81,6 +81,35 @@ img { line-height: 1; } +.train-direction-table { + width: 100%; + border-collapse: collapse; + font-family: mono; + font-size: 14px; +} + +.train-direction-table th, +.train-direction-table td { + border: 1px solid #000; + padding: 4px 8px; + text-align: left; + cursor: pointer; +} + +.train-direction-table th { + background-color: #f0f0f0; + font-weight: bold; +} + +.highlight-row td, +.highlight-row th { + background-color: #d0ebff !important; +} + +.highlight-col { + background-color: #d0ebff !important; +} + .bg-B1, .bg-B2, .bg-B3 { background-color: #FF661C; color: #ffffff; @@ -121,6 +150,8 @@ img { background-color: #ffffff; color: #000000; width: max-content; + height: max-content; + aspect-ratio: 3/2; line-height: 1; } .tscroll { diff --git a/api/config.yaml b/api/config.yaml index 5852e32..e24345b 100644 --- a/api/config.yaml +++ b/api/config.yaml @@ -1,10 +1,38 @@ gtfs_zips: - uri: "https://www3.septa.org/developer/gtfs_public.zip" subzip: "google_rail.zip" + prefix: "SEPTARAIL" - uri: "https://www3.septa.org/developer/gtfs_public.zip" + prefix: "SEPTABUS" subzip: "google_bus.zip" # - uri: "https://www.njtransit.com/rail_data.zip" # - uri: "https://www.njtransit.com/bus_data.zip" annotations: + multiplatform_stops: + - id: 'WTC' + name: 'Wissahickon Transit Center' + platform_station_ids: + - 'SEPTABUS_2' + - 'SEPTABUS_31032' + - 'SEPTABUS_32980' + - 'SEPTABUS_32988' + - 'SEPTABUS_32989' + - 'SEPTABUS_32990' + - 'SEPTABUS_32992' + - 'SEPTABUS_32993' + - id: 'STC' + name: "Susquehanna Transit Center" + platform_station_ids: + - 'SEPTABUS_740' + - 'SEPTABUS_703' + - 'SEPTABUS_699' + - 'SEPTABUS_22302' + - id: 'CCC' + name: "Center City Combined" + platform_station_ids: + - 'SEPTABUS_3057' + - 'SEPTABUS_2687' + - 'SEPTABUS_18451' + - 'SEPTABUS_17170' synthetic_routes: - id: 'NYC' diff --git a/api/src/controllers/mod.rs b/api/src/controllers/mod.rs index b9bb57f..a83d8c0 100644 --- a/api/src/controllers/mod.rs +++ b/api/src/controllers/mod.rs @@ -1 +1,2 @@ pub mod route; +pub mod stop; diff --git a/api/src/controllers/route.rs b/api/src/controllers/route.rs index fcc67fb..64537ab 100644 --- a/api/src/controllers/route.rs +++ b/api/src/controllers/route.rs @@ -1,11 +1,12 @@ use actix_web::{get, web::{self, Data}, HttpRequest, HttpResponse, Responder}; use anyhow::anyhow; -use log::info; use std::{collections::{HashMap, HashSet}, sync::Arc, time::Instant}; use libseptastic::{direction, route::RouteType, stop_schedule::Trip}; use serde::{Serialize, Deserialize}; -use crate::AppState; +use crate::AppState; +//use crate::{routing::{bfs_rts, construct_graph, get_stops_near}, AppState}; +//use crate::routing; #[get("/routes")] async fn get_routes_html(req: HttpRequest, state: Data>) -> impl Responder { @@ -21,7 +22,7 @@ async fn get_routes_html(req: HttpRequest, state: Data>) -> impl R let bus_routes = all_routes.into_iter().filter(|x| x.route_type == RouteType::TracklessTrolley || x.route_type == RouteType::Bus).collect(); Ok(crate::templates::ContentTemplate { - page_title: Some(String::from("SEPTASTIC | Routes")), + page_title: Some(String::from("Routes")), page_desc: Some(String::from("All SEPTA routes.")), widescreen: false, content: crate::templates::RoutesTemplate { @@ -75,106 +76,37 @@ async fn get_route_info(route_id: String, state: Data>) -> ::anyho schedule: trips }) } -pub fn haversine_distance(lat1: f64, lon1: f64, lat2: f64, lon2: f64) -> f64 { - let r = 6371.0; // Earth's radius in kilometers - let d_lat = (lat2 - lat1).to_radians(); - let d_lon = (lon2 - lon1).to_radians(); - - let lat1_rad = lat1.to_radians(); - let lat2_rad = lat2.to_radians(); - - let a = (d_lat / 2.0).sin().powi(2) - + lat1_rad.cos() * lat2_rad.cos() * (d_lon / 2.0).sin().powi(2); - - let c = 2.0 * a.sqrt().asin(); - - r * c -} - -enum RoutingNodeType { - Origin, - Destination, - Midpoint -} - -struct RoutingNodePointer { - pub stop_id: String, - pub route_id: String, - pub stop_sequence: u64, - pub direction: u64 -} - -struct RoutingNode { - pub node_type: RoutingNodeType, - pub stop_id: String, - pub next_stops_per_routes: HashMap>, - pub visited: bool -} - -struct TripState { - pub used_lines: HashSet -} - -struct Coordinates { - pub lat: f64, - pub lng: f64, -} - -#[get("/directions")] -async fn get_directions(state: Data>) -> impl Responder { - let near_thresh = 0.45; - - let sig_cds = Coordinates { - lat: 40.008420, - lng: -75.213439 - }; - - let home_cds = Coordinates { - lat: 39.957210, - lng: -75.166214 - }; - - let all_stops = state.gtfs_service.get_all_stops(); - - let mut response = String::new(); - - - let mut origin_stops: HashSet = HashSet::new(); - let mut dest_stops: HashSet = HashSet::new(); - - let mut graph = HashMap::::new(); - - for stop_p in &all_stops { - let stop = stop_p.1; - - let dist = haversine_distance(sig_cds.lat, sig_cds.lng, stop.lat, stop.lng); - - if dist.abs() < near_thresh { - origin_stops.insert(stop.id.clone()); - graph.insert(stop.id.clone(), RoutingNode { - node_type: RoutingNodeType::Origin, - stop_id: stop.id.clone(), - next_stops_per_routes: , - visited: false - }); - } - } - - for stop_p in &all_stops { - let stop = stop_p.1; - - let dist = haversine_distance(home_cds.lat, home_cds.lng, stop.lat, stop.lng); - - if dist.abs() < near_thresh { - dest_stops.insert(stop.id.clone()); - } - } - - - - return response; -} +//#[get("/directions")] +//async fn get_directions(state: Data>) -> impl Responder { +// let near_thresh = 0.45; +// +// let sig_cds = routing::Coordinates { +// lat: 40.008420, +// lng: -75.213439 +// }; +// +// let home_cds = routing::Coordinates { +// lat: 39.957210, +// lng: -75.166214 +// }; +// +// let all_stops = state.gtfs_service.get_all_stops(); +// +// +// +// let origin_stops: HashSet = get_stops_near(home_cds, &all_stops); +// let dest_stops: HashSet = get_stops_near(sig_cds.clone(), &all_stops); +// +// let mut graph = construct_graph(sig_cds, &all_stops, &state.gtfs_service); +// +// let mut response = String::new(); +// for stop in &origin_stops { +// response += bfs_rts(&stop, &mut graph, &dest_stops).as_str(); +// } +// +// return response; +//} #[get("/route/{route_id}")] async fn get_route(state: Data>, req: HttpRequest, info: web::Query, path: web::Path) -> impl Responder { @@ -183,12 +115,12 @@ async fn get_route(state: Data>, req: HttpRequest, info: web::Quer let infox = info.clone(); let statex = state.clone(); async move { - let mut filters: Option> = None; + let mut filters: Option> = None; if let Some (stops_v) = infox.stops.clone() { let mut items = Vec::new(); for sid in stops_v.split(",") { - items.push(sid.parse::().unwrap()); + items.push(String::from(sid)); } filters = Some(items); } @@ -201,7 +133,7 @@ async fn get_route(state: Data>, req: HttpRequest, info: web::Quer Ok(crate::templates::ContentTemplate { widescreen: false, - page_title: Some(format!("SEPTASTIC | Schedules for {}", route_id.clone())), + page_title: Some(format!("Schedules for {}", route_id.clone())), page_desc: Some(format!("Schedule information for {}", route_id.clone())), content: crate::templates::RouteTemplate { route: route_info.route, diff --git a/api/src/controllers/stop.rs b/api/src/controllers/stop.rs new file mode 100644 index 0000000..81ea372 --- /dev/null +++ b/api/src/controllers/stop.rs @@ -0,0 +1,145 @@ +use actix_web::{get, web::{self, Data}, HttpRequest, Responder}; +use anyhow::anyhow; +use chrono::Timelike; +use chrono_tz::America::New_York; +use libseptastic::stop_schedule::{self, Trip}; +use log::info; +use std::{collections::HashSet, sync::Arc, time::Instant}; + +use crate::{AppState, templates::TripPerspective}; + +#[get("/stops")] +async fn get_stops_html(req: HttpRequest, state: Data>) -> impl Responder { + crate::perform_action(req, move || { + let statex = state.clone(); + async move { + let start_time = Instant::now(); + let stops = statex.gtfs_service.get_all_stops().iter().filter_map(|f| { + if f.1.id.contains("ANNOTATED") { + Some(libseptastic::stop::Stop::clone(f.1)) + } else { + None + } + }).collect(); + + Ok(crate::ContentTemplate { + page_title: Some(String::from("Stops")), + page_desc: Some(String::from("Stops")), + widescreen: false, + content: crate::templates::StopsTemplate { + tc_stops: stops + }, + load_time_ms: Some(start_time.elapsed().as_millis()) + }) + } + }).await +} +#[get("/stop/{stop_id}")] +async fn get_stop_html(req: HttpRequest, state: Data>, path: web::Path) -> impl Responder { + crate::perform_action(req, move || { + let statex = state.clone(); + let pathx = path.clone(); + async move { + let stop_id = pathx; + let start_time = Instant::now(); + + if let Some(stop) = statex.gtfs_service.get_stop_by_id(&stop_id) { + let routes: Vec = statex.gtfs_service.get_routes_at_stop(&stop.id).iter().filter_map(|route| { + match statex.gtfs_service.get_route(route.clone()) { + Ok(route) => Some(route), + Err(_) => None + } + }).collect(); + + let route_ids: HashSet = routes.iter().map(|route| route.id.clone()).collect(); + + let mut trips = statex.gtfs_service.get_all_trips().iter().filter_map(|trip| { + if route_ids.contains(trip.0) { + Some(trip.1.clone()) + } else { + None + } + }).flatten().collect(); + + + statex.trip_tracking_service.annotate_trips(&mut trips).await; + + let now_utc = chrono::Utc::now(); + let now = now_utc.with_timezone(&New_York); + let naive_time = now.time(); + let cur_time = i64::from(naive_time.num_seconds_from_midnight()); + + let mut filtered_trips: Vec = trips.iter().filter_map(|trip| { + //if !trip.is_active_on(&now.naive_local()) { + // return None; + //} + // + // poor midnight handling? + if !trip.calendar_day.is_calendar_active_for_date(&now.naive_local().date()) { + return None + } + let mut est_arrival_time = 0; + let mut is_tracked = false; + let stop_sched : Vec<_> = trip.schedule.iter().filter(|stop_schedule| { + if stop_schedule.stop.id != stop_id { + return false; + } + + match &trip.tracking_data { + libseptastic::stop_schedule::TripTracking::Tracked(live) => { + let actual_arrival_time = stop_schedule.arrival_time + (live.delay * 60 as f64) as i64; + est_arrival_time = stop_schedule.arrival_time; + is_tracked = true; + return + (actual_arrival_time - cur_time) > -(1 * 60) + && + (actual_arrival_time - cur_time) < (60 * 60) + ; + }, + libseptastic::stop_schedule::TripTracking::Untracked => { + est_arrival_time = stop_schedule.arrival_time; + return + (stop_schedule.arrival_time - cur_time) > -(3 * 60) + && + (stop_schedule.arrival_time - cur_time) < (60 * 60) + ; + }, + libseptastic::stop_schedule::TripTracking::Cancelled => { + return false; + } + } + }).filter_map(|ss| Some(ss.clone())).collect(); + + if stop_sched.len() > 0 { + Some(TripPerspective { + est_arrival_time, + is_tracked, + perspective_stop: stop_sched.first().unwrap().clone(), + trip: trip.clone() + }) + } else { + None + } + }).collect(); + + filtered_trips.sort_by_key(|f| f.perspective_stop.arrival_time); + + Ok(crate::templates::ContentTemplate { + page_title: Some(stop.name.clone()), + page_desc: Some(String::from("Stop information")), + widescreen: false, + content: crate::templates::StopTemplate { + stop: stop.clone(), + routes, + trips: filtered_trips, + current_time: cur_time + }, + load_time_ms: Some(start_time.elapsed().as_millis()) + }) + } + else { + Err(anyhow!("Stop not found!")) + } + } + }).await +} diff --git a/api/src/main.rs b/api/src/main.rs index 833f99c..29e6169 100644 --- a/api/src/main.rs +++ b/api/src/main.rs @@ -11,6 +11,7 @@ use askama::Template; mod services; mod controllers; mod templates; +//mod routing; pub struct AppState { gtfs_service: services::gtfs_pull::GtfsPullService, @@ -51,7 +52,8 @@ where T: Template, .cookie(cookie) .body(y.render().unwrap()) }, - Err(_) => { + Err(err) => { + error!("Returned error b/c {:?}", err); HttpResponse::InternalServerError().body("Error") } } @@ -105,7 +107,9 @@ async fn main() -> ::anyhow::Result<()> { .service(controllers::route::get_route) .service(controllers::route::get_routes_json) .service(controllers::route::get_routes_html) - .service(controllers::route::get_directions) +// .service(controllers::route::get_directions) + .service(controllers::stop::get_stops_html) + .service(controllers::stop::get_stop_html) .service(get_index) .service(actix_files::Files::new("/assets", "./assets")) }) diff --git a/api/src/routing.rs b/api/src/routing.rs new file mode 100644 index 0000000..7c6e320 --- /dev/null +++ b/api/src/routing.rs @@ -0,0 +1,225 @@ +use std::{cmp::Ordering, collections::{BTreeSet, HashMap, HashSet}}; + +use log::info; + +use crate::services; + +pub struct RoutingNodePointer { + pub stop_id: String, + pub route_id: String, + pub stop_sequence: u64, + pub direction: u64, + pub dest_dist: f64 +} + +pub struct RoutingNode { + pub stop_id: String, + pub stop_name: String, + pub next_stops_per_routes: HashMap>, + pub visited: bool, + pub scratch: i64, +} + +impl Ord for RoutingNodePointer { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + if self.dest_dist > other.dest_dist { + Ordering::Greater + } else { + Ordering::Less + } + } +} + +impl PartialOrd for RoutingNodePointer { + fn partial_cmp(&self, other: &Self) -> Option { + if self.dest_dist > other.dest_dist { + Some(Ordering::Greater) + } else { + Some(Ordering::Less) + } + } +} + +impl PartialEq for RoutingNodePointer { + fn eq(&self, other: &Self) -> bool { + self.stop_id == other.stop_id + } +} +impl Eq for RoutingNodePointer { +} + + +struct TripState { + pub used_lines: HashSet +} + +#[derive(Clone)] +pub struct Coordinates { + pub lat: f64, + pub lng: f64, +} + +pub type RoutingGraph = HashMap::; + +pub fn haversine_distance(lat1: f64, lon1: f64, lat2: f64, lon2: f64) -> f64 { + let r = 6371.0; // Earth's radius in kilometers + + let d_lat = (lat2 - lat1).to_radians(); + let d_lon = (lon2 - lon1).to_radians(); + + let lat1_rad = lat1.to_radians(); + let lat2_rad = lat2.to_radians(); + + let a = (d_lat / 2.0).sin().powi(2) + + lat1_rad.cos() * lat2_rad.cos() * (d_lon / 2.0).sin().powi(2); + + let c = 2.0 * a.sqrt().asin(); + + r * c +} + + +pub fn get_stops_near(cds: Coordinates, + all_stops: &HashMap + ) -> HashSet { + let near_thresh_km = 0.45; + let mut stops: HashSet = HashSet::new(); + + for stop_p in all_stops { + let stop = stop_p.1; + + let dist = haversine_distance(cds.lat, cds.lng, stop.lat, stop.lng); + + if dist.abs() < near_thresh_km { + stops.insert(stop.id.clone()); + } + } + + stops +} + +pub fn get_stop_as_node() { +} + +pub fn construct_graph( + dest: Coordinates, + all_stops: &HashMap, + gtfs_service: &services::gtfs_pull::GtfsPullService + ) -> RoutingGraph { + let mut graph = RoutingGraph::new(); + + let limited_rts = vec!["44", "65", "27", "38", "124", "125", "1"]; + + for stop_p in all_stops { + let stop = stop_p.1; + + let ras = gtfs_service.get_routes_at_stop(&stop.id); + + let cont = { + let mut ret = false; + for l_rt in limited_rts.clone() { + if ras.contains(&String::from(l_rt)) { + ret = true; + break; + } + } + ret + }; + + if !cont { + continue; + } + + graph.insert(stop.id.clone(), RoutingNode { + stop_id: stop.id.clone(), + stop_name: stop.name.clone(), + next_stops_per_routes: { + let routes = gtfs_service.get_routes_at_stop(&stop.id); + + let mut other_stops = HashMap::>::new(); + + for route in &routes { + let mut stops = gtfs_service.get_stops_by_route(&route); + stops.remove(&stop.id); + let rnps = { + let mut ret = BTreeSet::new(); + for stop in &stops { + let stp = all_stops.get(stop).unwrap(); + ret.insert(RoutingNodePointer{ + dest_dist: haversine_distance(dest.lat, dest.lng, stp.lat, stp.lng), + stop_id: stop.clone(), + route_id: route.clone(), + stop_sequence: 0, + direction: 0 + }); + } + ret + }; + other_stops.insert(route.clone(), rnps); + } + + other_stops + }, + visited: false, + scratch: 0 + }); + } + + graph +} +pub fn bfs_rts_int(route_id: &String, origin: &String, graph: &RoutingGraph, dests: &HashSet, mut visited: HashSet, max_legs: u8) -> Option { + if max_legs == 0 { + return None; + } + let mut limited_rts = HashSet::new(); + for item in vec!["44", "65", "27", "38", "124", "125", "1"] { + limited_rts.insert(item); + } + + if !limited_rts.contains(&route_id.as_str()) { + return None; + } + + if let Some(origin_stop) = graph.get(origin) { + if dests.contains(origin) { + return Some(format!("[stop {} via rt {}] --> DEST", origin_stop.stop_name, route_id)) + } + if visited.contains(origin) { + return None; + } + + visited.insert(origin.clone()); + + for items in &origin_stop.next_stops_per_routes { + if route_id == items.0 { + continue; + } + + for rnp in items.1 { + if let Some(rt) = bfs_rts_int(items.0, &rnp.stop_id, graph, dests, visited.clone(), max_legs - 1) { + return Some(format!("[stop {} via rt {}] >>[XFER]>> {}", origin_stop.stop_name, route_id, rt)) + } + } + } + } + + None +} + +pub fn bfs_rts(origin: &String, graph: &RoutingGraph, dests: &HashSet) -> String { + let mut resp = String::new(); + + if let Some(origin_stop) = graph.get(origin) { + for items in &origin_stop.next_stops_per_routes { + let route_id = items.0; + + for rnp in items.1 { + if let Some(rt) = bfs_rts_int(route_id, &rnp.stop_id, graph, dests, HashSet::new(), 3) { + resp += format!("ORIGIN --> [stop {} via rt {}] --> {}\n", origin_stop.stop_name, route_id, rt).as_str(); + } + } + } + } + + resp +} diff --git a/api/src/services/gtfs_pull.rs b/api/src/services/gtfs_pull.rs index 68b5631..ce47f21 100644 --- a/api/src/services/gtfs_pull.rs +++ b/api/src/services/gtfs_pull.rs @@ -1,19 +1,39 @@ -use std::{collections::{HashMap, HashSet}, env, hash::Hash, io::Cursor, path::PathBuf, sync::{Arc, Mutex}, thread, time::Duration}; +use std::{collections::{HashMap, HashSet}, env, hash::Hash, io::Cursor, path::PathBuf, sync::{Arc, Mutex, MutexGuard}, thread, time::Duration}; use anyhow::anyhow; +use libseptastic::{stop::Platform, stop_schedule::CalendarDay}; use log::{info, error}; use serde::{Deserialize, Serialize}; use zip::ZipArchive; + +macro_rules! make_global_id { + ($prefix: expr, $id: expr) => (format!("{}_{}", $prefix, $id)) +} + #[derive(Serialize, Deserialize, PartialEq, Debug,Clone)] struct GtfsSource { pub uri: String, - pub subzip: Option + pub subzip: Option, + pub prefix: String +} + +#[derive(Serialize, Deserialize, PartialEq, Debug,Clone)] +struct MultiplatformStopConfig { + pub id: String, + pub name: String, + pub platform_station_ids: Vec +} + +#[derive(Serialize, Deserialize, PartialEq, Debug,Clone)] +struct Annotations { + pub multiplatform_stops: Vec } #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct Config { - pub gtfs_zips: Vec + pub gtfs_zips: Vec, + pub annotations: Annotations } #[derive(Clone)] @@ -23,17 +43,24 @@ struct GtfsFile { } struct TransitData { - pub routes: HashMap, + pub routes: HashMap>, pub agencies: HashMap, pub trips: HashMap>, - pub stops: HashMap, - pub route_id_by_stops: HashMap> + pub stops: HashMap>, + pub platforms: HashMap>, + pub calendar_days: HashMap>, + + // extended lookup methods + pub route_id_by_stops: HashMap>, + pub stops_by_route_id: HashMap>, + pub stops_by_platform_id: HashMap> } struct GtfsPullServiceState { pub gtfs_files: Vec, pub tmp_dir: PathBuf, pub ready: bool, + pub annotations: Annotations, pub transit_data: TransitData } @@ -43,12 +70,13 @@ pub struct GtfsPullService { impl TransitData { pub fn new() -> Self { - return TransitData { routes: HashMap::new(), agencies: HashMap::new(), trips: HashMap::new(), stops: HashMap::new(), route_id_by_stops: HashMap::new() } + return TransitData { routes: HashMap::new(), agencies: HashMap::new(), trips: HashMap::new(), stops: HashMap::new(), platforms: HashMap::new(), route_id_by_stops: HashMap::new(), stops_by_route_id: HashMap::new(), stops_by_platform_id: HashMap::new(), calendar_days: HashMap::new() } } } impl GtfsPullService { const UPDATE_SECONDS: u64 = 3600*24; + const READYSTATE_CHECK_MILLISECONDS: u64 = 500; pub fn new(config: Config) -> Self { Self { @@ -56,6 +84,7 @@ impl GtfsPullService { GtfsPullServiceState { gtfs_files: config.gtfs_zips.iter().map(|f| { GtfsFile { source: f.clone(), hash: None} }).collect(), tmp_dir: env::temp_dir(), + annotations: config.annotations.clone(), ready: false, transit_data: TransitData::new() } @@ -65,7 +94,9 @@ impl GtfsPullService { pub fn wait_for_ready(&self) { while !(self.state.lock().unwrap()).ready { - thread::sleep(Duration::from_millis(500)); + thread::sleep( + Duration::from_millis(Self::READYSTATE_CHECK_MILLISECONDS) + ); } } @@ -90,13 +121,13 @@ impl GtfsPullService { pub fn get_routes(&self) -> Vec { let l_state = self.state.lock().unwrap(); - l_state.transit_data.routes.iter().map(|r| r.1.clone()).collect() + l_state.transit_data.routes.iter().map(|r| libseptastic::route::Route::clone(r.1)).collect() } pub fn get_route(&self, route_id: String) -> anyhow::Result { let l_state = self.state.lock().unwrap(); if let Some(route) = l_state.transit_data.routes.get(&route_id) { - Ok(route.clone()) + Ok(libseptastic::route::Route::clone(route)) } else { Err(anyhow!("")) } @@ -104,10 +135,10 @@ impl GtfsPullService { pub fn get_all_routes(&self) -> HashMap { let l_state = self.state.lock().unwrap(); - l_state.transit_data.routes.clone() + l_state.transit_data.routes.iter().map(|r| (r.0.clone(), libseptastic::route::Route::clone(r.1))).collect() } - pub fn get_all_stops(&self) -> HashMap { + pub fn get_all_stops(&self) -> HashMap> { let l_state = self.state.lock().unwrap(); l_state.transit_data.stops.clone() } @@ -117,9 +148,22 @@ impl GtfsPullService { l_state.transit_data.trips.clone() } - pub fn get_routes_at_stop(&self, id: String) -> HashSet { + pub fn get_routes_at_stop(&self, id: &String) -> HashSet { let l_state = self.state.lock().unwrap(); - l_state.transit_data.route_id_by_stops.get(&id).unwrap_or(&HashSet::new()).clone() + l_state.transit_data.route_id_by_stops.get(id).unwrap_or(&HashSet::new()).clone() + } + + pub fn get_stops_by_route(&self, id: &String) -> HashSet { + let l_state = self.state.lock().unwrap(); + l_state.transit_data.stops_by_route_id.get(id).unwrap_or(&HashSet::new()).clone() + } + + pub fn get_stop_by_id(&self, id: &String) -> Option { + let l_state = self.state.lock().unwrap(); + match l_state.transit_data.stops.get(id) { + Some(stop) => Some(libseptastic::stop::Stop::clone(stop)), + None => None + } } pub fn get_schedule(&self, route_id: String) -> anyhow::Result> { @@ -131,9 +175,155 @@ impl GtfsPullService { } } + fn postprocess_stops(state: &mut MutexGuard<'_, GtfsPullServiceState>) -> anyhow::Result<()> { + for annotated_stop in state.annotations.multiplatform_stops.clone() { + let global_id = make_global_id!("ANNOTATED", annotated_stop.id.clone()); + let stop = Arc::new(libseptastic::stop::Stop { + id: global_id.clone(), + name: annotated_stop.name.clone(), + platforms: libseptastic::stop::StopType::MultiPlatform(annotated_stop.platform_station_ids.iter().map(|platform_id| { + info!("Folding {} stop into stop {} as platform", platform_id.clone(), annotated_stop.id.clone()); + let platform = match state.transit_data.stops.remove(platform_id).unwrap().platforms.clone() { + libseptastic::stop::StopType::SinglePlatform(plat) => Ok(plat), + _ => Err(anyhow!("")) + }.unwrap(); + + state.transit_data.stops_by_platform_id.remove(&platform.id).unwrap(); + + platform + }).collect()) + }); + + state.transit_data.stops.insert(global_id.clone(), stop.clone()); + match &stop.platforms { + libseptastic::stop::StopType::MultiPlatform(platforms) => { + for platform in platforms { + state.transit_data.stops_by_platform_id.insert(platform.id.clone(), stop.clone()); + } + Ok(()) + }, + _ => Err(anyhow!("")) + }? + } + + Ok(()) + } + + fn populate_stops(state: &mut MutexGuard<'_, GtfsPullServiceState>, prefix: &String, gtfs: >fs_structures::Gtfs) -> anyhow::Result<()> { + for stop in >fs.stops { + let global_id = make_global_id!(prefix, stop.1.id.clone()); + let platform = Arc::new(Platform { + id : global_id.clone(), + name: stop.1.name.clone().unwrap(), + lat: stop.1.latitude.unwrap(), + lng: stop.1.longitude.unwrap(), + platform_location: libseptastic::stop::PlatformLocationType::Normal + }); + + let stop = Arc::new(libseptastic::stop::Stop { + id: global_id.clone(), + name: stop.1.name.clone().unwrap(), + platforms: libseptastic::stop::StopType::SinglePlatform(platform.clone()) + }); + + state.transit_data.stops.insert(global_id.clone(), stop.clone()); + state.transit_data.platforms.insert(global_id.clone(), platform.clone()); + state.transit_data.stops_by_platform_id.insert(global_id.clone(), stop.clone()); + } + + Ok(()) + } + + fn populate_routes(state: &mut MutexGuard<'_, GtfsPullServiceState>, prefix: &String, gtfs: >fs_structures::Gtfs) -> anyhow::Result<()> { + for route in >fs.routes { + let global_rt_id = make_global_id!(prefix, route.1.id); + + let rt_name = match route.1.long_name.clone() { + Some(x) => x, + _ => String::from("Unknown") + }; + + state.transit_data.routes.insert(global_rt_id.clone(), Arc::new(libseptastic::route::Route{ + name: rt_name, + short_name: match route.1.short_name.clone() { + Some(x) => x, + _ => String::from("unknown") + }, + color_hex: match route.1.color{ + Some(x) => x.to_string(), + _ => String::from("unknown") + }, + id: global_rt_id, + route_type: match route.1.route_type { + gtfs_structures::RouteType::Bus => libseptastic::route::RouteType::Bus, + gtfs_structures::RouteType::Rail => libseptastic::route::RouteType::RegionalRail, + gtfs_structures::RouteType::Subway => libseptastic::route::RouteType::SubwayElevated, + gtfs_structures::RouteType::Tramway => libseptastic::route::RouteType::Trolley, + _ => libseptastic::route::RouteType::TracklessTrolley + } + })); + } + + Ok(()) + } + + fn populate_trips(state: &mut MutexGuard<'_, GtfsPullServiceState>, prefix: &String, gtfs: >fs_structures::Gtfs) -> anyhow::Result<()> { + for trip in >fs.trips { + let global_rt_id = make_global_id!(prefix, trip.1.route_id); + let sched = trip.1.stop_times.iter().map(|s| { + let global_stop_id = make_global_id!(prefix, s.stop.id); + + let stop = state.transit_data.stops_by_platform_id.get(&global_stop_id).unwrap().clone(); + let platform = state.transit_data.platforms.get(&global_stop_id).unwrap().clone(); + + state.transit_data.route_id_by_stops.entry(stop.id.clone()).or_insert(HashSet::new()).insert(global_rt_id.clone()); + state.transit_data.stops_by_route_id.entry(global_rt_id.clone()).or_insert(HashSet::new()).insert(stop.id.clone()); + + state.transit_data.route_id_by_stops.entry(platform.id.clone()).or_insert(HashSet::new()).insert(global_rt_id.clone()); + state.transit_data.stops_by_route_id.entry(global_rt_id.clone()).or_insert(HashSet::new()).insert(platform.id.clone()); + + libseptastic::stop_schedule::StopSchedule{ + arrival_time: i64::from(s.arrival_time.unwrap()), + stop_sequence: i64::from(s.stop_sequence), + stop, + platform + } + }).collect(); + + if let Some(calendar_day) = state.transit_data.calendar_days.get(&trip.1.service_id.clone()) { + let trip = libseptastic::stop_schedule::Trip{ + trip_id: trip.1.id.clone(), + route: state.transit_data.routes.get(&make_global_id!(prefix, trip.1.route_id)).unwrap().clone(), + direction: libseptastic::direction::Direction { + direction: match trip.1.direction_id.unwrap() { + gtfs_structures::DirectionType::Outbound => libseptastic::direction::CardinalDirection::Outbound, + gtfs_structures::DirectionType::Inbound => libseptastic::direction::CardinalDirection::Inbound + }, + direction_destination: trip.1.trip_headsign.clone().unwrap() + }, + tracking_data: libseptastic::stop_schedule::TripTracking::Untracked, + schedule: sched, + service_id: trip.1.service_id.clone(), + calendar_day: calendar_day.clone() + }; + + if let Some(trip_arr) = state.transit_data.trips.get_mut(&global_rt_id) { + trip_arr.push(trip); + } else { + state.transit_data.trips.insert(global_rt_id, vec![trip]); + } + } + } + + Ok(()) + } + pub fn update_gtfs_data(state: Arc>) -> anyhow::Result<()> { let mut l_state = state.lock().unwrap(); let files = l_state.gtfs_files.clone(); + l_state.transit_data = TransitData::new(); + + let mut gtfses = Vec::new(); for gtfs_file in files.iter() { let gtfs = if let Some(subzip) = gtfs_file.source.subzip.clone() { @@ -145,6 +335,8 @@ impl GtfsPullService { let mut file_path = l_state.tmp_dir.clone(); file_path.push(subzip.clone()); + + info!("Downloaded, parsing"); gtfs_structures::Gtfs::new(file_path.to_str().unwrap())? } else { @@ -152,115 +344,35 @@ impl GtfsPullService { gtfs_structures::Gtfs::new(gtfs_file.source.uri.as_str())? }; - let mut hack_agency = None; + gtfses.push((gtfs, gtfs_file.source.prefix.clone())); + } - for agency in >fs.agencies { - if let Some(a_id) = &agency.id { - l_state.transit_data.agencies.insert(a_id.clone(), libseptastic::agency::Agency{ - id: a_id.clone(), - name: agency.name.clone() - }); - hack_agency = Some(libseptastic::agency::Agency{ - id: a_id.clone(), - name: agency.name.clone() - }); - } + + info!("Data loaded, processing..."); + + for (gtfs, prefix) in >fses { + GtfsPullService::populate_routes(&mut l_state, &prefix, >fs)?; + GtfsPullService::populate_stops(&mut l_state, &prefix, >fs)?; + for calendar in >fs.calendar { + l_state.transit_data.calendar_days.insert(calendar.1.id.clone(), Arc::new(CalendarDay{ + id: calendar.1.id.clone(), + monday: calendar.1.monday, + tuesday: calendar.1.tuesday, + wednesday: calendar.1.wednesday, + thursday: calendar.1.thursday, + friday: calendar.1.friday, + saturday: calendar.1.saturday, + sunday: calendar.1.sunday, + start_date: calendar.1.start_date, + end_date: calendar.1.end_date + })); } + } + + GtfsPullService::postprocess_stops(&mut l_state)?; - for route in >fs.routes { - let agency = route.1.agency_id.as_ref() - .and_then(|agency_id| l_state.transit_data.agencies.get(agency_id)) - .map(|agency| agency.clone()); - - let global_rt_id = match &agency { - Some(a) => format!("{}_{}", a.id, route.0.clone()), - None => format!("{}", route.0.clone()) - }; - - let rt_name = match route.1.long_name.clone() { - Some(x) => x, - _ => match route.1.short_name.clone() { - Some(y) => match agency { - Some(z) => format!("{} {}", z.name, y), - None => y - }, - None => String::from("unknown") - } - }; - - l_state.transit_data.routes.insert(global_rt_id.clone(), libseptastic::route::Route{ - name: rt_name, - short_name: match route.1.short_name.clone() { - Some(x) => x, - _ => String::from("unknown") - }, - color_hex: match route.1.color{ - Some(x) => x.to_string(), - _ => String::from("unknown") - }, - id: global_rt_id, - route_type: match route.1.route_type { - gtfs_structures::RouteType::Bus => libseptastic::route::RouteType::Bus, - gtfs_structures::RouteType::Rail => libseptastic::route::RouteType::RegionalRail, - gtfs_structures::RouteType::Subway => libseptastic::route::RouteType::SubwayElevated, - gtfs_structures::RouteType::Tramway => libseptastic::route::RouteType::Trolley, - _ => libseptastic::route::RouteType::TracklessTrolley - } - }); - } - - for stop in >fs.stops { - l_state.transit_data.stops.insert(stop.1.id.clone(), libseptastic::stop::Stop { - id: stop.1.id.clone(), - name: stop.1.name.clone().unwrap(), - lat: stop.1.latitude.unwrap(), - lng: stop.1.longitude.unwrap(), - stop_type: libseptastic::stop::StopType::Normal - }); - } - - for trip in >fs.trips { - let global_rt_id = match &hack_agency { - Some(a) => format!("{}_{}", a.id, trip.1.route_id.clone()), - None => format!("{}", trip.1.route_id.clone()) - }; - let sched = trip.1.stop_times.iter().map(|s| { - - l_state.transit_data.route_id_by_stops.entry(s.stop.id.clone()).or_insert(HashSet::new()).insert(trip.1.route_id.clone()); - libseptastic::stop_schedule::StopSchedule{ - arrival_time: i64::from(s.arrival_time.unwrap()), - stop_sequence: i64::from(s.stop_sequence), - stop: libseptastic::stop::Stop { - name: s.stop.name.clone().unwrap(), - lat: s.stop.latitude.unwrap(), - lng: s.stop.longitude.unwrap(), - id: s.stop.id.parse().unwrap(), - stop_type: libseptastic::stop::StopType::Normal - }} - }).collect(); - - let trip = libseptastic::stop_schedule::Trip{ - trip_id: trip.1.id.clone(), - direction: libseptastic::direction::Direction { - direction: match trip.1.direction_id.unwrap() { - gtfs_structures::DirectionType::Outbound => libseptastic::direction::CardinalDirection::Outbound, - gtfs_structures::DirectionType::Inbound => libseptastic::direction::CardinalDirection::Inbound - }, - direction_destination: trip.1.trip_headsign.clone().unwrap() - }, - tracking_data: libseptastic::stop_schedule::TripTracking::Untracked, - schedule: sched, - service_id: trip.1.service_id.clone() - }; - - if let Some(trip_arr) = l_state.transit_data.trips.get_mut(&global_rt_id) { - trip_arr.push(trip); - } else { - l_state.transit_data.trips.insert(global_rt_id, vec![trip]); - } - } - - info!("Added {} routes", gtfs.routes.len()); + for (gtfs, prefix) in >fses { + GtfsPullService::populate_trips(&mut l_state, &prefix, >fs)?; } l_state.ready = true; diff --git a/api/src/templates.rs b/api/src/templates.rs index 3e32d40..ad5102f 100644 --- a/api/src/templates.rs +++ b/api/src/templates.rs @@ -20,7 +20,7 @@ pub struct ContentTemplate { pub struct RouteTemplate { pub route: libseptastic::route::Route, pub timetables: Vec, - pub filter_stops: Option> + pub filter_stops: Option> } #[derive(askama::Template)] @@ -32,6 +32,12 @@ pub struct RoutesTemplate { pub bus_routes: Vec } +#[derive(askama::Template)] +#[template(path = "stops.html")] +pub struct StopsTemplate { + pub tc_stops: Vec, +} + #[derive(askama::Template)] #[template(path = "index.html")] pub struct IndexTemplate { @@ -39,7 +45,7 @@ pub struct IndexTemplate { #[derive(Debug, Serialize)] pub struct TimetableStopRow { - pub stop_id: i64, + pub stop_id: String, pub stop_name: String, pub stop_sequence: i64, pub times: Vec> @@ -55,6 +61,21 @@ pub struct TimetableDirection { pub next_id: Option } +pub struct TripPerspective { + pub trip:libseptastic::stop_schedule::Trip, + pub perspective_stop: libseptastic::stop_schedule::StopSchedule, + pub est_arrival_time: i64, + pub is_tracked: bool +} + +#[derive(askama::Template)] +#[template(path = "stop.html")] +pub struct StopTemplate { + pub stop: libseptastic::stop::Stop, + pub routes: Vec, + pub trips: Vec, + pub current_time: i64 +} pub fn build_timetables( directions: Vec, @@ -120,7 +141,7 @@ pub fn build_timetables( let mut rows: Vec = stop_map .into_iter() .map(|(stop_id, (stop_sequence, stop_name, times))| TimetableStopRow { - stop_id: stop_id.parse().unwrap(), + stop_id, stop_sequence, stop_name, times, diff --git a/api/templates/layout.html b/api/templates/layout.html index 47a57f4..ac4882c 100644 --- a/api/templates/layout.html +++ b/api/templates/layout.html @@ -3,7 +3,7 @@ {% if let Some(title) = page_title %} - {{ title }} + {{ title }} | SEPTASTIC {% else %} SEPTASTIC {% endif %} @@ -58,6 +58,7 @@ window.onload = function () {
diff --git a/api/templates/route.html b/api/templates/route.html index 4935f7a..213bbf9 100644 --- a/api/templates/route.html +++ b/api/templates/route.html @@ -3,7 +3,7 @@ .train-direction-table { width: 100%; border-collapse: collapse; - font-family: sans-serif; + font-family: mono; font-size: 14px; } @@ -148,11 +148,7 @@ document.addEventListener("DOMContentLoaded", () => { {% let live_o = timetable.tracking_data[loop.index0] %} {% if let Tracked(live) = live_o %} {% let time = (t + (live.delay * 60.0) as i64) %} - {% if live.next_stop_id == Some(*row.stop_id) %} - - {% else %} - {% endif %} {{ time | format_time }} {% elif let TripTracking::Cancelled = live_o %} diff --git a/api/templates/stop.html b/api/templates/stop.html new file mode 100644 index 0000000..8b6f871 --- /dev/null +++ b/api/templates/stop.html @@ -0,0 +1,71 @@ +{%- import "route_symbol.html" as scope -%} + + + +
+

{{ stop.name }}

+
+ +

With service available on:

+
+ {% for route in routes %} +
+ {% call scope::route_symbol(route) %} +
+ {% endfor %} +
+ + +{#{% if let libseptastic::stop::StopType::MultiPlatform(platforms) = stop.platforms %} +
+

Platforms at this station:

+ {% for platform in platforms %} +

{{ platform.name }}

+ {% endfor %} +
+{% endif %}#} + + + + + + + + + +{% for trip in trips %} + + + + + {% if trip.is_tracked %} + + {% if let Tracked(tracked_trip) = trip.trip.tracking_data %} + + {% else %} + + {% endif %} + +{% endfor %} +
ROUTEDESTINATIONBOARDING AREATIMEVEHICLE
+ {% call scope::route_symbol(trip.trip.route) %} + +

{{ trip.trip.direction.direction_destination }}

+
+

{{ trip.perspective_stop.platform.name }}

+
+ {% else %} + + {% endif %} +

{{ trip.perspective_stop.arrival_time | format_time }}

+

{{ (trip.perspective_stop.arrival_time - current_time) / 60 }} mins

+
+ {{ tracked_trip.vehicle_ids.join(", ") }} + + - +
diff --git a/api/templates/stops.html b/api/templates/stops.html new file mode 100644 index 0000000..e1bf30a --- /dev/null +++ b/api/templates/stops.html @@ -0,0 +1,27 @@ +

Stops

+ +

Click on a route to see details and a schedule. Schedules in prevailing local time.

+ +
+

Transit Centers

+

Hubs to connect between different modes of transit

+ {% for stop in tc_stops %} + +

]

+
+ {% endfor %} +
+ + diff --git a/libseptastic/Cargo.lock b/libseptastic/Cargo.lock index 1260fb2..3a6511f 100644 --- a/libseptastic/Cargo.lock +++ b/libseptastic/Cargo.lock @@ -8,6 +8,15 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "atoi" version = "2.0.0" @@ -53,6 +62,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bumpalo" +version = "3.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" + [[package]] name = "byteorder" version = "1.5.0" @@ -65,12 +80,46 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" +[[package]] +name = "cc" +version = "1.2.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd4932aefd12402b36c60956a4fe0035421f544799057659ff86f923657aada3" +dependencies = [ + "find-msvc-tools", + "shlex", +] + [[package]] name = "cfg-if" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" +[[package]] +name = "chrono" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "chrono-tz" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6139a8597ed92cf816dfb33f5dd6cf0bb93a6adc938f11039f371bc5bcd26c3" +dependencies = [ + "chrono", + "phf", +] + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -86,6 +135,12 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -212,6 +267,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "find-msvc-tools" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f449e6c6c08c865631d4890cfacf252b3d396c9bcc83adb6623cdb02a8336c41" + [[package]] name = "flume" version = "0.11.1" @@ -390,6 +451,30 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "iana-time-zone" +version = "0.1.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "icu_collections" version = "2.0.0" @@ -513,6 +598,16 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" +[[package]] +name = "js-sys" +version = "0.3.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -538,6 +633,8 @@ checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" name = "libseptastic" version = "0.1.0" dependencies = [ + "chrono", + "chrono-tz", "serde", "serde_json", "sqlx", @@ -688,6 +785,24 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "phf" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "913273894cec178f401a31ec4b656318d95473527be05c0752cc41cdc32be8b7" +dependencies = [ + "phf_shared", +] + +[[package]] +name = "phf_shared" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06005508882fb681fd97892ecff4b7fd0fee13ef1aa569f8695dae7ab9099981" +dependencies = [ + "siphasher", +] + [[package]] name = "pin-project-lite" version = "0.2.16" @@ -822,6 +937,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "ryu" version = "1.0.20" @@ -900,6 +1021,12 @@ dependencies = [ "digest", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signature" version = "2.2.0" @@ -910,6 +1037,12 @@ dependencies = [ "rand_core", ] +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + [[package]] name = "slab" version = "0.4.10" @@ -1325,6 +1458,51 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" +[[package]] +name = "wasm-bindgen" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4" +dependencies = [ + "unicode-ident", +] + [[package]] name = "whoami" version = "1.6.0" @@ -1335,6 +1513,65 @@ dependencies = [ "wasite", ] +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/libseptastic/Cargo.toml b/libseptastic/Cargo.toml index 3f44792..536bac3 100644 --- a/libseptastic/Cargo.toml +++ b/libseptastic/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" edition = "2024" [dependencies] +chrono = { version = "0.4.42", features = [ "serde" ] } +chrono-tz = "0.10.4" serde = "1.0.219" serde_json = "1.0.140" sqlx = "0.8.6" diff --git a/libseptastic/src/stop.rs b/libseptastic/src/stop.rs index 47c8afa..4520120 100644 --- a/libseptastic/src/stop.rs +++ b/libseptastic/src/stop.rs @@ -1,18 +1,41 @@ +use std::{hash::{Hash, Hasher}, sync::Arc}; + use serde::{Deserialize, Serialize}; -#[derive(sqlx::Type, PartialEq, Debug, Clone, Serialize, Deserialize)] +#[derive(sqlx::Type, Eq, PartialEq, Debug, Clone, Serialize, Deserialize)] #[sqlx(type_name = "septa_stop_type", rename_all = "snake_case")] -pub enum StopType { +pub enum PlatformLocationType { FarSide, MiddleBlockNearSide, Normal } -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Stop { - pub id: String, +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub enum StopType { + SinglePlatform(Arc), + MultiPlatform(Vec>) +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct Platform { + pub id: String, pub name: String, pub lat: f64, pub lng: f64, - pub stop_type: StopType + pub platform_location: PlatformLocationType } + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct Stop { + pub id: String, + pub name: String, + pub platforms: StopType, +} + +impl Hash for Stop { + fn hash(&self, state: &mut H) { + self.id.hash(state) + } +} + +impl Eq for Stop {} diff --git a/libseptastic/src/stop_schedule.rs b/libseptastic/src/stop_schedule.rs index d27cf7b..28d8400 100644 --- a/libseptastic/src/stop_schedule.rs +++ b/libseptastic/src/stop_schedule.rs @@ -1,21 +1,51 @@ +use std::sync::Arc; + +use chrono::{Datelike, Days, TimeZone, Weekday}; use serde::{Deserialize, Serialize}; -use crate::direction::Direction; +use crate::{direction::Direction, route::Route, stop::Platform}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct StopSchedule { pub arrival_time: i64, pub stop_sequence: i64, - pub stop: crate::stop::Stop + pub stop: Arc, + pub platform: Arc } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Trip { pub service_id: String, + pub route: Arc, pub trip_id: String, pub direction: Direction, pub tracking_data: TripTracking, - pub schedule: Vec + pub schedule: Vec, + pub calendar_day: Arc +} + +impl Trip { + pub fn is_active_on(&self, datetime: &chrono::NaiveDateTime) -> bool { + if !self.calendar_day.is_calendar_active_for_date(&datetime.date()) { + return false; + } + + let time_trip_start = chrono::NaiveTime::from_num_seconds_from_midnight_opt(self.schedule.first().unwrap().arrival_time as u32 % (60*60*24), 0).unwrap(); + let mut dt_trip_start = chrono::NaiveDateTime::new(datetime.date(), time_trip_start); + + if self.schedule.first().unwrap().arrival_time > (60*60*24) { + dt_trip_start = dt_trip_start.checked_add_days(Days::new(1)).unwrap(); + } + + let time_trip_end = chrono::NaiveTime::from_num_seconds_from_midnight_opt(self.schedule.last().unwrap().arrival_time as u32 % (60*60*24), 0).unwrap(); + let mut dt_trip_end = chrono::NaiveDateTime::new(datetime.date(), time_trip_end); + + if self.schedule.last().unwrap().arrival_time > (60*60*24) { + dt_trip_end = dt_trip_end.checked_add_days(Days::new(1)).unwrap(); + } + + return *datetime >= dt_trip_start && *datetime <= dt_trip_end; + } } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -25,6 +55,38 @@ pub enum TripTracking { Cancelled } +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CalendarDay { + pub id: String, + pub monday: bool, + pub tuesday: bool, + pub wednesday: bool, + pub thursday: bool, + pub friday: bool, + pub saturday: bool, + pub sunday: bool, + pub start_date: chrono::NaiveDate, + pub end_date: chrono::NaiveDate +} + +impl CalendarDay { + pub fn is_calendar_active_for_date(&self, date: &chrono::NaiveDate) -> bool { + if *date < self.start_date || *date > self.end_date { + return false; + } + + match date.weekday() { + Weekday::Mon => self.monday, + Weekday::Tue => self.tuesday, + Weekday::Wed => self.wednesday, + Weekday::Thu => self.thursday, + Weekday::Fri => self.friday, + Weekday::Sat => self.saturday, + Weekday::Sun => self.sunday, + } + } +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct LiveTrip { pub delay: f64,