<commit_before># The wrapper script ensures variables like PKG_CONFIG_PATH and
# PKG_CONFIG_PATH_FOR_BUILD work properly.

{ stdenvNoCC
, buildPackages
, pkg-config
, baseBinName ? "pkg-config"
, propagateDoc ? pkg-config != null && pkg-config ? man
, extraPackages ? [], extraBuildCommands ? ""
}:

with stdenvNoCC.lib;

let
  stdenv = stdenvNoCC;
  inherit (stdenv) hostPlatform targetPlatform;

  # Prefix for binaries. Customarily ends with a dash separator.
  #
  # TODO(@Ericson2314) Make unconditional, or optional but always true by
  # default.
  targetPrefix = stdenv.lib.optionalString (targetPlatform != hostPlatform)
                                        (targetPlatform.config + "-");

  # See description in cc-wrapper.
  suffixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config;

in

stdenv.mkDerivation {
  pname = targetPrefix + pkg-config.pname + "-wrapper";
  inherit (pkg-config) version;

  preferLocalBuild = true;

  shell = getBin stdenvNoCC.shell + stdenvNoCC.shell.shellPath or "";

  inherit targetPrefix suffixSalt baseBinName;

  outputs = [ "out" ] ++ optionals propagateDoc ([ "man" ] ++ optional (pkg-config ? doc) "doc");

  passthru = {
    inherit pkg-config;
  };

  dontBuild = true;
  dontConfigure = true;

  unpackPhase = ''
    src=$PWD
  '';

  installPhase =
    ''
      mkdir -p $out/bin $out/nix-support

      wrap() {
        local dst="$1"
        local wrapper="$2"
        export prog="$3"
        substituteAll "$wrapper" "$out/bin/$dst"
        chmod +x "$out/bin/$dst"
      }

      echo $pkg-config > $out/nix-support/orig-pkg-config

      wrap ${targetPrefix}${baseBinName} ${./pkg-config-wrapper.sh} "${getBin pkg-config}/bin/${baseBinName}"
    ''
    # symlink in share for autoconf to find macros

    # TODO(@Ericson2314): in the future just make the unwrapped pkg-config a
    # propagated dep once we can rely on downstream deps comming first in
    # search paths. (https://github.com/NixOS/nixpkgs/pull/31414 took a crack
    # at this.)
    + ''
      ln -s ${pkg-config}/share $out/share
    '';

  strictDeps = true;

  wrapperName = "PKG_CONFIG_WRAPPER";

  setupHooks = [
    ../setup-hooks/role.bash
    ./setup-hook.sh
  ];

  postFixup =
    ''

      ##
      ## User env support
      ##

      # Propagate the underling unwrapped pkg-config so that if you
      # install the wrapper, you get anything else it might provide.
      printWords ${pkg-config} > $out/nix-support/propagated-user-env-packages
    ''

    + optionalString propagateDoc (''
      ##
      ## Man page and doc support
      ##

      ln -s ${pkg-config.man} $man
    '' + optionalString (pkg-config ? doc) ''
      ln -s ${pkg-config.doc} $doc
    '')

    + ''
      substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
      substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash

      ##
      ## Extra custom steps
      ##
    ''

    + extraBuildCommands;
<commit_msg>pkg-config-wrapper: Move comments outside of strings<commit_after># The wrapper script ensures variables like PKG_CONFIG_PATH and
# PKG_CONFIG_PATH_FOR_BUILD work properly.

{ stdenvNoCC
, buildPackages
, pkg-config
, baseBinName ? "pkg-config"
, propagateDoc ? pkg-config != null && pkg-config ? man
, extraPackages ? [], extraBuildCommands ? ""
}:

with stdenvNoCC.lib;

let
  stdenv = stdenvNoCC;
  inherit (stdenv) hostPlatform targetPlatform;

  # Prefix for binaries. Customarily ends with a dash separator.
  #
  # TODO(@Ericson2314) Make unconditional, or optional but always true by
  # default.
  targetPrefix = stdenv.lib.optionalString (targetPlatform != hostPlatform)
                                        (targetPlatform.config + "-");

  # See description in cc-wrapper.
  suffixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config;

in

stdenv.mkDerivation {
  pname = targetPrefix + pkg-config.pname + "-wrapper";
  inherit (pkg-config) version;

  preferLocalBuild = true;

  shell = getBin stdenvNoCC.shell + stdenvNoCC.shell.shellPath or "";

  inherit targetPrefix suffixSalt baseBinName;

  outputs = [ "out" ] ++ optionals propagateDoc ([ "man" ] ++ optional (pkg-config ? doc) "doc");

  passthru = {
    inherit pkg-config;
  };

  dontBuild = true;
  dontConfigure = true;

  unpackPhase = ''
    src=$PWD
  '';

  installPhase =
    ''
      mkdir -p $out/bin $out/nix-support

      wrap() {
        local dst="$1"
        local wrapper="$2"
        export prog="$3"
        substituteAll "$wrapper" "$out/bin/$dst"
        chmod +x "$out/bin/$dst"
      }

      echo $pkg-config > $out/nix-support/orig-pkg-config

      wrap ${targetPrefix}${baseBinName} ${./pkg-config-wrapper.sh} "${getBin pkg-config}/bin/${baseBinName}"
    ''
    # symlink in share for autoconf to find macros

    # TODO(@Ericson2314): in the future just make the unwrapped pkg-config a
    # propagated dep once we can rely on downstream deps comming first in
    # search paths. (https://github.com/NixOS/nixpkgs/pull/31414 took a crack
    # at this.)
    + ''
      ln -s ${pkg-config}/share $out/share
    '';

  strictDeps = true;

  wrapperName = "PKG_CONFIG_WRAPPER";

  setupHooks = [
    ../setup-hooks/role.bash
    ./setup-hook.sh
  ];

  postFixup =
    ##
    ## User env support
    ##

    # Propagate the underling unwrapped pkg-config so that if you
    # install the wrapper, you get anything else it might provide.
    ''
      printWords ${pkg-config} > $out/nix-support/propagated-user-env-packages
    ''

    ##
    ## Man page and doc support
    ##
    + optionalString propagateDoc (''
      ln -s ${pkg-config.man} $man
    '' + optionalString (pkg-config ? doc) ''
      ln -s ${pkg-config.doc} $doc
    '')

    + ''
      substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
      substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
    ''

    ##
    ## Extra custom steps
    ##
    + extraBuildCommands;

{'fraction_non_alphanumeric': 0.13141993957703926, 'fraction_numerical': 0.005370929842228936, 'mean_word_length': 2.667076923076923, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '928492', 'n_tokens_mistral': 2010, 'n_tokens_neox': 1888, 'n_words': 467}