xref: /freebsd/tools/build/freebsd-yeet.pl (revision b376ef36f569c85cbd135349b6e8b9737bba5d2a)
1*b376ef36SWarner Losh#!/usr/local/bin/perl
2*b376ef36SWarner Losh#
33b6b4765SWarner Losh# Remove almost all of the $ FreeBSD $ tags in the tree.
43b6b4765SWarner Losh#
53b6b4765SWarner Losh# Copyright (c) 2023, Warner Losh
63b6b4765SWarner Losh# SPDX-License-Identifier: BSD-2-Clause
73b6b4765SWarner Losh#
83b6b4765SWarner Losh# Needs p5-File-Lib package
93b6b4765SWarner Losh# Caveat Emptor
103b6b4765SWarner Losh#
113b6b4765SWarner Loshuse strict;
123b6b4765SWarner Loshuse warnings;
133b6b4765SWarner Loshuse File::Find;
143b6b4765SWarner Losh
153b6b4765SWarner Loshsub skip_list
163b6b4765SWarner Losh{
173b6b4765SWarner Losh    my $fn = $_[0];
183b6b4765SWarner Losh
193b6b4765SWarner Losh    if ($fn =~ m=^./contrib/=) {
203b6b4765SWarner Losh	return 1;
213b6b4765SWarner Losh    }
223b6b4765SWarner Losh    if ($fn =~ m=^./sys/contrib/=) {
233b6b4765SWarner Losh	return 1;
243b6b4765SWarner Losh    }
253b6b4765SWarner Losh    if ($fn =~ m=^./cddl/contrib/=) {
263b6b4765SWarner Losh	return 1;
273b6b4765SWarner Losh    }
283b6b4765SWarner Losh    if ($fn =~ m=^./crypto/=) {
293b6b4765SWarner Losh	return 1;
303b6b4765SWarner Losh    }
313b6b4765SWarner Losh    if ($fn =~ m=^./.git/=) {
323b6b4765SWarner Losh	return 1;
333b6b4765SWarner Losh    }
343b6b4765SWarner Losh    if ($fn =~ m=~$=) {
353b6b4765SWarner Losh	return 1;
363b6b4765SWarner Losh    }
373b6b4765SWarner Losh    return 0;
383b6b4765SWarner Losh}
393b6b4765SWarner Losh
403b6b4765SWarner Loshmy $pretty;
413b6b4765SWarner Loshmy $pattern;
423b6b4765SWarner Loshmy $repl;
433b6b4765SWarner Loshmy $count;
44*b376ef36SWarner Loshmy $syshash;
45*b376ef36SWarner Loshmy $hash;
463b6b4765SWarner Losh
473b6b4765SWarner Loshsub do_one
483b6b4765SWarner Losh{
493b6b4765SWarner Losh    $pretty = $_[0];
503b6b4765SWarner Losh    $pattern = $_[1];
513b6b4765SWarner Losh    $repl = "";
52*b376ef36SWarner Losh    $repl = $_[2];
53*b376ef36SWarner Losh    $syshash = $_[3];
54*b376ef36SWarner Losh    $hash = $_[4];
553b6b4765SWarner Losh    $count = 0;
563b6b4765SWarner Losh
573b6b4765SWarner Losh    sub findfiles
583b6b4765SWarner Losh    {
593b6b4765SWarner Losh	return unless -f;
603b6b4765SWarner Losh	my $fn="$File::Find::name";
613b6b4765SWarner Losh	return if skip_list($fn);
623b6b4765SWarner Losh	open my $fh, '<', $_ or die "Can't open $fn: $!\n";
633b6b4765SWarner Losh	local $/;
643b6b4765SWarner Losh	my $file = <$fh>;
653b6b4765SWarner Losh	close $fh;
663b6b4765SWarner Losh	my $len = length($file);
673b6b4765SWarner Losh
683b6b4765SWarner Losh	$file =~ s=$pattern=$repl=gm;
693b6b4765SWarner Losh	my $len2 = length($file);
703b6b4765SWarner Losh	return if $len2 == $len;
713b6b4765SWarner Losh	print "$pretty: $fn\n";
723b6b4765SWarner Losh	open my $fhw, '>', $_ or die "Can't write $fn: $!\n";
733b6b4765SWarner Losh	print $fhw $file;
743b6b4765SWarner Losh	close $fhw;
753b6b4765SWarner Losh	$count++;
763b6b4765SWarner Losh    }
773b6b4765SWarner Losh
783b6b4765SWarner Losh    $count = 0;
793b6b4765SWarner Losh    find({ wanted => \&findfiles, }, './sys');
803b6b4765SWarner Losh    if ($count > 0) {
813b6b4765SWarner Losh	print "Changed $pretty\n";
82*b376ef36SWarner Losh	system("git commit -a -m'sys: Remove \$FreeBSD\$: $pretty\n\nRemove /$pattern/\n\nSimilar commit in current:\n(cherry picked from commit $syshash)'");
833b6b4765SWarner Losh    }
843b6b4765SWarner Losh    $count = 0;
853b6b4765SWarner Losh    find({ wanted => \&findfiles, }, '.');
863b6b4765SWarner Losh    if ($count > 0) {
873b6b4765SWarner Losh	print "Changed $pretty\n";
88*b376ef36SWarner Losh	system("git commit -a -m'Remove \$FreeBSD\$: $pretty\n\nRemove /$pattern/\n\nSimilar commit in main:\n(cherry picked from commit $hash)'");
893b6b4765SWarner Losh    }
903b6b4765SWarner Losh}
913b6b4765SWarner Losh
92*b376ef36SWarner Losh# These are the commits to head
93*b376ef36SWarner Losh# 9524e274b548 Remove $FreeBSD$: one-line xdr pattern
94*b376ef36SWarner Losh# 26a58599a09a Remove $FreeBSD$: one-line forth tag
95*b376ef36SWarner Losh# 401ab69cff8f Remove $FreeBSD$: one-line ps tag
96*b376ef36SWarner Losh# 6ef644f5889a Remove $FreeBSD$: one-line lua tag
97*b376ef36SWarner Losh# 9636a14538f5 Remove $FreeBSD$: two-line lua tag
98*b376ef36SWarner Losh# 8c99d94c900f sys: Remove $FreeBSD$: two-line lua tag
99*b376ef36SWarner Losh# ae992a336e8d Remove $FreeBSD$: one-line catalog
100*b376ef36SWarner Losh# 2063df147163 sys: Remove $FreeBSD$: one-line catalog
101*b376ef36SWarner Losh# 05248206f720 Remove $FreeBSD$: one-line bare tag
102*b376ef36SWarner Losh# 78d146160dc5 sys: Remove $FreeBSD$: one-line bare tag
103*b376ef36SWarner Losh# b2c76c41be32 Remove $FreeBSD$: one-line nroff pattern
104*b376ef36SWarner Losh# fa9896e082a1 Remove $FreeBSD$: two-line nroff pattern
105*b376ef36SWarner Losh# 9e7892125655 sys: Remove $FreeBSD$: two-line nroff pattern
106*b376ef36SWarner Losh# d0b2dbfa0ecf Remove $FreeBSD$: one-line sh pattern
107*b376ef36SWarner Losh# 031beb4e239b sys: Remove $FreeBSD$: one-line sh pattern
108*b376ef36SWarner Losh# b1cfcffa89e6 Remove $FreeBSD$: one-line .S pattern
109*b376ef36SWarner Losh# d4bf8003ee42 sys: Remove $FreeBSD$: one-line .S pattern
110*b376ef36SWarner Losh# c8573564095b Remove $FreeBSD$: alt one-line .c pattern
111*b376ef36SWarner Losh# da5432eda807 Remove $FreeBSD$: alt two-line .c pattern
112*b376ef36SWarner Losh# 1d386b48a555 Remove $FreeBSD$: one-line .c pattern
113*b376ef36SWarner Losh# 685dc743dc3b sys: Remove $FreeBSD$: one-line .c pattern
114*b376ef36SWarner Losh# e5d258c9e599 Remove $FreeBSD$: two-line .c pattern
115*b376ef36SWarner Losh# dfc016587a1e sys: Remove $FreeBSD$: two-line .c pattern
116*b376ef36SWarner Losh# 2a63c3be1582 Remove $FreeBSD$: one-line .c comment pattern
117*b376ef36SWarner Losh# 71625ec9ad2a sys: Remove $FreeBSD$: one-line .c comment pattern
118*b376ef36SWarner Losh# 42b388439bd3 Remove $FreeBSD$: one-line .h pattern
119*b376ef36SWarner Losh# 2ff63af9b88c sys: Remove $FreeBSD$: one-line .h pattern
120*b376ef36SWarner Losh# b3e7694832e8 Remove $FreeBSD$: two-line .h pattern
121*b376ef36SWarner Losh# 95ee2897e98f sys: Remove $FreeBSD$: two-line .h pattern
122*b376ef36SWarner Losh# d54a7d337331 Remove $FreeBSD$: one-line m4 tag
123*b376ef36SWarner Losh# 82a265ad9bad sys: Remove $FreeBSD$: sound driver version
124*b376ef36SWarner Losh
1253b6b4765SWarner Losh# Note: Do two line before one line
126*b376ef36SWarner Losh#	commit message			pattern					replacement or ''		sys hash	src hash
127*b376ef36SWarner Loshdo_one("sound driver version",		'SND_DECLARE_FILE\("\$FreeBSD\$"\);',	'SND_DECLARE_FILE("");',	'',		'82a265ad9bad');
128*b376ef36SWarner Loshdo_one("one-line m4 tag",		'^dnl\s*\$FreeBSD\$.*$\n',		'',				'',		'd54a7d337331');
129*b376ef36SWarner Loshdo_one("two-line .h pattern",		'^\s*\*\n \*\s+\$FreeBSD\$$\n',		'',				'95ee2897e98f',	'b3e7694832e8');
130*b376ef36SWarner Loshdo_one("one-line .h pattern",		'^\s*\*+\s*\$FreeBSD\$.*$\n',		'',				'2ff63af9b88c',	'42b388439bd3');
131*b376ef36SWarner Loshdo_one("one-line .c comment pattern",	'^/[*/]\s*\$FreeBSD\$.*\n',		'',				'71625ec9ad2a',	'2a63c3be1582');
132*b376ef36SWarner Loshdo_one("two-line .c pattern",		'^#include\s+<sys/cdefs.h>.*$\n\s+__FBSDID\("\$FreeBSD\$"\);\n','',	'dfc016587a1e',	'e5d258c9e599');
133*b376ef36SWarner Loshdo_one("one-line .c pattern",		'^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n', '',				'685dc743dc3b',	'1d386b48a555');
134*b376ef36SWarner Loshdo_one("alt two-line .c pattern",	'^\s*__RCSID\("\$FreeBSD\$"\);\n\n',	'',				'',		'da5432eda807');
135*b376ef36SWarner Loshdo_one("alt one-line .c pattern",	'^\s*__RCSID\("\$FreeBSD\$"\);\n',	'',				'',		'c8573564095b');
136*b376ef36SWarner Loshdo_one("one-line .S pattern",		'^\s\.(asciz|ident)\s+\"\$FreeBSD\$\".*\n', '',				'd4bf8003ee42',	'b1cfcffa89e6');
137*b376ef36SWarner Loshdo_one("one-line sh pattern",		'^\s*#[#!]?\s*\$FreeBSD\$.*$\n',	'',				'031beb4e239b',	'd0b2dbfa0ecf');
138*b376ef36SWarner Loshdo_one("two-line nroff pattern",	'^\.\\\\"\n\.\\\\"\s*\$FreeBSD\$$\n',	'',				'9e7892125655',	'fa9896e082a1');
139*b376ef36SWarner Loshdo_one("one-line nroff pattern",	'^\.\\\\"\s*\$FreeBSD\$$\n',		'',				'',		'b2c76c41be32');
140*b376ef36SWarner Loshdo_one("one-line bare tag",		'^\s*\$FreeBSD\$$\n',			'',				'78d146160dc5',	'05248206f720');
141*b376ef36SWarner Loshdo_one("one-line catalog",		'^\s*\$\s*\$FreeBSD\$$\n',		'',				'2063df147163',	'ae992a336e8d');
142*b376ef36SWarner Loshdo_one("two-line lua tag",		'^--\n--\s*\$FreeBSD\$.*$\n',		'',				'8c99d94c900f',	'9636a14538f5');
143*b376ef36SWarner Loshdo_one("one-line lua tag",		'^--\s*\$FreeBSD\$.*$\n',		'',				'',		'6ef644f5889a');
144*b376ef36SWarner Loshdo_one("one-line ps tag",		'^%\s*RCSID:\s*\$FreeBSD\$.*$\n',	'',				'',		'401ab69cff8f');
145*b376ef36SWarner Loshdo_one("one-line forth tag",		'^\\\\[\s*]*\$FreeBSD\$.*$\n',		'',				'',		'26a58599a09a');
146*b376ef36SWarner Loshdo_one("one-line xdr pattern",		'^\s*%\s*__FBSDID\("\$FreeBSD\$"\);?\s*\n', '',				'',		'9524e274b548');
1473b6b4765SWarner Loshexit;
148