Skip to content

Commit

Permalink
Merge pull request #33 from brave/override_cc
Browse files Browse the repository at this point in the history
override cc files during compilation
  • Loading branch information
bbondy authored Feb 9, 2018
2 parents c931073 + eadbd16 commit 6d02af7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
13 changes: 0 additions & 13 deletions patches/chrome-install_static-BUILD.gn.patch

This file was deleted.

57 changes: 57 additions & 0 deletions script/redirect-cc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python
import sys
import subprocess
import os.path

def main():
args = sys.argv[1:]
replace_cc_arg(args)
cc_retcode = subprocess.call(args)
return cc_retcode

def replace_cc_arg(args):
# Interested in -c <path>.cc
index_c = args.index('-c')

if 0 == len(args) or index_c == len(args) - 1:
# Something wrong, we have -c but have no path in the next arg
# Just then give all to cc as is
return
index_path = index_c + 1

path_cc = args[index_path]

# Get the absolute *.cc path
abs_path_cc = os.path.abspath(path_cc)

# Get this `brave/src/brave/script/redirect-cc.py` script absolute location
this_py_path = os.path.realpath(__file__)

# Get the original chromium dir location, triple parent of current redirect-cc.py
chromium_original_dir = os.path.abspath(os.path.join(this_py_path, os.pardir, os.pardir, os.pardir))

if len(chromium_original_dir) >= len(abs_path_cc) + 1:
# Could not get original chromium src dir
return

# Relative path
rel_path = abs_path_cc[len(chromium_original_dir) + 1:];

# Filter away out and out_x86
# Maybe this dir can be queried from env variable instead of hardcoding
OUT_DIR_NAMES = ['out', 'out_x86']
start_dir = rel_path.split(os.sep)[0]
if start_dir in OUT_DIR_NAMES:
# Don't even try to substitute path for auto-generated cc
return

# Build possible brave/chromium_src_path
brave_path = os.path.join(chromium_original_dir, 'brave', 'chromium_src', rel_path)
if os.path.isfile(brave_path):
# Okay, we can replace
args[index_path] = brave_path

return

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

0 comments on commit 6d02af7

Please # to comment.