Skip to content

Instantly share code, notes, and snippets.

@epipping
Last active September 10, 2017 16:55
Show Gist options
  • Save epipping/33220afc91b53bad68c94bf5c49cf2de to your computer and use it in GitHub Desktop.
Save epipping/33220afc91b53bad68c94bf5c49cf2de to your computer and use it in GitHub Desktop.
Create a git repository and populate it with XNU sources in a helpful way
#!/usr/bin/env bash
## WARNING: This will operate in the directory in which it is invoked!
## These are meant to be configured
cachedir=$HOME/xnu_cache
orgfile=$HOME/xnu.org
## Can be set here or passed on the command line
platform=${1:-ppc}
old_macOS_minor=
git init --quiet
git commit --quiet --allow-empty --message 'Dummy commit'
gawk -F'|' '{ print $2 " " $3 " " $4 }' ${orgfile} | while read macOS XNU platforms; do
if [[ ${platforms} != *${platform}* ]]; then
continue
fi
echo macOS=${macOS} XNU=${XNU}
macOS_minor_rev=${macOS#10.}
macOS_minor=${macOS_minor_rev%.*}
if [[ ${old_macOS_minor} != ${macOS_minor} ]]; then
if [[ -n ${old_macOS_minor} ]]; then
# Discard the last bogus commit
git reset --quiet --hard 'HEAD~1'
fi
git checkout --quiet -b "macOS-10.${macOS_minor}.x" master
old_macOS_minor=${macOS_minor}
fi
dirname=xnu-${XNU}
tarball=${dirname}.tar.gz
cache_name=${cachedir}/${tarball}
if [[ ! -f ${cache_name} ]]; then
wget --quiet https://opensource.apple.com/tarballs/xnu/${tarball} -P ${cachedir}/
fi
tar --strip-components=1 --exclude='*.save' --exclude='*.rej' --exclude='*.orig' -xf ${cache_name}
date=$(tar -tvf ${cache_name} | grep -v '\.\(save\|rej\|orig\)$' | gawk '
BEGIN {
m["Jan"]=1; m["Feb"]=2; m["Mar"]=3; m["Apr"]=4; m["May"]=5; m["Jun"]=6;
m["Jul"]=7; m["Aug"]=8; m["Sep"]=9; m["Oct"]=10; m["Nov"]=11; m["Dec"]=12;
}
{
time[NR] = sprintf("%d-%02d-%02d", $8, m[$6], $7)
}
END {
asort(time)
print time[NR]
}')
git add .
git commit --quiet --all --amend --allow-empty \
--message "macOS-${macOS}: XNU-${XNU}" \
--author 'Apple <opensource@apple.com>' \
--date="${date}T00:00:00"
git tag macOS-${macOS}
git tag XNU-${XNU}
tar -tf ${cache_name} | grep -v '\.\(save\|rej\|orig\)$' | while read f; do
f=${f#xnu-${XNU}/}
if [[ -f ./"${f}" || -L ./"${f}" ]]; then
rm -f ./"${f}"
fi
done
git commit --quiet --all --message 'Dummy commit'
if [[ $(git ls-files | wc -l) -ne 0 ]]; then
echo WARNING: sanity check failed;
echo these are the files:
git ls-files
fi
done
# Discard the last bogus commit
git reset --quiet --hard 'HEAD~1'
git branch --quiet --delete --force master
#!/usr/bin/env perl
use 5.22.0; # for /n
use strict;
use warnings;
use File::Slurp qw{read_file};;
use List::Util qw{pairs};
my $comment = qr|\ ? \* (?! \/)|x;
foreach my $file (@ARGV) {
my $text = read_file($file);
$text =~ s/
## Starting at the beginning of a line
(?<= \n)
## Empty lines
(
${comment} \ * \n
)*
## Copyright notice(s); optional: sometimes buried in the license body
(
${comment} \ Copyright .* \n
)*
## Empty lines
(
${comment} \ * \n
)*
## Header
${comment} \ @ [a-zA-Z_]* _HEADER_START @ \ * \n
## License body (i.e., lines that no finish the comment)
(
${comment} .* \n
)*
## Footer
${comment} \ @ [a-zA-Z_]* _HEADER_END @ \ * \n
## Empty lines
(
${comment} \ * \n
)*
## Leaving else inside the comment intact, also the closing
//xng;
print $text;
}
#!/usr/bin/env perl
use 5.22.0; # for /n
use strict;
use warnings;
use File::Slurp qw{read_file};;
use List::Util qw{pairs};
my $comment = qr|\. \\ "|x;
foreach my $file (@ARGV) {
my $text = read_file($file);
$text =~ s/
## Starting at the beginning of a line
(?<= \n)
## Empty lines
(
${comment} \ * \n
)*
## Copyright notice(s); optional: sometimes buried in the license body
(
${comment} \ Copyright .* \n
)*
## Empty lines
(
${comment} \ * \n
)*
## Header
${comment} \ @ [a-zA-Z_]* _HEADER_START @ \ * \n
## License body (i.e., lines that no finish the comment)
(
${comment} .* \n
)*
## Footer
${comment} \ @ [a-zA-Z_]* _HEADER_END @ \ * \n
## Empty lines
(
${comment} \ * \n
)*
## Leaving else inside the comment intact, also the closing
//xng;
print $text;
}
#!/usr/bin/env perl
use 5.22.0; # for /n
use strict;
use warnings;
use File::Slurp qw{read_file};;
use List::Util qw{pairs};
my $comment = qr|\#|x;
foreach my $file (@ARGV) {
my $text = read_file($file);
$text =~ s/
## Starting at the beginning of a line
(?<= \n)
## Empty lines
(
${comment} \ * \n
)*
## Copyright notice(s); optional: sometimes buried in the license body
(
${comment} \ Copyright .* \n
)*
## Empty lines
(
${comment} \ * \n
)*
## Header
${comment} \ @ [a-zA-Z_]* _HEADER_START @ \ * \n
## License body (i.e., lines that no finish the comment)
(
${comment} .* \n
)*
## Footer
${comment} \ @ [a-zA-Z_]* _HEADER_END @ \ * \n
## Empty lines
(
${comment} \ * \n
)*
## Leaving else inside the comment intact, also the closing
//xng;
print $text;
}
10.0123.5ppc
10.0.1124.1ppc
10.0.2124.7ppc
10.0.3124.8ppc????
10.0.4124.13ppc
10.1201ppc
10.1.1201.5ppc
10.1.2201.14ppc
10.1.3201.19ppc
10.1.4201.19.3ppc
10.1.5201.42.3ppc
10.2344ppc
10.2.1344.2ppc
10.2.2344.12.2ppc
10.2.3344.23ppc
10.2.4344.26ppc
10.2.5344.32ppc
10.2.6344.34ppc
10.2.8344.49ppc
10.2.7344.21.73g5/powerbook-specific; defective
10.2.8344.21.74g5-specific
10.3517ppc
10.3.1517ppc????
10.3.2517.3.7ppc
10.3.3517.3.15ppc
10.3.4517.7.7ppc
10.3.5517.7.21ppc
10.3.6517.9.4ppc
10.3.7517.9.5ppc
10.3.8517.11.1ppc
10.3.9517.12.7ppc
10.4792ppc
10.4.1792.1.5ppc
10.4.2792.2.4ppc
10.4.3792.6.22ppc
10.4.4792.6.56ppc
10.4.5792.6.61ppc
10.4.6792.6.70ppc
10.4.7792.6.76ppc
10.4.7+792.10.96x86
10.4.8792.13.8x86
10.4.8792.12.6ppc
10.4.9792.17.14ppc
10.4.9792.18.15x86
10.4.10792.21.3ppc
10.4.10792.22.5x86
10.4.11792.24.17ppc
10.4.11792.25.20x86
10.51228x86,ppc
10.5.11228.0.2x86,ppc
10.5.21228.3.13x86,ppc
10.5.31228.5.18x86,ppc
10.5.41228.5.20x86,ppc
10.5.51228.7.58x86,ppc
10.5.61228.9.59x86,ppc
10.5.71228.12.14x86,ppc
10.5.81228.15.4x86,ppc
10.61456.1.26x86
10.6.11456.1.26x86no change?
10.6.21486.2.11x86
10.6.31504.3.12x86
10.6.41504.7.4x86
10.6.51504.9.17x86
10.6.61504.9.26x86
10.6.71504.9.37x86
10.6.81504.15.3x86
10.71699.22.73x86
10.7.11699.22.81x86
10.7.21699.24.8x86
10.7.31699.24.23x86
10.7.41699.26.8x86
10.7.51699.32.7x86
10.82050.7.9x86
10.8.12050.9.2x86
10.8.22050.18.24x86
10.8.32050.22.13x86
10.8.42050.24.15x86
10.8.52050.48.11x86
10.92422.1.72x86
10.9.12422.1.72x86no change?
10.9.22422.90.20x86
10.9.32422.100.13x86
10.9.42422.110.17x86
10.9.52422.115.4x86
10.102782.1.97x86
10.10.12782.1.97x86no change?
10.10.22782.10.72x86
10.10.32782.20.48x86
10.10.42782.30.5x86
10.10.52782.40.9x86
10.113247.1.106x86
10.11.13247.10.11x86
10.11.23248.20.55x86
10.11.33248.30.4x86
10.11.43248.40.184x86
10.11.53248.50.21x86
10.11.63248.60.10x86
10.123789.1.32x86
10.12.13789.21.4x86
10.12.23789.31.2x86
10.12.33789.41.3x86
10.12.43789.51.2x86
10.12.53789.60.24x86
10.12.63789.70.16x86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment