Skip to content

Commit fc95104

Browse files
committed
Revert "Bug 1967834 - remove the preprocessing scripts in favor of direct changes in gn_processor.py r=ng" for causing bc and xpcshell failures.
This reverts commit e485a3d10af8d69475ec1802291bdd3ece3b6696. UltraBlame original commit: 430549b5a8144b587efd8eb3578202cc7d380516
1 parent 0bfc739 commit fc95104

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

build/gn_processor.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import tempfile
1111
from collections import defaultdict, deque
1212
from copy import deepcopy
13+
from importlib import util
1314
from pathlib import Path
1415
from shutil import which
1516

@@ -719,6 +720,7 @@ def generate_gn_config(
719720
input_variables,
720721
sandbox_variables,
721722
gn_target,
723+
preprocessor,
722724
moz_build_flag,
723725
):
724726
def str_for_arg(v):
@@ -773,19 +775,25 @@ def str_for_arg(v):
773775
subprocess.check_call(gen_args, cwd=build_root_dir, stderr=subprocess.STDOUT)
774776

775777
gn_config_file = resolved_tempdir / "project.json"
778+
if preprocessor:
779+
preprocessor.main(gn_config_file)
780+
776781
with open(gn_config_file) as fh:
777-
raw_json = fh.read()
778-
raw_json = raw_json.replace(f"{target_dir}/", "")
779-
raw_json = raw_json.replace(f"{target_dir}:", ":")
780-
gn_config = json.loads(raw_json)
781-
gn_config = filter_gn_config(
782-
resolved_tempdir,
783-
gn_config,
784-
sandbox_variables,
785-
input_variables,
786-
gn_target,
782+
gn_out = json.load(fh)
783+
gn_out = filter_gn_config(
784+
resolved_tempdir, gn_out, sandbox_variables, input_variables, gn_target
787785
)
788-
return gn_config
786+
return gn_out
787+
788+
789+
def load_preprocessor(script_name):
790+
if script_name and os.path.isfile(script_name):
791+
print(f"Loading preprocessor {script_name}")
792+
spec = util.spec_from_file_location("preprocess", script_name)
793+
module = util.module_from_spec(spec)
794+
spec.loader.exec_module(module)
795+
return module
796+
return None
789797

790798

791799
def main():
@@ -832,6 +840,8 @@ def main():
832840
vars["use_x11"] = True
833841
vars_set.append(vars)
834842

843+
preprocessor = load_preprocessor(config.get("preprocessing_script", None))
844+
835845
gn_configs = []
836846
for vars in vars_set:
837847
gn_configs.append(
@@ -842,6 +852,7 @@ def main():
842852
vars,
843853
config["gn_sandbox_variables"],
844854
config["gn_target"],
855+
preprocessor,
845856
config["moz_build_flag"],
846857
)
847858
)

dom/media/webrtc/third_party_build/gn-configs/abseil.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"build_root_dir": "third_party",
33
"target_dir": "abseil-cpp",
4+
"preprocessing_script": "dom/media/webrtc/third_party_build/gn-configs/abseil_preprocessor.py",
45
"moz_build_flag": "build_mozilla_absl",
56
"gn_target": "//:absl",
67
"gn_sandbox_variables": {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
4+
5+
6+
def main(gn_config_file):
7+
target_dir = "abseil-cpp"
8+
raw_file_contents = ""
9+
with open(gn_config_file) as fh:
10+
raw_file_contents = fh.read()
11+
raw_file_contents = raw_file_contents.replace(f"{target_dir}/", "")
12+
raw_file_contents = raw_file_contents.replace(f"{target_dir}:", ":")
13+
with open(gn_config_file, "w") as fh:
14+
fh.write(raw_file_contents)

dom/media/webrtc/third_party_build/gn-configs/webrtc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"build_root_dir": "third_party",
33
"target_dir": "libwebrtc",
4+
"preprocessing_script": "dom/media/webrtc/third_party_build/gn-configs/webrtc_preprocessor.py",
45
"moz_build_flag": "build_mozilla_webrtc",
56
"gn_target": "//:webrtc",
67
"gn_sandbox_variables": {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
4+
5+
6+
def main(gn_config_file):
7+
target_dir = "libwebrtc"
8+
raw_file_contents = ""
9+
with open(gn_config_file) as fh:
10+
raw_file_contents = fh.read()
11+
raw_file_contents = raw_file_contents.replace(f"{target_dir}/", "")
12+
raw_file_contents = raw_file_contents.replace(f"{target_dir}:", ":")
13+
with open(gn_config_file, "w") as fh:
14+
fh.write(raw_file_contents)

0 commit comments

Comments
 (0)