Skip to content

Commit

Permalink
Update Servo project and its build environment
Browse files Browse the repository at this point in the history
  • Loading branch information
loki04 committed Apr 20, 2016
1 parent 04a9ea2 commit c4d0ae9
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 47 deletions.
20 changes: 11 additions & 9 deletions gen/servo/compiler.py → bin/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import sys
import subprocess
import os
from csibe import logger

if __name__ == '__main__':
if __name__ == "__main__":
def which_next(program, old):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
Expand All @@ -15,25 +16,25 @@ def is_exe(fpath):
return exe_file
return None

optflags = ['-O', '-O0', '-O1', '-O2', '-O3', '-O4', '-Os', '-Oz']
optflags = ["-O", "-O0", "-O1", "-O2", "-O3", "-O4", "-Os", "-Oz"]

basename = os.path.basename(sys.argv[0])
abspath = os.path.abspath(sys.argv[0])
next = which_next(basename, abspath);
if not next:
logging.error("Missing '" + basename + "' from PATH!")
logger.error("Missing "%s" from PATH!" % basename)
sys.exit(1)

clearopts=False
if basename.endswith("g++") or basename.endswith("clang++"):
flags = os.getenv('CSiBE_CXXFLAGS', '').split()
ext = ['.cxx', '.cpp']
flags = os.getenv("CSiBE_CXXFLAGS", "").split()
ext = [".cxx", ".cpp"]
elif basename.endswith("rustc"):
flags = os.getenv('CSiBE_RUSTCFLAGS', '').split()
ext = ['.rs']
flags = os.getenv("CSiBE_RUSTCFLAGS", "").split()
ext = [".rs"]
else:
flags = os.getenv('CSiBE_CFLAGS', '').split()
ext = ['.c']
flags = os.getenv("CSiBE_CFLAGS", "").split()
ext = [".c"]

if flags and flags[0] == "!":
clearopts = True
Expand Down Expand Up @@ -61,4 +62,5 @@ def is_exe(fpath):
cmd = [next]
cmd.extend(sys.argv[1:])

logger.debug("[Executing] %s" % " ".join(cmd))
sys.exit(subprocess.call(cmd))
1 change: 1 addition & 0 deletions bin/csibe/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
1 change: 1 addition & 0 deletions bin/csibe/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from logger import logger
33 changes: 33 additions & 0 deletions bin/csibe/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import inspect
import logging

"""
CSiBE logging facality
If CSiBE_DEBUG_FILE environmental variable is set all CRITICAL and ERROR
messages will be sent to the required file. Otherwise the messages will be sent
to stdout and stderr.
If CSiBE_DEBUG environmental variable is set to 1 all DEBUG, INFO, WARNING,
ERROR, and CRITICAL messages will be displayed.
Sample usage:
from csibe import logger
logger.error(error_text)
logger.debug(debug_text)
"""

if os.getenv("CSiBE_DEBUG_FILE", ""):
__args = {"filename": os.environ["CSiBE_DEBUG_FILE"], "level": logging.ERROR}
else:
__args = {"level": logging.CRITICAL}
__frame = inspect.stack()[2]
__module = inspect.getmodule(__frame[0])
logging.basicConfig(**__args)

"""The main logger facality for CSiBE"""
logger = logging.getLogger(__module.__file__)

if os.getenv("CSiBE_DEBUG", "") == "1":
logger.setLevel(logging.DEBUG)
11 changes: 5 additions & 6 deletions gen/servo/rustc-wrapper.py → bin/rustc-wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import sys
import subprocess
import os
from csibe import logger

if __name__ == '__main__':
if __name__ == "__main__":
done = False
rsfile = False
addopts = os.getenv('CSiBE_RUSTCFLAGS','').split()
addopts = os.getenv("CSiBE_RUSTCFLAGS","").split()

cmd = ['rustc-orig']
cmd = ["%s-orig" % os.path.abspath(__file__)]

for arg in sys.argv[1:]:
if "--" == arg:
Expand All @@ -22,8 +23,6 @@
if rsfile:
if not done:
cmd.extend(addopts)
else:
cmd = ['rustc-orig']
cmd.extend(sys.argv[1:])

logger.debug("[Executing] %s" % " ".join(cmd))
sys.exit(subprocess.call(cmd))
35 changes: 16 additions & 19 deletions gen/servo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,26 @@ project (servo)
include(${CSiBE_DIR}/cmake/csibe-env.cmake)

set (SIZE_RESULT ${PROJECT_BINARY_DIR}/result.csv)
set (PROJECT_GEN_DIR ${CSiBE_GEN_DIR}/${PROJECT_NAME})
set (CARGO_TARGET_DIR ${PROJECT_BINARY_DIR}/target)

if(NOT EXISTS ${SIZE_RESULT})
set (PROJECT_SOURCE_DIR ${CSiBE_SRC_DIR}/${PROJECT_NAME})
set (PROJECT_GEN_DIR ${CSiBE_GEN_DIR}/${PROJECT_NAME})
set (PROJECT_SOURCE_DIR ${CSiBE_SRC_DIR}/${PROJECT_NAME})

# For build directories
set (ENV{SERVO_CACHE_DIR} ${PROJECT_BINARY_DIR}/.servo)
set (ENV{CARGO_HOME} ${PROJECT_BINARY_DIR}/.cargo)
set (ENV{CARGO_TARGET_DIR} ${CARGO_TARGET_DIR})

# Use wrappers for compilers (native)
set (ENV{CC} ${PROJECT_GEN_DIR}/gcc)
set (ENV{CXX} ${PROJECT_GEN_DIR}/g++)

execute_process(COMMAND ${PROJECT_SOURCE_DIR}/mach bootstrap-rust)
execute_process(COMMAND ${PROJECT_GEN_DIR}/setup-csibe.py ${PROJECT_BINARY_DIR}/.servo)
execute_process(COMMAND ${PROJECT_SOURCE_DIR}/mach bootstrap-cargo)
execute_process(COMMAND ${PROJECT_SOURCE_DIR}/mach build -r -v)
endif(NOT EXISTS ${SIZE_RESULT})
set (SERVO_CACHE_DIR ${PROJECT_BINARY_DIR}/.servo)
set (CARGO_HOME ${PROJECT_BINARY_DIR}/.cargo)
set (CARGO_TARGET_DIR ${PROJECT_BINARY_DIR}/target)

add_custom_target (${PROJECT_NAME}_size
DEPENDS ${SIZE_RESULT})
DEPENDS ${SIZE_RESULT}
COMMAND
CSiBE_BIN_DIR=${CSiBE_BIN_DIR}
PROJECT_BINARY_DIR=${PROJECT_BINARY_DIR}
PROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
PROJECT_GEN_DIR=${PROJECT_GEN_DIR}
SERVO_CACHE_DIR=${SERVO_CACHE_DIR}
CARGO_HOME=${CARGO_HOME}
CARGO_TARGET_DIR=${CARGO_TARGET_DIR}
${PROJECT_GEN_DIR}/build-servo.py
)

add_custom_command (
OUTPUT ${SIZE_RESULT}
Expand Down
40 changes: 40 additions & 0 deletions gen/servo/build-servo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/python

import sys
import subprocess
import os

if __name__ == "__main__":
pbdir = os.environ["PROJECT_BINARY_DIR"]
psdir = os.environ["PROJECT_SOURCE_DIR"]
pgdir = os.environ["PROJECT_GEN_DIR"]

if not pbdir or not psdir or not pgdir:
sys.exit(1)

# For build directories
if "SERVO_CACHE_DIR" not in os.environ:
os.environ["SERVO_CACHE_DIR"] = os.path.join(pbdir, ".servo")

if "CARGO_HOME" not in os.environ:
os.environ["CARGO_HOME"] = os.path.join(pbdir, ".cargo")

if "CARGO_TARGET_DIR" not in os.environ:
os.environ["CARGO_TARGET_DIR"] = os.path.join(pbdir, "target")

# Use wrappers for compilers (native)
if "CC" not in os.environ:
os.environ["CC"] = "gcc"

if "CXX" not in os.environ:
os.environ["CXX"] = "c++"

if os.getenv("CSiBE_DEBUG", "") == "1":
mach_debug = ["-v"]
else:
mach_debug = []

subprocess.call([os.path.join(psdir, "mach"), "bootstrap-rust"])
subprocess.call([os.path.join(pgdir, "setup-csibe.py"), os.path.join(pbdir, ".servo")])
subprocess.call([os.path.join(psdir, "mach"), "bootstrap-cargo"])
subprocess.call([os.path.join(psdir, "mach"), "build", "-r"] + mach_debug)
19 changes: 7 additions & 12 deletions gen/servo/setup-csibe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
import shutil

if __name__ == '__main__':
if __name__ == "__main__":
if len(sys.argv) <= 1:
sys.exit(1)

Expand All @@ -14,30 +14,25 @@
matchdir = None
match = None
for root, dirnames, filenames in os.walk(path):
for filename in fnmatch.filter(filenames, 'rustc'):
for filename in fnmatch.filter(filenames, "rustc"):
matchdir = root
match = os.path.join(root, filename)
break

if not match:
sys.exit(1)

scriptdir = os.path.dirname(os.path.realpath(__file__))
wrapper = os.path.join(scriptdir, 'rustc-wrapper.py')
scriptdir = os.getenv("CSiBE_BIN_DIR", os.path.dirname(os.path.realpath(__file__)))
wrapper = os.path.join(scriptdir, "rustc-wrapper.py")

original = match + "-orig"
if os.path.isfile(original):
sys.exit(0)

os.rename(match, original)
shutil.copy2(wrapper, match)

# compilers
for compiler in ['cc', 'c++', 'gcc', 'g++', 'clang', 'clang++']:
target = os.path.join(scriptdir, compiler)
if not os.path.isfile(target):
os.symlink(os.path.join(scriptdir, 'compiler.py'), target)
os.symlink(wrapper, match)

for compiler in ["cc", "c++", "gcc", "g++", "clang", "clang++"]:
target = os.path.join(matchdir, compiler)
if not os.path.isfile(target):
os.symlink(os.path.join(scriptdir, 'compiler.py'), target)
os.symlink(os.path.join(scriptdir, "compiler.py"), target)
2 changes: 1 addition & 1 deletion src/servo
Submodule servo updated 8839 files

0 comments on commit c4d0ae9

Please sign in to comment.