Unverified Commit 33a22fc1 authored by r-vdp's avatar r-vdp
Browse files

minimal-bootstrap.mes: convert sources from Nix to JSON

Replace sources.nix with sources.json, consumed via lib.importJSON.
Update gen-sources.sh to emit JSON using jq for correctness.
parent 51153c6a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ let
    }
    .${buildPlatform.system};

  sources = (import ./sources.nix).${arch}.linux.mescc;
  sources = (lib.importJSON ./sources.json).${arch}.linux.mescc;

  inherit (sources)
    libc_mini_SOURCES
+32 −29
Original line number Diff line number Diff line
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash coreutils gnutar
#!nix-shell -i bash -p bash coreutils gnutar jq

# Generate a sources.nix for a version of GNU mes. Creates lists of source files
# Generate a sources.json for a version of GNU mes. Creates lists of source files
# from build-aux/configure-lib.sh.
#
# You may point this tool at a manually downloaded tarball, but more ideal is
# using the source tarball from Nixpkgs. For example:
#
# MES_TARBALL="$(nix-build --no-link -A minimal-bootstrap.mes.src ../../../../..)"
# ./gen-sources.sh "$MES_TARBALL" > ./new-sources.nix
# ./gen-sources.sh "$MES_TARBALL" > ./new-sources.json

set -eu

@@ -18,10 +18,12 @@ KERNELS="linux"
COMPILERS="mescc gcc"


format() {
  echo "["
  echo $* | xargs printf '      "%s"\n'
  echo "    ]"
to_json_array() {
  if [ $# -eq 0 ]; then
    echo '[]'
  else
    printf '%s\n' "$@" | jq --raw-input --null-input '[inputs]'
  fi
}

gen_sources() {
@@ -34,17 +36,24 @@ gen_sources() {
  # Populate source file lists
  source $CONFIGURE_LIB_SH

  cat <<EOF
  $mes_cpu.$mes_kernel.$compiler = {
    libc_mini_SOURCES = $(format $libc_mini_SOURCES);
    libmescc_SOURCES = $(format $libmescc_SOURCES);
    libtcc1_SOURCES = $(format $libtcc1_SOURCES);
    libc_SOURCES = $(format $libc_SOURCES);
    libc_tcc_SOURCES = $(format $libc_tcc_SOURCES);
    libc_gnu_SOURCES = $(format $libc_gnu_SOURCES);
    mes_SOURCES = $(format $mes_SOURCES);
  };
EOF
  jq --null-input \
    --arg key "$mes_cpu.$mes_kernel.$compiler" \
    --argjson libc_mini_SOURCES "$(to_json_array $libc_mini_SOURCES)" \
    --argjson libmescc_SOURCES "$(to_json_array $libmescc_SOURCES)" \
    --argjson libtcc1_SOURCES "$(to_json_array $libtcc1_SOURCES)" \
    --argjson libc_SOURCES "$(to_json_array $libc_SOURCES)" \
    --argjson libc_tcc_SOURCES "$(to_json_array $libc_tcc_SOURCES)" \
    --argjson libc_gnu_SOURCES "$(to_json_array $libc_gnu_SOURCES)" \
    --argjson mes_SOURCES "$(to_json_array $mes_SOURCES)" \
    '{($key): {
      libc_mini_SOURCES: $libc_mini_SOURCES,
      libmescc_SOURCES: $libmescc_SOURCES,
      libtcc1_SOURCES: $libtcc1_SOURCES,
      libc_SOURCES: $libc_SOURCES,
      libc_tcc_SOURCES: $libc_tcc_SOURCES,
      libc_gnu_SOURCES: $libc_gnu_SOURCES,
      mes_SOURCES: $mes_SOURCES
    }}'
}


@@ -53,7 +62,7 @@ if [ ! -f $MES_TARBALL ]; then
    echo "Provide path to mes-x.x.x.tar.gz as first argument" >&2
    exit 1
fi
echo "Generating sources.nix from $MES_TARBALL" >&2
echo "Generating sources.json from $MES_TARBALL" >&2

TMP=$(mktemp -d)
cd $TMP
@@ -75,20 +84,14 @@ chmod +x config.sh

echo "Configuring with $CONFIGURE_LIB_SH" >&2

cat <<EOF
# This file is generated by ./gen-sources.sh.
# Do not edit!
{
EOF

RESULT='{}'
for arch in $ARCHS; do
  for kernel in $KERNELS; do
    for compiler in $COMPILERS; do
      gen_sources $arch $kernel $compiler
      PART=$(gen_sources $arch $kernel $compiler)
      RESULT=$(jq --null-input --argjson a "$RESULT" --argjson b "$PART" '$a * $b')
    done
  done
done

cat <<EOF
}
EOF
echo "$RESULT" | jq --sort-keys .
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ let
    }
    .${buildPlatform.system};

  sources = (import ./sources.nix).${arch}.linux.gcc;
  sources = (lib.importJSON ./sources.json).${arch}.linux.gcc;
  inherit (sources) libtcc1_SOURCES libc_gnu_SOURCES;

  ldexpl = fetchurl {
+2314 −0

File added.

Preview size limit exceeded, changes collapsed.

+0 −2308

File deleted.

Preview size limit exceeded, changes collapsed.