.PP
.B hwloc-patch
[\fIoptions\fR]
-\fI<topology.xml>\fR
+\fI[<topology.xml> | refname]\fR
\fI[<diff.xml> | -]\fR
\fI<output.xml>\fR
.PP
.B hwloc-patch
[\fIoptions\fR]
-\fI<topology.xml>\fR
+\fI[<topology.xml> | refname]\fR
\fI[<diff.xml> | -]\fR
.
.\" **************************
existing topology, generating a new, modified one.
.
.PP
+The XML difference may have been computed earlier with hwloc-diff
+or hwloc-compress-dir.
+.
+.PP
If <output.xml> is given, the new, modified topology is stored in that
new file. Otherwise, <topology.xml> is modified in place.
.
.PP
-If - is used instead of <diff.xml>, the topology difference is read from
-the standard input.
+If \fBrefname\fR is given instead of <topology.xml>, the input topology filename
+is automatically guessed by reading the refname field of the XML diff file.
+By default hwloc-diff generates XML diffs with the right reference topology
+filename (without any path prefix).
.
.PP
-The XML difference may have been computed earlier with hwloc-diff
-or hwloc-compress-dir.
+If \fB-\fR is given instead of <diff.xml>, the topology difference is read from
+the standard input.
.
.PP
.B NOTE:
$ hwloc-patch fourmi023.xml diff.xml fourmi023-new.xml
+Apply a XML topology difference file whole refname field contains the right input topology:
+
+ $ hwloc-patch refname diff.xml fourmi023-new.xml
+
Apply a XML topology from the standard intput:
$ cat diff.xml | hwloc-patch fourmi023.xml - fourmi023-new.xml
static void usage(const char *callname __hwloc_attribute_unused, FILE *where)
{
- fprintf(where, "Usage: hwloc-patch [options] <old.xml> [ <diff.xml> | - ] [<output.xml>]\n");
+ fprintf(where, "Usage: hwloc-patch [options] [<old.xml> | refname] [<diff.xml> | -] [<output.xml>]\n");
fprintf(where, "Options:\n");
fprintf(where, " -R --reverse Reverse the sense of the difference\n");
fprintf(where, " --version Report version and exit\n");
}
-static int hwloc_diff_read(hwloc_topology_t topo, const char *inputdiff, hwloc_topology_diff_t *firstdiffp)
+static int hwloc_diff_read(hwloc_topology_t topo, const char *inputdiff,
+ hwloc_topology_diff_t *firstdiffp, char **refnamep)
{
size_t buflen, offset, readlen;
char *buffer;
int err;
if (strcmp(inputdiff, "-"))
- return hwloc_topology_diff_load_xml(topo, inputdiff, firstdiffp, NULL);
+ return hwloc_topology_diff_load_xml(topo, inputdiff, firstdiffp, refnamep);
buflen = 4096;
buffer = malloc(buflen+1); /* one more byte for the ending \0 */
readlen = buflen/2;
}
- err = hwloc_topology_diff_load_xmlbuffer(topo, buffer, offset+1, firstdiffp, NULL);
+ err = hwloc_topology_diff_load_xmlbuffer(topo, buffer, offset+1, firstdiffp, refnamep);
free(buffer);
return err;
hwloc_topology_diff_t firstdiff = NULL;
unsigned long flags = HWLOC_TOPOLOGY_FLAG_WHOLE_IO | HWLOC_TOPOLOGY_FLAG_ICACHES;
unsigned long patchflags = 0;
- char *callname, *input, *inputdiff, *output = NULL;
+ char *callname, *input, *inputdiff, *output = NULL, *refname = NULL;
int err;
putenv("HWLOC_XML_VERBOSE=1");
argv++;
}
+ /* load a temporary topology so that we can play with diffs */
hwloc_topology_init(&topo);
- hwloc_topology_set_flags(topo, flags);
- err = hwloc_topology_set_xml(topo, input);
- if (err < 0) {
- fprintf(stderr, "Failed to load XML topology %s\n", input);
- goto out;
- }
hwloc_topology_load(topo);
- err = hwloc_diff_read(topo, inputdiff, &firstdiff);
+ /* load the diff and get the refname */
+ err = hwloc_diff_read(topo, inputdiff, &firstdiff, &refname);
if (err < 0) {
fprintf(stderr, "Failed to load XML topology diff %s\n", inputdiff);
goto out_with_topo;
}
+ /* switch to the actual input topology */
+ hwloc_topology_destroy(topo);
+ hwloc_topology_init(&topo);
+ hwloc_topology_set_flags(topo, flags);
+ if (!strcmp(input, "refname")) {
+ /* use the diff refname as input */
+ if (!refname) {
+ fprintf(stderr, "Couldn't find the reference topology name from the input diff %s\n", inputdiff);
+ goto out_with_diff;
+ }
+ err = hwloc_topology_set_xml(topo, refname);
+ if (err < 0) {
+ fprintf(stderr, "Failed to load XML topology %s (from input diff %s refname)\n", refname, inputdiff);
+ goto out;
+ }
+ } else {
+ /* use the given input */
+ err = hwloc_topology_set_xml(topo, input);
+ if (err < 0) {
+ fprintf(stderr, "Failed to load XML topology %s\n", input);
+ goto out;
+ }
+ }
+
+ hwloc_topology_load(topo);
+
err = hwloc_topology_diff_apply(topo, firstdiff, patchflags);
if (err < 0) {
fprintf(stderr, "Failed to%s apply topology diff %s, failed for hunk #%d hunk\n",
(umask 077 && mkdir "$tmp")
} || exit $?
-diffoutput="$tmp/test-hwloc-diffpatch.diff.xml"
-output1="$tmp/test-hwloc-diffpatch.output1"
-output2="$tmp/test-hwloc-diffpatch.output2"
+cd "$tmp"
+diffoutput="test-hwloc-diffpatch.diff.xml"
+output1="test-hwloc-diffpatch.output1"
+output2="test-hwloc-diffpatch.output2"
set -e
$diff $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input1 $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input2 > $diffoutput
-cat $diffoutput | $patch $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input1 - $output1
+cp $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input1 .
+#cat $diffoutput | $patch $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input1 - $output1
+cat $diffoutput | $patch refname - $output1
$patch -R $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input2 $diffoutput $output2
-diff @HWLOC_DIFF_U@ $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input1 "$output2"
-diff @HWLOC_DIFF_U@ $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input2 "$output1"
+diff -u $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input1 "$output2"
+diff -u $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input2 "$output1"
rm -rf "$tmp"