darwin.mkAppleDerivation: use lib.extendMkDerivation (#453094)

This commit is contained in:
Emily 2025-10-23 00:19:23 +00:00 committed by GitHub
commit 8cf6f340f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 51 additions and 69 deletions

View file

@ -19,8 +19,6 @@ mkAppleDerivation (finalAttrs: {
./patches/0001-Support-setting-an-upper-bound-on-versions.patch
];
noCC = true;
nativeBuildInputs = [ unifdef ];
buildPhase = ''

View file

@ -8,83 +8,67 @@ in
fetchFromGitHub,
meson,
ninja,
stdenv,
stdenvNoCC,
xcodeProjectCheckHook,
}:
let
hasBasenamePrefix = prefix: file: lib.hasPrefix prefix (baseNameOf file);
in
lib.makeOverridable (
attrs:
let
attrs' = if lib.isFunction attrs then attrs else _: attrs;
attrsFixed = lib.fix attrs';
stdenv' =
if attrsFixed.noCC or false then
stdenvNoCC
else if attrsFixed.noBootstrap or false then
stdenv
else
bootstrapStdenv;
in
stdenv'.mkDerivation (
lib.extends (
self: super:
assert super ? releaseName;
let
inherit (super) releaseName;
info = versions.${releaseName};
files = lib.filesystem.listFilesRecursive (lib.path.append ./. releaseName);
mesonFiles = lib.filter (hasBasenamePrefix "meson") files;
in
# You have to have at least `meson.build.in` when using xcodeHash to trigger the Meson
# build support in `mkAppleDerivation`.
assert super ? xcodeHash -> lib.length mesonFiles > 0;
{
pname = super.pname or releaseName;
inherit (info) version;
lib.extendMkDerivation {
constructDrv = bootstrapStdenv.mkDerivation;
extendDrvArgs =
finalAttrs: args:
assert args ? releaseName;
let
inherit (args) releaseName;
info = versions.${releaseName};
files = lib.filesystem.listFilesRecursive (lib.path.append ./. releaseName);
mesonFiles = lib.filter (hasBasenamePrefix "meson") files;
in
# You have to have at least `meson.build.in` when using xcodeHash to trigger the Meson
# build support in `mkAppleDerivation`.
assert args ? xcodeHash -> lib.length mesonFiles > 0;
{
pname = args.pname or releaseName;
inherit (info) version;
src = super.src or fetchFromGitHub {
owner = "apple-oss-distributions";
repo = releaseName;
rev = info.rev or "${releaseName}-${info.version}";
inherit (info) hash;
};
src = args.src or fetchFromGitHub {
owner = "apple-oss-distributions";
repo = releaseName;
rev = info.rev or "${releaseName}-${info.version}";
inherit (info) hash;
};
strictDeps = true;
__structuredAttrs = true;
strictDeps = true;
__structuredAttrs = true;
meta = {
homepage = "https://opensource.apple.com/releases/";
license = lib.licenses.apple-psl20;
teams = [ lib.teams.darwin ];
platforms = lib.platforms.darwin;
}
// super.meta or { };
meta = {
homepage = "https://opensource.apple.com/releases/";
license = lib.licenses.apple-psl20;
teams = [ lib.teams.darwin ];
platforms = lib.platforms.darwin;
}
// lib.optionalAttrs (super ? xcodeHash) {
postUnpack =
super.postUnpack or ""
+ lib.concatMapStrings (
file:
if baseNameOf file == "meson.build.in" then
"substitute ${lib.escapeShellArg "${file}"} \"$sourceRoot/meson.build\" --subst-var version\n"
else
"cp ${lib.escapeShellArg "${file}"} \"$sourceRoot/\"${lib.escapeShellArg (baseNameOf file)}\n"
) mesonFiles;
// args.meta or { };
}
// lib.optionalAttrs (args ? xcodeHash) {
postUnpack =
args.postUnpack or ""
+ lib.concatMapStrings (
file:
if baseNameOf file == "meson.build.in" then
"substitute ${lib.escapeShellArg "${file}"} \"$sourceRoot/meson.build\" --subst-var version\n"
else
"cp ${lib.escapeShellArg "${file}"} \"$sourceRoot/\"${lib.escapeShellArg (baseNameOf file)}\n"
) mesonFiles;
xcodeProject = super.xcodeProject or "${releaseName}.xcodeproj";
xcodeProject = args.xcodeProject or "${releaseName}.xcodeproj";
nativeBuildInputs = super.nativeBuildInputs or [ ] ++ [
meson
ninja
xcodeProjectCheckHook
];
nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [
meson
ninja
xcodeProjectCheckHook
];
mesonBuildType = "release";
}
) attrs'
)
)
mesonBuildType = "release";
};
}