roll our own 'git rev-parse --short HEAD'
This commit is contained in:
parent
b1da05dbe0
commit
21a09f23d4
|
@ -14,6 +14,7 @@
|
||||||
<property name="jni.define.name" value="SIGAR"/>
|
<property name="jni.define.name" value="SIGAR"/>
|
||||||
<property name="sigar-bin" location="sigar-bin"/>
|
<property name="sigar-bin" location="sigar-bin"/>
|
||||||
<property name="sigar-bin-dir" location="${sigar-bin}"/>
|
<property name="sigar-bin-dir" location="${sigar-bin}"/>
|
||||||
|
<property name="jni.git" location="../../.git"/>
|
||||||
<property name="jni.bin" location="${sigar-bin}"/>
|
<property name="jni.bin" location="${sigar-bin}"/>
|
||||||
<property name="jni.source.dir" location="../.."/>
|
<property name="jni.source.dir" location="../.."/>
|
||||||
<property name="jni.src.java" value="hyperic_jni/src"/>
|
<property name="jni.src.java" value="hyperic_jni/src"/>
|
||||||
|
@ -116,7 +117,7 @@
|
||||||
<replace file="${version.tofile}">
|
<replace file="${version.tofile}">
|
||||||
<replacefilter token="@@BUILD_DATE@@" value="${BUILD_DATE}"/>
|
<replacefilter token="@@BUILD_DATE@@" value="${BUILD_DATE}"/>
|
||||||
<replacefilter token="@@VERSION_STRING@@" value="${sigar.version}.${version.build}"/>
|
<replacefilter token="@@VERSION_STRING@@" value="${sigar.version}.${version.build}"/>
|
||||||
<replacefilter token="@@SCM_REVISION@@" value="${sigar.scmrev}"/>
|
<replacefilter token="@@SCM_REVISION@@" value="${jni.scmrev}"/>
|
||||||
<replacefilter token="@@ARCHNAME@@" value="${jni.libarch}"/>
|
<replacefilter token="@@ARCHNAME@@" value="${jni.libarch}"/>
|
||||||
<replacefilter token="@@ARCHLIB@@" value="${jni.libname.full}"/>
|
<replacefilter token="@@ARCHLIB@@" value="${jni.libname.full}"/>
|
||||||
<replacefilter token="@@BINNAME@@" value="${jni.project.archname}"/>
|
<replacefilter token="@@BINNAME@@" value="${jni.project.archname}"/>
|
||||||
|
@ -128,59 +129,12 @@
|
||||||
</replace>
|
</replace>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="check-svn">
|
<target name="sigar-version">
|
||||||
<condition property="svn.available">
|
|
||||||
<and>
|
|
||||||
<available file=".svn" type="dir"/>
|
|
||||||
<available file="svn" type="file">
|
|
||||||
<filepath>
|
|
||||||
<pathelement path="${env.PATH}"/>
|
|
||||||
</filepath>
|
|
||||||
</available>
|
|
||||||
</and>
|
|
||||||
</condition>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="svn-revision" if="svn.available">
|
|
||||||
<exec executable="svnversion" dir="."
|
|
||||||
outputproperty="sigar.scmrev"
|
|
||||||
failifexecutionfails="false">
|
|
||||||
<arg value="."/>
|
|
||||||
</exec>
|
|
||||||
<echo message="SIGAR svn revision #${sigar.scmrev}"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="check-git">
|
|
||||||
<condition property="git.available">
|
|
||||||
<and>
|
|
||||||
<available file="../../.git" type="dir"/>
|
|
||||||
<available file="git" type="file">
|
|
||||||
<filepath>
|
|
||||||
<pathelement path="${env.PATH}"/>
|
|
||||||
</filepath>
|
|
||||||
</available>
|
|
||||||
</and>
|
|
||||||
</condition>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="git-revision" if="git.available">
|
|
||||||
<exec executable="git" dir="."
|
|
||||||
outputproperty="sigar.scmrev"
|
|
||||||
failifexecutionfails="false">
|
|
||||||
<arg value="rev-parse"/>
|
|
||||||
<arg value="--short"/>
|
|
||||||
<arg value="HEAD"/>
|
|
||||||
</exec>
|
|
||||||
<echo message="SIGAR git revision #${sigar.scmrev}"/>
|
|
||||||
</target>
|
|
||||||
|
|
||||||
<target name="sigar-version" depends="check-svn,svn-revision,check-git,git-revision">
|
|
||||||
<tstamp>
|
<tstamp>
|
||||||
<format property="BUILD_DATE" pattern="MM/dd/yyyy hh:mm aa"/>
|
<format property="BUILD_DATE" pattern="MM/dd/yyyy hh:mm aa"/>
|
||||||
</tstamp>
|
</tstamp>
|
||||||
|
|
||||||
<!-- in the case of release source builds -->
|
<echo message="SIGAR git revision ${jni.scmrev}"/>
|
||||||
<property name="sigar.scmrev" value="exported"/>
|
|
||||||
|
|
||||||
<antcall target="version-file">
|
<antcall target="version-file">
|
||||||
<param name="version.file"
|
<param name="version.file"
|
||||||
|
|
|
@ -18,8 +18,11 @@
|
||||||
|
|
||||||
package org.hyperic.jni;
|
package org.hyperic.jni;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.Reader;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.apache.tools.ant.Task;
|
import org.apache.tools.ant.Task;
|
||||||
|
@ -134,5 +137,50 @@ public class ArchNameTask extends Task {
|
||||||
System.out.println("Using -mmacosx-version-min=" + min);
|
System.out.println("Using -mmacosx-version-min=" + min);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
getProject().setProperty("jni.scmrev", getSourceRevision());
|
||||||
|
}
|
||||||
|
|
||||||
|
//XXX source rev stuff should be in another task
|
||||||
|
private String readLine(String filename) {
|
||||||
|
Reader reader = null;
|
||||||
|
try {
|
||||||
|
reader = new FileReader(filename);
|
||||||
|
return new BufferedReader(reader).readLine();
|
||||||
|
} catch (Exception e) {
|
||||||
|
} finally {
|
||||||
|
if (reader != null) {
|
||||||
|
try { reader.close(); } catch (Exception e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSourceRevision() {
|
||||||
|
final String exported = "exported";
|
||||||
|
String sha1 = getGitSourceRevision();
|
||||||
|
if (sha1 == null) {
|
||||||
|
return exported;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return sha1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//same as: git rev-parse --short HEAD
|
||||||
|
//same as: (cd .git && cat HEAD | awk '{print $2}' | xargs cat | cut -b 1-7)
|
||||||
|
private String getGitSourceRevision() {
|
||||||
|
String git = getProject().getProperty("jni.git");
|
||||||
|
if (git == null) {
|
||||||
|
git = ".git";
|
||||||
|
}
|
||||||
|
if (new File(git).exists()) {
|
||||||
|
String head = readLine(git + "/HEAD");
|
||||||
|
|
||||||
|
if (head != null) {
|
||||||
|
String ref = head.substring(5).trim(); //'ref: '
|
||||||
|
return readLine(git + "/" + ref).substring(0, 7);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue