aboutsummaryrefslogtreecommitdiff
path: root/tools/make_readme.py
blob: 29fc817776c1bc5365619e81f9a6adf00c607384 (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
141
142
143
144
145
146
# Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
# reserved. Use of this source code is governed by a BSD-style license that
# can be found in the LICENSE file.

from __future__ import absolute_import
from __future__ import print_function
from date_util import *
from file_util import *
from optparse import OptionParser
import os
import re
from readme_util import read_readme_file
import shlex
import subprocess
import git_util as git
import sys
import zipfile


def get_readme_component(name):
  """ Loads a README file component. """
  paths = []
  # platform directory
  paths.append(os.path.join(script_dir, 'distrib', platform))

  # shared directory
  paths.append(os.path.join(script_dir, 'distrib'))

  # load the file if it exists
  for path in paths:
    file = os.path.join(path, 'README.' + name + '.txt')
    if path_exists(file):
      return read_file(file)

  raise Exception('Readme component not found: ' + name)


def create_readme():
  """ Creates the README.TXT file. """
  # gather the components
  header_data = get_readme_component('header')
  mode_data = get_readme_component('standard')
  redistrib_data = get_readme_component('redistrib')
  footer_data = get_readme_component('footer')

  # format the file
  data = header_data + '\n\n' + mode_data + '\n\n' + redistrib_data + '\n\n' + footer_data
  data = data.replace('$JCEF_URL$', jcef_url)
  data = data.replace('$JCEF_REV$', jcef_commit_hash)
  data = data.replace('$JCEF_VER$', jcef_ver)
  data = data.replace('$CEF_URL$', cef_url)
  data = data.replace('$CEF_VER$', cef_ver)
  data = data.replace('$CHROMIUM_URL$', chromium_url)
  data = data.replace('$CHROMIUM_VER$', chromium_ver)
  data = data.replace('$DATE$', date)

  if platform == 'win32':
    platform_str = 'Windows 32-bit'
  elif platform == 'win64':
    platform_str = 'Windows 64-bit'
  elif platform == 'macosx64':
    platform_str = 'Mac OS-X 64-bit'
  elif platform == 'linux32':
    platform_str = 'Linux 32-bit'
  elif platform == 'linux64':
    platform_str = 'Linux 64-bit'

  data = data.replace('$PLATFORM$', platform_str)

  write_file(os.path.join(output_dir, 'README.txt'), data.encode('utf-8'))
  if not options.quiet:
    sys.stdout.write('Creating README.TXT file.\n')


# cannot be loaded as a module
if __name__ != "__main__":
  sys.stderr.write('This file cannot be loaded as a module!')
  sys.exit()

# parse command-line options
disc = """
This utility builds the JCEF README.txt for the distribution.
"""

parser = OptionParser(description=disc)
parser.add_option(
    '--output-dir',
    dest='outputdir',
    metavar='DIR',
    help='output directory [required]')
parser.add_option(
    '--platform',
    dest='platform',
    help='target platform for distribution [required]')
parser.add_option(
    '-q',
    '--quiet',
    action='store_true',
    dest='quiet',
    default=False,
    help='do not output detailed status information')
(options, args) = parser.parse_args()

# the outputdir option is required
if options.outputdir is None or options.platform is None:
  parser.print_help(sys.stderr)
  sys.exit(1)
output_dir = options.outputdir

# Test the operating system.
platform = options.platform
if (platform != 'linux32' and platform != 'linux64' and
    platform != 'macosx64' and platform != 'win32' and platform != 'win64'):
  print('Unsupported target \"' + platform + '\"')
  sys.exit(1)

# script directory
script_dir = os.path.dirname(__file__)

# JCEF root directory
jcef_dir = os.path.abspath(os.path.join(script_dir, os.pardir))

# Read and parse the CEF version file.
args = {}
read_readme_file(os.path.join(jcef_dir, 'jcef_build', 'README.txt'), args)

# retrieve url and revision information for CEF
if not git.is_checkout(jcef_dir):
  raise Exception('Not a valid checkout: %s' % (jcef_dir))

jcef_commit_number = git.get_commit_number(jcef_dir)
jcef_commit_hash = git.get_hash(jcef_dir)
jcef_url = git.get_url(jcef_dir)
jcef_ver = '%s.%s.%s.%s+g%s' % (args['CEF_MAJOR'], args['CEF_MINOR'],
                                args['CEF_PATCH'], jcef_commit_number,
                                jcef_commit_hash[:7])

date = get_date()

cef_ver = args['CEF_VER']
cef_url = args['CEF_URL']
chromium_ver = args['CHROMIUM_VER']
chromium_url = args['CHROMIUM_URL']

# create the README.TXT file
create_readme()