xref: /freebsd/tools/build/freebsd-yeet.pl (revision 1719886f6d08408b834d270c59ffcfd821c8f63a)
1#!/usr/local/bin/perl
2#
3# Remove almost all of the $ FreeBSD $ tags in the tree.
4#
5# Copyright (c) 2023, Warner Losh
6# SPDX-License-Identifier: BSD-2-Clause
7#
8# Needs p5-File-Lib package
9# Caveat Emptor
10#
11use strict;
12use warnings;
13use File::Find;
14
15sub skip_list
16{
17    my $fn = $_[0];
18
19    if ($fn =~ m=^./contrib/=) {
20	return 1;
21    }
22    if ($fn =~ m=^./sys/contrib/=) {
23	return 1;
24    }
25    if ($fn =~ m=^./cddl/contrib/=) {
26	return 1;
27    }
28    if ($fn =~ m=^./crypto/=) {
29	return 1;
30    }
31    if ($fn =~ m=^./.git/=) {
32	return 1;
33    }
34    if ($fn =~ m=~$=) {
35	return 1;
36    }
37    return 0;
38}
39
40my $pretty;
41my $pattern;
42my $repl;
43my $count;
44my $syshash;
45my $hash;
46
47sub do_one
48{
49    $pretty = $_[0];
50    $pattern = $_[1];
51    $repl = "";
52    $repl = $_[2];
53    $syshash = $_[3];
54    $hash = $_[4];
55    $count = 0;
56
57    sub findfiles
58    {
59	return unless -f;
60	my $fn="$File::Find::name";
61	return if skip_list($fn);
62	open my $fh, '<', $_ or die "Can't open $fn: $!\n";
63	local $/;
64	my $file = <$fh>;
65	close $fh;
66	my $len = length($file);
67
68	$file =~ s=$pattern=$repl=gm;
69	my $len2 = length($file);
70	return if $len2 == $len;
71	print "$pretty: $fn\n";
72	open my $fhw, '>', $_ or die "Can't write $fn: $!\n";
73	print $fhw $file;
74	close $fhw;
75	$count++;
76    }
77
78    $count = 0;
79    find({ wanted => \&findfiles, }, './sys');
80    if ($count > 0) {
81	print "Changed $pretty\n";
82	system("git commit -a -m'sys: Remove \$FreeBSD\$: $pretty\n\nRemove /$pattern/\n\nSimilar commit in current:\n(cherry picked from commit $syshash)'");
83    }
84    $count = 0;
85    find({ wanted => \&findfiles, }, '.');
86    if ($count > 0) {
87	print "Changed $pretty\n";
88	system("git commit -a -m'Remove \$FreeBSD\$: $pretty\n\nRemove /$pattern/\n\nSimilar commit in main:\n(cherry picked from commit $hash)'");
89    }
90}
91
92# These are the commits to head
93# 9524e274b548 Remove $FreeBSD$: one-line xdr pattern
94# 26a58599a09a Remove $FreeBSD$: one-line forth tag
95# 401ab69cff8f Remove $FreeBSD$: one-line ps tag
96# 6ef644f5889a Remove $FreeBSD$: one-line lua tag
97# 9636a14538f5 Remove $FreeBSD$: two-line lua tag
98# 8c99d94c900f sys: Remove $FreeBSD$: two-line lua tag
99# ae992a336e8d Remove $FreeBSD$: one-line catalog
100# 2063df147163 sys: Remove $FreeBSD$: one-line catalog
101# 05248206f720 Remove $FreeBSD$: one-line bare tag
102# 78d146160dc5 sys: Remove $FreeBSD$: one-line bare tag
103# b2c76c41be32 Remove $FreeBSD$: one-line nroff pattern
104# fa9896e082a1 Remove $FreeBSD$: two-line nroff pattern
105# 9e7892125655 sys: Remove $FreeBSD$: two-line nroff pattern
106# d0b2dbfa0ecf Remove $FreeBSD$: one-line sh pattern
107# 031beb4e239b sys: Remove $FreeBSD$: one-line sh pattern
108# b1cfcffa89e6 Remove $FreeBSD$: one-line .S pattern
109# d4bf8003ee42 sys: Remove $FreeBSD$: one-line .S pattern
110# c8573564095b Remove $FreeBSD$: alt one-line .c pattern
111# da5432eda807 Remove $FreeBSD$: alt two-line .c pattern
112# 1d386b48a555 Remove $FreeBSD$: one-line .c pattern
113# 685dc743dc3b sys: Remove $FreeBSD$: one-line .c pattern
114# e5d258c9e599 Remove $FreeBSD$: two-line .c pattern
115# dfc016587a1e sys: Remove $FreeBSD$: two-line .c pattern
116# 2a63c3be1582 Remove $FreeBSD$: one-line .c comment pattern
117# 71625ec9ad2a sys: Remove $FreeBSD$: one-line .c comment pattern
118# 42b388439bd3 Remove $FreeBSD$: one-line .h pattern
119# 2ff63af9b88c sys: Remove $FreeBSD$: one-line .h pattern
120# b3e7694832e8 Remove $FreeBSD$: two-line .h pattern
121# 95ee2897e98f sys: Remove $FreeBSD$: two-line .h pattern
122# d54a7d337331 Remove $FreeBSD$: one-line m4 tag
123# 82a265ad9bad sys: Remove $FreeBSD$: sound driver version
124
125# Note: Do two line before one line
126#	commit message			pattern					replacement or ''		sys hash	src hash
127do_one("sound driver version",		'SND_DECLARE_FILE\("\$FreeBSD\$"\);',	'SND_DECLARE_FILE("");',	'',		'82a265ad9bad');
128do_one("one-line m4 tag",		'^dnl\s*\$FreeBSD\$.*$\n',		'',				'',		'd54a7d337331');
129do_one("two-line .h pattern",		'^\s*\*\n \*\s+\$FreeBSD\$$\n',		'',				'95ee2897e98f',	'b3e7694832e8');
130do_one("one-line .h pattern",		'^\s*\*+\s*\$FreeBSD\$.*$\n',		'',				'2ff63af9b88c',	'42b388439bd3');
131do_one("one-line .c comment pattern",	'^/[*/]\s*\$FreeBSD\$.*\n',		'',				'71625ec9ad2a',	'2a63c3be1582');
132do_one("two-line .c pattern",		'^#include\s+<sys/cdefs.h>.*$\n\s+__FBSDID\("\$FreeBSD\$"\);\n','',	'dfc016587a1e',	'e5d258c9e599');
133do_one("one-line .c pattern",		'^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n', '',				'685dc743dc3b',	'1d386b48a555');
134do_one("alt two-line .c pattern",	'^\s*__RCSID\("\$FreeBSD\$"\);\n\n',	'',				'',		'da5432eda807');
135do_one("alt one-line .c pattern",	'^\s*__RCSID\("\$FreeBSD\$"\);\n',	'',				'',		'c8573564095b');
136do_one("one-line .S pattern",		'^\s\.(asciz|ident)\s+\"\$FreeBSD\$\".*\n', '',				'd4bf8003ee42',	'b1cfcffa89e6');
137do_one("one-line sh pattern",		'^\s*#[#!]?\s*\$FreeBSD\$.*$\n',	'',				'031beb4e239b',	'd0b2dbfa0ecf');
138do_one("two-line nroff pattern",	'^\.\\\\"\n\.\\\\"\s*\$FreeBSD\$$\n',	'',				'9e7892125655',	'fa9896e082a1');
139do_one("one-line nroff pattern",	'^\.\\\\"\s*\$FreeBSD\$$\n',		'',				'',		'b2c76c41be32');
140do_one("one-line bare tag",		'^\s*\$FreeBSD\$$\n',			'',				'78d146160dc5',	'05248206f720');
141do_one("one-line catalog",		'^\s*\$\s*\$FreeBSD\$$\n',		'',				'2063df147163',	'ae992a336e8d');
142do_one("two-line lua tag",		'^--\n--\s*\$FreeBSD\$.*$\n',		'',				'8c99d94c900f',	'9636a14538f5');
143do_one("one-line lua tag",		'^--\s*\$FreeBSD\$.*$\n',		'',				'',		'6ef644f5889a');
144do_one("one-line ps tag",		'^%\s*RCSID:\s*\$FreeBSD\$.*$\n',	'',				'',		'401ab69cff8f');
145do_one("one-line forth tag",		'^\\\\[\s*]*\$FreeBSD\$.*$\n',		'',				'',		'26a58599a09a');
146do_one("one-line xdr pattern",		'^\s*%\s*__FBSDID\("\$FreeBSD\$"\);?\s*\n', '',				'',		'9524e274b548');
147exit;
148