Replace bash build script with python script.

This is for cross platform support. gyp_packager.py is modified
from build/gyp_chromium and adapted to packager code.

New build instructions:

1. Setup gyp: ./gyp_packager.py

clang is not enabled by default, which can be enabled by overriding
GYP_DEFINE environment variable, i.e. "GYP_DEFINES='clang=1
use_openssl=1' ./gyp_packager.py".

Ninja is the default build system. User can also change to make by
overriding GYP_GENERATORS to make, i.e. "GYP_GENERATORS='make'
./gyp_packager.py".

2. The first step generates the make files but does not start the
build process. Ninja is the default build system. Refer to Ninja
manual on how to do the build.

Common syntaxes: ninja -C out/{Debug/Release} [Module]
Module is optional. If not specified, build everything.

Step 1 is only required if there is any gyp file change. Otherwise, you
may just run ninja.

Change-Id: I89cade7278bfdd3992644457e896e5a10085568b
This commit is contained in:
Kongqun Yang 2014-02-13 19:03:12 -08:00 committed by KongQun Yang
parent d4a3b6c520
commit 859da912fc
2 changed files with 76 additions and 52 deletions

View File

@ -1,52 +0,0 @@
#!/bin/bash
#
# 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.
#
# ./build.sh {BuildType} {Module}
#
# The two parameters are optional, e.g.
#
# ./build.sh # build all modules in Debug mode.
# ./build.sh Release # build all modules in Release mode.
# ./build.sh Debug mp4 # build mp4 module in Debug mode.
#
# We use Ninja from Chrome to build our code. It's very very fast.
#
# A re-run of build.sh is required if there is any GYP file or build type
# change. Otherwise, you may just run Ninja directly:
#
# ninja -C out/Debug {Module} # Again, Module is optional.
# ninja -C out/Release {Module} # Again, Module is optional.
set -e
function setup_packager_env() {
if [ $# -lt 1 ]; then
local type="Debug"
else
local type="$1"
if [[ "${type}" != "Release" &&
"${type}" != "Debug" ]]; then
echo "Incorrect BUILDTYPE ${type}"
return
fi
fi
# Note: You'd have to run ./tools/clang/scripts/update.sh before you run GYP
# with clang=1 flag.
export GYP_DEFINES="clang=1 use_openssl=1"
export BUILDTYPE="${type}"
export BUILD_OUT="."
export GYP_GENERATOR_FLAGS="output_dir=${BUILD_OUT}"
tools/gyp/gyp --depth=. --generator-output=out -I build/common.gypi --no-circular-check packager.gyp
}
export GYP_GENERATORS="ninja"
setup_packager_env $@
# Note: If this fails due to some error about "not having clang", read the note
# above.
ninja -C "out/${BUILDTYPE}" $2

76
gyp_packager.py Executable file
View File

@ -0,0 +1,76 @@
#!/usr/bin/env python
#
# Copyright 2014 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 or at
# https://developers.google.com/open-source/licenses/bsd
#
# This script is a wrapper for Packager that adds some support for how GYP
# is invoked by Packager.
#
# Build instructions:
#
# 1. Setup gyp: ./gyp_packager.py
#
# clang is not enabled by default, which can be enabled by overriding
# GYP_DEFINE environment variable, i.e. "GYP_DEFINES='clang=1
# use_openssl=1' ./gyp_packager.py".
#
# Ninja is the default build system. User can also change to make by
# overriding GYP_GENERATORS to make, i.e. "GYP_GENERATORS='make'
# ./gyp_packager.py".
#
# 2. The first step generates the make files but does not start the
# build process. Ninja is the default build system. Refer to Ninja
# manual on how to do the build.
#
# Common syntaxes: ninja -C out/{Debug/Release} [Module]
# Module is optional. If not specified, build everything.
#
# Step 1 is only required if there is any gyp file change. Otherwise, you
# may just run ninja.
import os
import sys
src_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.join(src_dir, 'tools', 'gyp', 'pylib'))
import gyp
if __name__ == '__main__':
args = sys.argv[1:]
# If we didn't get a gyp file, then fall back to assuming 'packager.gyp' from
# the same directory as the script.
if [arg.endswith('.gyp') for arg in args].count(True) == 0:
args.append(os.path.join(src_dir, 'packager.gyp'))
# Always include common.gypi.
args.extend(['-I' + os.path.join(src_dir, 'build/common.gypi')])
# Gyp should run from current directory.
args.append('--depth=.')
# Set GYP_DEFINES if it is not explicitly set yet.
if not os.environ.get('GYP_DEFINES'):
os.environ['GYP_DEFINES'] = 'use_openssl=1'
# 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.
if sys.platform not in ('darwin',):
args.append('--no-circular-check')
# Default to ninja, but only if no generator has explicitly been set.
if not os.environ.get('GYP_GENERATORS'):
os.environ['GYP_GENERATORS'] = 'ninja'
print 'Updating projects from gyp files...'
sys.stdout.flush()
# Off we go...
sys.exit(gyp.main(args))