diff options
author | schnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f> | 2008-03-03 21:24:10 +0000 |
---|---|---|
committer | schnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f> | 2008-03-03 21:24:10 +0000 |
commit | 5dc6bf5dbaee733d856efe3a1a19b9dc14341296 (patch) | |
tree | 871d656a9576eeaa663c37aa054775ad585165ed | |
parent | 0120ee1f037154a81bd13e9b7dde775c65fdeb7e (diff) |
Declare the build id etc. as "char const *" instead of "char[]".
Add and commit to the git repository in a perl script instead of
directly in the Makefile.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@164 83718e91-0e4f-0410-abf4-91180603181f
-rw-r--r-- | src/id.cc | 8 | ||||
-rw-r--r-- | src/make.code.deps | 5 | ||||
-rw-r--r-- | src/make.configuration.deps | 12 | ||||
-rwxr-xr-x | src/util/git-commit.pl | 177 |
4 files changed, 194 insertions, 8 deletions
@@ -43,13 +43,13 @@ namespace Formaline // Configuration ID - extern "C" char const config_id[]; + extern "C" char const * const config_id; // Unique source tree ID - extern "C" char const source_id[]; + extern "C" char const * const source_id; // Unique build ID - extern "C" char const build_id[]; + extern "C" char const * const build_id; @@ -131,7 +131,7 @@ namespace Formaline ostringstream run_idbuf; run_idbuf << "run-"; - char cparfilename [10000]; + char cparfilename [1000]; CCTK_ParameterFilename (sizeof cparfilename, cparfilename); string parfilename (cparfilename); size_t const last_slash = parfilename.rfind ('/'); diff --git a/src/make.code.deps b/src/make.code.deps index 424c242..7f48ec8 100644 --- a/src/make.code.deps +++ b/src/make.code.deps @@ -8,7 +8,7 @@ TARBALL_DIR = $(SCRATCH_BUILD) -$(CCTK_TARGET): $(TARBALL_DIR)/gethostname.pl $(TARBALL_DIR)/makeblob.pl $(TARBALL_DIR)/makemetablob.pl +$(CCTK_TARGET): $(TARBALL_DIR)/gethostname.pl $(TARBALL_DIR)/makeblob.pl $(TARBALL_DIR)/makemetablob.pl $(TARBALL_DIR)/git-commit.pl @@ -20,3 +20,6 @@ $(TARBALL_DIR)/makeblob.pl: $(SRCDIR)/util/makeblob.pl $(TARBALL_DIR)/makemetablob.pl: $(SRCDIR)/util/makemetablob.pl cd $(TARBALL_DIR) && cp $^ $@ + +$(TARBALL_DIR)/git-commit.pl: $(SRCDIR)/util/git-commit.pl + cd $(TARBALL_DIR) && cp $^ $@ diff --git a/src/make.configuration.deps b/src/make.configuration.deps index 83c3ac9..d55d6a8 100644 --- a/src/make.configuration.deps +++ b/src/make.configuration.deps @@ -81,11 +81,11 @@ $(TARBALL_DIR)/build-id.c: $(TOP)/BUILD-ID $(TOP)/GIT-COMMIT-ID { \ echo '/* This is an auto-generated file -- do not edit */' && \ build_id="$$(cat $(TOP)/BUILD-ID)" && \ - echo 'char const build_id[] = "'$$build_id'";' && \ + echo 'char const * const build_id = "'$$build_id'";' && \ git_commit_id="$$(cat $(TOP)/GIT-COMMIT-ID || echo 'NO-GIT-ID')" && \ - echo 'char const source_id[] = "git-'$$git_commit_id'";' && \ + echo 'char const * const source_id = "git-'$$git_commit_id'";' && \ config_id="$$(cat $(TOP)/CONFIG-ID || echo 'NO-CONFIG-ID')" && \ - echo 'char const config_id[] = "'$$config_id'";'; \ + echo 'char const * const config_id = "'$$config_id'";'; \ } > $@ @@ -266,6 +266,12 @@ ifeq ($(HAVE-GIT),true) .PRECIOUS: $(TOP)/GIT-COMMIT-ID $(TOP)/GIT-COMMIT-ID: $(TOP)/BUILD-ID $(TARBALL_DIR)/cactus-flesh-source.files $(patsubst %,$(TARBALL_DIR)/cactus-thorn-source-%.files,$(notdir $(THORNS))) + $(TARBALL_DIR)/git-commit.pl --git='$(GIT)' --git-repo='$(GIT-REPO)' \ + --CCTK_HOME='$(CCTK_HOME)' --TOP='$(TOP)' \ + --TARBALL_DIR='$(TARBALL_DIR)' \ + $(notdir $(THORNS)) + +unused-$(TOP)/GIT-COMMIT-ID: $(TOP)/BUILD-ID $(TARBALL_DIR)/cactus-flesh-source.files $(patsubst %,$(TARBALL_DIR)/cactus-thorn-source-%.files,$(notdir $(THORNS))) cd $(GIT-REPO) && \ true "Ensure that the git repository exists" && \ if ! test -e $(GIT-DIR) -a -e $(GIT-DIR)/HEAD; then \ diff --git a/src/util/git-commit.pl b/src/util/git-commit.pl new file mode 100755 index 0000000..d28e023 --- /dev/null +++ b/src/util/git-commit.pl @@ -0,0 +1,177 @@ +#! /usr/bin/perl -w + +# Commit the current source tree to a git repository + +# 2008-03-02 Erik Schnetter <schnetter@cct.lsu.edu> + +use strict; +#use Fcntl ':flock'; +use Getopt::Long; + +# $(GIT-REPO) +# $(CCTK-HOME) +# $(CONFIG-DIR) +# $(SCRATCH-DIR) + +my %options; +GetOptions + (\%options, + 'git=s', # git command + 'git-repo=s', # git repository + 'CCTK_HOME=s', # main Cactus directory + 'TOP=s', # main directory of the configuration + 'TARBALL_DIR=s', # Formaline's directory + ) or die "Could not parse command line options"; + +my $git = $options{'git'}; +my $git_repo = $options{'git-repo'}; +my $cctk_home = $options{'CCTK_HOME'}; +my $config_dir = $options{'TOP'}; +my $tarball_dir = $options{'TARBALL_DIR'}; + +defined $git or die; +defined $git_repo or die; +defined $cctk_home or die; +defined $config_dir or die; +defined $tarball_dir or die; + +chdir $git_repo or die; + +# Use relative path names +$config_dir =~ m+/configs/+; +$config_dir = "configs/$'"; + +my $config_id_file = "$config_dir/CONFIG-ID"; +my $build_id_file = "$config_dir/BUILD-ID"; +my $commit_id_file = "$config_dir/GIT-COMMIT-ID"; + +my @thorns = @ARGV; + + + +# Obtain exclusive access to the repository + +# We cannot use flock since the file system may be remote +#open LOCKFILE, "$cctk_home/Makefile"; +#flock LOCKFILE, LOCK_EX; + +my $gitlock = "$cctk_home/GITLOCK"; +my $waittime = 1; +my $maxwaittime = 30; +while (! (mkdir $gitlock)) { + # Check whether the locking process still exists + my $pid = `cat $gitlock/PID`; + chomp $pid; + if ($pid ne '') { + system "ps $pid > /dev/null 2>&1"; + if ($?) { + # Break the lock + print "Git repository seems free -- breaking the lock\n"; + unlink "$gitlock/PID" or die; + rmdir "$gitlock" or die; + $waittime = 1; + next; + } + } + # Wait some time + my $unit = $waittime==1 ? "second" : "seconds"; + print "Git repository is busy; waiting $waittime $unit...\n"; + system "sleep $waittime"; + # Back off exponentially + $waittime *= 2; + $waittime = $maxwaittime if $waittime > $maxwaittime; +} +# Ensure that the lock exists +die unless -d $gitlock; +# Add our PID +open PID, '>', "$gitlock/PID.tmp" or die; +print PID "$$\n"; +close PID; +rename "$gitlock/PID.tmp", "$gitlock/PID" or die; +# Check whether it is really our PID +my $pid = `cat $gitlock/PID`; +chomp $pid; +die unless $pid == $$; + + + +# Ensure that the git repository exists +if (! -e "$git_repo/.git/HEAD") { + print "Formaline: Creating new git repository...\n"; + system "$git init"; $? and die; + # Add a root commit to please some tools + system ": >> README"; $? and die; + system "$git add README"; $? and die; + system "$git commit -m 'README'"; $? and die; +} + +# Remove all staged files +print "Formaline: Preparing git repository...\n"; +system "$git rm --cached -r . > /dev/null 2>&1"; # may fail + +# Add flesh files to repository +print "Formaline: Adding flesh to git repository...\n"; +system "xargs ls < $tarball_dir/cactus-flesh-source.files > $tarball_dir/cactus-flesh-source.files.tmp 2> /dev/null"; $? and die; +system "xargs $git add < $tarball_dir/cactus-flesh-source.files.tmp"; $? and die; +unlink "$tarball_dir/cactus-flesh-source.files.tmp" or die; + +# Add thorn files to repository +foreach my $thorn (@thorns) { + print "Formaline: Adding thorn $thorn to git repository...\n"; + system "xargs ls < $tarball_dir/cactus-thorn-source-$thorn.files > $tarball_dir/cactus-thorn-source-$thorn.files.tmp 2> /dev/null"; $? and die; + system "xargs $git add < $tarball_dir/cactus-thorn-source-$thorn.files.tmp"; $? and die; + unlink "$tarball_dir/cactus-thorn-source-$thorn.files.tmp" or die; +} + +# Write source tree and create a commit +print "Formaline: Committing source tree to git repository...\n"; +system "$git add $config_id_file $build_id_file"; $? and die; +my $tree_id_file = "$tarball_dir/GIT-TREE-ID"; +system "$git write-tree > $tree_id_file"; $? and die; +my $tree_id = `cat $tree_id_file`; +chomp $tree_id; + +# Try to use the previous commit as parent, if possible +my $old_commit_id; +if (-e $commit_id_file) { + $old_commit_id = `cat $commit_id_file`; + chomp $old_commit_id; +} + +# (Use the build id as commit message) +my $did_commit = 0; +if (defined $old_commit_id && $old_commit_id ne '') { + system "$git commit-tree $tree_id -p $old_commit_id < $build_id_file > $commit_id_file.new"; + $did_commit = $? == 0; +} +if (! $did_commit) { + system "$git commit-tree $tree_id < $build_id_file > $commit_id_file.new"; $? and die; +} +rename "$commit_id_file.new", "$commit_id_file" or die; +my $commit_id = `cat $commit_id_file`; +chomp $commit_id; +print "Formaline: Git commit id is $commit_id\n"; + +# Remember the commit id +mkdir "$cctk_home/GIT-COMMIT-IDS"; +system "cp $commit_id_file $cctk_home/GIT-COMMIT-IDS/$commit_id"; $? and die; + +# Update branch +my $config_id = `cat $config_id_file`; +chomp $config_id; +die unless defined $config_id && $config_id ne ''; +system "$git branch -f $config_id $commit_id"; $? and die; + +print "Formaline: Cleaning up git repository...\n"; +system "$git rm --cached -r . > /dev/null 2>&1"; # may fail + +# Call git-gc for good measure +print "Formaline: Optimising git repository (slow only the first time)...\n"; +system "$git gc > /dev/null 2>&1"; $? and die; + + + +# Release the lock +system "rm -rf $gitlock"; + +print "Formaline: Done.\n"; |