summaryrefslogtreecommitdiff
path: root/deps/gyp/test/win/generator-output-different-drive/gyptest-generator-output-different-drive.py
blob: 8c8c365d5ee81a4de98ca0785068647fa877b37c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python

# Copyright (c) 2013 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""
Test that the generator output can be written to a different drive on Windows.
"""

import os
import TestGyp
import string
import subprocess
import sys


if sys.platform == 'win32':
  import win32api

  test = TestGyp.TestGyp(formats=['msvs', 'ninja'])

  def GetFirstFreeDriveLetter():
    """ Returns the first unused Windows drive letter in [A, Z] """
    all_letters = [c for c in string.uppercase]
    in_use = win32api.GetLogicalDriveStrings()
    free = list(set(all_letters) - set(in_use))
    return free[0]

  output_dir = os.path.join('different-drive', 'output')
  if not os.path.isdir(os.path.abspath(output_dir)):
    os.makedirs(os.path.abspath(output_dir))
  output_drive = GetFirstFreeDriveLetter()
  subprocess.call(['subst', '%c:' % output_drive, os.path.abspath(output_dir)])
  try:
    test.run_gyp('prog.gyp', '--generator-output=%s' % (
        os.path.join(output_drive, 'output')))
    test.build('prog.gyp', test.ALL, chdir=os.path.join(output_drive, 'output'))
    test.built_file_must_exist('program', chdir=os.path.join(output_drive,
                                                             'output'),
                               type=test.EXECUTABLE)
    test.pass_test()
  finally:
    subprocess.call(['subst', '%c:' % output_drive, '/D'])