Add helpers for extending properties to proptools

It is common for a mutator to append or prepend property structs
together.  Add helper functions to append or prepend properties in property
structs.  The append operation is defined as appending string and slices
of strings normally, OR-ing bool values, and recursing into embedded
structs, pointers to structs, and interfaces containing pointers to
structs.  Appending or prepending the zero value of a property will
always be a no-op.
diff --git a/Blueprints b/Blueprints
index df3ad60..640e372 100644
--- a/Blueprints
+++ b/Blueprints
@@ -64,7 +64,13 @@
 bootstrap_go_package(
     name = "blueprint-proptools",
     pkgPath = "github.com/google/blueprint/proptools",
-    srcs = ["proptools/proptools.go"],
+    srcs = [
+        "proptools/extend.go",
+        "proptools/proptools.go",
+    ],
+    testSrcs = [
+        "proptools/extend_test.go",
+    ],
 )
 
 bootstrap_go_package(
diff --git a/build.ninja.in b/build.ninja.in
index 751dec0..635b77b 100644
--- a/build.ninja.in
+++ b/build.ninja.in
@@ -81,7 +81,7 @@
 # Variant:
 # Type:    bootstrap_go_package
 # Factory: github.com/google/blueprint/bootstrap.func·003
-# Defined: Blueprints:70:1
+# Defined: Blueprints:76:1
 
 build $
         ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap/pkg/github.com/google/blueprint/bootstrap.a $
@@ -108,7 +108,7 @@
 # Variant:
 # Type:    bootstrap_go_package
 # Factory: github.com/google/blueprint/bootstrap.func·003
-# Defined: Blueprints:89:1
+# Defined: Blueprints:95:1
 
 build $
         ${g.bootstrap.buildDir}/.bootstrap/blueprint-bootstrap-bpdoc/pkg/github.com/google/blueprint/bootstrap/bpdoc.a $
@@ -179,7 +179,8 @@
 
 build $
         ${g.bootstrap.buildDir}/.bootstrap/blueprint-proptools/pkg/github.com/google/blueprint/proptools.a $
-        : g.bootstrap.compile ${g.bootstrap.srcDir}/proptools/proptools.go | $
+        : g.bootstrap.compile ${g.bootstrap.srcDir}/proptools/extend.go $
+        ${g.bootstrap.srcDir}/proptools/proptools.go | $
         ${g.bootstrap.compileCmd}
     pkgPath = github.com/google/blueprint/proptools
 default $
@@ -190,7 +191,7 @@
 # Variant:
 # Type:    bootstrap_core_go_binary
 # Factory: github.com/google/blueprint/bootstrap.func·005
-# Defined: Blueprints:132:1
+# Defined: Blueprints:138:1
 
 build ${g.bootstrap.buildDir}/.bootstrap/choosestage/obj/choosestage.a: $
         g.bootstrap.compile ${g.bootstrap.srcDir}/choosestage/choosestage.go | $
@@ -212,7 +213,7 @@
 # Variant:
 # Type:    bootstrap_core_go_binary
 # Factory: github.com/google/blueprint/bootstrap.func·005
-# Defined: Blueprints:122:1
+# Defined: Blueprints:128:1
 
 build ${g.bootstrap.buildDir}/.bootstrap/gotestmain/obj/gotestmain.a: $
         g.bootstrap.compile ${g.bootstrap.srcDir}/gotestmain/gotestmain.go | $
@@ -234,7 +235,7 @@
 # Variant:
 # Type:    bootstrap_core_go_binary
 # Factory: github.com/google/blueprint/bootstrap.func·005
-# Defined: Blueprints:127:1
+# Defined: Blueprints:133:1
 
 build ${g.bootstrap.buildDir}/.bootstrap/gotestrunner/obj/gotestrunner.a: $
         g.bootstrap.compile ${g.bootstrap.srcDir}/gotestrunner/gotestrunner.go $
@@ -256,7 +257,7 @@
 # Variant:
 # Type:    bootstrap_core_go_binary
 # Factory: github.com/google/blueprint/bootstrap.func·005
-# Defined: Blueprints:101:1
+# Defined: Blueprints:107:1
 
 build ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a: $
         g.bootstrap.compile ${g.bootstrap.srcDir}/bootstrap/minibp/main.go | $
diff --git a/proptools/extend.go b/proptools/extend.go
new file mode 100644
index 0000000..241643b
--- /dev/null
+++ b/proptools/extend.go
@@ -0,0 +1,316 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package proptools
+
+import (
+	"fmt"
+	"reflect"
+)
+
+// AppendProperties appends the values of properties in the property struct src to the property
+// struct dst. dst and src must be the same type, and both must be pointers to structs.
+//
+// The filter function can prevent individual properties from being appended by returning false, or
+// abort AppendProperties with an error by returning an error.  Passing nil for filter will append
+// all properties.
+//
+// An error returned by AppendProperties that applies to a specific property will be an
+// *ExtendPropertyError, and can have the property name and error extracted from it.
+//
+// The append operation is defined as appending string and slices of strings normally, OR-ing
+// bool values, and recursing into embedded structs, pointers to structs, and interfaces containing
+// pointers to structs.  Appending the zero value of a property will always be a no-op.
+func AppendProperties(dst interface{}, src interface{}, filter ExtendPropertyFilterFunc) error {
+	return extendProperties(dst, src, filter, false)
+}
+
+// PrependProperties prepends the values of properties in the property struct src to the property
+// struct dst. dst and src must be the same type, and both must be pointers to structs.
+//
+// The filter function can prevent individual properties from being prepended by returning false, or
+// abort PrependProperties with an error by returning an error.  Passing nil for filter will prepend
+// all properties.
+//
+// An error returned by PrependProperties that applies to a specific property will be an
+// *ExtendPropertyError, and can have the property name and error extracted from it.
+//
+// The prepend operation is defined as prepending string and slices of strings normally, OR-ing
+// bool values, and recursing into embedded structs, pointers to structs, and interfaces containing
+// pointers to structs.  Prepending the zero value of a property will always be a no-op.
+func PrependProperties(dst interface{}, src interface{}, filter ExtendPropertyFilterFunc) error {
+	return extendProperties(dst, src, filter, true)
+}
+
+// AppendMatchingProperties appends the values of properties in the property struct src to the
+// property structs in dst.  dst and src do not have to be the same type, but every property in src
+// must be found in at least one property in dst.  dst must be a slice of pointers to structs, and
+// src must be a pointer to a struct.
+//
+// The filter function can prevent individual properties from being appended by returning false, or
+// abort AppendProperties with an error by returning an error.  Passing nil for filter will append
+// all properties.
+//
+// An error returned by AppendMatchingProperties that applies to a specific property will be an
+// *ExtendPropertyError, and can have the property name and error extracted from it.
+//
+// The append operation is defined as appending string and slices of strings normally, OR-ing
+// bool values, and recursing into embedded structs, pointers to structs, and interfaces containing
+// pointers to structs.  Appending the zero value of a property will always be a no-op.
+func AppendMatchingProperties(dst []interface{}, src interface{},
+	filter ExtendPropertyFilterFunc) error {
+	return extendMatchingProperties(dst, src, filter, false)
+}
+
+// PrependMatchingProperties prepends the values of properties in the property struct src to the
+// property structs in dst.  dst and src do not have to be the same type, but every property in src
+// must be found in at least one property in dst.  dst must be a slice of pointers to structs, and
+// src must be a pointer to a struct.
+//
+// The filter function can prevent individual properties from being prepended by returning false, or
+// abort PrependProperties with an error by returning an error.  Passing nil for filter will prepend
+// all properties.
+//
+// An error returned by PrependProperties that applies to a specific property will be an
+// *ExtendPropertyError, and can have the property name and error extracted from it.
+//
+// The prepend operation is defined as prepending string and slices of strings normally, OR-ing
+// bool values, and recursing into embedded structs, pointers to structs, and interfaces containing
+// pointers to structs.  Prepending the zero value of a property will always be a no-op.
+func PrependMatchingProperties(dst []interface{}, src interface{},
+	filter ExtendPropertyFilterFunc) error {
+	return extendMatchingProperties(dst, src, filter, true)
+}
+
+type ExtendPropertyFilterFunc func(property string,
+	dstField, srcField reflect.StructField,
+	dstValue, srcValue interface{}) (bool, error)
+
+type ExtendPropertyError struct {
+	Err      error
+	Property string
+}
+
+func (e *ExtendPropertyError) Error() string {
+	return fmt.Sprintf("can't extend property %q: %s", e.Property, e.Err)
+}
+
+func extendPropertyErrorf(property string, format string, a ...interface{}) *ExtendPropertyError {
+	return &ExtendPropertyError{
+		Err:      fmt.Errorf(format, a...),
+		Property: property,
+	}
+}
+
+func extendProperties(dst interface{}, src interface{}, filter ExtendPropertyFilterFunc,
+	prepend bool) error {
+
+	dstValue, err := getStruct(dst)
+	if err != nil {
+		return err
+	}
+	srcValue, err := getStruct(src)
+	if err != nil {
+		return err
+	}
+
+	if dstValue.Type() != srcValue.Type() {
+		return fmt.Errorf("expected matching types for dst and src, got %T and %T", dst, src)
+	}
+
+	dstValues := []reflect.Value{dstValue}
+
+	return extendPropertiesRecursive(dstValues, srcValue, "", filter, true, prepend)
+}
+
+func extendMatchingProperties(dst []interface{}, src interface{}, filter ExtendPropertyFilterFunc,
+	prepend bool) error {
+
+	dstValues := make([]reflect.Value, len(dst))
+	for i := range dst {
+		var err error
+		dstValues[i], err = getStruct(dst[i])
+		if err != nil {
+			return err
+		}
+	}
+
+	srcValue, err := getStruct(src)
+	if err != nil {
+		return err
+	}
+
+	return extendPropertiesRecursive(dstValues, srcValue, "", filter, false, prepend)
+}
+
+func extendPropertiesRecursive(dstValues []reflect.Value, srcValue reflect.Value,
+	prefix string, filter ExtendPropertyFilterFunc, sameTypes, prepend bool) error {
+
+	srcType := srcValue.Type()
+	for i := 0; i < srcValue.NumField(); i++ {
+		srcField := srcType.Field(i)
+		if srcField.PkgPath != "" {
+			// The field is not exported so just skip it.
+			continue
+		}
+		if HasTag(srcField, "blueprint", "mutated") {
+			continue
+		}
+
+		propertyName := prefix + PropertyNameForField(srcField.Name)
+		srcFieldValue := srcValue.Field(i)
+
+		found := false
+		for _, dstValue := range dstValues {
+			dstType := dstValue.Type()
+			var dstField reflect.StructField
+
+			if dstType == srcType {
+				dstField = dstType.Field(i)
+			} else {
+				var ok bool
+				dstField, ok = dstType.FieldByName(srcField.Name)
+				if !ok {
+					continue
+				}
+			}
+
+			found = true
+
+			dstFieldValue := dstValue.FieldByIndex(dstField.Index)
+
+			if srcFieldValue.Kind() != dstFieldValue.Kind() {
+				return extendPropertyErrorf(propertyName, "mismatched types %s and %s",
+					dstFieldValue.Type(), srcFieldValue.Type())
+			}
+
+			switch srcFieldValue.Kind() {
+			case reflect.Interface:
+				if dstFieldValue.IsNil() != srcFieldValue.IsNil() {
+					return extendPropertyErrorf(propertyName, "nilitude mismatch")
+				}
+				if dstFieldValue.IsNil() {
+					continue
+				}
+
+				dstFieldValue = dstFieldValue.Elem()
+				srcFieldValue = srcFieldValue.Elem()
+
+				if srcFieldValue.Kind() != reflect.Ptr || dstFieldValue.Kind() != reflect.Ptr {
+					return extendPropertyErrorf(propertyName, "interface not a pointer")
+				}
+
+				fallthrough
+			case reflect.Ptr:
+				if dstFieldValue.IsNil() != srcFieldValue.IsNil() {
+					return extendPropertyErrorf(propertyName, "nilitude mismatch")
+				}
+				if dstFieldValue.IsNil() {
+					continue
+				}
+
+				dstFieldValue = dstFieldValue.Elem()
+				srcFieldValue = srcFieldValue.Elem()
+
+				if srcFieldValue.Kind() != reflect.Struct || dstFieldValue.Kind() != reflect.Struct {
+					return extendPropertyErrorf(propertyName, "pointer not to a struct")
+				}
+
+				fallthrough
+			case reflect.Struct:
+				if sameTypes && dstFieldValue.Type() != srcFieldValue.Type() {
+					return extendPropertyErrorf(propertyName, "mismatched types %s and %s",
+						dstFieldValue.Type(), srcFieldValue.Type())
+				}
+
+				// Recursively extend the struct's fields.
+				err := extendPropertiesRecursive([]reflect.Value{dstFieldValue}, srcFieldValue,
+					propertyName+".", filter, sameTypes, prepend)
+				if err != nil {
+					return err
+				}
+				continue
+			case reflect.Bool, reflect.String, reflect.Slice:
+				if srcFieldValue.Type() != dstFieldValue.Type() {
+					return extendPropertyErrorf(propertyName, "mismatched types %s and %s",
+						dstFieldValue.Type(), srcFieldValue.Type())
+				}
+			default:
+				return extendPropertyErrorf(propertyName, "unsupported kind %s",
+					srcFieldValue.Kind())
+			}
+
+			if filter != nil {
+				b, err := filter(propertyName, dstField, srcField,
+					dstFieldValue.Interface(), srcFieldValue.Interface())
+				if err != nil {
+					return &ExtendPropertyError{
+						Property: propertyName,
+						Err:      err,
+					}
+				}
+				if !b {
+					continue
+				}
+			}
+
+			switch srcFieldValue.Kind() {
+			case reflect.Bool:
+				// Boolean OR
+				dstFieldValue.Set(reflect.ValueOf(srcFieldValue.Bool() || dstFieldValue.Bool()))
+			case reflect.String:
+				// Append the extension string.
+				if prepend {
+					dstFieldValue.SetString(srcFieldValue.String() +
+						dstFieldValue.String())
+				} else {
+					dstFieldValue.SetString(dstFieldValue.String() +
+						srcFieldValue.String())
+				}
+			case reflect.Slice:
+				if srcFieldValue.IsNil() {
+					break
+				}
+
+				newSlice := reflect.MakeSlice(srcFieldValue.Type(), 0,
+					dstFieldValue.Len()+srcFieldValue.Len())
+				if prepend {
+					newSlice = reflect.AppendSlice(newSlice, srcFieldValue)
+					newSlice = reflect.AppendSlice(newSlice, dstFieldValue)
+				} else {
+					newSlice = reflect.AppendSlice(newSlice, dstFieldValue)
+					newSlice = reflect.AppendSlice(newSlice, srcFieldValue)
+				}
+				dstFieldValue.Set(newSlice)
+			}
+		}
+		if !found {
+			return extendPropertyErrorf(propertyName, "failed to find property to extend")
+		}
+	}
+
+	return nil
+}
+
+func getStruct(in interface{}) (reflect.Value, error) {
+	value := reflect.ValueOf(in)
+	if value.Kind() != reflect.Ptr {
+		return reflect.Value{}, fmt.Errorf("expected pointer to struct, got %T", in)
+	}
+	value = value.Elem()
+	if value.Kind() != reflect.Struct {
+		return reflect.Value{}, fmt.Errorf("expected pointer to struct, got %T", in)
+	}
+	return value, nil
+}
diff --git a/proptools/extend_test.go b/proptools/extend_test.go
new file mode 100644
index 0000000..a2482cc
--- /dev/null
+++ b/proptools/extend_test.go
@@ -0,0 +1,824 @@
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package proptools
+
+import (
+	"errors"
+	"fmt"
+	"reflect"
+	"strings"
+	"testing"
+)
+
+var appendPropertiesTestCases = []struct {
+	in1     interface{}
+	in2     interface{}
+	out     interface{}
+	prepend bool
+	filter  ExtendPropertyFilterFunc
+	err     error
+}{
+	// Valid inputs
+
+	{
+		// Append bool
+		in1: &struct{ B1, B2, B3, B4 bool }{
+			B1: true,
+			B2: false,
+			B3: true,
+			B4: false,
+		},
+		in2: &struct{ B1, B2, B3, B4 bool }{
+			B1: true,
+			B2: true,
+			B3: false,
+			B4: false,
+		},
+		out: &struct{ B1, B2, B3, B4 bool }{
+			B1: true,
+			B2: true,
+			B3: true,
+			B4: false,
+		},
+	},
+	{
+		// Prepend bool
+		in1: &struct{ B1, B2, B3, B4 bool }{
+			B1: true,
+			B2: false,
+			B3: true,
+			B4: false,
+		},
+		in2: &struct{ B1, B2, B3, B4 bool }{
+			B1: true,
+			B2: true,
+			B3: false,
+			B4: false,
+		},
+		out: &struct{ B1, B2, B3, B4 bool }{
+			B1: true,
+			B2: true,
+			B3: true,
+			B4: false,
+		},
+		prepend: true,
+	},
+	{
+		// Append strings
+		in1: &struct{ S string }{
+			S: "string1",
+		},
+		in2: &struct{ S string }{
+			S: "string2",
+		},
+		out: &struct{ S string }{
+			S: "string1string2",
+		},
+	},
+	{
+		// Prepend strings
+		in1: &struct{ S string }{
+			S: "string1",
+		},
+		in2: &struct{ S string }{
+			S: "string2",
+		},
+		out: &struct{ S string }{
+			S: "string2string1",
+		},
+		prepend: true,
+	},
+	{
+		// Append slice
+		in1: &struct{ S []string }{
+			S: []string{"string1"},
+		},
+		in2: &struct{ S []string }{
+			S: []string{"string2"},
+		},
+		out: &struct{ S []string }{
+			S: []string{"string1", "string2"},
+		},
+	},
+	{
+		// Prepend slice
+		in1: &struct{ S []string }{
+			S: []string{"string1"},
+		},
+		in2: &struct{ S []string }{
+			S: []string{"string2"},
+		},
+		out: &struct{ S []string }{
+			S: []string{"string2", "string1"},
+		},
+		prepend: true,
+	},
+	{
+		// Append empty slice
+		in1: &struct{ S1, S2 []string }{
+			S1: []string{"string1"},
+			S2: []string{},
+		},
+		in2: &struct{ S1, S2 []string }{
+			S1: []string{},
+			S2: []string{"string2"},
+		},
+		out: &struct{ S1, S2 []string }{
+			S1: []string{"string1"},
+			S2: []string{"string2"},
+		},
+	},
+	{
+		// Prepend empty slice
+		in1: &struct{ S1, S2 []string }{
+			S1: []string{"string1"},
+			S2: []string{},
+		},
+		in2: &struct{ S1, S2 []string }{
+			S1: []string{},
+			S2: []string{"string2"},
+		},
+		out: &struct{ S1, S2 []string }{
+			S1: []string{"string1"},
+			S2: []string{"string2"},
+		},
+		prepend: true,
+	},
+	{
+		// Append nil slice
+		in1: &struct{ S1, S2, S3 []string }{
+			S1: []string{"string1"},
+		},
+		in2: &struct{ S1, S2, S3 []string }{
+			S2: []string{"string2"},
+		},
+		out: &struct{ S1, S2, S3 []string }{
+			S1: []string{"string1"},
+			S2: []string{"string2"},
+			S3: nil,
+		},
+	},
+	{
+		// Prepend nil slice
+		in1: &struct{ S1, S2, S3 []string }{
+			S1: []string{"string1"},
+		},
+		in2: &struct{ S1, S2, S3 []string }{
+			S2: []string{"string2"},
+		},
+		out: &struct{ S1, S2, S3 []string }{
+			S1: []string{"string1"},
+			S2: []string{"string2"},
+			S3: nil,
+		},
+		prepend: true,
+	},
+	{
+		// Append pointer
+		in1: &struct{ S *struct{ S string } }{
+			S: &struct{ S string }{
+				S: "string1",
+			},
+		},
+		in2: &struct{ S *struct{ S string } }{
+			S: &struct{ S string }{
+				S: "string2",
+			},
+		},
+		out: &struct{ S *struct{ S string } }{
+			S: &struct{ S string }{
+				S: "string1string2",
+			},
+		},
+	},
+	{
+		// Prepend pointer
+		in1: &struct{ S *struct{ S string } }{
+			S: &struct{ S string }{
+				S: "string1",
+			},
+		},
+		in2: &struct{ S *struct{ S string } }{
+			S: &struct{ S string }{
+				S: "string2",
+			},
+		},
+		out: &struct{ S *struct{ S string } }{
+			S: &struct{ S string }{
+				S: "string2string1",
+			},
+		},
+		prepend: true,
+	},
+	{
+		// Append interface
+		in1: &struct{ S interface{} }{
+			S: &struct{ S string }{
+				S: "string1",
+			},
+		},
+		in2: &struct{ S interface{} }{
+			S: &struct{ S string }{
+				S: "string2",
+			},
+		},
+		out: &struct{ S interface{} }{
+			S: &struct{ S string }{
+				S: "string1string2",
+			},
+		},
+	},
+	{
+		// Prepend interface
+		in1: &struct{ S interface{} }{
+			S: &struct{ S string }{
+				S: "string1",
+			},
+		},
+		in2: &struct{ S interface{} }{
+			S: &struct{ S string }{
+				S: "string2",
+			},
+		},
+		out: &struct{ S interface{} }{
+			S: &struct{ S string }{
+				S: "string2string1",
+			},
+		},
+		prepend: true,
+	},
+	{
+		// Unexported field
+		in1: &struct{ s string }{
+			s: "string1",
+		},
+		in2: &struct{ s string }{
+			s: "string2",
+		},
+		out: &struct{ s string }{
+			s: "string1",
+		},
+	},
+	{
+		// Empty struct
+		in1: &struct{}{},
+		in2: &struct{}{},
+		out: &struct{}{},
+	},
+	{
+		// Interface nil
+		in1: &struct{ S interface{} }{
+			S: nil,
+		},
+		in2: &struct{ S interface{} }{
+			S: nil,
+		},
+		out: &struct{ S interface{} }{
+			S: nil,
+		},
+	},
+	{
+		// Pointer nil
+		in1: &struct{ S *struct{} }{
+			S: nil,
+		},
+		in2: &struct{ S *struct{} }{
+			S: nil,
+		},
+		out: &struct{ S *struct{} }{
+			S: nil,
+		},
+	},
+
+	// Errors
+
+	{
+		// Non-pointer in1
+		in1: struct{}{},
+		err: errors.New("expected pointer to struct, got struct {}"),
+		out: struct{}{},
+	},
+	{
+		// Non-pointer in2
+		in1: &struct{}{},
+		in2: struct{}{},
+		err: errors.New("expected pointer to struct, got struct {}"),
+		out: &struct{}{},
+	},
+	{
+		// Non-struct in1
+		in1: &[]string{"bad"},
+		err: errors.New("expected pointer to struct, got *[]string"),
+		out: &[]string{"bad"},
+	},
+	{
+		// Non-struct in2
+		in1: &struct{}{},
+		in2: &[]string{"bad"},
+		err: errors.New("expected pointer to struct, got *[]string"),
+		out: &struct{}{},
+	},
+	{
+		// Mismatched types
+		in1: &struct{ A string }{
+			A: "string1",
+		},
+		in2: &struct{ B string }{
+			B: "string2",
+		},
+		out: &struct{ A string }{
+			A: "string1",
+		},
+		err: errors.New("expected matching types for dst and src, got *struct { A string } and *struct { B string }"),
+	},
+	{
+		// Unsupported kind
+		in1: &struct{ I int }{
+			I: 1,
+		},
+		in2: &struct{ I int }{
+			I: 2,
+		},
+		out: &struct{ I int }{
+			I: 1,
+		},
+		err: extendPropertyErrorf("i", "unsupported kind int"),
+	},
+	{
+		// Interface nilitude mismatch
+		in1: &struct{ S interface{} }{
+			S: &struct{ S string }{
+				S: "string1",
+			},
+		},
+		in2: &struct{ S interface{} }{
+			S: nil,
+		},
+		out: &struct{ S interface{} }{
+			S: &struct{ S string }{
+				S: "string1",
+			},
+		},
+		err: extendPropertyErrorf("s", "nilitude mismatch"),
+	},
+	{
+		// Interface type mismatch
+		in1: &struct{ S interface{} }{
+			S: &struct{ A string }{
+				A: "string1",
+			},
+		},
+		in2: &struct{ S interface{} }{
+			S: &struct{ B string }{
+				B: "string2",
+			},
+		},
+		out: &struct{ S interface{} }{
+			S: &struct{ A string }{
+				A: "string1",
+			},
+		},
+		err: extendPropertyErrorf("s", "mismatched types struct { A string } and struct { B string }"),
+	},
+	{
+		// Interface not a pointer
+		in1: &struct{ S interface{} }{
+			S: struct{ S string }{
+				S: "string1",
+			},
+		},
+		in2: &struct{ S interface{} }{
+			S: struct{ S string }{
+				S: "string2",
+			},
+		},
+		out: &struct{ S interface{} }{
+			S: struct{ S string }{
+				S: "string1",
+			},
+		},
+		err: extendPropertyErrorf("s", "interface not a pointer"),
+	},
+	{
+		// Pointer nilitude mismatch
+		in1: &struct{ S *struct{ S string } }{
+			S: &struct{ S string }{
+				S: "string1",
+			},
+		},
+		in2: &struct{ S *struct{ S string } }{
+			S: nil,
+		},
+		out: &struct{ S *struct{ S string } }{
+			S: &struct{ S string }{
+				S: "string1",
+			},
+		},
+		err: extendPropertyErrorf("s", "nilitude mismatch"),
+	},
+	{
+		// Pointer not a struct
+		in1: &struct{ S *[]string }{
+			S: &[]string{"string1"},
+		},
+		in2: &struct{ S *[]string }{
+			S: &[]string{"string2"},
+		},
+		out: &struct{ S *[]string }{
+			S: &[]string{"string1"},
+		},
+		err: extendPropertyErrorf("s", "pointer not to a struct"),
+	},
+	{
+		// Error in nested struct
+		in1: &struct{ S interface{} }{
+			S: &struct{ I int }{
+				I: 1,
+			},
+		},
+		in2: &struct{ S interface{} }{
+			S: &struct{ I int }{
+				I: 2,
+			},
+		},
+		out: &struct{ S interface{} }{
+			S: &struct{ I int }{
+				I: 1,
+			},
+		},
+		err: extendPropertyErrorf("s.i", "unsupported kind int"),
+	},
+
+	// Filters
+
+	{
+		// Filter true
+		in1: &struct{ S string }{
+			S: "string1",
+		},
+		in2: &struct{ S string }{
+			S: "string2",
+		},
+		out: &struct{ S string }{
+			S: "string1string2",
+		},
+		filter: func(property string,
+			dstField, srcField reflect.StructField,
+			dstValue, srcValue interface{}) (bool, error) {
+			return true, nil
+		},
+	},
+	{
+		// Filter false
+		in1: &struct{ S string }{
+			S: "string1",
+		},
+		in2: &struct{ S string }{
+			S: "string2",
+		},
+		out: &struct{ S string }{
+			S: "string1",
+		},
+		filter: func(property string,
+			dstField, srcField reflect.StructField,
+			dstValue, srcValue interface{}) (bool, error) {
+			return false, nil
+		},
+	},
+	{
+		// Filter check args
+		in1: &struct{ S string }{
+			S: "string1",
+		},
+		in2: &struct{ S string }{
+			S: "string2",
+		},
+		out: &struct{ S string }{
+			S: "string1string2",
+		},
+		filter: func(property string,
+			dstField, srcField reflect.StructField,
+			dstValue, srcValue interface{}) (bool, error) {
+			return property == "s" &&
+				dstField.Name == "S" && srcField.Name == "S" &&
+				dstValue.(string) == "string1" && srcValue.(string) == "string2", nil
+		},
+	},
+	{
+		// Filter mutated
+		in1: &struct {
+			S string `blueprint:"mutated"`
+		}{
+			S: "string1",
+		},
+		in2: &struct {
+			S string `blueprint:"mutated"`
+		}{
+			S: "string2",
+		},
+		out: &struct {
+			S string `blueprint:"mutated"`
+		}{
+			S: "string1",
+		},
+	},
+	{
+		// Filter error
+		in1: &struct{ S string }{
+			S: "string1",
+		},
+		in2: &struct{ S string }{
+			S: "string2",
+		},
+		out: &struct{ S string }{
+			S: "string1",
+		},
+		filter: func(property string,
+			dstField, srcField reflect.StructField,
+			dstValue, srcValue interface{}) (bool, error) {
+			return true, fmt.Errorf("filter error")
+		},
+		err: extendPropertyErrorf("s", "filter error"),
+	},
+}
+
+func TestAppendProperties(t *testing.T) {
+	for _, testCase := range appendPropertiesTestCases {
+		testString := fmt.Sprintf("%v, %v -> %v", testCase.in1, testCase.in2, testCase.out)
+
+		got := testCase.in1
+		var err error
+		var testType string
+
+		if testCase.prepend {
+			testType = "prepend"
+			err = PrependProperties(got, testCase.in2, testCase.filter)
+		} else {
+			testType = "append"
+			err = AppendProperties(got, testCase.in2, testCase.filter)
+		}
+
+		check(t, testType, testString, got, err, testCase.out, testCase.err)
+	}
+}
+
+var appendMatchingPropertiesTestCases = []struct {
+	in1     []interface{}
+	in2     interface{}
+	out     []interface{}
+	prepend bool
+	filter  ExtendPropertyFilterFunc
+	err     error
+}{
+	{
+		// Append strings
+		in1: []interface{}{&struct{ S string }{
+			S: "string1",
+		}},
+		in2: &struct{ S string }{
+			S: "string2",
+		},
+		out: []interface{}{&struct{ S string }{
+			S: "string1string2",
+		}},
+	},
+	{
+		// Prepend strings
+		in1: []interface{}{&struct{ S string }{
+			S: "string1",
+		}},
+		in2: &struct{ S string }{
+			S: "string2",
+		},
+		out: []interface{}{&struct{ S string }{
+			S: "string2string1",
+		}},
+		prepend: true,
+	},
+	{
+		// Append all
+		in1: []interface{}{
+			&struct{ S, A string }{
+				S: "string1",
+			},
+			&struct{ S, B string }{
+				S: "string2",
+			},
+		},
+		in2: &struct{ S string }{
+			S: "string3",
+		},
+		out: []interface{}{
+			&struct{ S, A string }{
+				S: "string1string3",
+			},
+			&struct{ S, B string }{
+				S: "string2string3",
+			},
+		},
+	},
+	{
+		// Append some
+		in1: []interface{}{
+			&struct{ S, A string }{
+				S: "string1",
+			},
+			&struct{ B string }{},
+		},
+		in2: &struct{ S string }{
+			S: "string2",
+		},
+		out: []interface{}{
+			&struct{ S, A string }{
+				S: "string1string2",
+			},
+			&struct{ B string }{},
+		},
+	},
+	{
+		// Append mismatched structs
+		in1: []interface{}{&struct{ S, A string }{
+			S: "string1",
+		}},
+		in2: &struct{ S string }{
+			S: "string2",
+		},
+		out: []interface{}{&struct{ S, A string }{
+			S: "string1string2",
+		}},
+	},
+	{
+		// Append mismatched pointer structs
+		in1: []interface{}{&struct{ S *struct{ S, A string } }{
+			S: &struct{ S, A string }{
+				S: "string1",
+			},
+		}},
+		in2: &struct{ S *struct{ S string } }{
+			S: &struct{ S string }{
+				S: "string2",
+			},
+		},
+		out: []interface{}{&struct{ S *struct{ S, A string } }{
+			S: &struct{ S, A string }{
+				S: "string1string2",
+			},
+		}},
+	},
+
+	// Errors
+
+	{
+		// Non-pointer in1
+		in1: []interface{}{struct{}{}},
+		err: errors.New("expected pointer to struct, got struct {}"),
+		out: []interface{}{struct{}{}},
+	},
+	{
+		// Non-pointer in2
+		in1: []interface{}{&struct{}{}},
+		in2: struct{}{},
+		err: errors.New("expected pointer to struct, got struct {}"),
+		out: []interface{}{&struct{}{}},
+	},
+	{
+		// Non-struct in1
+		in1: []interface{}{&[]string{"bad"}},
+		err: errors.New("expected pointer to struct, got *[]string"),
+		out: []interface{}{&[]string{"bad"}},
+	},
+	{
+		// Non-struct in2
+		in1: []interface{}{&struct{}{}},
+		in2: &[]string{"bad"},
+		err: errors.New("expected pointer to struct, got *[]string"),
+		out: []interface{}{&struct{}{}},
+	},
+	{
+		// Append none
+		in1: []interface{}{
+			&struct{ A string }{},
+			&struct{ B string }{},
+		},
+		in2: &struct{ S string }{
+			S: "string1",
+		},
+		out: []interface{}{
+			&struct{ A string }{},
+			&struct{ B string }{},
+		},
+		err: extendPropertyErrorf("s", "failed to find property to extend"),
+	},
+	{
+		// Append mismatched kinds
+		in1: []interface{}{
+			&struct{ S string }{
+				S: "string1",
+			},
+		},
+		in2: &struct{ S []string }{
+			S: []string{"string2"},
+		},
+		out: []interface{}{
+			&struct{ S string }{
+				S: "string1",
+			},
+		},
+		err: extendPropertyErrorf("s", "mismatched types string and []string"),
+	},
+	{
+		// Append mismatched types
+		in1: []interface{}{
+			&struct{ S []int }{
+				S: []int{1},
+			},
+		},
+		in2: &struct{ S []string }{
+			S: []string{"string2"},
+		},
+		out: []interface{}{
+			&struct{ S []int }{
+				S: []int{1},
+			},
+		},
+		err: extendPropertyErrorf("s", "mismatched types []int and []string"),
+	},
+}
+
+func TestAppendMatchingProperties(t *testing.T) {
+	for _, testCase := range appendMatchingPropertiesTestCases {
+		testString := fmt.Sprintf("%s, %s -> %s", p(testCase.in1), p(testCase.in2), p(testCase.out))
+
+		got := testCase.in1
+		var err error
+		var testType string
+
+		if testCase.prepend {
+			testType = "prepend matching"
+			err = PrependMatchingProperties(got, testCase.in2, testCase.filter)
+		} else {
+			testType = "append matching"
+			err = AppendMatchingProperties(got, testCase.in2, testCase.filter)
+		}
+
+		check(t, testType, testString, got, err, testCase.out, testCase.err)
+	}
+}
+
+func check(t *testing.T, testType, testString string,
+	got interface{}, err error,
+	expected interface{}, expectedErr error) {
+
+	printedTestCase := false
+	e := func(s string, expected, got interface{}) {
+		if !printedTestCase {
+			t.Errorf("test case %s: %s", testType, testString)
+			printedTestCase = true
+		}
+		t.Errorf("incorrect %s", s)
+		t.Errorf("  expected: %s", p(expected))
+		t.Errorf("       got: %s", p(got))
+	}
+
+	if err != nil {
+		if expectedErr != nil {
+			if err.Error() != expectedErr.Error() {
+				e("unexpected error", expectedErr.Error(), err.Error())
+			}
+		} else {
+			e("unexpected error", nil, err.Error())
+		}
+	} else {
+		if expectedErr != nil {
+			e("missing error", expectedErr, nil)
+		}
+	}
+
+	if !reflect.DeepEqual(expected, got) {
+		e("output:", expected, got)
+	}
+}
+
+func p(in interface{}) string {
+	if v, ok := in.([]interface{}); ok {
+		s := make([]string, len(v))
+		for i := range v {
+			s[i] = fmt.Sprintf("%#v", v[i])
+		}
+		return "[" + strings.Join(s, ", ") + "]"
+	} else {
+		return fmt.Sprintf("%#v", in)
+	}
+}
diff --git a/proptools/proptools.go b/proptools/proptools.go
index ebfe42a..e761926 100644
--- a/proptools/proptools.go
+++ b/proptools/proptools.go
@@ -17,6 +17,7 @@
 import (
 	"fmt"
 	"reflect"
+	"strings"
 	"unicode"
 	"unicode/utf8"
 )
@@ -201,3 +202,14 @@
 		}
 	}
 }
+
+func HasTag(field reflect.StructField, name, value string) bool {
+	tag := field.Tag.Get(name)
+	for _, entry := range strings.Split(tag, ",") {
+		if entry == value {
+			return true
+		}
+	}
+
+	return false
+}
diff --git a/unpack.go b/unpack.go
index 83fcd32..e188d6f 100644
--- a/unpack.go
+++ b/unpack.go
@@ -173,7 +173,7 @@
 			}
 
 		case reflect.Int, reflect.Uint:
-			if !hasTag(field, "blueprint", "mutated") {
+			if !proptools.HasTag(field, "blueprint", "mutated") {
 				panic(fmt.Errorf(`int field %s must be tagged blueprint:"mutated"`, field.Name))
 			}
 
@@ -192,7 +192,7 @@
 
 		packedProperty.unpacked = true
 
-		if hasTag(field, "blueprint", "mutated") {
+		if proptools.HasTag(field, "blueprint", "mutated") {
 			errs = append(errs,
 				&Error{
 					Err: fmt.Errorf("mutated field %s cannot be set in a Blueprint file", propertyName),
@@ -204,7 +204,7 @@
 			continue
 		}
 
-		if filterKey != "" && !hasTag(field, filterKey, filterValue) {
+		if filterKey != "" && !proptools.HasTag(field, filterKey, filterValue) {
 			errs = append(errs,
 				&Error{
 					Err: fmt.Errorf("filtered field %s cannot be set in a Blueprint file", propertyName),
@@ -326,17 +326,6 @@
 	return unpackStructValue(namePrefix, structValue, propertyMap, filterKey, filterValue)
 }
 
-func hasTag(field reflect.StructField, name, value string) bool {
-	tag := field.Tag.Get(name)
-	for _, entry := range strings.Split(tag, ",") {
-		if entry == value {
-			return true
-		}
-	}
-
-	return false
-}
-
 func HasFilter(field reflect.StructTag) (k, v string, err error) {
 	tag := field.Get("blueprint")
 	for _, entry := range strings.Split(tag, ",") {