patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob 62863e78f157f1d9a0f6dbdb0f4380db9c9d48cb 3395 bytes (raw)
name: scripts/genfiles.awk 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
 
#!/usr/bin/env -S LC_ALL=C LANGUAGE=C awk -E
# SPDX-License-Identifier: EUPL-1.2+
# SPDX-FileCopyrightText: 2025 Demi Marie Obenour <demiobenour@gmail.com>
function check_status(status) {
	if (status < 0) {
		printf "FATAL: getline: %s\n", status > "/dev/stderr";
		exit 1;
	}
	return status;
}

function check_close(value,    status) {
	status = check_status(close(value));
	if (status != 0) {
		printf "FATAL: command exited with status %d\n", status > "/dev/stderr";
		exit status;
	}
}

function shell_quote(command) {
	gsub(/'/, "'\\\\&'", command);
	return ("'" command "'");
}

function get(command,          line, path, array_index, inode_type, mode, modes, symlink_count, symlinks, file_count, files, rc_count, rc_files, is_license, is_rc) {
	file_count = 0;
	symlink_count = 0;
	rc_count = 0;
	modes["120000"] = "symlink";
	modes["040644"] = "directory";
	modes["040755"] = "directory";
	modes["100644"] = "regular";
	modes["100755"] = "regular";
	print "# SPDX-License-Identifier: CC0-1.0";
	print "# SPDX-FileCopyRightText: Not Copyrightable (machine-written)";
	print "# Generated by scripts/genfile.awk, DO NOT EDIT!";
	while (check_status(command | getline line)) {
		if (line !~ /^[0-7]{6}\t/) {
			# this is a git bug
			print "FATAL: git ls-files output didn't start with a valid mode" > "/dev/stderr";
			exit 1;
		}
		path = substr(line, 8);
		if (path !~ /^[ -~]+$/) {
			# also a git bug
			print "FATAL: git ls-files didn't quote properly" > "/dev/stderr";
			exit 1;
		}
		if (path ~ /^\/|((^|\/)\.{0,2}($|\/))/) {
			# also a git bug
			printf "FATAL: git ls-files output non-canonical path '%s'\n", path > "/dev/stderr";
			exit 1;
		}
		if (path !~ /^[[:alnum:]_.+@/-]+$/) {
			printf "FATAL: filename '%s' has forbidden characters\n", path > "/dev/stderr";
			exit 1;
		}
		mode = modes[substr(line, 1, 6)];
		is_license = path ~ /\.license$/;
		is_rc = path ~ /^etc\/s6-rc\//;
		if (mode == "regular") {
			if (is_license) {
				continue;
			}
			if (is_rc) {
				rc_count += 1;
				rc_files[rc_count] = path;
			} else {
				file_count += 1;
				files[file_count] = path;
			}
			continue;
		}
		if (mode == "symlink") {
			if (is_rc) {
				printf "FATAL: symlink in s6-rc-compile input: %s\n", path;
				exit 1;
			}
			symlink_count += 1;
			symlinks[symlink_count] = path;
		} else if (mode != "directory") {
			printf "FATAL: file %s has unknown mode %s\n", path, substr(line, 1, 6) > "/dev/stderr";
			exit 1;
		}
		if (is_license) {
			printf "FATAL: %s (type %s) ends in .license\n", path, mode > "/dev/stderr";
			exit 1;
		}
	}
	check_close(command);

	printf "override FILES ::=";
	for (array_index = 1; array_index <= file_count; array_index += 1) {
		printf " \\\n\t%s", files[array_index];
	}
	printf ("\n\n" \
"# These are separate because they need to be included, but putting\n" \
"# them as make dependencies would confuse make.\n" \
"override LINKS ::=");
	for (array_index = 1; array_index <= symlink_count; array_index += 1) {
		printf " \\\n\t%s", symlinks[array_index];
	}
	printf "\n\noverride S6_RC_FILES ::=";
	for (array_index = 1; array_index <= rc_count; array_index += 1) {
		printf " \\\n\t%s", rc_files[array_index];
	}
	printf "\n"
}

BEGIN {
	RS = "\n";
	FS = "\t";
	get("set -euo pipefail && { git -c core.quotePath=true -C " shell_quote(ARGV[1]) " ls-files '--format=%(objectmode)\t%(path)' -- .|sort -t '\t' -k 2;}");
	exit 0;
}

debug log:

solving 62863e78f157f1d9a0f6dbdb0f4380db9c9d48cb ...
found 62863e78f157f1d9a0f6dbdb0f4380db9c9d48cb in https://inbox.spectrum-os.org/spectrum-devel/20250903-genfiles-v1-2-cc993fcb1e4c@gmail.com/

applying [1/1] https://inbox.spectrum-os.org/spectrum-devel/20250903-genfiles-v1-2-cc993fcb1e4c@gmail.com/
diff --git a/scripts/genfiles.awk b/scripts/genfiles.awk
new file mode 100755
index 0000000000000000000000000000000000000000..62863e78f157f1d9a0f6dbdb0f4380db9c9d48cb

Checking patch scripts/genfiles.awk...
Applied patch scripts/genfiles.awk cleanly.

index at:
100755 62863e78f157f1d9a0f6dbdb0f4380db9c9d48cb	scripts/genfiles.awk

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).