mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-15 22:36:23 +01:00
buildDartApplication: Link the package_config.json in a separate derivation
This commit is contained in:
parent
4f623fa0a1
commit
4eb35ef711
4 changed files with 25 additions and 9 deletions
|
@ -51,7 +51,7 @@
|
|||
}@args:
|
||||
|
||||
let
|
||||
generators = callPackage ./generators.nix { inherit dart; } { inherit sdkSetupScript; buildDrvArgs = args; };
|
||||
generators = callPackage ./generators.nix { inherit dart; } { buildDrvArgs = args; };
|
||||
|
||||
generatedDepsList = generators.mkDepsList { inherit pubspecLockFile pubspecLockData packageConfig; };
|
||||
|
||||
|
@ -64,7 +64,7 @@ let
|
|||
|
||||
pubspecLockFile = builtins.toJSON pubspecLock;
|
||||
pubspecLockData = pub2nix.readPubspecLock { inherit src packageRoot pubspecLock gitHashes sdkSourceBuilders; };
|
||||
packageConfig = pub2nix.generatePackageConfig {
|
||||
packageConfig = generators.linkPackageConfig (pub2nix.generatePackageConfig {
|
||||
pname = if args.pname != null then "${args.pname}-${args.version}" else null;
|
||||
|
||||
dependencies =
|
||||
|
@ -78,7 +78,7 @@ let
|
|||
builtins.concatLists (builtins.attrValues pubspecLockData.dependencies);
|
||||
|
||||
inherit (pubspecLockData) dependencySources;
|
||||
};
|
||||
});
|
||||
|
||||
inherit (dartHooks.override { inherit dart; }) dartConfigHook dartBuildHook dartInstallHook dartFixupHook;
|
||||
|
||||
|
|
|
@ -2,18 +2,17 @@
|
|||
, stdenvNoCC
|
||||
, dart
|
||||
, dartHooks
|
||||
, jq
|
||||
, yq
|
||||
, cacert
|
||||
}:
|
||||
|
||||
{
|
||||
# Commands to run once before using Dart or pub.
|
||||
sdkSetupScript ? ""
|
||||
# Arguments used in the derivation that builds the Dart package.
|
||||
# Passing these is recommended to ensure that the same steps are made to
|
||||
# prepare the sources in both this derivation and the one that builds the Dart
|
||||
# package.
|
||||
, buildDrvArgs ? { }
|
||||
buildDrvArgs ? { }
|
||||
, ...
|
||||
}@args:
|
||||
|
||||
|
@ -50,6 +49,24 @@ let
|
|||
drvArgs = buildDrvInheritArgs // (removeAttrs args [ "buildDrvArgs" ]);
|
||||
name = (if drvArgs ? name then drvArgs.name else "${drvArgs.pname}-${drvArgs.version}");
|
||||
|
||||
# Adds the root package to a dependency package_config.json file from pub2nix.
|
||||
linkPackageConfig = packageConfig: stdenvNoCC.mkDerivation (drvArgs // {
|
||||
name = "${name}-package-config-with-root.json";
|
||||
|
||||
nativeBuildInputs = drvArgs.nativeBuildInputs or [ ] ++ args.nativeBuildInputs or [ ] ++ [ jq yq ];
|
||||
|
||||
dontBuild = true;
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
packageName="$(yq --raw-output .name pubspec.yaml)"
|
||||
jq --arg name "$packageName" '.packages |= . + [{ name: $name, rootUri: "../", packageUri: "lib/" }]' '${packageConfig}' > "$out"
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
});
|
||||
|
||||
mkDepsDrv = { pubspecLockFile, pubspecLockData, packageConfig }: args: stdenvNoCC.mkDerivation (drvArgs // args // {
|
||||
inherit pubspecLockFile packageConfig;
|
||||
|
||||
|
@ -76,5 +93,6 @@ let
|
|||
in
|
||||
{
|
||||
inherit
|
||||
linkPackageConfig
|
||||
mkDepsList;
|
||||
}
|
||||
|
|
|
@ -8,8 +8,7 @@ dartConfigHook() {
|
|||
|
||||
echo "Installing dependencies"
|
||||
mkdir -p .dart_tool
|
||||
packageName="$(@yq@ --raw-output .name pubspec.yaml)"
|
||||
@jq@ '.packages |= . + [{ name: "'"$packageName"'", rootUri: "../", packageUri: "lib/" }]' "$packageConfig" > .dart_tool/package_config.json
|
||||
cp "$packageConfig" .dart_tool/package_config.json
|
||||
|
||||
echo "Generating the dependency list"
|
||||
dart pub deps --json | @jq@ .packages > deps.json
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
{
|
||||
dartConfigHook = makeSetupHook {
|
||||
name = "dart-config-hook";
|
||||
substitutions.yq = "${yq}/bin/yq";
|
||||
substitutions.jq = "${jq}/bin/jq";
|
||||
} ./dart-config-hook.sh;
|
||||
dartBuildHook = makeSetupHook {
|
||||
|
|
Loading…
Reference in a new issue