Use gyp.common.EnsureDirExists() in more places.

No intended behavior change.

R=scottmg@chromium.org

Review URL: https://codereview.chromium.org/113463003

git-svn-id: http://gyp.googlecode.com/svn/trunk@1815 78cadc50-ecff-11dd-a971-7dbc132099af
diff --git a/pylib/gyp/generator/android.py b/pylib/gyp/generator/android.py
index 63036bb..41346e2 100644
--- a/pylib/gyp/generator/android.py
+++ b/pylib/gyp/generator/android.py
@@ -145,7 +145,7 @@
       spec, configs: gyp info
       part_of_all: flag indicating this target is part of 'all'
     """
-    make.ensure_directory_exists(output_filename)
+    gyp.common.EnsureDirExists(output_filename)
 
     self.fp = open(output_filename, 'w')
 
@@ -983,7 +983,7 @@
   makefile_path = os.path.join(options.toplevel_dir, makefile_name)
   assert not options.generator_output, (
       'The Android backend does not support options.generator_output.')
-  make.ensure_directory_exists(makefile_path)
+  gyp.common.EnsureDirExists(makefile_path)
   root_makefile = open(makefile_path, 'w')
 
   root_makefile.write(header)
diff --git a/pylib/gyp/generator/cmake.py b/pylib/gyp/generator/cmake.py
index 1611899..10d015e 100644
--- a/pylib/gyp/generator/cmake.py
+++ b/pylib/gyp/generator/cmake.py
@@ -118,13 +118,6 @@
   return os.path.normpath(os.path.join(base_path, rel_path))
 
 
-def EnsureDirectoryExists(path):
-  """Python version of 'mkdir -p'."""
-  dirPath = os.path.dirname(path)
-  if dirPath and not os.path.exists(dirPath):
-    os.makedirs(dirPath)
-
-
 def CMakeStringEscape(a):
   """Escapes the string 'a' for use inside a CMake string.
 
@@ -1041,7 +1034,7 @@
   toplevel_build = os.path.join(options.toplevel_dir, build_dir)
 
   output_file = os.path.join(toplevel_build, 'CMakeLists.txt')
-  EnsureDirectoryExists(output_file)
+  gyp.common.EnsureDirExists(output_file)
 
   output = open(output_file, 'w')
   output.write('cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)\n')
diff --git a/pylib/gyp/generator/eclipse.py b/pylib/gyp/generator/eclipse.py
index a80edc8..84380b0 100644
--- a/pylib/gyp/generator/eclipse.py
+++ b/pylib/gyp/generator/eclipse.py
@@ -270,9 +270,9 @@
   shared_intermediate_dirs = [os.path.join(toplevel_build, 'obj', 'gen'),
                               os.path.join(toplevel_build, 'gen')]
 
-  if not os.path.exists(toplevel_build):
-    os.makedirs(toplevel_build)
-  out = open(os.path.join(toplevel_build, 'eclipse-cdt-settings.xml'), 'w')
+  out_name = os.path.join(toplevel_build, 'eclipse-cdt-settings.xml')
+  gyp.common.EnsureDirExists(out_name)
+  out = open(out_name, 'w')
 
   out.write('<?xml version="1.0" encoding="UTF-8"?>\n')
   out.write('<cdtprojectproperties>\n')
diff --git a/pylib/gyp/generator/make.py b/pylib/gyp/generator/make.py
index d407843..5cf6763 100644
--- a/pylib/gyp/generator/make.py
+++ b/pylib/gyp/generator/make.py
@@ -117,12 +117,6 @@
   }
 
 
-def ensure_directory_exists(path):
-  dir = os.path.dirname(path)
-  if dir and not os.path.exists(dir):
-    os.makedirs(dir)
-
-
 # The .d checking code below uses these functions:
 # wildcard, sort, foreach, shell, wordlist
 # wildcard can handle spaces, the rest can't.
@@ -691,7 +685,7 @@
       spec, configs: gyp info
       part_of_all: flag indicating this target is part of 'all'
     """
-    ensure_directory_exists(output_filename)
+    gyp.common.EnsureDirExists(output_filename)
 
     self.fp = open(output_filename, 'w')
 
@@ -820,7 +814,7 @@
       targets: list of "all" targets for this sub-project
       build_dir: build output directory, relative to the sub-project
     """
-    ensure_directory_exists(output_filename)
+    gyp.common.EnsureDirExists(output_filename)
     self.fp = open(output_filename, 'w')
     self.fp.write(header)
     # For consistency with other builders, put sub-project build output in the
@@ -2067,7 +2061,7 @@
 
   header_params['make_global_settings'] = make_global_settings
 
-  ensure_directory_exists(makefile_path)
+  gyp.common.EnsureDirExists(makefile_path)
   root_makefile = open(makefile_path, 'w')
   root_makefile.write(SHARED_HEADER % header_params)
   # Currently any versions have the same effect, but in future the behavior
diff --git a/pylib/gyp/generator/msvs.py b/pylib/gyp/generator/msvs.py
index c48a953..f9bfcec 100644
--- a/pylib/gyp/generator/msvs.py
+++ b/pylib/gyp/generator/msvs.py
@@ -941,9 +941,7 @@
     generator_flags: dict of generator-specific flags.
   """
   spec = project.spec
-  vcproj_dir = os.path.dirname(project.path)
-  if vcproj_dir and not os.path.exists(vcproj_dir):
-    os.makedirs(vcproj_dir)
+  gyp.common.EnsureDirExists(project.path)
 
   platforms = _GetUniquePlatforms(spec)
   p = MSVSProject.Writer(project.path, version, spec['target_name'],
@@ -3096,9 +3094,7 @@
   spec = project.spec
   configurations = spec['configurations']
   project_dir, project_file_name = os.path.split(project.path)
-  msbuildproj_dir = os.path.dirname(project.path)
-  if msbuildproj_dir and not os.path.exists(msbuildproj_dir):
-    os.makedirs(msbuildproj_dir)
+  gyp.common.EnsureDirExists(project.path)
   # Prepare list of sources and excluded sources.
   gyp_path = _NormalizedSource(project.build_file)
   relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir)
diff --git a/pylib/gyp/input.py b/pylib/gyp/input.py
index 9bc449d..6472912 100644
--- a/pylib/gyp/input.py
+++ b/pylib/gyp/input.py
@@ -822,8 +822,7 @@
           rel_build_file_dir = build_file_dir
         qualified_out_dir = generator_filelist_paths['qualified_out_dir']
         path = os.path.join(qualified_out_dir, rel_build_file_dir, replacement)
-        if not os.path.isdir(os.path.dirname(path)):
-          os.makedirs(os.path.dirname(path))
+        gyp.common.EnsureDirExists(path)
 
       replacement = gyp.common.RelativePath(path, build_file_dir)
       f = gyp.common.WriteOnDiff(path)