summaryrefslogtreecommitdiffstats
path: root/webkit/build/webkit_version.py
blob: 93def61317a9b59fb3c596227852ad975cd32c64 (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
#!/usr/bin/env python
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

'''Emits a webkit_version.h header file with
WEBKIT_MAJOR_VERSION and WEBKIT_MINOR_VERSION macros.
'''

import os
import re
import sys

# Get the full path of the current script which would be something like
# src/webkit/build/webkit_version.py and navigate backwards twice to strip the
# last two path components to get to the srcroot.
# This is to ensure that the script can load the lastchange module by updating
# the sys.path variable with the desired location.
path = os.path.dirname(os.path.realpath(__file__))
path = os.path.dirname(os.path.dirname(path))
path = os.path.join(path, 'build', 'util')

sys.path.insert(0, path)
import lastchange


def GetWebKitRevision(webkit_src_dir):
  """Get the WebKit revision, in the form 'trunk@1234'."""

  version_info = lastchange.FetchVersionInfo(
      default_lastchange=None,
      directory=webkit_src_dir,
      directory_regex_prior_to_src_url='webkit')

  if version_info.url == None:
    version_info.url = 'Unknown URL'
  version_info.url = version_info.url.strip('/')

  if version_info.revision == None:
    version_info.revision = '0'

  return "%s@%s" % (version_info.url, version_info.revision)


def EmitVersionHeader(webkit_src_dir, output_dir):
  '''Emit a header file that we can use from within webkit_glue.cc.'''

  # These are hard-coded from when we forked Blink. Presumably these
  # would be better in a header somewhere.
  major, minor = (537, 36)
  webkit_revision = GetWebKitRevision(webkit_src_dir)

  fname = os.path.join(output_dir, "webkit_version.h")
  f = open(fname, 'wb')
  template = """// webkit_version.h
// generated from %s

#define WEBKIT_VERSION_MAJOR %d
#define WEBKIT_VERSION_MINOR %d
#define WEBKIT_SVN_REVISION "%s"
""" % (webkit_src_dir, major, minor, webkit_revision)
  f.write(template)
  f.close()
  return 0


def main():
  return EmitVersionHeader(*sys.argv[1:])


if __name__ == "__main__":
  sys.exit(main())