Skip to content

Commit d0844b1

Browse files
committed
Fix and enhance tools for Linux (cztomczak#327)...
Add 32-bit support to automate.py. Fix build.py and build_distrib.py on Linux. Run unit tests in build_distrib.py after wheel package was installed.
1 parent 0c8a3b0 commit d0844b1

File tree

7 files changed

+237
-152
lines changed

7 files changed

+237
-152
lines changed

docs/Build-instructions.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ requirements common for all platforms.
204204
[cef/BuildingOnDebian7.md](https://bitbucket.org/chromiumembedded/cef/wiki/BuildingOnDebian7.md) and
205205
[cef/#1575](https://bitbucket.org/chromiumembedded/cef/issues/1575),
206206
and [cef/#1697](https://bitbucket.org/chromiumembedded/cef/issues/1697)
207+
* If building CEF from sources, 32-bit on 64-bit machine:
208+
* Follow the configuration [here](https://bitbucket.org/chromiumembedded/cef/wiki/AutomatedBuildSetup.md#markdown-header-linux-configuration)
207209
* To perform a 32-bit Linux build on a 64-bit Linux system see
208210
Linux configuration in upstream cef/AutomatedBuildSetup.md. See also
209211
[cef/#1804](https://bitbucket.org/chromiumembedded/cef/issues/1804).
@@ -311,14 +313,15 @@ On Linux if there are errors about missing packages or others,
311313
then see solutions in the [Possible errors](#possible-errors) section.
312314

313315
The commands below will build CEF from sources with custom CEF Python
314-
patches applied and then build the CEF Python package (xx.x is version
315-
number):
316+
patches applied and then build the CEF Python package. "xx.x" is version
317+
number and "ninja-jobs 4" means to run 4 parallel jobs for compiling,
318+
increase it if you have more CPU cores and want things to build faster:
316319
```
317320
git clone https://github.com/cztomczak/cefpython.git
318321
cd cefpython/
319322
mkdir build/
320323
cd build/
321-
python ../tools/automate.py --build-cef --ninja-jobs 6
324+
python ../tools/automate.py --build-cef --ninja-jobs 4
322325
python ../tools/build.py xx.x
323326
```
324327

src/compile_time_constants.pxi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# This file was generated by setup.py
2-
DEF UNAME_SYSNAME = "Windows"
2+
DEF UNAME_SYSNAME = "Linux"
33
DEF PY_MAJOR_VERSION = 3

tools/automate.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
Prepares CEF binaries and libraries for work with the build.py tool.
77
88
Option 1 is to build CEF from sources with the CEF Python patches applied
9-
using the --build-cef flag.
9+
using the --build-cef flag. Building CEF from sources is supported only
10+
on 64-bit systems. 32-bit is also built on 64-bit using cross-compiling.
11+
Note that building CEF from sources was last tested with v56 on Linux
12+
and with v50 on Windows, so if there are issues report them on the Forum.
1013
1114
Option 2 is to use CEF binaries from Spotify Automated Builds using
1215
the --prebuilt-cef flag. In such case check the cefpython/src/version/
@@ -22,6 +25,7 @@
2225
2326
Usage:
2427
automate.py (--prebuilt-cef | --build-cef)
28+
[--x86 X86]
2529
[--fast-build FAST_BUILD]
2630
[--force-chromium-update FORCE_CHROMIUM_UPDATE]
2731
[--no-cef-update NO_CEF_UPDATE]
@@ -37,6 +41,7 @@
3741
binaries for Linux are built on Ubuntu.
3842
--build-cef Whether to build CEF from sources with the
3943
cefpython patches applied.
44+
--x86 Build 32-bit CEF on 64-bit system
4045
--fast-build Fast build with is_official_build=False
4146
--force-chromium-update Force Chromium update (gclient sync etc).
4247
--no-cef-update Do not update CEF sources (by default both cef/
@@ -82,6 +87,7 @@ class Options(object):
8287
# From command-line
8388
prebuilt_cef = False
8489
build_cef = False
90+
x86 = False
8591
fast_build = False
8692
force_chromium_update = False
8793
no_cef_update = False
@@ -223,17 +229,20 @@ def prebuilt_cef():
223229
# eg. tag 'upstream-cef47'.
224230

225231
# Find cef_binary directory in the build directory
232+
postfix2 = CEF_POSTFIX2
233+
if Options.x86:
234+
postfix2 = get_cef_postfix2_for_arch("32bit")
226235
if Options.cef_version:
227236
cef_binary = os.path.join(Options.build_dir,
228237
"cef_binary_{cef_version}_{os}{sep}"
229238
.format(cef_version=Options.cef_version,
230-
os=CEF_POSTFIX2,
239+
os=postfix2,
231240
sep=os.sep))
232241
else:
233242
cef_binary = os.path.join(Options.build_dir,
234243
"cef_binary_3.{cef_branch}.*_{os}{sep}"
235244
.format(cef_branch=Options.cef_branch,
236-
os=CEF_POSTFIX2,
245+
os=postfix2,
237246
sep=os.sep))
238247
dirs = glob.glob(cef_binary)
239248
if len(dirs) == 1:
@@ -336,8 +345,11 @@ def build_cef_projects():
336345
cef_binary = symbols.replace("_debug_symbols", "")
337346
assert "symbols" not in os.path.basename(cef_binary)
338347
else:
348+
postfix2 = CEF_POSTFIX2
349+
if Options.x86:
350+
postfix2 = get_cef_postfix2_for_arch("32bit")
339351
files = glob.glob(os.path.join(Options.binary_distrib,
340-
"cef_binary_*_"+OS_POSTFIX2))
352+
"cef_binary_*_"+postfix2))
341353
assert len(files) == 1, "Error finding binary distrib"
342354
cef_binary = files[0]
343355
assert os.path.exists(cef_binary)
@@ -832,7 +844,6 @@ def getenv():
832844
# GN configuration
833845
env["CEF_USE_GN"] = "1"
834846
# Issue #73 patch applied here with "use_allocator=none"
835-
# TODO: 32-bit GN defines: host_arch=x86_64 target_arch=ia32
836847
env["GN_DEFINES"] = "use_sysroot=true use_allocator=none symbol_level=1"
837848
# env["GN_DEFINES"] += " use_gtk3=false"
838849
# To perform an official build set GYP_DEFINES=buildtype=Official.
@@ -845,7 +856,8 @@ def getenv():
845856
# upstream Linux configuration on AutomatedBuildSetup wiki page,
846857
# so setting it here as well.
847858
env["GYP_DEFINES"] = "disable_nacl=1 use_sysroot=1 use_allocator=none"
848-
# Note: 32-bit GYP defines: host_arch=x86_64 target_arch=ia32
859+
if Options.x86:
860+
env["GYP_DEFINES"] += " host_arch=x86_64 target_arch=ia32"
849861
if Options.release_build and not Options.fast_build:
850862
env["GYP_DEFINES"] += " buildtype=Official"
851863

@@ -872,8 +884,7 @@ def run_command(command, working_dir, env=None):
872884
args = command
873885
if not env:
874886
env = getenv()
875-
return subprocess.check_call(args, cwd=working_dir, env=env,
876-
shell=(platform.system() == "Windows"))
887+
return subprocess.check_call(args, cwd=working_dir, env=env, shell=True)
877888

878889

879890
def run_git(command_line, working_dir):
@@ -893,7 +904,7 @@ def run_automate_git():
893904
ninja -v -j2 -Cout\Release cefclient
894905
"""
895906
args = []
896-
if ARCH64:
907+
if ARCH64 and not Options.x86:
897908
args.append("--x64-build")
898909
args.append("--download-dir=" + Options.cef_build_dir)
899910
args.append("--branch=" + Options.cef_branch)
@@ -972,10 +983,13 @@ def get_prebuilt_name(header_file=""):
972983
version = get_version_from_file(header_file)
973984
else:
974985
version = get_cefpython_version()
986+
postfix2 = OS_POSTFIX2
987+
if Options.x86:
988+
postfix2 = get_os_postfix2_for_arch("32bit")
975989
name = "cef%s_%s_%s" % (
976990
version["CHROME_VERSION_MAJOR"],
977991
version["CEF_VERSION"],
978-
OS_POSTFIX2,
992+
postfix2
979993
)
980994
return name
981995

tools/build.py

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,8 @@ def fix_cefpython_api_header_file():
313313

314314
# Pragma fix on Windows
315315
if WINDOWS:
316-
already_fixed = False
317316
pragma = "#pragma warning(disable:4190)"
318317
if pragma in contents:
319-
already_fixed = True
320318
print("[build.py] cefpython API header file is already fixed")
321319
else:
322320
contents = ("%s\n\n" % pragma) + contents
@@ -701,18 +699,11 @@ def build_cefpython_module():
701699

702700
os.chdir(BUILD_CEFPYTHON)
703701

702+
command = ("\"{python}\" {tools_dir}/cython_setup.py build_ext"
703+
.format(python=sys.executable, tools_dir=TOOLS_DIR))
704704
if FAST_FLAG:
705-
ret = subprocess.call("\"{python}\" {tools_dir}/cython_setup.py"
706-
" build_ext --fast"
707-
.format(python=sys.executable,
708-
tools_dir=TOOLS_DIR),
709-
shell=True)
710-
else:
711-
ret = subprocess.call("\"{python}\" {tools_dir}/cython_setup.py"
712-
" build_ext"
713-
.format(python=sys.executable,
714-
tools_dir=TOOLS_DIR),
715-
shell=True)
705+
command += " --fast"
706+
ret = subprocess.call(command, shell=True)
716707

717708
# if DEBUG_FLAG:
718709
# shutil.rmtree("./../binaries_%s/cython_debug/" % BITS,
@@ -741,7 +732,8 @@ def build_cefpython_module():
741732
args.append(os.path.join(TOOLS_DIR, os.path.basename(__file__)))
742733
assert __file__ in sys.argv[0]
743734
args.extend(sys.argv[1:])
744-
ret = subprocess.call(" ".join(args), shell=True)
735+
command = " ".join(args)
736+
ret = subprocess.call(command, shell=True)
745737
sys.exit(ret)
746738
else:
747739
print("[build.py] ERROR: failed to build the cefpython module")
@@ -806,19 +798,22 @@ def install_and_run():
806798
# Make setup installer
807799
print("[build.py] Make setup installer")
808800
make_tool = os.path.join(TOOLS_DIR, "make_installer.py")
809-
ret = os.system("\"{python}\" {make_tool} --version {version}"
810-
.format(python=sys.executable,
811-
make_tool=make_tool,
812-
version=VERSION))
801+
command = ("\"{python}\" {make_tool} --version {version}"
802+
.format(python=sys.executable,
803+
make_tool=make_tool,
804+
version=VERSION))
805+
ret = os.system(command)
813806
if ret != 0:
814807
print("[build.py] ERROR while making installer package")
815808
sys.exit(ret)
816809

817810
# Install
818811
print("[build.py] Install the cefpython package")
819812
os.chdir(setup_installer_dir)
820-
ret = os.system("{sudo} \"{python}\" setup.py install"
821-
.format(sudo=get_sudo(), python=sys.executable))
813+
command = ("\"{python}\" setup.py install"
814+
.format(python=sys.executable))
815+
command = sudo_command(command, python=sys.executable)
816+
ret = os.system(command)
822817
if ret != 0:
823818
print("[build.py] ERROR while installing package")
824819
sys.exit(ret)
@@ -830,8 +825,10 @@ def install_and_run():
830825
# Run unittests
831826
print("[build.py] Run unittests")
832827
test_runner = os.path.join(UNITTESTS_DIR, "_test_runner.py")
833-
ret = os.system("\"{python}\" {test_runner}"
834-
.format(python=sys.executable, test_runner=test_runner))
828+
command = ("\"{python}\" {test_runner}"
829+
.format(python=sys.executable,
830+
test_runner=test_runner))
831+
ret = os.system(command)
835832
if ret != 0:
836833
print("[build.py] ERROR while running unit tests")
837834
sys.exit(ret)
@@ -842,26 +839,18 @@ def install_and_run():
842839
os.chdir(EXAMPLES_DIR)
843840
kivy_flag = "--kivy" if KIVY_FLAG else ""
844841
run_examples = os.path.join(TOOLS_DIR, "run_examples.py")
845-
ret = os.system("\"{python}\" {run_examples} {kivy_flag}"
846-
.format(python=sys.executable,
847-
run_examples=run_examples,
848-
kivy_flag=kivy_flag))
842+
command = ("\"{python}\" {run_examples} {kivy_flag}"
843+
.format(python=sys.executable,
844+
run_examples=run_examples,
845+
kivy_flag=kivy_flag))
846+
ret = os.system(command)
849847
if ret != 0:
850848
print("[build.py] ERROR while running examples")
851849
sys.exit(1)
852850

853851
print("[build.py] Everything OK")
854852

855853

856-
def get_sudo():
857-
# System Python requires sudo when installing package
858-
if sys.executable.startswith("/usr/"):
859-
sudo = "sudo"
860-
else:
861-
sudo = ""
862-
return sudo
863-
864-
865854
def delete_directory_reliably(adir):
866855
assert len(adir) > 2
867856
assert os.path.isdir(adir)
@@ -873,8 +862,9 @@ def delete_directory_reliably(adir):
873862
# On Linux sudo might be required to delete directory, as this
874863
# might be a setup installer directory with package installed
875864
# using sudo and in such case files were created with sudo.
876-
os.system("{sudo} rm -rf {dir}"
877-
.format(sudo=get_sudo(), dir=adir))
865+
command = "rm -rf {dir}".format(dir=adir)
866+
command = sudo_command(command, python=sys.executable)
867+
os.system(command)
878868

879869

880870
if __name__ == "__main__":

0 commit comments

Comments
 (0)