From 3210dd3039798a10884925cae98ef3b2a4c10703 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Wed, 27 Jun 2018 15:35:07 -0400 Subject: generators: add PLIST handling /cc @LnL7 @3noch --- lib/generators.nix | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'lib') diff --git a/lib/generators.nix b/lib/generators.nix index c09384c00f572..aab4498f9c643 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -175,4 +175,52 @@ rec { else "<λ:{${showFnas}}>" else abort "toPretty: should never happen (v = ${v})"; + # PLIST handling + + toPLIST = x: '' + + + + '' + pprExpr "" x + + "\n"; + + pprExpr = ind: x: with builtins; + if isNull x then "" else + if isBool x then pprBool ind x else + if isInt x then pprInt ind x else + if isString x then pprStr ind x else + if isList x then pprList ind x else + if isAttrs x then pprAttrs ind x else + throw "invalid plist type"; + + pprLiteral = ind: x: ind + x; + + pprBool = ind: x: pprLiteral ind (if x then "" else ""); + pprInt = ind: x: pprLiteral ind "${toString x}"; + pprStr = ind: x: pprLiteral ind "${x}"; + pprKey = ind: x: pprLiteral ind "${x}"; + + pprIndent = ind: pprExpr "\t${ind}"; + + pprItem = ind: libStr.concatMapStringsSep "\n" (pprIndent ind); + + pprList = ind: x: libStr.concatStringsSep "\n" [ + (pprLiteral ind "") + (pprItem ind x) + (pprLiteral ind "") + ]; + + pprAttrs = ind: x: libStr.concatStringsSep "\n" [ + (pprLiteral ind "") + (pprAttr ind x) + (pprLiteral ind "") + ]; + + attrFilter = name: value: name != "_module" && value != null; + + pprAttr = ind: x: libStr.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList (name: value: lib.optional (attrFilter name value) [ + (pprKey "\t${ind}" name) + (pprExpr "\t${ind}" value) + ]) x)); + } -- cgit 1.4.1 From d361371d236c90bfb550e827124b5350deeadbda Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Thu, 28 Jun 2018 11:11:19 -0400 Subject: generators: refactor toPLIST --- lib/generators.nix | 86 ++++++++++++++-------------- pkgs/development/tools/xcbuild/platform.nix | 10 ++-- pkgs/development/tools/xcbuild/sdk.nix | 4 +- pkgs/development/tools/xcbuild/toolchain.nix | 2 +- 4 files changed, 51 insertions(+), 51 deletions(-) (limited to 'lib') diff --git a/lib/generators.nix b/lib/generators.nix index aab4498f9c643..1433298158375 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -176,51 +176,51 @@ rec { else abort "toPretty: should never happen (v = ${v})"; # PLIST handling - - toPLIST = x: '' + toPLIST = {}: v: let + pprExpr = ind: x: with builtins; + if isNull x then "" else + if isBool x then pprBool ind x else + if isInt x then pprInt ind x else + if isString x then pprStr ind x else + if isList x then pprList ind x else + if isAttrs x then pprAttrs ind x else + abort "pprExpr: should never happen (v = ${v})"; + + pprLiteral = ind: x: ind + x; + + pprBool = ind: x: pprLiteral ind (if x then "" else ""); + pprInt = ind: x: pprLiteral ind "${toString x}"; + pprStr = ind: x: pprLiteral ind "${x}"; + pprKey = ind: x: pprLiteral ind "${x}"; + + pprIndent = ind: pprExpr "\t${ind}"; + + pprItem = ind: libStr.concatMapStringsSep "\n" (pprIndent ind); + + pprList = ind: x: libStr.concatStringsSep "\n" [ + (pprLiteral ind "") + (pprItem ind x) + (pprLiteral ind "") + ]; + + pprAttrs = ind: x: libStr.concatStringsSep "\n" [ + (pprLiteral ind "") + (pprAttr ind x) + (pprLiteral ind "") + ]; + + pprAttr = let attrFilter = name: value: name != "_module" && value != null; + in ind: x: libStr.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList + (name: value: lib.optional (attrFilter name value) [ + (pprKey "\t${ind}" name) + (pprExpr "\t${ind}" value) + ]) x)); + + in '' - '' + pprExpr "" x - + "\n"; - - pprExpr = ind: x: with builtins; - if isNull x then "" else - if isBool x then pprBool ind x else - if isInt x then pprInt ind x else - if isString x then pprStr ind x else - if isList x then pprList ind x else - if isAttrs x then pprAttrs ind x else - throw "invalid plist type"; - - pprLiteral = ind: x: ind + x; - - pprBool = ind: x: pprLiteral ind (if x then "" else ""); - pprInt = ind: x: pprLiteral ind "${toString x}"; - pprStr = ind: x: pprLiteral ind "${x}"; - pprKey = ind: x: pprLiteral ind "${x}"; - - pprIndent = ind: pprExpr "\t${ind}"; - - pprItem = ind: libStr.concatMapStringsSep "\n" (pprIndent ind); - - pprList = ind: x: libStr.concatStringsSep "\n" [ - (pprLiteral ind "") - (pprItem ind x) - (pprLiteral ind "") - ]; - - pprAttrs = ind: x: libStr.concatStringsSep "\n" [ - (pprLiteral ind "") - (pprAttr ind x) - (pprLiteral ind "") - ]; - - attrFilter = name: value: name != "_module" && value != null; - - pprAttr = ind: x: libStr.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList (name: value: lib.optional (attrFilter name value) [ - (pprKey "\t${ind}" name) - (pprExpr "\t${ind}" value) - ]) x)); + ${pprExpr "" v} + ''; } diff --git a/pkgs/development/tools/xcbuild/platform.nix b/pkgs/development/tools/xcbuild/platform.nix index e3fb83edc674f..502c3bcdbc87c 100644 --- a/pkgs/development/tools/xcbuild/platform.nix +++ b/pkgs/development/tools/xcbuild/platform.nix @@ -286,11 +286,11 @@ let in runCommand "MacOSX.platform" {} '' - install -D ${writeText "Info.plist" (toPLIST Info)} $out/Info.plist - install -D ${writeText "version.plist" (toPLIST Version)} $out/version.plist - install -D ${writeText "Architectures.xcspec" (toPLIST Architectures)} $out/Developer/Library/Xcode/Specifications/Architectures.xcspec - install -D ${writeText "PackageTypes.xcspec" (toPLIST PackageTypes)} $out/Developer/Library/Xcode/Specifications/PackageTypes.xcspec - install -D ${writeText "ProductTypes.xcspec" (toPLIST ProductTypes)} $out/Developer/Library/Xcode/Specifications/ProductTypes.xcspec + install -D ${writeText "Info.plist" (toPLIST {} Info)} $out/Info.plist + install -D ${writeText "version.plist" (toPLIST {} Version)} $out/version.plist + install -D ${writeText "Architectures.xcspec" (toPLIST {} Architectures)} $out/Developer/Library/Xcode/Specifications/Architectures.xcspec + install -D ${writeText "PackageTypes.xcspec" (toPLIST {} PackageTypes)} $out/Developer/Library/Xcode/Specifications/PackageTypes.xcspec + install -D ${writeText "ProductTypes.xcspec" (toPLIST {} ProductTypes)} $out/Developer/Library/Xcode/Specifications/ProductTypes.xcspec mkdir -p $out/Developer/SDKs/ cd $out/Developer/SDKs/ diff --git a/pkgs/development/tools/xcbuild/sdk.nix b/pkgs/development/tools/xcbuild/sdk.nix index 2d43347da03dc..5fdfe5877228d 100644 --- a/pkgs/development/tools/xcbuild/sdk.nix +++ b/pkgs/development/tools/xcbuild/sdk.nix @@ -24,6 +24,6 @@ in runCommand "MacOSX${version}.sdk" { inherit version; } '' - install -D ${writeText "SDKSettings.plist" (toPLIST SDKSettings)} $out/SDKSettings.plist - install -D ${writeText "SystemVersion.plist" (toPLIST SystemVersion)} $out/System/Library/CoreServices/SystemVersion.plist + install -D ${writeText "SDKSettings.plist" (toPLIST {} SDKSettings)} $out/SDKSettings.plist + install -D ${writeText "SystemVersion.plist" (toPLIST {} SystemVersion)} $out/System/Library/CoreServices/SystemVersion.plist '' diff --git a/pkgs/development/tools/xcbuild/toolchain.nix b/pkgs/development/tools/xcbuild/toolchain.nix index d8c80b53831ca..ed5730abddf6b 100644 --- a/pkgs/development/tools/xcbuild/toolchain.nix +++ b/pkgs/development/tools/xcbuild/toolchain.nix @@ -24,7 +24,7 @@ runCommand "nixpkgs.xctoolchain" { nativeBuildInputs = [ makeWrapper ]; } ('' mkdir -p $out - install -D ${writeText "ToolchainInfo.plist" (toPLIST ToolchainInfo)} $out/ToolchainInfo.plist + install -D ${writeText "ToolchainInfo.plist" (toPLIST {} ToolchainInfo)} $out/ToolchainInfo.plist mkdir -p $out/usr/include mkdir -p $out/usr/lib -- cgit 1.4.1 From 337b58950b9f945933eb82b46c9c4ceb1af3f997 Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Thu, 28 Jun 2018 11:12:39 -0400 Subject: generators: refactor toPlist Address PR comments Refactors - Rename toPLIST -> toPlist --- lib/generators.nix | 65 ++++++++++++++-------------- pkgs/development/tools/xcbuild/platform.nix | 12 ++--- pkgs/development/tools/xcbuild/sdk.nix | 6 +-- pkgs/development/tools/xcbuild/toolchain.nix | 4 +- 4 files changed, 43 insertions(+), 44 deletions(-) (limited to 'lib') diff --git a/lib/generators.nix b/lib/generators.nix index 1433298158375..073bb6982e14a 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -173,54 +173,53 @@ rec { fna); in if fna == {} then "<λ>" else "<λ:{${showFnas}}>" - else abort "toPretty: should never happen (v = ${v})"; + else abort "generators.toPretty: should never happen (v = ${v})"; # PLIST handling - toPLIST = {}: v: let - pprExpr = ind: x: with builtins; + toPlist = {}: v: let + expr = ind: x: with builtins; if isNull x then "" else - if isBool x then pprBool ind x else - if isInt x then pprInt ind x else - if isString x then pprStr ind x else - if isList x then pprList ind x else - if isAttrs x then pprAttrs ind x else - abort "pprExpr: should never happen (v = ${v})"; + if isBool x then bool ind x else + if isInt x then int ind x else + if isString x then str ind x else + if isList x then list ind x else + if isAttrs x then attrs ind x else + abort "generators.toPlist: should never happen (v = ${v})"; - pprLiteral = ind: x: ind + x; + literal = ind: x: ind + x; - pprBool = ind: x: pprLiteral ind (if x then "" else ""); - pprInt = ind: x: pprLiteral ind "${toString x}"; - pprStr = ind: x: pprLiteral ind "${x}"; - pprKey = ind: x: pprLiteral ind "${x}"; + bool = ind: x: literal ind (if x then "" else ""); + int = ind: x: literal ind "${toString x}"; + str = ind: x: literal ind "${x}"; + key = ind: x: literal ind "${x}"; - pprIndent = ind: pprExpr "\t${ind}"; + indent = ind: expr "\t${ind}"; - pprItem = ind: libStr.concatMapStringsSep "\n" (pprIndent ind); + item = ind: libStr.concatMapStringsSep "\n" (indent ind); - pprList = ind: x: libStr.concatStringsSep "\n" [ - (pprLiteral ind "") - (pprItem ind x) - (pprLiteral ind "") + list = ind: x: libStr.concatStringsSep "\n" [ + (literal ind "") + (item ind x) + (literal ind "") ]; - pprAttrs = ind: x: libStr.concatStringsSep "\n" [ - (pprLiteral ind "") - (pprAttr ind x) - (pprLiteral ind "") + attrs = ind: x: libStr.concatStringsSep "\n" [ + (literal ind "") + (attr ind x) + (literal ind "") ]; - pprAttr = let attrFilter = name: value: name != "_module" && value != null; + attr = let attrFilter = name: value: name != "_module" && value != null; in ind: x: libStr.concatStringsSep "\n" (lib.flatten (lib.mapAttrsToList (name: value: lib.optional (attrFilter name value) [ - (pprKey "\t${ind}" name) - (pprExpr "\t${ind}" value) + (key "\t${ind}" name) + (expr "\t${ind}" value) ]) x)); - in '' - - - - ${pprExpr "" v} - ''; + in '' + + +${expr "" v} +''; } diff --git a/pkgs/development/tools/xcbuild/platform.nix b/pkgs/development/tools/xcbuild/platform.nix index 502c3bcdbc87c..bb91df474aae9 100644 --- a/pkgs/development/tools/xcbuild/platform.nix +++ b/pkgs/development/tools/xcbuild/platform.nix @@ -2,7 +2,7 @@ let - inherit (lib.generators) toPLIST; + inherit (lib.generators) toPlist; Info = { CFBundleIdentifier = platformName; @@ -286,11 +286,11 @@ let in runCommand "MacOSX.platform" {} '' - install -D ${writeText "Info.plist" (toPLIST {} Info)} $out/Info.plist - install -D ${writeText "version.plist" (toPLIST {} Version)} $out/version.plist - install -D ${writeText "Architectures.xcspec" (toPLIST {} Architectures)} $out/Developer/Library/Xcode/Specifications/Architectures.xcspec - install -D ${writeText "PackageTypes.xcspec" (toPLIST {} PackageTypes)} $out/Developer/Library/Xcode/Specifications/PackageTypes.xcspec - install -D ${writeText "ProductTypes.xcspec" (toPLIST {} ProductTypes)} $out/Developer/Library/Xcode/Specifications/ProductTypes.xcspec + install -D ${writeText "Info.plist" (toPlist {} Info)} $out/Info.plist + install -D ${writeText "version.plist" (toPlist {} Version)} $out/version.plist + install -D ${writeText "Architectures.xcspec" (toPlist {} Architectures)} $out/Developer/Library/Xcode/Specifications/Architectures.xcspec + install -D ${writeText "PackageTypes.xcspec" (toPlist {} PackageTypes)} $out/Developer/Library/Xcode/Specifications/PackageTypes.xcspec + install -D ${writeText "ProductTypes.xcspec" (toPlist {} ProductTypes)} $out/Developer/Library/Xcode/Specifications/ProductTypes.xcspec mkdir -p $out/Developer/SDKs/ cd $out/Developer/SDKs/ diff --git a/pkgs/development/tools/xcbuild/sdk.nix b/pkgs/development/tools/xcbuild/sdk.nix index 5fdfe5877228d..c97d17d739baf 100644 --- a/pkgs/development/tools/xcbuild/sdk.nix +++ b/pkgs/development/tools/xcbuild/sdk.nix @@ -1,7 +1,7 @@ { runCommand, lib, toolchainName, sdkName, writeText }: let - inherit (lib.generators) toPLIST; + inherit (lib.generators) toPlist; # TODO: expose MACOSX_DEPLOYMENT_TARGET in nix so we can use it here. version = "10.10"; @@ -24,6 +24,6 @@ in runCommand "MacOSX${version}.sdk" { inherit version; } '' - install -D ${writeText "SDKSettings.plist" (toPLIST {} SDKSettings)} $out/SDKSettings.plist - install -D ${writeText "SystemVersion.plist" (toPLIST {} SystemVersion)} $out/System/Library/CoreServices/SystemVersion.plist + install -D ${writeText "SDKSettings.plist" (toPlist {} SDKSettings)} $out/SDKSettings.plist + install -D ${writeText "SystemVersion.plist" (toPlist {} SystemVersion)} $out/System/Library/CoreServices/SystemVersion.plist '' diff --git a/pkgs/development/tools/xcbuild/toolchain.nix b/pkgs/development/tools/xcbuild/toolchain.nix index ed5730abddf6b..51bc5d60bcfea 100644 --- a/pkgs/development/tools/xcbuild/toolchain.nix +++ b/pkgs/development/tools/xcbuild/toolchain.nix @@ -4,7 +4,7 @@ let inherit (lib) getBin optionalString; - inherit (lib.generators) toPLIST; + inherit (lib.generators) toPlist; ToolchainInfo = { Identifier = toolchainName; @@ -24,7 +24,7 @@ runCommand "nixpkgs.xctoolchain" { nativeBuildInputs = [ makeWrapper ]; } ('' mkdir -p $out - install -D ${writeText "ToolchainInfo.plist" (toPLIST {} ToolchainInfo)} $out/ToolchainInfo.plist + install -D ${writeText "ToolchainInfo.plist" (toPlist {} ToolchainInfo)} $out/ToolchainInfo.plist mkdir -p $out/usr/include mkdir -p $out/usr/lib -- cgit 1.4.1