<commit_before>/* This file contains various functions that take a stdenv and return
   a new stdenv with different behaviour, e.g. using a different C
   compiler. */

pkgs:

rec {


  # Override the compiler in stdenv for specific packages.
  overrideCC = stdenv: cc: stdenv.override { allowedRequisites = null; cc = cc; };


  # Add some arbitrary packages to buildInputs for specific packages.
  # Used to override packages in stdenv like Make.  Should not be used
  # for other dependencies.
  overrideInStdenv = stdenv: pkgs:
    stdenv.override (prev: { allowedRequisites = null; extraBuildInputs = prev.extraBuildInputs or [] ++ pkgs; });


  # Override the setup script of stdenv.  Useful for testing new
  # versions of the setup script without causing a rebuild of
  # everything.
  #
  # Example:
  #   randomPkg = import ../bla { ...
  #     stdenv = overrideSetup stdenv ../stdenv/generic/setup-latest.sh;
  #   };
  overrideSetup = stdenv: setupScript: stdenv.override { inherit setupScript; };


  # Return a modified stdenv that tries to build statically linked
  # binaries.
  makeStaticBinaries = stdenv: stdenv //
    { mkDerivation = args: stdenv.mkDerivation (args // {
        NIX_CFLAGS_LINK = "-static";
        configureFlags =
          toString args.configureFlags or ""
          + " --disable-shared"; # brrr...
      });
      isStatic = true;
    };


  # Return a modified stdenv that builds static libraries instead of
  # shared libraries.
  makeStaticLibraries = stdenv: stdenv //
    { mkDerivation = args: stdenv.mkDerivation (args // {
        dontDisableStatic = true;
        configureFlags =
          toString args.configureFlags or ""
          + " --enable-static --disable-shared";
      });
    };


  # Return a modified stdenv that adds a cross compiler to the
  # builds.
  makeStdenvCross = { stdenv
                    , cc
                    , buildPlatform, hostPlatform, targetPlatform
                    } @ overrideArgs: let
    stdenv = overrideArgs.stdenv.override {
      # TODO(@Ericson2314): Cannot do this for now because then Nix thinks the
      # resulting derivation should be built on the host platform.
      #hostPlatform = buildPlatform;
      #targetPlatform = hostPlatform;
      inherit cc;

      allowedRequisites = null;

      # Overrides are surely not valid as packages built with this run on a
      # different platform.
      overrides = _: _: {};
    };
  in stdenv // {
    mkDerivation =
      { name ? "", buildInputs ? [], nativeBuildInputs ? []
      , propagatedBuildInputs ? [], propagatedNativeBuildInputs ? []
      , configureFlags ? []
      , # Target is not included by default because most programs don't care.
        # Including it then would cause needless massive rebuilds.
        configurePlatforms   ? args.crossAttrs.configurePlatforms   or [ "build" "host" ]
      , selfNativeBuildInput ? args.crossAttrs.selfNativeBuildInput or false
      , ...
      } @ args:

      let
        # *BuildInputs exists temporarily as another name for
        # *HostInputs.

        # The base stdenv already knows that nativeBuildInputs and
        # buildInputs should be built with the usual gcc-wrapper
        # And the same for propagatedBuildInputs.
        nativeDrv = stdenv.mkDerivation args;

        # Temporary expression until the cross_renaming, to handle the
        # case of pkgconfig given as buildInput, but to be used as
        # nativeBuildInput.
        hostAsNativeDrv = drv:
            builtins.unsafeDiscardStringContext drv.nativeDrv.drvPath
            == builtins.unsafeDiscardStringContext drv.crossDrv.drvPath;
        buildInputsNotNull = stdenv.lib.filter
            (drv: builtins.isAttrs drv && drv ? nativeDrv) buildInputs;
        nativeInputsFromBuildInputs = stdenv.lib.filter hostAsNativeDrv buildInputsNotNull;
      in
        stdenv.mkDerivation (args // {
          name = name + "-" + hostPlatform.config;
          nativeBuildInputs = nativeBuildInputs
            ++ nativeInputsFromBuildInputs
            ++ stdenv.lib.optional selfNativeBuildInput nativeDrv
              # without proper `file` command, libtool sometimes fails
              # to recognize 64-bit DLLs
            ++ stdenv.lib.optional (hostPlatform.config == "x86_64-w64-mingw32") pkgs.file
            ++ stdenv.lib.optional (hostPlatform.config == "aarch64-linux-gnu") pkgs.updateAutotoolsGnuConfigScriptsHook
            ;

          # This parameter is sometimes a string and sometimes a list, yuck
          configureFlags = let inherit (stdenv.lib) optional elem; in
            (if stdenv.lib.isString configureFlags then [configureFlags] else configureFlags)
            ++ optional (elem "build"  configurePlatforms) "--build=${buildPlatform.config}"
            ++ optional (elem "host"   configurePlatforms) "--host=${hostPlatform.config}"
            ++ optional (elem "target" configurePlatforms) "--target=${targetPlatform.config}";

          # Cross-linking dynamic libraries, every buildInput should
          # be propagated because ld needs the -rpath-link to find
          # any library needed to link the program dynamically at
          # loader time. ld(1) explains it.
          buildInputs = [];
          propagatedBuildInputs = propagatedBuildInputs ++ buildInputs;
          propagatedNativeBuildInputs = propagatedNativeBuildInputs;<commit_msg>cross stdenv adaptor: Disable checkPhase by default<commit_after>/* This file contains various functions that take a stdenv and return
   a new stdenv with different behaviour, e.g. using a different C
   compiler. */

pkgs:

rec {


  # Override the compiler in stdenv for specific packages.
  overrideCC = stdenv: cc: stdenv.override { allowedRequisites = null; cc = cc; };


  # Add some arbitrary packages to buildInputs for specific packages.
  # Used to override packages in stdenv like Make.  Should not be used
  # for other dependencies.
  overrideInStdenv = stdenv: pkgs:
    stdenv.override (prev: { allowedRequisites = null; extraBuildInputs = prev.extraBuildInputs or [] ++ pkgs; });


  # Override the setup script of stdenv.  Useful for testing new
  # versions of the setup script without causing a rebuild of
  # everything.
  #
  # Example:
  #   randomPkg = import ../bla { ...
  #     stdenv = overrideSetup stdenv ../stdenv/generic/setup-latest.sh;
  #   };
  overrideSetup = stdenv: setupScript: stdenv.override { inherit setupScript; };


  # Return a modified stdenv that tries to build statically linked
  # binaries.
  makeStaticBinaries = stdenv: stdenv //
    { mkDerivation = args: stdenv.mkDerivation (args // {
        NIX_CFLAGS_LINK = "-static";
        configureFlags =
          toString args.configureFlags or ""
          + " --disable-shared"; # brrr...
      });
      isStatic = true;
    };


  # Return a modified stdenv that builds static libraries instead of
  # shared libraries.
  makeStaticLibraries = stdenv: stdenv //
    { mkDerivation = args: stdenv.mkDerivation (args // {
        dontDisableStatic = true;
        configureFlags =
          toString args.configureFlags or ""
          + " --enable-static --disable-shared";
      });
    };


  # Return a modified stdenv that adds a cross compiler to the
  # builds.
  makeStdenvCross = { stdenv
                    , cc
                    , buildPlatform, hostPlatform, targetPlatform
                    } @ overrideArgs: let
    stdenv = overrideArgs.stdenv.override {
      # TODO(@Ericson2314): Cannot do this for now because then Nix thinks the
      # resulting derivation should be built on the host platform.
      #hostPlatform = buildPlatform;
      #targetPlatform = hostPlatform;
      inherit cc;

      allowedRequisites = null;

      # Overrides are surely not valid as packages built with this run on a
      # different platform.
      overrides = _: _: {};
    };
  in stdenv // {
    mkDerivation =
      { name ? "", buildInputs ? [], nativeBuildInputs ? []
      , propagatedBuildInputs ? [], propagatedNativeBuildInputs ? []
      , # Disabling the tests by default when cross compiling, as usually the
        # tests rely on being able to run produced binaries.
        doCheck ? false
      , configureFlags ? []
      , # Target is not included by default because most programs don't care.
        # Including it then would cause needless massive rebuilds.
        configurePlatforms   ? args.crossAttrs.configurePlatforms   or [ "build" "host" ]
      , selfNativeBuildInput ? args.crossAttrs.selfNativeBuildInput or false
      , ...
      } @ args:

      let
        # *BuildInputs exists temporarily as another name for
        # *HostInputs.

        # The base stdenv already knows that nativeBuildInputs and
        # buildInputs should be built with the usual gcc-wrapper
        # And the same for propagatedBuildInputs.
        nativeDrv = stdenv.mkDerivation args;

        # Temporary expression until the cross_renaming, to handle the
        # case of pkgconfig given as buildInput, but to be used as
        # nativeBuildInput.
        hostAsNativeDrv = drv:
            builtins.unsafeDiscardStringContext drv.nativeDrv.drvPath
            == builtins.unsafeDiscardStringContext drv.crossDrv.drvPath;
        buildInputsNotNull = stdenv.lib.filter
            (drv: builtins.isAttrs drv && drv ? nativeDrv) buildInputs;
        nativeInputsFromBuildInputs = stdenv.lib.filter hostAsNativeDrv buildInputsNotNull;
      in
        stdenv.mkDerivation (args // {
          name = name + "-" + hostPlatform.config;
          nativeBuildInputs = nativeBuildInputs
            ++ nativeInputsFromBuildInputs
            ++ stdenv.lib.optional selfNativeBuildInput nativeDrv
              # without proper `file` command, libtool sometimes fails
              # to recognize 64-bit DLLs
            ++ stdenv.lib.optional (hostPlatform.config == "x86_64-w64-mingw32") pkgs.file
            ++ stdenv.lib.optional (hostPlatform.config == "aarch64-linux-gnu") pkgs.updateAutotoolsGnuConfigScriptsHook
            ;

          inherit doCheck;

          # This parameter is sometimes a string and sometimes a list, yuck
          configureFlags = let inherit (stdenv.lib) optional elem; in
            (if stdenv.lib.isString configureFlags then [configureFlags] else configureFlags)
            ++ optional (elem "build"  configurePlatforms) "--build=${buildPlatform.config}"
            ++ optional (elem "host"   configurePlatforms) "--host=${hostPlatform.config}"
            ++ optional (elem "target" configurePlatforms) "--target=${targetPlatform.config}";

          # Cross-linking dynamic libraries, every buildInput should
          # be propagated because ld needs the -rpath-link to find
          # any library needed to link the program dynamically at
          # loader time. ld(1) explains it.
          buildInputs = [];
          propagatedBuildInputs = propagatedBuildInputs ++ buildInputs;
          propagatedNativeBuildInputs = propagatedNativeBuildInputs;
{'fraction_non_alphanumeric': 0.0815399981839644, 'fraction_numerical': 0.003087260510306002, 'mean_word_length': 2.5426182052106787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1844762', 'n_tokens_mistral': 3028, 'n_tokens_neox': 2949, 'n_words': 927}