Check that local, top level, and exported include paths exist

Require directories listed in the include_dirs, local_include_dirs, and
exported_include_dirs properties to exist.

Change-Id: I5b079bd2c607839bb28dae43801cd7345bde2299
diff --git a/cc/cc.go b/cc/cc.go
index a928312..61e2568 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -404,6 +404,9 @@
 	}
 
 	// Include dir cflags
+	common.CheckSrcDirsExist(ctx, c.Properties.Include_dirs, "include_dirs")
+	common.CheckModuleSrcDirsExist(ctx, c.Properties.Local_include_dirs, "local_include_dirs")
+
 	rootIncludeDirs := pathtools.PrefixPaths(c.Properties.Include_dirs, ctx.AConfig().SrcDir())
 	localIncludeDirs := pathtools.PrefixPaths(c.Properties.Local_include_dirs, common.ModuleSrcDir(ctx))
 	flags.GlobalFlags = append(flags.GlobalFlags,
@@ -1096,6 +1099,8 @@
 
 	c.objFiles = objFiles
 	c.out = outputFile
+
+	common.CheckModuleSrcDirsExist(ctx, c.Properties.Export_include_dirs, "export_include_dirs")
 	includeDirs := pathtools.PrefixPaths(c.Properties.Export_include_dirs, common.ModuleSrcDir(ctx))
 	c.exportFlags = []string{includeDirsToFlags(includeDirs)}
 
diff --git a/common/paths.go b/common/paths.go
index bcd6d8c..070662a 100644
--- a/common/paths.go
+++ b/common/paths.go
@@ -16,6 +16,7 @@
 
 import (
 	"path/filepath"
+	"os"
 )
 
 // ModuleOutDir returns the path to the module-specific output directory.
@@ -74,3 +75,33 @@
 func ModuleJSCompiledDir(ctx AndroidModuleContext) string {
 	return filepath.Join(ModuleOutDir(ctx), "js")
 }
+
+// CheckModuleSrcDirsExist logs an error on a property if any of the directories relative to the
+// Blueprints file don't exist.
+func CheckModuleSrcDirsExist(ctx AndroidModuleContext, dirs []string, prop string) {
+	for _, dir := range dirs {
+		fullDir := filepath.Join(ModuleSrcDir(ctx), dir)
+		if _, err := os.Stat(fullDir); err != nil {
+			if os.IsNotExist(err) {
+				ctx.PropertyErrorf(prop, "module source directory %q does not exist", dir)
+			} else {
+				ctx.PropertyErrorf(prop, "%s", err.Error())
+			}
+		}
+	}
+}
+
+// CheckModuleSrcDirsExist logs an error on a property if any of the directories relative to the
+// top of the source tree don't exist.
+func CheckSrcDirsExist(ctx AndroidModuleContext, dirs []string, prop string) {
+	for _, dir := range dirs {
+		fullDir := filepath.Join(ctx.AConfig().SrcDir(), dir)
+		if _, err := os.Stat(fullDir); err != nil {
+			if os.IsNotExist(err) {
+				ctx.PropertyErrorf(prop, "top-level source directory %q does not exist", dir)
+			} else {
+				ctx.PropertyErrorf(prop, "%s", err.Error())
+			}
+		}
+	}
+}