Skip to content

Commit

Permalink
Fix --version when built from a Git repository (PR samtools#844)
Browse files Browse the repository at this point in the history
Revert the parts of 3ecdcc4
unrelated to the sam_hdr_change_HD() changes described in that
commit's log message.
  • Loading branch information
jmarshall authored and daviesrob committed May 22, 2018
1 parent 2035cf3 commit 2c7cd7c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 39 deletions.
5 changes: 5 additions & 0 deletions bamtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ DEALINGS IN THE SOFTWARE. */

#include "htslib/hts.h"
#include "samtools.h"
#include "version.h"

int bam_taf2baf(int argc, char *argv[]);
int bam_mpileup(int argc, char *argv[]);
Expand Down Expand Up @@ -63,6 +64,10 @@ int main_addreplacerg(int argc, char *argv[]);
int faidx_main(int argc, char *argv[]);
int dict_main(int argc, char *argv[]);

const char *samtools_version()
{
return SAMTOOLS_VERSION;
}

static void usage(FILE *fp)
{
Expand Down
28 changes: 0 additions & 28 deletions sam_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ DEALINGS IN THE SOFTWARE. */
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>

#include "samtools.h"
#include "version.h"

static void vprint_error_core(const char *subcommand, const char *format, va_list args, const char *extra)
{
Expand Down Expand Up @@ -60,29 +58,3 @@ void print_error_errno(const char *subcommand, const char *format, ...)
vprint_error_core(subcommand, format, args, err? strerror(err) : NULL);
va_end(args);
}

const char *samtools_version()
{
return SAMTOOLS_VERSION;
}

const char *samtools_version_short()
{
char *sv, *hyph, *v;
int len;

v = SAMTOOLS_VERSION;
hyph = strchr(v, '-');
if (!hyph)
return strdup(v);

len = hyph - v;
sv = (char *)malloc(len+1);
if (!sv)
return NULL;

strncpy(sv, v, len);
sv[len] = '\0';

return (const char*)sv;
}
1 change: 0 additions & 1 deletion samtools.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ DEALINGS IN THE SOFTWARE. */
#define SAMTOOLS_H

const char *samtools_version(void);
const char *samtools_version_short(void);

#if defined __GNUC__ && __GNUC__ >= 2
#define CHECK_PRINTF(fmt,args) __attribute__ ((format (printf, fmt, args)))
Expand Down
18 changes: 8 additions & 10 deletions test/split/test_filter_header_rg.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ void setup_test_1(bam_hdr_t** hdr_in)
}

bool check_test_1(const bam_hdr_t* hdr) {
char test1_res[200];
snprintf(test1_res, 199,
const char *test1_res =
"@HD\tVN:1.4\n"
"@SQ\tSN:blah\n"
"@PG\tID:samtools\tPN:samtools\tVN:%s\tCL:test_filter_header_rg foo bar baz\n", samtools_version());
"@PG\tID:samtools\tPN:samtools\tVN:x.y.test\tCL:test_filter_header_rg foo bar baz\n";

if (strcmp(hdr->text, test1_res)) {
return false;
Expand All @@ -64,12 +63,11 @@ void setup_test_2(bam_hdr_t** hdr_in)
}

bool check_test_2(const bam_hdr_t* hdr) {
char test2_res[200];
snprintf(test2_res, 199,
const char *test2_res =
"@HD\tVN:1.4\n"
"@SQ\tSN:blah\n"
"@RG\tID:fish\n"
"@PG\tID:samtools\tPN:samtools\tVN:%s\tCL:test_filter_header_rg foo bar baz\n", samtools_version());
"@PG\tID:samtools\tPN:samtools\tVN:x.y.test\tCL:test_filter_header_rg foo bar baz\n";

if (strcmp(hdr->text, test2_res)) {
return false;
Expand Down Expand Up @@ -114,7 +112,7 @@ int main(int argc, char *argv[])
bam_hdr_t* hdr1;
const char* id_to_keep_1 = "1#2.3";
setup_test_1(&hdr1);
if (verbose > 0) {
if (verbose > 1) {
printf("hdr1\n");
dump_hdr(hdr1);
}
Expand All @@ -126,7 +124,7 @@ int main(int argc, char *argv[])
fclose(stderr);

if (verbose) printf("END RUN test 1\n");
if (verbose > 0) {
if (verbose > 1) {
printf("hdr1\n");
dump_hdr(hdr1);
}
Expand All @@ -153,7 +151,7 @@ int main(int argc, char *argv[])
bam_hdr_t* hdr2;
const char* id_to_keep_2 = "fish";
setup_test_2(&hdr2);
if (verbose > 0) {
if (verbose > 1) {
printf("hdr2\n");
dump_hdr(hdr2);
}
Expand All @@ -165,7 +163,7 @@ int main(int argc, char *argv[])
fclose(stderr);

if (verbose) printf("END RUN test 2\n");
if (verbose > 0) {
if (verbose > 1) {
printf("hdr2\n");
dump_hdr(hdr2);
}
Expand Down
6 changes: 6 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ void dump_hdr(const bam_hdr_t* hdr)
}
printf("text: \"%s\"\n", hdr->text);
}

// For tests, just return a constant that can be embedded in expected output.
const char *samtools_version(void)
{
return "x.y.test";
}

0 comments on commit 2c7cd7c

Please sign in to comment.