Skip to content

Commit 6d02af7

Browse files
authored
Merge pull request #33 from brave/override_cc
override cc files during compilation
2 parents c931073 + eadbd16 commit 6d02af7

File tree

2 files changed

+57
-13
lines changed

2 files changed

+57
-13
lines changed

patches/chrome-install_static-BUILD.gn.patch

-13
This file was deleted.

script/redirect-cc.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python
2+
import sys
3+
import subprocess
4+
import os.path
5+
6+
def main():
7+
args = sys.argv[1:]
8+
replace_cc_arg(args)
9+
cc_retcode = subprocess.call(args)
10+
return cc_retcode
11+
12+
def replace_cc_arg(args):
13+
# Interested in -c <path>.cc
14+
index_c = args.index('-c')
15+
16+
if 0 == len(args) or index_c == len(args) - 1:
17+
# Something wrong, we have -c but have no path in the next arg
18+
# Just then give all to cc as is
19+
return
20+
index_path = index_c + 1
21+
22+
path_cc = args[index_path]
23+
24+
# Get the absolute *.cc path
25+
abs_path_cc = os.path.abspath(path_cc)
26+
27+
# Get this `brave/src/brave/script/redirect-cc.py` script absolute location
28+
this_py_path = os.path.realpath(__file__)
29+
30+
# Get the original chromium dir location, triple parent of current redirect-cc.py
31+
chromium_original_dir = os.path.abspath(os.path.join(this_py_path, os.pardir, os.pardir, os.pardir))
32+
33+
if len(chromium_original_dir) >= len(abs_path_cc) + 1:
34+
# Could not get original chromium src dir
35+
return
36+
37+
# Relative path
38+
rel_path = abs_path_cc[len(chromium_original_dir) + 1:];
39+
40+
# Filter away out and out_x86
41+
# Maybe this dir can be queried from env variable instead of hardcoding
42+
OUT_DIR_NAMES = ['out', 'out_x86']
43+
start_dir = rel_path.split(os.sep)[0]
44+
if start_dir in OUT_DIR_NAMES:
45+
# Don't even try to substitute path for auto-generated cc
46+
return
47+
48+
# Build possible brave/chromium_src_path
49+
brave_path = os.path.join(chromium_original_dir, 'brave', 'chromium_src', rel_path)
50+
if os.path.isfile(brave_path):
51+
# Okay, we can replace
52+
args[index_path] = brave_path
53+
54+
return
55+
56+
if __name__ == '__main__':
57+
sys.exit(main())

0 commit comments

Comments
 (0)