Remove runfiles dependency from make_specs.
@@ -11,23 +11,9 @@ import signal
# TODO: As we add support for more compilers we could generalize this script
# to work with other compiler services rather than hardcoding to LLVM.
import sys
-import types
from pathlib import Path
-# TODO(github.com/facebookresearch/CompilerGym/issues/506): Avoids circular
-# dependency during specs.py generation, because it is imported from
-# compiler_gym.envs.llvm before being generated.
-sys.modules["compiler_gym.envs.llvm.is_making_specs"] = types.ModuleType(
- "compiler_gym.envs.llvm.is_making_specs"
-)
-
-from compiler_gym.envs.llvm.llvm_env import LlvmEnv # noqa: E402
-from compiler_gym.util.runfiles_path import runfiles_path # noqa: E402
-
-with open(
- runfiles_path("compiler_gym/envs/llvm/service/passes/10.0.0/flag_descriptions.txt")
-) as f:
- _FLAG_DESCRIPTIONS = [ln.rstrip() for ln in f.readlines()]
+from compiler_gym.envs.llvm.llvm_env import LlvmEnv
# The maximum number of seconds to wait before timing out.
TIMEOUT_SECONDS = 300
@@ -41,12 +27,17 @@ def timeout_handler(signum, frame):
def main(argv):
- assert len(argv) == 3, "Usage: make_specs.py <service_binary> <output_path>"
- service_path, output_path = argv[1:]
+ assert (
+ len(argv) == 3
+ ), "Usage: make_specs.py <service_binary> <flag_descriptions> <output_path>"
+ service_path, flag_descriptions, output_path = argv[1:]
signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(TIMEOUT_SECONDS)
+ with open(flag_descriptions) as f:
+ flag_descriptions = [ln.rstrip() for ln in f.readlines()]
+
with LlvmEnv(Path(service_path)) as env:
with open(output_path, "w") as f:
print("from enum import Enum", file=f)
@@ -65,7 +56,7 @@ def main(argv):
print(f' {enum_name} = "{name}"', file=f)
print(file=f)
print("class action_descriptions(Enum):", file=f)
- for name, description in zip(env.action_space.names, _FLAG_DESCRIPTIONS):
+ for name, description in zip(env.action_space.names, flag_descriptions):
enum_name = "".join([x.capitalize() for x in name[1:].split("-")])
sanitized_description = description.replace('" "', "")
sanitized_description = sanitized_description.replace('"', "")
