Unverified Commit 07132823 authored by Paul Haerle's avatar Paul Haerle Committed by GitHub
Browse files

pkgs-lib/formats: use go-toml instead of yj for toml.generate, go-toml: drop...

pkgs-lib/formats: use go-toml instead of yj for toml.generate, go-toml: drop allowGoReference (#512319)
parents 2bfec39a e23ad3bd
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -25,10 +25,6 @@ buildGoModule {
    "cmd/tomltestgen"
  ];

  # allowGoReference adds the flag `-trimpath` which is also denoted by, go-toml's goreleaser config
  #  <https://github.com/pelletier/go-toml/blob/a3d5a0bb530b5206c728eed9cb57323061922bcb/.goreleaser.yaml#L13>
  allowGoReference = true;

  ldflags = [
    "-s"
    "-w"
+5 −3
Original line number Diff line number Diff line
@@ -461,16 +461,18 @@ optionalAttrs allowAliases aliases
      generate =
        name: value:
        pkgs.callPackage (
          { runCommand, yj }:
          { runCommand, go-toml }:
          runCommand name
            {
              nativeBuildInputs = [ yj ];
              nativeBuildInputs = [ go-toml ];
              value = builtins.toJSON value;
              passAsFile = [ "value" ];
              preferLocalBuild = true;
            }
            # -use-json-number: preserve JSON ints as TOML ints
            # (Go's json.Decoder defaults to float64 for all numbers)
            ''
              yj -jt < "$valuePath" > "$out"
              jsontoml -use-json-number < "$valuePath" > "$out"
            ''
        ) { };

+38 −3
Original line number Diff line number Diff line
@@ -695,16 +695,51 @@ runBuildTests {
      float = 3.141
      int = 10
      list = [1, 2]
      str = "foo"
      str = 'foo'
      true = true

      [attrs]
      foo = "foo"
      foo = 'foo'

      [level1]
      [level1.level2]
      [level1.level2.level3]
      level4 = "deep"
      level4 = 'deep'
    '';
  };

  # Regression test for https://github.com/NixOS/nixpkgs/issues/511970
  # yj crashes on arrays mixing scalars and attrsets (heterogeneous arrays),
  # e.g. Helix language-server configs like ["bash-ls", {name = "ts-ls"; ...}].
  # TOML 1.0 allows mixed-type arrays; the converter must emit them as
  # inline arrays with inline tables.
  tomlHeterogeneousArray = shouldPass {
    format = formats.toml { };
    input = {
      language-server = [
        "bash-language-server"
        {
          name = "typescript-language-server";
          except-features = [ "diagnostics" ];
        }
      ];
    };
    expected = ''
      language-server = ['bash-language-server', {except-features = ['diagnostics'], name = 'typescript-language-server'}]
    '';
  };

  # Regression test for https://github.com/sclevine/yj/issues/52
  # yj truncates keys at the first comma because it stores TOML keys in Go
  # struct tags, where commas are option separators.
  # e.g. "stack(x,n)" is emitted as "stack(x" — silently losing data.
  tomlCommaInKey = shouldPass {
    format = formats.toml { };
    input = {
      "stack(x,n)" = "foobar";
    };
    expected = ''
      'stack(x,n)' = 'foobar'
    '';
  };