Merge pull request #79 from colincross/enotdir

End removing directories on ENOTDIR
diff --git a/.travis.yml b/.travis.yml
index 1004a71..315b799 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,8 @@
 language: go
 
+go:
+    - 1.5.1
+
 cache:
     directories:
         - $HOME/ninjabin
diff --git a/build.ninja.in b/build.ninja.in
index f165c40..9ba88c8 100644
--- a/build.ninja.in
+++ b/build.ninja.in
@@ -54,7 +54,7 @@
 # Module:  blueprint
 # Variant:
 # Type:    bootstrap_go_package
-# Factory: github.com/google/blueprint/bootstrap.func·003
+# Factory: github.com/google/blueprint/bootstrap.newGoPackageModuleFactory.func1
 # Defined: Blueprints:1:1
 
 build $
@@ -80,7 +80,7 @@
 # Module:  blueprint-bootstrap
 # Variant:
 # Type:    bootstrap_go_package
-# Factory: github.com/google/blueprint/bootstrap.func·003
+# Factory: github.com/google/blueprint/bootstrap.newGoPackageModuleFactory.func1
 # Defined: Blueprints:80:1
 
 build $
@@ -107,7 +107,7 @@
 # Module:  blueprint-bootstrap-bpdoc
 # Variant:
 # Type:    bootstrap_go_package
-# Factory: github.com/google/blueprint/bootstrap.func·003
+# Factory: github.com/google/blueprint/bootstrap.newGoPackageModuleFactory.func1
 # Defined: Blueprints:99:1
 
 build $
@@ -127,7 +127,7 @@
 # Module:  blueprint-deptools
 # Variant:
 # Type:    bootstrap_go_package
-# Factory: github.com/google/blueprint/bootstrap.func·003
+# Factory: github.com/google/blueprint/bootstrap.newGoPackageModuleFactory.func1
 # Defined: Blueprints:46:1
 
 build $
@@ -142,7 +142,7 @@
 # Module:  blueprint-parser
 # Variant:
 # Type:    bootstrap_go_package
-# Factory: github.com/google/blueprint/bootstrap.func·003
+# Factory: github.com/google/blueprint/bootstrap.newGoPackageModuleFactory.func1
 # Defined: Blueprints:31:1
 
 build $
@@ -159,7 +159,7 @@
 # Module:  blueprint-pathtools
 # Variant:
 # Type:    bootstrap_go_package
-# Factory: github.com/google/blueprint/bootstrap.func·003
+# Factory: github.com/google/blueprint/bootstrap.newGoPackageModuleFactory.func1
 # Defined: Blueprints:52:1
 
 build $
@@ -174,7 +174,7 @@
 # Module:  blueprint-proptools
 # Variant:
 # Type:    bootstrap_go_package
-# Factory: github.com/google/blueprint/bootstrap.func·003
+# Factory: github.com/google/blueprint/bootstrap.newGoPackageModuleFactory.func1
 # Defined: Blueprints:64:1
 
 build $
@@ -192,7 +192,7 @@
 # Module:  choosestage
 # Variant:
 # Type:    bootstrap_core_go_binary
-# Factory: github.com/google/blueprint/bootstrap.func·005
+# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1
 # Defined: Blueprints:142:1
 
 build ${g.bootstrap.buildDir}/.bootstrap/choosestage/obj/choosestage.a: $
@@ -206,6 +206,7 @@
         ${g.bootstrap.buildDir}/.bootstrap/choosestage/obj/choosestage.a | $
         ${g.bootstrap.linkCmd}
 default ${g.bootstrap.buildDir}/.bootstrap/choosestage/obj/a.out
+
 build ${g.bootstrap.BinDir}/choosestage: g.bootstrap.cp $
         ${g.bootstrap.buildDir}/.bootstrap/choosestage/obj/a.out
 default ${g.bootstrap.BinDir}/choosestage
@@ -214,7 +215,7 @@
 # Module:  gotestmain
 # Variant:
 # Type:    bootstrap_core_go_binary
-# Factory: github.com/google/blueprint/bootstrap.func·005
+# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1
 # Defined: Blueprints:132:1
 
 build ${g.bootstrap.buildDir}/.bootstrap/gotestmain/obj/gotestmain.a: $
@@ -228,6 +229,7 @@
         ${g.bootstrap.buildDir}/.bootstrap/gotestmain/obj/gotestmain.a | $
         ${g.bootstrap.linkCmd}
 default ${g.bootstrap.buildDir}/.bootstrap/gotestmain/obj/a.out
+
 build ${g.bootstrap.BinDir}/gotestmain: g.bootstrap.cp $
         ${g.bootstrap.buildDir}/.bootstrap/gotestmain/obj/a.out
 default ${g.bootstrap.BinDir}/gotestmain
@@ -236,7 +238,7 @@
 # Module:  gotestrunner
 # Variant:
 # Type:    bootstrap_core_go_binary
-# Factory: github.com/google/blueprint/bootstrap.func·005
+# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1
 # Defined: Blueprints:137:1
 
 build ${g.bootstrap.buildDir}/.bootstrap/gotestrunner/obj/gotestrunner.a: $
@@ -250,6 +252,7 @@
         ${g.bootstrap.buildDir}/.bootstrap/gotestrunner/obj/gotestrunner.a | $
         ${g.bootstrap.linkCmd}
 default ${g.bootstrap.buildDir}/.bootstrap/gotestrunner/obj/a.out
+
 build ${g.bootstrap.BinDir}/gotestrunner: g.bootstrap.cp $
         ${g.bootstrap.buildDir}/.bootstrap/gotestrunner/obj/a.out
 default ${g.bootstrap.BinDir}/gotestrunner
@@ -258,7 +261,7 @@
 # Module:  minibp
 # Variant:
 # Type:    bootstrap_core_go_binary
-# Factory: github.com/google/blueprint/bootstrap.func·005
+# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModuleFactory.func1
 # Defined: Blueprints:111:1
 
 build ${g.bootstrap.buildDir}/.bootstrap/minibp/obj/minibp.a: $
@@ -287,7 +290,7 @@
 
 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 # Singleton: bootstrap
-# Factory:   github.com/google/blueprint/bootstrap.func·012
+# Factory:   github.com/google/blueprint/bootstrap.newSingletonFactory.func1
 
 rule s.bootstrap.primarybp
     command = ${g.bootstrap.BinDir}/minibp --build-primary ${runTests} -m ${g.bootstrap.bootstrapManifest} --timestamp ${timestamp} --timestampdep ${timestampdep} -b ${g.bootstrap.buildDir} -d ${outfile}.d -o ${outfile} ${in}
@@ -316,8 +319,10 @@
         s.bootstrap.minibp ${g.bootstrap.srcDir}/Blueprints | $
         ${g.bootstrap.bootstrapManifest} ${g.bootstrap.BinDir}/minibp
 default ${g.bootstrap.buildDir}/.bootstrap/bootstrap.ninja.in
+
 build ${g.bootstrap.buildDir}/.bootstrap/notAFile: phony
 default ${g.bootstrap.buildDir}/.bootstrap/notAFile
+
 build ${g.bootstrap.buildDir}/.bootstrap/build.ninja.in: $
         g.bootstrap.chooseStage $
         ${g.bootstrap.buildDir}/.bootstrap/bootstrap.ninja.in $
diff --git a/context.go b/context.go
index e45c237..a20de91 100644
--- a/context.go
+++ b/context.go
@@ -2144,6 +2144,23 @@
 	c.visitDepsDepthFirstIf(c.moduleInfo[module], pred, visit)
 }
 
+func (c *Context) PrimaryModule(module Module) Module {
+	return c.moduleInfo[module].group.modules[0].logicModule
+}
+
+func (c *Context) FinalModule(module Module) Module {
+	modules := c.moduleInfo[module].group.modules
+	return modules[len(modules)-1].logicModule
+}
+
+func (c *Context) VisitAllModuleVariants(module Module,
+	visit func(Module)) {
+
+	for _, module := range c.moduleInfo[module].group.modules {
+		visit(module.logicModule)
+	}
+}
+
 // WriteBuildFile writes the Ninja manifeset text for the generated build
 // actions to w.  If this is called before PrepareBuildActions successfully
 // completes then ErrBuildActionsNotReady is returned.
diff --git a/ninja_defs.go b/ninja_defs.go
index 0919ea4..a49d309 100644
--- a/ninja_defs.go
+++ b/ninja_defs.go
@@ -354,7 +354,7 @@
 		nw.Default(outputs...)
 	}
 
-	return nil
+	return nw.BlankLine()
 }
 
 func valueList(list []*ninjaString, pkgNames map[*PackageContext]string,
diff --git a/singleton_ctx.go b/singleton_ctx.go
index e982086..c4c0b6c 100644
--- a/singleton_ctx.go
+++ b/singleton_ctx.go
@@ -49,6 +49,11 @@
 	VisitDepsDepthFirstIf(module Module, pred func(Module) bool,
 		visit func(Module))
 
+	VisitAllModuleVariants(module Module, visit func(Module))
+
+	PrimaryModule(module Module) Module
+	FinalModule(module Module) Module
+
 	AddNinjaFileDeps(deps ...string)
 }
 
@@ -166,6 +171,18 @@
 	s.context.VisitDepsDepthFirstIf(module, pred, visit)
 }
 
+func (s *singletonContext) PrimaryModule(module Module) Module {
+	return s.context.PrimaryModule(module)
+}
+
+func (s *singletonContext) FinalModule(module Module) Module {
+	return s.context.FinalModule(module)
+}
+
+func (s *singletonContext) VisitAllModuleVariants(module Module, visit func(Module)) {
+	s.context.VisitAllModuleVariants(module, visit)
+}
+
 func (s *singletonContext) AddNinjaFileDeps(deps ...string) {
 	s.ninjaFileDeps = append(s.ninjaFileDeps, deps...)
 }