summaryrefslogtreecommitdiffstats
path: root/gyp_blinq
blob: e98e3e8abc80774848ea550744a25ab9627b09f6 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python

import glob
import os
import subprocess
import sys

#FIXME(pierre): mandatory until we have a git submodule, for now we can't guess where the chromium checkout lives.
if "CHROMIUM_SRC_DIR" not in os.environ:
  print "Please set the environment variable CHROMIUM_SRC_DIR to point to your checkout of chromium's 'src' directory"
  sys.exit(1)

chrome_src = os.path.abspath(os.environ.get('CHROMIUM_SRC_DIR'));
script_dir = os.path.abspath(os.path.join(chrome_src, 'build'));
if not os.path.isdir(script_dir):
  print script_dir + " is not a valid directory"
  sys.exit(1)

sys.path.insert(0, script_dir)
import gyp_helper
sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
import gyp

# Add paths so that pymod_do_main(...) can import files.
sys.path.insert(1, os.path.join(chrome_src, 'tools', 'grit'))
sys.path.insert(1, os.path.join(chrome_src, 'third_party', 'WebKit',
    'Source', 'WebCore', 'WebCore.gyp', 'scripts'))
sys.path.insert(1, os.path.join(chrome_src, 'chrome', 'tools', 'build'))

import repack_locales

def additional_include_files(args=[]):
  """
  Returns a list of additional (.gypi) files to include, without
  duplicating ones that are already specified on the command line.
  """
  # Determine the include files specified on the command line.
  # This doesn't cover all the different option formats you can use,
  # but it's mainly intended to avoid duplicating flags on the automatic
  # makefile regeneration which only uses this format.
  specified_includes = set()
  for arg in args:
    if arg.startswith('-I') and len(arg) > 2:
      specified_includes.add(os.path.realpath(arg[2:]))

  result = []
  def AddInclude(path):
    if os.path.realpath(path) not in specified_includes:
      result.append(path)

  # Always include common.gypi.
  AddInclude(os.path.join(script_dir, 'common.gypi'))

  # Optionally add supplemental .gypi files if present.
  supplements = glob.glob(os.path.join(chrome_src, '*', 'supplement.gypi'))
  for supplement in supplements:
    AddInclude(supplement)

  return result

# TODO: later we probably want to hook that up with qmake to allow shadow builds. (Might not play nice with the rest of chromium though)
def get_output_dir():
  outdir = os.path.join(os.getcwd(), "out") # Hardcode for now
  if not os.path.isdir(outdir):
    os.mkdir(outdir)

  return outdir

if __name__ == '__main__':
  args = sys.argv[1:]

  gyp_helper.apply_chromium_gyp_env()

  # This could give false positives since it doesn't actually do real option
  # parsing.  Oh well.
  gyp_file_specified = False
  for arg in args:
    if arg.endswith('.gyp'):
      gyp_file_specified = True
      break

  if not gyp_file_specified:
      args.append(os.path.join(os.getcwd(), 'blinq.gyp'))

  args.extend(['-I' + i for i in additional_include_files(args)])

  # There shouldn't be a circular dependency relationship between .gyp files,
  # but in Chromium's .gyp files, on non-Mac platforms, circular relationships
  # currently exist.  The check for circular dependencies is currently
  # bypassed on other platforms, but is left enabled on the Mac, where a
  # violation of the rule causes Xcode to misbehave badly.
  # TODO(mark): Find and kill remaining circular dependencies, and remove this
  # option.  http://crbug.com/35878.
  # TODO(tc): Fix circular dependencies in ChromiumOS then add linux2 to the
  # list.
  if sys.platform not in ('darwin',):
    args.append('--no-circular-check')

  # QMake detection
  proc = subprocess.Popen(["qmake", "-query"], stdout=subprocess.PIPE)
  out = proc.communicate()[0].split('\n')
  for line in out:
    if line.startswith("QT_INSTALL_LIBS"):
      qt_libs = line.split(':')[1]
    elif line.startswith("QT_INSTALL_HEADERS"):
      qt_headers = line.split(':')[1]
    elif line.startswith("QMAKE_SPEC"):
      qmake_spec = line.split(':')[1]
    elif line.startswith("QT_VERSION"):
      qt_version = line.split(':')[1]
      # FIXME: remove this check once it's move up in the pro file
      if not qt_version.startswith('5'):
        print "Qt 5 is a minimum requirement for Blinq"
        sys.exit(5)

  args.extend(['-D', 'use_aura=1'])
  args.extend(['-D', 'qt_libdir=' + qt_libs])
  args.extend(['-D', 'qt_headers=' + qt_headers])
  args.extend(['-D', 'qmake_spec=' + qmake_spec])
  args.extend(['-D', 'webkit_src_dir=' + chrome_src + '/third_party/WebKit'])
  args.extend(["--depth=" + chrome_src])
  args.extend(['-D', 'chromium_src_dir=' + chrome_src])
  # Tweak the output location and format (hardcode ninja for now)
  args.extend(['--generator-output', os.path.abspath(get_output_dir())])
  args.extend(['-Goutput_dir='+ os.path.abspath(get_output_dir())])
  args.extend(['--format=ninja'])
  if "BLINQ_GYP_DEBUG" in os.environ:
    args.append("--check")
    args.append("-d all")
    print args
    ret_code = gyp.main(args)
    sys.exit(ret_code)

  ###################################

  print 'Updating projects from gyp files...'
  #sys.stdout.flush()

  # Off we go...
  sys.exit(gyp.main(args))