uboot: (firmwareOdroidC2/C4) don't invoke patch tool, use patches = [] instead

https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh#L948
this can do it nicely.

Signed-off-by: Anton Arapov <anton@deadbeef.mx>
This commit is contained in:
Anton Arapov 2021-04-03 12:58:10 +02:00 committed by Alan Daniels
commit 56de2bcd43
30691 changed files with 3076956 additions and 0 deletions

View file

@ -0,0 +1,132 @@
{ lib, pkgs }:
let
inherit (lib) types;
inherit (types) attrsOf oneOf coercedTo str bool int float package;
in
{
javaProperties = { comment ? "Generated with Nix", boolToString ? lib.boolToString }: {
# Design note:
# A nested representation of inevitably leads to bad UX:
# 1. keys like "a.b" must be disallowed, or
# the addition of options in a freeformType module
# become breaking changes
# 2. adding a value for "a" after "a"."b" was already
# defined leads to a somewhat hard to understand
# Nix error, because that's not something you can
# do with attrset syntax. Workaround: "a"."", but
# that's too little too late. Another workaround:
# mkMerge [ { a = ...; } { a.b = ...; } ].
#
# Choosing a non-nested representation does mean that
# we sacrifice the ability to override at the (conceptual)
# hierarchical levels, _if_ an application exhibits those.
#
# Some apps just use periods instead of spaces in an odd
# mix of attempted categorization and natural language,
# with no meaningful hierarchy.
#
# We _can_ choose to support hierarchical config files
# via nested attrsets, but the module author should
# make sure that problem (2) does not occur.
type = let
elemType =
oneOf ([
# `package` isn't generalized to `path` because path values
# are ambiguous. Are they host path strings (toString /foo/bar)
# or should they be added to the store? ("${/foo/bar}")
# The user must decide.
(coercedTo package toString str)
(coercedTo bool boolToString str)
(coercedTo int toString str)
(coercedTo float toString str)
])
// { description = "string, package, bool, int or float"; };
in attrsOf elemType;
generate = name: value:
pkgs.runCommandLocal name
{
# Requirements
# ============
#
# 1. Strings in Nix carry over to the same
# strings in Java => need proper escapes
# 2. Generate files quickly
# - A JVM would have to match the app's
# JVM to avoid build closure bloat
# - Even then, JVM startup would slow
# down config generation.
#
#
# Implementation
# ==============
#
# Escaping has two steps
#
# 1. jq
# Escape known separators, in order not
# to break up the keys and values.
# This handles typical whitespace correctly,
# but may produce garbage for other control
# characters.
#
# 2. iconv
# Escape >ascii code points to java escapes,
# as .properties files are supposed to be
# encoded in ISO 8859-1. It's an old format.
# UTF-8 behavior may exist in some apps and
# libraries, but we can't rely on this in
# general.
passAsFile = [ "value" ];
value = builtins.toJSON value;
nativeBuildInputs = [
pkgs.jq
pkgs.libiconvReal
];
jqCode =
let
main = ''
to_entries
| .[]
| "\(
.key
| ${commonEscapes}
| gsub(" "; "\\ ")
| gsub("="; "\\=")
) = \(
.value
| ${commonEscapes}
| gsub("^ "; "\\ ")
| gsub("\\n "; "\n\\ ")
)"
'';
# Most escapes are equal for both keys and values.
commonEscapes = ''
gsub("\\\\"; "\\\\")
| gsub("\\n"; "\\n\\\n")
| gsub("#"; "\\#")
| gsub("!"; "\\!")
| gsub("\\t"; "\\t")
| gsub("\r"; "\\r")
'';
in
main;
inputEncoding = "UTF-8";
inherit comment;
} ''
(
echo "$comment" | while read -r ln; do echo "# $ln"; done
echo
jq -r --arg hash '#' "$jqCode" "$valuePath" \
| iconv --from-code "$inputEncoding" --to-code JAVA \
) > "$out"
'';
};
}

View file

@ -0,0 +1,27 @@
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
import java.util.SortedSet;
import java.util.TreeSet;
class Main {
public static void main (String args[]) {
try {
InputStream input = new FileInputStream(args[0]);
Properties prop = new Properties();
prop.load(input);
SortedSet<String> keySet = new TreeSet(prop.keySet());
for (String key : keySet) {
System.out.println("KEY");
System.out.println(key);
System.out.println("VALUE");
System.out.println(prop.get(key));
System.out.println("");
}
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.toString());
System.exit(1);
}
}
}

View file

@ -0,0 +1,92 @@
{ fetchurl
, formats
, glibcLocales
, jdk
, lib
, stdenv
}:
# This test primarily tests correct escaping.
# See also testJavaProperties in
# pkgs/pkgs-lib/tests/formats.nix, which tests
# type coercions and is a bit easier to read.
let
inherit (lib) concatStrings attrValues mapAttrs;
javaProperties = formats.javaProperties { };
input = {
foo = "bar";
"empty value" = "";
"typical.dot.syntax" = "com.sun.awt";
"" = "empty key's value";
"1" = "2 3";
"#" = "not a comment # still not";
"!" = "not a comment!";
"!a" = "still not! a comment";
"!b" = "still not ! a comment";
"dos paths" = "C:\\Program Files\\Nix For Windows\\nix.exe";
"a \t\nb" = " c";
"angry \t\nkey" = ''
multi
${"\tline\r"}
space-
indented
trailing-space${" "}
trailing-space${" "}
value
'';
"this=not" = "bad";
"nor = this" = "bad";
"all stuff" = "foo = bar";
"unicode big brain" = "e = mc";
"ütf-8" = "dûh";
# NB: Some editors (vscode) show this _whole_ line in right-to-left order
"الجبر" = "أكثر من مجرد أرقام";
};
in
stdenv.mkDerivation {
name = "pkgs.formats.javaProperties-test-${jdk.name}";
nativeBuildInputs = [
jdk
glibcLocales
];
# technically should go through the type.merge first, but that's tested
# in tests/formats.nix.
properties = javaProperties.generate "example.properties" input;
# Expected output as printed by Main.java
passAsFile = [ "expected" ];
expected = concatStrings (attrValues (
mapAttrs
(key: value:
''
KEY
${key}
VALUE
${value}
''
)
input
));
src = lib.sourceByRegex ./. [
".*\.java"
];
# On Linux, this can be C.UTF-8, but darwin + zulu requires en_US.UTF-8
LANG = "en_US.UTF-8";
buildPhase = ''
javac Main.java
'';
doCheck = true;
checkPhase = ''
cat -v $properties
java Main $properties >actual
diff -U3 $expectedPath actual
'';
installPhase = "touch $out";
}