diff --git a/docs/user/FlowVariables.md b/docs/user/FlowVariables.md index b031f9bca2..1be31d3308 100644 --- a/docs/user/FlowVariables.md +++ b/docs/user/FlowVariables.md @@ -289,6 +289,7 @@ configuration file. | SETUP_MOVE_SEQUENCE| Passed as -sequence to repair_timing. This should be a string of move keywords separated by commas.| | | SETUP_REPAIR_PHASES| Passed as -phases to repair_timing. This should be a string of setup repair phase names separated by spaces. Set to PARALLEL_EVAL to repair setup timing with the experimental parallel evaluation policy. When unset, repair_timing runs its default phases.| | | SETUP_SLACK_MARGIN| Specifies a time margin for the slack when fixing setup violations. This option allows you to overfix or underfix(negative value, terminate retiming before 0 or positive slack). See HOLD_SLACK_MARGIN for more details.| 0| +| SIG_MAP_FILE| Signal map file for ICeWall-based floorplan initialization: the signal each pad of the FOOTPRINT file connects to.| | | SKIP_ANTENNA_REPAIR| Skips antenna repair entirely.| 0| | SKIP_ANTENNA_REPAIR_POST_DRT| Skips antenna repair post-detailed routing.| 0| | SKIP_BUFFER_REMOVAL| Passed as -skip_buffer_removal to repair_timing. Do not remove buffers as a transform to fix timing violations (default: allow buffer removal).| | @@ -480,6 +481,7 @@ configuration file. - [SETUP_MOVE_SEQUENCE](#SETUP_MOVE_SEQUENCE) - [SETUP_REPAIR_PHASES](#SETUP_REPAIR_PHASES) - [SETUP_SLACK_MARGIN](#SETUP_SLACK_MARGIN) +- [SIG_MAP_FILE](#SIG_MAP_FILE) - [SKIP_BUFFER_REMOVAL](#SKIP_BUFFER_REMOVAL) - [SKIP_CRIT_VT_SWAP](#SKIP_CRIT_VT_SWAP) - [SKIP_FLOORPLAN_REPAIR_TIMING](#SKIP_FLOORPLAN_REPAIR_TIMING) diff --git a/flow/scripts/variables.mk b/flow/scripts/variables.mk index 7c607fc375..a3cdee8dc8 100644 --- a/flow/scripts/variables.mk +++ b/flow/scripts/variables.mk @@ -207,7 +207,7 @@ export COMMAND_LINE_ARGS := $(foreach V,$(.VARIABLES),$(if $(filter command% lin .PHONY: vars vars: mkdir -p $(OBJECTS_DIR) - $(UTILS_DIR)/generate-vars.sh $(OBJECTS_DIR)/vars + $(PYTHON_EXE) $(UTILS_DIR)/generate_vars.py $(OBJECTS_DIR)/vars .PHONY: print-% print-%: diff --git a/flow/scripts/variables.yaml b/flow/scripts/variables.yaml index 21b48f712c..ba4a8fa1c0 100644 --- a/flow/scripts/variables.yaml +++ b/flow/scripts/variables.yaml @@ -134,9 +134,13 @@ TECH_LEF: description: > A technology LEF file of the PDK that includes all relevant information regarding metal layers, vias, and spacing requirements. + type: file + platform: true SC_LEF: description: | Path to technology standard cell LEF file. + type: file + platform: true GDS_FILES: description: | Path to platform GDS files. @@ -145,6 +149,8 @@ LIB_FILES: A Liberty file of the standard cell library with PVT characterization, input and output characteristics, timing and power definitions for each cell. + type: file + platform: true LIB_MODEL: description: > Selects between NLDM and CCS timing models for the ASAP7 platform. @@ -398,6 +404,7 @@ SYNTH_NETLIST_FILES: subsequent modules are silently ignored and only the first module is used. stages: - synth + type: file SYNTH_CANONICALIZE_TCL: description: > Specifies a Tcl script with commands to run as part of the synth @@ -450,16 +457,22 @@ LATCH_MAP_FILE: Optional mapping file supplied to Yosys to map latches stages: - synth + type: file + platform: true CLKGATE_MAP_FILE: description: | Optional mapping file supplied to Yosys to map clock gating cells stages: - synth + type: file + platform: true ADDER_MAP_FILE: description: | Optional mapping file supplied to Yosys to map adders stages: - synth + type: file + platform: true INFER_CLKGATES: description: > Enables Yosys clock gate inference. By default, it uses the Liberty cell @@ -634,6 +647,8 @@ TAPCELL_TCL: Path to Endcap and Welltie cells file. stages: - floorplan + type: file + platform: true MACRO_PLACEMENT_TCL: description: | Specifies the path of a TCL file on how to place macros manually. @@ -646,6 +661,7 @@ MACRO_PLACEMENT_TCL: and those locations impact global placement. stages: - floorplan + type: file PDN_TCL: description: > File path which has a set of power grid policies used by pdn to be applied @@ -653,6 +669,8 @@ PDN_TCL: the actual metal straps. stages: - floorplan + type: file + platform: true GLOBAL_CONNECT_TCL: description: > File path to the add_global_connection rules that connect the supply pins @@ -663,16 +681,21 @@ GLOBAL_CONNECT_TCL: grids. stages: - floorplan + type: file + platform: true MAKE_TRACKS: description: | Tcl file that defines add routing tracks to a floorplan. stages: - floorplan + type: file + platform: true IO_CONSTRAINTS: description: | File path to the IO constraints .tcl file. Also used for manual placement. stages: - floorplan + type: file IO_PLACER_H: description: > A list of metal layers on which the I/O pins are placed horizontally (top and @@ -1068,9 +1091,13 @@ OR_SEED: RCX_RULES: description: | RC Extraction rules file path. + type: file + platform: true FILL_CONFIG: description: | JSON rule file for metal fill during chip finishing. + type: file + platform: true KLAYOUT_TECH_FILE: description: | A mapping from LEF/DEF to GDS using the KLayout tool. @@ -1106,6 +1133,7 @@ VERILOG_FILES: of modules. stages: - synth + type: file VERILOG_DEFINES: description: > Preprocessor defines passed to the language frontend. @@ -1118,13 +1146,17 @@ SDC_FILE: The path to design constraint (SDC) file. stages: - synth + type: file ADDITIONAL_FILES: description: | Additional files to be added to `make issue` archive. + type: file + platform: true ADDITIONAL_LEFS: description: > Hardened macro LEF view files listed here. The LEF information of the macros is immutable and used throughout all stages. Stored in the .odb file. + type: file ADDITIONAL_LIBS: description: > Hardened macro library files listed here. The library information is @@ -1182,6 +1214,8 @@ DFF_LIB_FILE: synthesis. Takes precedence over DFF_MAP_FILE when set. stages: - synth + type: file + platform: true SYNTH_KEEP_MODULES: description: | Mark modules to keep from getting removed in flattening. @@ -1268,6 +1302,7 @@ MACRO_WRAPPERS: The wrapper file that replaces existing macros with their wrapped version. stages: - floorplan + type: file CTS_BUF_DISTANCE: description: | Distance (in microns) between buffers. @@ -1324,6 +1359,8 @@ POST_CTS_TCL: Specifies a Tcl script with commands to run after CTS is completed. stages: - cts + type: file + platform: true POST_DENSITY_FILL_TCL: description: | Specifies a Tcl script with commands to run after density fill. @@ -1339,6 +1376,8 @@ POST_DETAIL_ROUTE_TCL: Specifies a Tcl script with commands to run after detailed route. stages: - route + type: file + platform: true POST_FILLCELL_TCL: description: | Specifies a Tcl script with commands to run after fillcell insertion. @@ -1354,6 +1393,8 @@ POST_FLOORPLAN_TCL: Specifies a Tcl script with commands to run after floorplan is completed. stages: - floorplan + type: file + platform: true POST_GLOBAL_PLACE_SKIP_IO_TCL: description: | Specifies a Tcl script with commands to run after global placement (skip IO). @@ -1384,6 +1425,8 @@ POST_PDN_TCL: Specifies a Tcl script with commands to run after PDN generation. stages: - floorplan + type: file + platform: true POST_RESIZE_TCL: description: | Specifies a Tcl script with commands to run after resize. @@ -1477,6 +1520,8 @@ PRE_TAPCELL_TCL: FASTROUTE_TCL: description: | Specifies a Tcl script with commands to run before FastRoute. + type: file + platform: true USE_FILL: description: > Whether to perform metal density filling. @@ -1494,6 +1539,8 @@ PRE_GLOBAL_ROUTE_TCL: Specifies a Tcl script with commands to run before global route. stages: - grt + type: file + platform: true GLOBAL_ROUTE_ARGS: description: > Replaces default arguments for global route. The -congestion_iterations @@ -1679,11 +1726,20 @@ FOOTPRINT: Custom footprint definition file for ICeWall-based floorplan initialization. Mutually exclusive with FLOORPLAN_DEF or DIE_AREA/CORE_AREA or CORE_UTILIZATION. stages: - floorplan + type: file +SIG_MAP_FILE: + description: | + Signal map file for ICeWall-based floorplan initialization: the signal + each pad of the FOOTPRINT file connects to. + stages: + - floorplan + type: file FOOTPRINT_TCL: description: | Specifies a Tcl script with custom footprint-related commands for floorplan setup. stages: - floorplan + type: file FLOW_INPUT_VARIANT: description: > Flow variant a stage reads the previous stage's result from, the @@ -1836,6 +1892,8 @@ CDL_FILE: for generating Circuit Description Language output. stages: - final + type: file + platform: true OPT_POST_GRT_WNS: default: 1 description: > diff --git a/flow/test/test_generate_vars.py b/flow/test/test_generate_vars.py new file mode 100644 index 0000000000..bfbc7f6049 --- /dev/null +++ b/flow/test/test_generate_vars.py @@ -0,0 +1,247 @@ +#!/usr/bin/env python3 +"""`make vars` and `make _issue` write the flow's variables as vars +files that bash, Tcl and gdb source: generate_vars.py. + +The tests call write_vars() with ISSUE_VARIABLES as the flow's Makefile +exports it, one NAME=value per line, and read the files it writes in a +temporary directory. Nothing needs to be installed. +""" + +import os +import subprocess +import sys +import tempfile +import unittest +from unittest import mock + +UTILS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "util") +GENERATE_VARS = os.path.join(UTILS_DIR, "generate_vars.py") + +sys.path.insert(0, UTILS_DIR) +import generate_vars # noqa: E402 + + +class VarsTestCase(unittest.TestCase): + """A flow directory, /orfs/flow, and the vars files written + from it.""" + + def setUp(self): + tmp_dir = tempfile.TemporaryDirectory() + self.addCleanup(tmp_dir.cleanup) + self.tmp = os.path.realpath(tmp_dir.name) + self.orfs = os.path.join(self.tmp, "orfs") + self.flow = os.path.join(self.orfs, "flow") + os.makedirs(self.flow) + self.basename = os.path.join(self.tmp, "vars") + + def env(self, issue_variables, **extra): + return dict(extra, FLOW_HOME=self.flow, ISSUE_VARIABLES=issue_variables) + + def generate(self, issue_variables, **extra): + """Writes the vars files and returns their lines by extension.""" + generate_vars.write_vars(self.basename, self.env(issue_variables, **extra)) + return self.read() + + def read(self): + lines = {} + for ext in ["sh", "tcl", "gdb"]: + with open(f"{self.basename}.{ext}") as f: + lines[ext] = f.read().splitlines() + return lines + + +class TestVarsFiles(VarsTestCase): + def test_each_variable_in_each_file(self): + lines = self.generate("PLATFORM=nangate45\n DESIGN_NAME=gcd\n") + self.assertIn('export PLATFORM="nangate45"', lines["sh"]) + self.assertIn('set env(PLATFORM) "nangate45"', lines["tcl"]) + self.assertIn("set env PLATFORM nangate45", lines["gdb"]) + self.assertIn('export DESIGN_NAME="gcd"', lines["sh"]) + + def test_variables_in_make_order(self): + lines = self.generate("B=1\nA=2\n") + self.assertLess( + lines["sh"].index('export B="1"'), lines["sh"].index('export A="2"') + ) + + def test_shell_file_sets_flow_home_first(self): + self.assertEqual( + self.generate("")["sh"][0], "export FLOW_HOME=${FLOW_HOME:-$(pwd)}" + ) + + def test_flow_home_and_issue_variables_are_required(self): + with self.assertRaises(KeyError): + generate_vars.write_vars(self.basename, {"ISSUE_VARIABLES": ""}) + with self.assertRaises(KeyError): + generate_vars.write_vars(self.basename, {"FLOW_HOME": self.flow}) + + def test_work_home_resolved_from_the_working_directory(self): + with mock.patch.object( + generate_vars.os.path, "realpath", side_effect=lambda p: p + ) as realpath: + generate_vars.write_vars(self.basename, self.env("A=1", WORK_HOME="w")) + self.assertIn(mock.call("w"), realpath.call_args_list) + self.assertIn(mock.call(self.flow), realpath.call_args_list) + + +class TestLeftOut(VarsTestCase): + """The vars hold the flow's and the design's variables, not make's own + or the machine's, which mean nothing elsewhere: make's step and copy + macros (#1240, #1231) and its other internals, commands, executables, + the shell and search paths (#1303), names that are not shell names + (#1303, #1331), FLOW_HOME, which the shell file sets once from where + it is sourced (#1380), the newline macro (#1386), and CURDIR and the + GUI switches (#1410). Variables named *_DIR stay (#1331).""" + + LEFT_OUT = [ + "do-step", + "do-copy", + "get_variables", + "UNSET_VARIABLES_NAMES", + "MAKE", + "MAKEFLAGS", + "MAKEFILE_LIST", + "OPENROAD_EXE", + "YOSYS_EXE", + "OPENROAD_CMD", + "TIME_CMD", + "SHELL", + "HOME", + "PWD", + "LD_LIBRARY_PATH", + "PATH", + "NPROC", + "NUM_CORES", + "FLOW_HOME", + "\\n", + "CURDIR", + "OPEN_GUI", + "OPEN_GUI_SHORTCUT", + "COMMAND_LINE_ARGS", + "a.b", + "1ST", + ] + + def test_left_out(self): + lines = self.generate("".join(f"{name}=x\n" for name in self.LEFT_OUT)) + for ext, header in [("sh", 2), ("tcl", 1), ("gdb", 0)]: + self.assertEqual(lines[ext][header:], [], ext) + + def test_dir_variables_stay(self): + lines = self.generate("RESULTS_DIR=results\n") + self.assertIn('export RESULTS_DIR="results"', lines["sh"]) + + def test_flow_home_set_once(self): + sh = self.generate(f"FLOW_HOME={self.flow}\n")["sh"] + self.assertEqual([l for l in sh if "FLOW_HOME=" in l], [sh[0]]) + + +class TestValues(VarsTestCase): + """A value is written as make holds it: an empty one too, which make + spells '' (#1336), one with '=' in it (#3292), and a list such as + GND_NETS_VOLTAGES, a single quoted value in every file (#2673). The + blanks make's foreach puts around each line are not part of it.""" + + def test_empty_value(self): + lines = self.generate("EMPTY=''\n BLANK= \n") + for name in ["EMPTY", "BLANK"]: + self.assertIn(f'export {name}=""', lines["sh"]) + self.assertIn(f'set env({name}) ""', lines["tcl"]) + self.assertIn(f"set env {name} ", lines["gdb"]) + + def test_value_with_equals(self): + lines = self.generate("SYNTH_ARGS=-flatten -abc9=1\n") + self.assertIn('export SYNTH_ARGS="-flatten -abc9=1"', lines["sh"]) + + def test_list_value(self): + lines = self.generate("GND_NETS_VOLTAGES=VSS 0.0\n") + self.assertIn('export GND_NETS_VOLTAGES="VSS 0.0"', lines["sh"]) + self.assertIn('set env(GND_NETS_VOLTAGES) "VSS 0.0"', lines["tcl"]) + self.assertIn("set env GND_NETS_VOLTAGES VSS 0.0", lines["gdb"]) + + +class TestFlowHome(VarsTestCase): + """The vars spell the flow's paths through FLOW_HOME, so that they + work wherever the flow is: a path under FLOW_HOME and one under the + ORFS root above it (#1331), wherever in the value it is (#1976), and + each one of several (#2673). Tcl and gdb read FLOW_HOME from the + environment (#1386). SCRIPTS_DIR is the scripts next to the vars + files, which an issue archive carries (#2012).""" + + def test_flow_and_orfs_paths(self): + lines = self.generate( + f"VERILOG_FILES={self.flow}/designs/a.v {self.orfs}/tools/b.v\n" + f"SYNTH_ARGS=-I{self.flow}/include\n" + ) + self.assertIn( + 'export VERILOG_FILES="${FLOW_HOME}/designs/a.v ${FLOW_HOME}/../tools/b.v"', + lines["sh"], + ) + self.assertIn('export SYNTH_ARGS="-I${FLOW_HOME}/include"', lines["sh"]) + + def test_tcl_and_gdb_read_flow_home_from_the_environment(self): + lines = self.generate(f"LIBS={self.flow}/a.lib {self.flow}/b.lib\n") + self.assertIn( + 'set env(LIBS) "$::env(FLOW_HOME)/a.lib $::env(FLOW_HOME)/b.lib"', + lines["tcl"], + ) + self.assertIn( + 'set env LIBS getenv("FLOW_HOME")/a.lib getenv("FLOW_HOME")/b.lib', + lines["gdb"], + ) + + def test_scripts_dir_next_to_the_vars(self): + lines = self.generate(f"SCRIPTS_DIR={self.flow}/scripts\n") + self.assertIn('export SCRIPTS_DIR="./scripts"', lines["sh"]) + self.assertIn('set env(SCRIPTS_DIR) "./scripts"', lines["tcl"]) + + +class TestWrittenAfresh(VarsTestCase): + """`make vars` run again writes the files afresh: the .gdb file held + every earlier run's variables too, and gdb set each one again from + the oldest value to the newest.""" + + def test_written_afresh(self): + self.generate("A=old\n") + lines = self.generate("A=new\n") + for ext, line in [ + ("sh", 'export A="new"'), + ("tcl", 'set env(A) "new"'), + ("gdb", "set env A new"), + ]: + self.assertEqual( + [l for l in lines[ext] if "A" in l and "PYTHON" not in l], + [line], + ext, + ) + + +class TestCommandLine(VarsTestCase): + """The flow's Makefile runs it as `generate_vars.py ` with + the variables in its environment.""" + + def run_script(self, *args, **env): + return subprocess.run( + [sys.executable, GENERATE_VARS] + list(args), + env=dict(os.environ, **env), + cwd=self.flow, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + universal_newlines=True, + ) + + def test_writes_the_files_from_the_environment(self): + result = self.run_script( + self.basename, FLOW_HOME=self.flow, ISSUE_VARIABLES="A=1\n" + ) + self.assertEqual(result.returncode, 0, result.stdout) + self.assertIn('export A="1"', self.read()["sh"]) + + def test_usage(self): + result = self.run_script() + self.assertNotEqual(result.returncode, 0) + self.assertIn("usage", result.stdout) + + +if __name__ == "__main__": + unittest.main() diff --git a/flow/test/test_make_issue.py b/flow/test/test_make_issue.py new file mode 100644 index 0000000000..7cb3cdfc89 --- /dev/null +++ b/flow/test/test_make_issue.py @@ -0,0 +1,705 @@ +#!/usr/bin/env python3 +"""`make _issue` archives a flow step as a reproducible: makeIssue.py. + +The unit tests call makeIssue's functions with the tools they would run +mocked. The end-to-end tests run makeIssue.py as the flow's Makefile runs +it, from the flow directory, on a stub flow: a scripts directory with the +step's script, a platform and a design. The archive is unpacked elsewhere +and its run-me script run with a stub openroad on PATH that records what +it can read from where run-me started it. Nothing beyond bash, tar and +gzip needs to be installed. +""" + +import os +import re +import shutil +import subprocess +import sys +import tarfile +import tempfile +import textwrap +import unittest +from unittest import mock + +UTILS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "util") +MAKE_ISSUE = os.path.join(UTILS_DIR, "makeIssue.py") + +sys.path.insert(0, UTILS_DIR) +import makeIssue # noqa: E402 + +STEP = "detail_place" +TAG = "test" +NICKNAME = "stub" +PLATFORM = "stubpdk" +VARIANT = "base" +FLOW_NAME = f"{NICKNAME}-{PLATFORM}-{VARIANT}" + +FAKE_OPENROAD = textwrap.dedent("""\ + #!/usr/bin/env bash + # Records the script it was given, whether that script and the step's + # input are readable from where run-me started it, and its arguments. + script="${@: -1}" + { + echo "args=$*" + echo "script=$script" + [ -r "$script" ] && echo "script_readable=1" || echo "script_readable=0" + [ -r "$RESULTS_DIR/3_place.odb" ] && echo "input_readable=1" \\ + || echo "input_readable=0" + } > "$OPENROAD_REPORT" + """) + + +class StubFlow: + """A flow directory with one step, a platform and a design, in a + temporary directory that is removed with cleanup().""" + + def __init__(self): + self.tmp_dir = tempfile.TemporaryDirectory() + self.tmp = self.tmp_dir.name + # FLOW_HOME/.. is the ORFS root, which the vars files spell + # ${FLOW_HOME}/..; a WORK_HOME in self.tmp is outside it, as a CI + # workspace is. + self.flow = os.path.join(self.tmp, "orfs", "flow") + self.scripts = os.path.join(self.flow, "scripts") + self.platform_dir = os.path.join(self.flow, "platforms", PLATFORM) + self.design_dir = os.path.join(self.flow, "designs", PLATFORM, NICKNAME) + self.design_config = os.path.join(self.design_dir, "config.mk") + for path, text in [ + (os.path.join(self.scripts, STEP + ".tcl"), "puts step\n"), + (os.path.join(self.platform_dir, "config.mk"), "\n"), + (os.path.join(self.platform_dir, "pdn.tcl"), "\n"), + (self.design_config, "\n"), + ]: + self.write(path, text) + + self.bin = os.path.join(self.tmp, "bin") + self.write(os.path.join(self.bin, "openroad"), FAKE_OPENROAD) + os.chmod(os.path.join(self.bin, "openroad"), 0o755) + + def cleanup(self): + self.tmp_dir.cleanup() + + @staticmethod + def write(path, text): + os.makedirs(os.path.dirname(path), exist_ok=True) + with open(path, "w") as f: + f.write(text) + + def flow_dirs(self, work_home): + return { + name: f"{work_home}/{name.lower()}/{PLATFORM}/{NICKNAME}/{VARIANT}" + for name in ["LOG_DIR", "OBJECTS_DIR", "REPORTS_DIR", "RESULTS_DIR"] + } + + def make_issue(self, work_home, step=STEP, **extra): + """Runs makeIssue.py as `make _issue` does and returns the + archive's path.""" + dirs = self.flow_dirs(work_home) + for path in dirs.values(): + os.makedirs(os.path.join(self.flow, path), exist_ok=True) + self.write(os.path.join(self.flow, dirs["RESULTS_DIR"], "3_place.odb"), "") + + variables = dict( + dirs, + DESIGN_NICKNAME=NICKNAME, + PLATFORM=PLATFORM, + FLOW_VARIANT=VARIANT, + PLATFORM_DIR=self.platform_dir, + DESIGN_DIR=self.design_dir, + DESIGN_CONFIG=self.design_config, + SCRIPTS_DIR=self.scripts, + UTILS_DIR=UTILS_DIR, + WORK_HOME=work_home, + ) + variables.update(extra) + env = dict( + os.environ, + FLOW_HOME=self.flow, + ISSUE_TAG=TAG, + ISSUE_VARIABLES="\n".join(f"{k}={v}" for k, v in variables.items()), + **variables, + ) + result = subprocess.run( + [sys.executable, MAKE_ISSUE, f"{work_home}/{step}"], + cwd=self.flow, + env=env, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + universal_newlines=True, + ) + if result.returncode != 0: + raise AssertionError(f"makeIssue.py failed:\n{result.stdout}") + return os.path.join(self.flow, work_home, f"{step}_{TAG}.tar.gz") + + def unpack(self, archive, step=STEP): + """Unpacks the archive away from the flow; returns its root.""" + unpacked = os.path.join(self.tmp, "unpacked") + shutil.rmtree(unpacked, ignore_errors=True) + with tarfile.open(archive) as tar: + tar.extractall(unpacked) + return os.path.join(unpacked, f"{step}_{TAG}") + + @staticmethod + def members(archive): + with tarfile.open(archive) as tar: + return [m.name for m in tar.getmembers()] + + @staticmethod + def find(root, name): + found = [ + os.path.join(d, name) for d, _, files in os.walk(root) if name in files + ] + if len(found) != 1: + raise AssertionError(f"{len(found)} {name} in {root}") + return found[0] + + def run_me(self, root): + """Runs the unpacked archive's run-me script from elsewhere and + returns what the stub openroad recorded.""" + report = os.path.join(self.tmp, "openroad_report") + if os.path.exists(report): + os.remove(report) + env = dict( + os.environ, + PATH=self.bin + os.pathsep + os.environ["PATH"], + OPENROAD_REPORT=report, + ) + env.pop("FLOW_HOME", None) + result = subprocess.run( + [self.find(root, f"run-me-{FLOW_NAME}.sh")], + cwd=self.tmp, + env=env, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + universal_newlines=True, + ) + if result.returncode != 0 or not os.path.exists(report): + raise AssertionError(f"run-me did not start openroad:\n{result.stdout}") + with open(report) as f: + return dict(line.split("=", 1) for line in f.read().splitlines()) + + +class StubFlowTestCase(unittest.TestCase): + def setUp(self): + self.stub = StubFlow() + self.addCleanup(self.stub.cleanup) + + +class TestRunMe(StubFlowTestCase): + """The archive's run-me runs the step from wherever it is unpacked.""" + + def assert_runs(self, work_home): + archive = self.stub.make_issue(work_home) + recorded = self.stub.run_me(self.stub.unpack(archive)) + self.assertEqual(os.path.basename(recorded["script"]), STEP + ".tcl") + self.assertEqual(recorded["script_readable"], "1", recorded) + self.assertEqual(recorded["input_readable"], "1", recorded) + + def test_work_home_default(self): + self.assert_runs(".") + + def test_work_home_absolute(self): + self.assert_runs(os.path.join(self.stub.tmp, "work")) + + def test_work_home_relative(self): + self.assert_runs("work/stub") + + def test_work_home_relative_through_a_symlink(self): + """tar keeps WORK_HOME's spelling in the member names, so run-me + follows the spelling, not the directory the link resolves to.""" + os.makedirs(os.path.join(self.stub.flow, "work", "real")) + os.symlink(os.path.join("work", "real"), os.path.join(self.stub.flow, "link")) + self.assert_runs("link") + + +class TestOptions(StubFlowTestCase): + def test_copy_issue_copies_the_archive(self): + copies = os.path.join(self.stub.tmp, "copies") + archive = self.stub.make_issue(".", COPY_ISSUE=copies) + self.assertEqual(os.listdir(copies), [os.path.basename(archive)]) + + def test_full_issue_archives_the_design_and_platform_directories(self): + self.stub.write(os.path.join(self.stub.design_dir, "rtl.v"), "\n") + members = self.stub.members(self.stub.make_issue(".", FULL_ISSUE="1")) + self.assertIn(f"{STEP}_{TAG}/designs/{PLATFORM}/{NICKNAME}/rtl.v", members) + + def test_exclude_platform_drops_liberty_and_lef(self): + for name in ["cells.lib", "cells.lef", "tech.tlef"]: + self.stub.write(os.path.join(self.stub.platform_dir, name), "\n") + # FULL_ISSUE archives the platform directory, so the liberty and + # LEF files are in the archive until EXCLUDE_PLATFORM drops them. + archive = self.stub.make_issue(".", EXCLUDE_PLATFORM="1", FULL_ISSUE="1") + names = [os.path.basename(m) for m in self.stub.members(archive)] + for name in ["cells.lib", "cells.lef", "tech.tlef"]: + self.assertNotIn(name, names) + self.assertIn("pdn.tcl", names) + self.assertIn(f"run-me-{FLOW_NAME}.sh", names) + + +class TestCompressor(unittest.TestCase): + def test_pigz_when_installed(self): + with mock.patch("shutil.which", return_value="/usr/bin/pigz"): + self.assertEqual(makeIssue.compressor(), "pigz") + + def test_gzip_otherwise(self): + with mock.patch("shutil.which", return_value=None): + self.assertEqual(makeIssue.compressor(), "gzip") + + +class TestFileVariables(StubFlowTestCase): + """Every file a file variable names is archived on its own, whatever + else is set (#914: DFF_LIB_FILE and LIB_FILES ran together into one + name), and a variable may name several files or a glob + (ADDITIONAL_FILES, #2060).""" + + def files(self, **variables): + env = dict( + variables, + PLATFORM_DIR=self.stub.platform_dir, + UTILS_DIR=UTILS_DIR, + ) + return makeIssue.issue_files(env, "work/vars", "work/run-me.sh") + + def test_adjacent_variables_stay_separate(self): + files = self.files(DFF_LIB_FILE="dff.lib", LIB_FILES="a.lib b.lib") + for name in ["dff.lib", "a.lib", "b.lib"]: + self.assertIn(name, files) + + def test_every_file_variable_is_archived(self): + variables = { + name: f"{name.lower()}.file" for name in makeIssue.file_variables() + } + files = self.files(**variables) + for name, path in variables.items(): + self.assertIn(path, files, name) + + def test_other_variables_are_not_archived(self): + self.assertNotIn("gcd.v", self.files(DESIGN_NAME="gcd.v")) + + def test_a_file_variable_needs_only_its_variables_yaml_entry(self): + variables_yaml = os.path.join(self.stub.tmp, "variables.yaml") + self.stub.write( + variables_yaml, + "NEW_FILE:\n description: x\n type: file\n" + "NEW_NUMBER:\n description: y\n type: int\n", + ) + with mock.patch.object(makeIssue, "VARIABLES_YAML", variables_yaml): + files = self.files(NEW_FILE="new.file", NEW_NUMBER="new.number") + self.assertIn("new.file", files) + self.assertNotIn("new.number", files) + + def test_a_glob_names_the_files_it_matches(self): + extra = os.path.join(self.stub.platform_dir, "extra") + for name in ["a.v", "b.v"]: + self.stub.write(os.path.join(extra, name), "\n") + files = self.files(ADDITIONAL_FILES=f"{extra}/*.v") + self.assertIn(os.path.join(extra, "a.v"), files) + self.assertIn(os.path.join(extra, "b.v"), files) + self.assertNotIn(f"{extra}/*.v", files) + + def test_the_issue_files_are_archived(self): + files = self.files() + for name in [ + "work/run-me.sh", + "work/vars.sh", + "work/vars.tcl", + "work/vars.gdb", + ]: + self.assertIn(name, files) + + def test_exclude_platform_leaves_out_the_platform_files(self): + """By where a file is, not by which variable names it: a design + variable may name a platform file and a platform variable a file + of the design's own.""" + platform_lib = os.path.join(self.stub.platform_dir, "cells.lib") + platform_dff = os.path.join(self.stub.platform_dir, "dff.lib") + macro_lef = os.path.join(self.stub.design_dir, "macro.lef") + sdc = os.path.join(self.stub.design_dir, "constraint.sdc") + files = self.files( + EXCLUDE_PLATFORM="1", + LIB_FILES=platform_lib, + DFF_LIB_FILE=platform_dff, + ADDITIONAL_LEFS=macro_lef, + SDC_FILE=sdc, + ) + self.assertNotIn(platform_lib, files) + self.assertNotIn(platform_dff, files) + self.assertIn(macro_lef, files) + self.assertIn(sdc, files) + self.assertFalse([f for f in files if f.startswith(self.stub.platform_dir)]) + + def outside_platform(self): + """The platform's files where a PDK installed outside PLATFORM_DIR + has them, and a link to one of them inside it.""" + pdk = os.path.join(self.stub.tmp, "pdk") + files = { + name: os.path.join(pdk, name) + for name in ["cells.lib.gz", "cells.cdl", "rcx.rules", "pdk.sdc"] + } + for path in files.values(): + self.stub.write(path, "\n") + link = os.path.join(self.stub.platform_dir, "link.sdc") + os.symlink(files["pdk.sdc"], link) + return files, link + + def test_exclude_platform_leaves_out_the_platform_variables(self): + """By name: a PDK may be installed outside PLATFORM_DIR, where + only the variable says a file is the platform's.""" + outside, _ = self.outside_platform() + files = self.files( + EXCLUDE_PLATFORM="1", + LIB_FILES=outside["cells.lib.gz"], + CDL_FILE=outside["cells.cdl"], + RCX_RULES=outside["rcx.rules"], + ) + for path in outside.values(): + self.assertNotIn(path, files) + + def test_exclude_platform_leaves_out_a_link_in_the_platform(self): + """A file in PLATFORM_DIR that is a link to somewhere else is + the platform's, as much as a link from elsewhere into it.""" + outside, link = self.outside_platform() + into = os.path.join(self.stub.design_dir, "into.sdc") + self.stub.write(os.path.join(self.stub.platform_dir, "platform.sdc"), "\n") + os.symlink(os.path.join(self.stub.platform_dir, "platform.sdc"), into) + for sdc in [link, into]: + self.assertEqual( + [f for f in self.files(EXCLUDE_PLATFORM="1", SDC_FILE=sdc) if f == sdc], + [], + ) + + def test_the_platform_variables_are_file_variables(self): + platform = makeIssue.platform_file_variables() + self.assertIn("LIB_FILES", platform) + self.assertNotIn("SDC_FILE", platform) + self.assertLessEqual(set(platform), set(makeIssue.file_variables())) + + def test_exclude_platform_end_to_end(self): + outside, link = self.outside_platform() + sdc = os.path.join(self.stub.design_dir, "constraint.sdc") + self.stub.write(sdc, "\n") + archive = self.stub.make_issue( + ".", + EXCLUDE_PLATFORM="1", + LIB_FILES=outside["cells.lib.gz"], + CDL_FILE=outside["cells.cdl"], + RCX_RULES=outside["rcx.rules"], + IO_CONSTRAINTS=link, + SDC_FILE=sdc, + ) + names = [os.path.basename(m) for m in self.stub.members(archive)] + for name in list(outside) + ["link.sdc"]: + self.assertNotIn(name, names) + self.assertIn("constraint.sdc", names) + + def test_exclude_platform_keeps_the_design_lef(self): + """In the finished archive: the platform's liberty and LEF files + are dropped from it after it is written, the design's stay.""" + macro_lef = os.path.join(self.stub.design_dir, "macro.lef") + platform_lef = os.path.join(self.stub.platform_dir, "cells.lef") + merged_lib = os.path.join( + self.stub.flow, self.stub.flow_dirs(".")["OBJECTS_DIR"], "lib", "merged.lib" + ) + for path in [macro_lef, platform_lef, merged_lib]: + self.stub.write(path, "\n") + archive = self.stub.make_issue( + ".", + EXCLUDE_PLATFORM="1", + FULL_ISSUE="1", + ADDITIONAL_LEFS=f"{macro_lef} {platform_lef}", + ) + members = self.stub.members(archive) + self.assertEqual( + [m for m in members if m.endswith((".lef", ".lib"))], + [f"{STEP}_{TAG}/designs/{PLATFORM}/{NICKNAME}/macro.lef"], + ) + + def test_exclude_platform_leaves_out_the_flip_flop_liberty(self): + """DFF_LIB_FILE names a liberty file of the platform's, wherever + the platform keeps it.""" + dff = os.path.join(self.stub.tmp, "pdk", "dff.lib") + self.stub.write(dff, "\n") + archive = self.stub.make_issue(".", EXCLUDE_PLATFORM="1", DFF_LIB_FILE=dff) + names = [os.path.basename(m) for m in self.stub.members(archive)] + self.assertNotIn("dff.lib", names) + + def test_archived_end_to_end(self): + lib = os.path.join(self.stub.platform_dir, "dff.lib") + cells = os.path.join(self.stub.platform_dir, "cells.lib") + for path in [lib, cells]: + self.stub.write(path, "\n") + names = [ + os.path.basename(m) + for m in self.stub.members( + self.stub.make_issue(".", DFF_LIB_FILE=lib, LIB_FILES=cells) + ) + ] + self.assertIn("dff.lib", names) + self.assertIn("cells.lib", names) + + +class TestFileVariableNames(unittest.TestCase): + """Which flow variables name files is said once, in variables.yaml + (`type: file`), and each of them is a variable the flow reads. A flow + variable that is renamed or retired takes its entry with it + (SYNTH_NETLIST_FILES #2899, PRE_GLOBAL_ROUTE_TCL #3333, + MACRO_PLACEMENT_TCL #3469, GLOBAL_CONNECT_TCL #4785); a name left + behind silently archives nothing.""" + + FLOW = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..") + SOURCES = [".tcl", ".mk", ".py", ".sh", ".yaml", ".cfg"] + # where the names are listed rather than read + LISTS = ["makeIssue.py", "variables.yaml"] + + def flow_text(self): + texts = [] + for top in ["scripts", "util", "platforms", "Makefile"]: + top = os.path.join(self.FLOW, top) + paths = ( + [top] + if os.path.isfile(top) + else [os.path.join(d, f) for d, _, fs in os.walk(top) for f in fs] + ) + for path in paths: + if os.path.basename(path) in self.LISTS: + continue + if path != top and os.path.splitext(path)[1] not in self.SOURCES: + continue + with open(path, errors="replace") as f: + texts.append(f.read()) + return "\n".join(texts) + + def test_there_are_file_variables(self): + self.assertIn("VERILOG_FILES", makeIssue.file_variables()) + + def read_names(self): + """The names the flow reads: those its sources spell out, the + hooks `source_step_tcl PRE CTS` composes (PRE_CTS_TCL), and + ADDITIONAL_FILES, which only make issue reads.""" + text = self.flow_text() + hooks = re.findall(r"source_step_tcl\s+(\w+)\s+(\w+)", text) + return text, {f"{kind}_{step}_TCL" for kind, step in hooks} | { + "ADDITIONAL_FILES" + } + + def test_every_file_variable_is_read_by_the_flow(self): + text, names = self.read_names() + unread = [ + name + for name in makeIssue.file_variables() + if name not in names and not re.search(r"\b" + name + r"\b", text) + ] + self.assertEqual(unread, []) + + +class TestRunMeScript(StubFlowTestCase): + """The run-me script runs the step's tool on the step's script from + the unpacked archive: the script is found through the archive's own + SCRIPTS_DIR, not the path of the flow that made it (#1410), it is + named after the step and not after the WORK_HOME path makeIssue is + given (#3466), openroad gets the flow's thread count (#3870), and a + synthesis step runs yosys, not openroad (#4129).""" + + SCRIPTS = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "scripts") + + def text(self, yosys, **env): + return makeIssue.run_me_text(env, "cts", "/abs/work/vars-x", yosys) + + def test_script_found_through_the_archive_scripts_dir(self): + text = self.text(False) + self.assertIn("${SCRIPTS_DIR}/cts.tcl", text) + self.assertNotIn(self.SCRIPTS, text) + + def test_vars_sourced_next_to_run_me(self): + text = self.text(False) + self.assertIn('cd "$(dirname "$0")"', text) + self.assertIn("source ./vars-x.sh", text) + self.assertNotIn("/abs/work", text) + + def test_openroad_threads(self): + self.assertIn("-threads 8 ", self.text(False, NUM_CORES="8")) + self.assertIn("-threads 1 ", self.text(False)) + + def test_gdb_on_request(self): + self.assertIn("gdb --args openroad", self.text(False)) + + def test_yosys_step_runs_yosys(self): + text = self.text(True, YOSYS_FLAGS="-v 3") + self.assertIn("yosys -v 3 -c ${SCRIPTS_DIR}/cts.tcl", text) + self.assertNotIn("openroad", text) + + def test_the_flow_scripts_pick_their_tool(self): + def tool(script): + path = os.path.join(self.SCRIPTS, script + ".tcl") + return "yosys" if makeIssue.is_yosys_step(path) else "openroad" + + for script in ["synth", "synth_canonicalize"]: + self.assertEqual(tool(script), "yosys", script) + for script in ["floorplan", "global_place", "cts", "global_route"]: + self.assertEqual(tool(script), "openroad", script) + + def test_step_named_after_the_target_not_its_path(self): + archive = self.stub.make_issue(os.path.join(self.stub.tmp, "work")) + recorded = self.stub.run_me(self.stub.unpack(archive)) + self.assertEqual(os.path.basename(recorded["script"]), STEP + ".tcl") + self.assertTrue(recorded["script"].startswith("./scripts/"), recorded) + + +class TestArchiveLayout(StubFlowTestCase): + """Archive members are relative to the archive's root: files under + FLOW_HOME lose its path, so a design outside the ORFS checkout works + (#1410), and so do files under an absolute WORK_HOME, however it is + spelled: through a symlink or with a trailing slash (#4274). A + directory that only starts with WORK_HOME's name keeps its path + (#4274).""" + + def root_entries(self, archive): + prefix = f"{STEP}_{TAG}/" + members = self.stub.members(archive) + for member in members: + self.assertTrue(member.startswith(prefix), member) + return {os.path.normpath(m[len(prefix) :]).split("/")[0] for m in members} + + def assert_at_root(self, work_home, **extra): + archive = self.stub.make_issue(work_home, **extra) + entries = self.root_entries(archive) + for entry in [ + "results_dir", + "log_dir", + f"run-me-{FLOW_NAME}.sh", + f"vars-{FLOW_NAME}.sh", + "scripts", + "designs", + "platforms", + ]: + self.assertIn(entry, entries) + tmp_top = self.stub.tmp.strip("/").split("/")[0] + self.assertNotIn(tmp_top, entries) + return archive + + def test_flow_home_files(self): + self.assert_at_root(".") + + def test_absolute_work_home(self): + self.assert_at_root(os.path.join(self.stub.tmp, "work")) + + def test_absolute_work_home_with_trailing_slash(self): + self.assert_at_root(os.path.join(self.stub.tmp, "work") + "/") + + def test_work_home_through_a_symlink(self): + real = os.path.join(self.stub.tmp, "real_work") + os.makedirs(real) + link = os.path.join(self.stub.tmp, "work") + os.symlink(real, link) + self.assert_at_root(link) + + def test_a_sibling_of_work_home_keeps_its_path(self): + work = os.path.join(self.stub.tmp, "work") + sibling = os.path.join(self.stub.tmp, "work_other", "d.sdc") + self.stub.write(sibling, "\n") + archive = self.stub.make_issue(work, SDC_FILE=sibling) + members = self.stub.members(archive) + self.assertIn(f"{STEP}_{TAG}{sibling}", members) + + +class TestVarsFiles(StubFlowTestCase): + """The archive's vars files run on another machine: python3 is the + default PYTHON_EXE in both the shell and the Tcl vars (#4792), paths + under an absolute WORK_HOME are relative to the archive's root while + a directory that only starts with WORK_HOME's name keeps its path + (#4274), and paths under a docker image's /workspace and /platforms + are relative too (#3870). PRESERVE_PATHS keeps every path.""" + + def vars_text(self, work_home, ext, **extra): + root = self.stub.unpack(self.stub.make_issue(work_home, **extra)) + with open(self.stub.find(root, f"vars-{FLOW_NAME}.{ext}")) as f: + return f.read() + + def test_python_exe_default(self): + self.assertIn( + "export PYTHON_EXE=${PYTHON_EXE:-python3}", self.vars_text(".", "sh") + ) + self.assertIn("set env(PYTHON_EXE) python3", self.vars_text(".", "tcl")) + + def test_work_home_paths_are_relative(self): + work = os.path.join(self.stub.tmp, "work") + text = self.vars_text(work, "sh", SIBLING=f"{work}_other/x") + self.assertIn( + f'export RESULTS_DIR="./results_dir/{PLATFORM}/{NICKNAME}/{VARIANT}"', text + ) + self.assertIn(f'export SIBLING="{work}_other/x"', text) + + def test_docker_paths_are_relative(self): + text = self.vars_text(".", "sh", DOCKER_FILE="/workspace/a /platforms/b") + self.assertIn('export DOCKER_FILE="./workspace/a ./platforms/b"', text) + + def test_preserve_paths(self): + work = os.path.join(self.stub.tmp, "work") + text = self.vars_text(work, "sh", PRESERVE_PATHS="1") + self.assertIn(f'export RESULTS_DIR="{work}/results_dir/', text) + + +class TestPlatformAndDesignFiles(StubFlowTestCase): + """The platform's Tcl, SDC and .cfg files are archived, and only + those it has (#2222); of the design and platform directories only the + config files are, unless FULL_ISSUE asks for all of them (#1771), + every platform config*.mk among them (#3870).""" + + def names(self, **extra): + archive = self.stub.make_issue(".", **extra) + return [os.path.basename(m) for m in self.stub.members(archive)] + + def test_platform_sdc_and_cfg(self): + for name in ["constraints.sdc", "fill.cfg"]: + self.stub.write(os.path.join(self.stub.platform_dir, name), "\n") + names = self.names() + for name in ["pdn.tcl", "constraints.sdc", "fill.cfg"]: + self.assertIn(name, names) + + def test_no_glob_for_files_the_platform_does_not_have(self): + globs = makeIssue.platform_globs(self.stub.platform_dir) + self.assertEqual(globs, [f"{self.stub.platform_dir}/*.tcl"]) + + def test_only_config_files_by_default(self): + self.stub.write(os.path.join(self.stub.platform_dir, "config_extra.mk"), "\n") + self.stub.write(os.path.join(self.stub.platform_dir, "cells.gds"), "\n") + self.stub.write(os.path.join(self.stub.design_dir, "rtl.v"), "\n") + names = self.names() + self.assertIn("config.mk", names) + self.assertIn("config_extra.mk", names) + self.assertNotIn("cells.gds", names) + self.assertNotIn("rtl.v", names) + + def test_full_issue_archives_everything(self): + self.stub.write(os.path.join(self.stub.platform_dir, "cells.gds"), "\n") + self.stub.write(os.path.join(self.stub.design_dir, "rtl.v"), "\n") + names = self.names(FULL_ISSUE="1") + self.assertIn("cells.gds", names) + self.assertIn("rtl.v", names) + + +class TestExcludePlatformWorkHome(StubFlowTestCase): + """EXCLUDE_PLATFORM drops the liberty and LEF files from the archive + makeIssue writes in WORK_HOME, wherever WORK_HOME is.""" + + def assert_excluded(self, work_home): + for name in ["cells.lib", "cells.lef"]: + self.stub.write(os.path.join(self.stub.platform_dir, name), "\n") + archive = self.stub.make_issue(work_home, EXCLUDE_PLATFORM="1", FULL_ISSUE="1") + names = [os.path.basename(m) for m in self.stub.members(archive)] + self.assertNotIn("cells.lib", names) + self.assertNotIn("cells.lef", names) + self.assertIn("pdn.tcl", names) + + def test_work_home_default(self): + self.assert_excluded(".") + + def test_work_home_absolute(self): + self.assert_excluded(os.path.join(self.stub.tmp, "work")) + + def test_work_home_relative(self): + self.assert_excluded("work/stub") + + +if __name__ == "__main__": + unittest.main() diff --git a/flow/util/generate-vars.sh b/flow/util/generate-vars.sh deleted file mode 100755 index 27feedf4fe..0000000000 --- a/flow/util/generate-vars.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -FLOW_ROOT=$(realpath "${FLOW_HOME}") -ORFS_ROOT=$(realpath "${FLOW_HOME}/../") -WORK_ROOT=$(realpath "${WORK_HOME:-.}") - -# exclude system and CI variables -EXCLUDED_VARS='MAKE|MAKEFLAGS|PERL5LIB|QT_QPA_PLATFORM' -EXCLUDED_VARS+='|RESULTS_ODB|PUBLIC|ISSUE_SCRIPTS' -EXCLUDED_VARS+='|HOME|PWD|MAIL|SHELL|NPROC|NUM_CORES|FLOW_HOME|\\n' -EXCLUDED_VARS+='|UNSET_VARIABLES_NAMES|do-step|get_variables|do-copy' -EXCLUDED_VARS+='|CURDIR|OPEN_GUI|OPEN_GUI_SHORTCUT' -EXCLUDED_VARS+='|COMMAND_LINE_ARGS' - -EXCLUDED_PATTERNS="_EXE$|PATH$|_CMD$|\." - -echo 'export FLOW_HOME=${FLOW_HOME:-$(pwd)}' > $1.sh -# *_EXE paths are machine specific and excluded below; default to PATH lookup. -echo 'export PYTHON_EXE=${PYTHON_EXE:-python3}' >> $1.sh -echo 'if { ![info exists env(PYTHON_EXE)] } { set env(PYTHON_EXE) python3 }' > $1.tcl - -while read -r VAR; do - if [[ ${VAR} != *"="* ]] ; then - # skip variables that do not have an equal sign - # they are invalid in shell - continue - fi - name="${VAR%%=*}" - value="${VAR#*=}" - if [[ "${name}" =~ ^[[:digit:]] ]] ; then - # skip if the name starts with a number - # they are invalid in shell - continue - fi - if [[ "${value}" == "''" ]]; then - # avoid exporting empty variables as var='''' - # instead export as var='' - value= - fi - if [[ "${name}" == *"MAKEFILE"* ]] ; then - # skip make variables - continue - fi - if [[ "${name}" =~ ^(${EXCLUDED_VARS})$ ]] ; then - # skip variables from the exclude list - continue - fi - if [[ "${name}" =~ ${EXCLUDED_PATTERNS} ]] ; then - # skip variables that match the exclude patterns - continue - fi - - # convert absolute paths if possible to use FLOW_HOME variable - if [[ "${name}" == *"SCRIPTS_DIR"* ]]; then - value=$(sed -e "s,${FLOW_ROOT},.,g" <<< "${value}") - fi - - # PII members use PRESERVE_PATHS=1 make issue ... - if [[ ! -v PRESERVE_PATHS ]]; then - # Relativize paths under WORK_HOME (e.g. a CI workspace); makeIssue.sh - # stores those files at the tarball root. Both the literal and the - # symlink-resolved form may appear in values. Skip when WORK_HOME is - # FLOW_HOME, which is handled via ${FLOW_HOME} below. - for work_path in "${WORK_HOME:-.}" "${WORK_ROOT}"; do - work_path="${work_path%/}" - if [[ "${work_path}" == /* && "${work_path}" != "${FLOW_ROOT}" ]]; then - # require a path boundary after the match so e.g. /tmp/work - # does not corrupt /tmp/work_other - value=$(sed -e "s,\(^\|[: \"']\)${work_path}\(/\|[: \"']\|$\),\1.\2,g" <<< "${value}") - fi - done - for path in workspace platforms; do - value=$(sed -e "s,\(^\|[: \"']\)/${path},\1./${path},g" <<< "${value}") - done - fi - value=$(sed -e "s,${FLOW_ROOT},\${FLOW_HOME},g" <<< "${value}") - value=$(sed -e "s,${ORFS_ROOT},\${FLOW_HOME}/\.\.,g" <<< "${value}") - - echo "export ${name}=\"${value}\"" >> $1.sh - if [[ "${value}" == *'$'* ]]; then - echo "set env ${name} $(sed -e 's,${FLOW_HOME},getenv("FLOW_HOME"),g' <<< ${value})" >> $1.gdb - echo "set env(${name}) \"$(sed -e 's,${FLOW_HOME},$::env(FLOW_HOME),g' <<< ${value})\"" >> $1.tcl - else - echo "set env(${name}) \"${value}\"" >> $1.tcl - echo "set env ${name} ${value}" >> $1.gdb - fi -done <<< "$ISSUE_VARIABLES" diff --git a/flow/util/generate_vars.py b/flow/util/generate_vars.py new file mode 100644 index 0000000000..8cac5e4a34 --- /dev/null +++ b/flow/util/generate_vars.py @@ -0,0 +1,150 @@ +#!/usr/bin/env python3 +"""Write the flow's variables as vars files: .sh, .tcl and .gdb. + +`make vars` and `make _issue` write them, so that a step can be run +by hand, under gdb or from an issue archive on another machine: + + source vars.sh # bash + source vars.tcl # openroad, yosys + source vars.gdb # gdb --args openroad ... + +The variables come from ISSUE_VARIABLES, which the flow's Makefile +exports as one NAME=value per line. Paths are spelled through FLOW_HOME, +and paths under WORK_HOME and a docker image's /workspace and /platforms +are made relative, so that the files work wherever the flow is unpacked; +PRESERVE_PATHS keeps every other path as it is. + +Usage: generate_vars.py +""" + +import os +import re +import sys + +# The make machinery's and the machine's own variables, which mean +# nothing on another machine. +EXCLUDED_VARS = re.compile( + r"^(" + r"MAKE|MAKEFLAGS|PERL5LIB|QT_QPA_PLATFORM" + r"|RESULTS_ODB|PUBLIC|ISSUE_SCRIPTS" + r"|HOME|PWD|MAIL|SHELL|NPROC|NUM_CORES|FLOW_HOME|\\n" + r"|UNSET_VARIABLES_NAMES|do-step|get_variables|do-copy" + r"|CURDIR|OPEN_GUI|OPEN_GUI_SHORTCUT" + r"|COMMAND_LINE_ARGS" + r")$" +) + +# Executables and commands are machine specific, as are search paths; +# a name with a dot is not a shell variable. +EXCLUDED_PATTERNS = re.compile(r"_EXE$|PATH$|_CMD$|\.") + +# A path in a value starts at the value's start or after a separator. +SEPARATOR = "[: \"']" + +SH_HEADER = ( + "export FLOW_HOME=${FLOW_HOME:-$(pwd)}\n" + # *_EXE paths are machine specific and excluded; default to PATH lookup. + "export PYTHON_EXE=${PYTHON_EXE:-python3}\n" +) +TCL_HEADER = "if { ![info exists env(PYTHON_EXE)] } { set env(PYTHON_EXE) python3 }\n" + + +def path_pattern(path): + """A path as a pattern that matches it where it appears in a value.""" + return re.escape(path) + + +def replace_path(value, path, replacement): + return re.sub(path_pattern(path), lambda _: replacement, value) + + +def variables(issue_variables): + """The (name, value) pairs of ISSUE_VARIABLES that belong in the vars + files, in order: one NAME=value per line, surrounding blanks ignored, + the value everything after the first '='.""" + for line in issue_variables.split("\n"): + line = line.strip(" \t") + if "=" not in line: + continue + name, value = line.split("=", 1) + if name[:1].isdigit(): + # not a valid shell name + continue + if value == "''": + # make's spelling of an empty value + value = "" + if "MAKEFILE" in name: + continue + if EXCLUDED_VARS.search(name) or EXCLUDED_PATTERNS.search(name): + continue + yield name, value + + +def relative_value(name, value, env, flow_root, orfs_root, work_root): + """The value with its paths spelled so that it works on another + machine.""" + if "SCRIPTS_DIR" in name: + # the scripts are in the archive, next to the vars files + value = replace_path(value, flow_root, ".") + + if "PRESERVE_PATHS" not in env: + # Paths under WORK_HOME (a CI workspace, say) are relative to the + # archive's root, where makeIssue.py stores those files. Both the + # literal and the symlink-resolved WORK_HOME may appear. WORK_HOME + # inside FLOW_HOME is spelled through FLOW_HOME below. + for work_path in [env.get("WORK_HOME") or ".", work_root]: + if work_path.endswith("/"): + work_path = work_path[:-1] + if work_path.startswith("/") and work_path != flow_root: + # a path boundary after it, so that /tmp/work does not + # match /tmp/work_other + value = re.sub( + f"(^|{SEPARATOR}){path_pattern(work_path)}(/|{SEPARATOR}|$)", + lambda m: m.group(1) + "." + m.group(2), + value, + ) + for path in ["workspace", "platforms"]: + value = re.sub( + f"(^|{SEPARATOR})/{path}", + lambda m, path=path: m.group(1) + "./" + path, + value, + ) + + value = replace_path(value, flow_root, "${FLOW_HOME}") + return replace_path(value, orfs_root, "${FLOW_HOME}/..") + + +def write_vars(basename, env): + """Writes .sh, .tcl and .gdb from env's ISSUE_VARIABLES.""" + flow_root = os.path.realpath(env["FLOW_HOME"]) + orfs_root = os.path.realpath(env["FLOW_HOME"] + "/../") + work_root = os.path.realpath(env.get("WORK_HOME") or ".") + + sh = [SH_HEADER] + tcl = [TCL_HEADER] + gdb = [] + for name, value in variables(env["ISSUE_VARIABLES"]): + value = relative_value(name, value, env, flow_root, orfs_root, work_root) + sh.append(f'export {name}="{value}"\n') + if "$" in value: + gdb_value = value.replace("${FLOW_HOME}", 'getenv("FLOW_HOME")') + tcl_value = value.replace("${FLOW_HOME}", "$::env(FLOW_HOME)") + gdb.append(f"set env {name} {gdb_value}\n") + tcl.append(f'set env({name}) "{tcl_value}"\n') + else: + tcl.append(f'set env({name}) "{value}"\n') + gdb.append(f"set env {name} {value}\n") + + for ext, lines in [("sh", sh), ("tcl", tcl), ("gdb", gdb)]: + with open(f"{basename}.{ext}", "w") as f: + f.write("".join(lines)) + + +def main(): + if len(sys.argv) != 2: + sys.exit(f"usage: {sys.argv[0]} ") + write_vars(sys.argv[1], os.environ) + + +if __name__ == "__main__": + main() diff --git a/flow/util/makeIssue.py b/flow/util/makeIssue.py new file mode 100755 index 0000000000..46e83ecafc --- /dev/null +++ b/flow/util/makeIssue.py @@ -0,0 +1,303 @@ +#!/usr/bin/env python3 +"""Archive a flow step as a self-contained reproducible: `make _issue`. + +The archive holds the step's inputs (the flow's logs, objects, reports and +results, the scripts, the design and platform files the flow variables +name), a vars file with every flow variable, and a run-me script that runs +the step from wherever the archive is unpacked. + +Usage: makeIssue.py / + +The flow's Makefile exports the variables this reads (WORK_HOME, the +*_DIR variables, DESIGN_NICKNAME, PLATFORM, FLOW_VARIANT, ...) and +ISSUE_VARIABLES, which generate_vars.py writes into the vars files. +""" + +import datetime +import glob +import os +import re +import shutil +import subprocess +import sys + +import yaml + +import generate_vars + +UTILS_DIR = os.path.dirname(os.path.abspath(__file__)) + +# variables.yaml describes every flow variable; `type: file` marks the +# ones that name files a step may read. +VARIABLES_YAML = os.path.join(UTILS_DIR, "..", "scripts", "variables.yaml") + +# Platform files dropped from the archive with EXCLUDE_PLATFORM: a name +# that ends in lib, lef or tlef after any character. +PLATFORM_LIBRARY = re.compile(r".(lib|lef|tlef)$", re.IGNORECASE) + +YOSYS_SCRIPT = re.compile(r"synth_preamble|yosys -import") + + +def expand(words): + """Splits on whitespace and expands each glob, as an unquoted shell + word would be; a glob that matches nothing stays as written.""" + expanded = [] + for word in words.split(): + matches = sorted(glob.glob(word)) + expanded.extend(matches if matches else [word]) + return expanded + + +def platform_globs(platform_dir): + """The platform's Tcl scripts, and its SDC and .cfg files if it has any.""" + globs = [f"{platform_dir}/*.tcl"] + for ext in ["sdc", "cfg"]: + if glob.glob(f"{platform_dir}/*.{ext}"): + globs.append(f"{platform_dir}/*.{ext}") + return globs + + +def flow_variables(): + with open(VARIABLES_YAML) as f: + return yaml.safe_load(f) + + +def file_variables(): + """The flow variables that name files: `type: file` in + variables.yaml.""" + return sorted( + name + for name, variable in flow_variables().items() + if variable.get("type") == "file" + ) + + +def platform_file_variables(): + """The file variables that name the platform's files, wherever the + platform keeps them: `platform: true` in variables.yaml.""" + return sorted( + name + for name, variable in flow_variables().items() + if variable.get("type") == "file" and variable.get("platform") + ) + + +def in_platform(path, platform_dir): + """Whether the file lies under the platform directory, as it is + named or through a symlink.""" + return any( + resolve(path).startswith(resolve(platform_dir) + os.sep) + for resolve in [os.path.abspath, os.path.realpath] + ) + + +def issue_files(env, vars_basename, run_me_script): + """The files the flow variables name, the platform's scripts and the + issue's own vars and run-me files, sorted and without duplicates. + EXCLUDE_PLATFORM leaves out the files the platform's variables name + and the files under the platform directory, whichever variable names + them.""" + names = file_variables() + words = [] + if "EXCLUDE_PLATFORM" in env: + platform = platform_file_variables() + names = [name for name in names if name not in platform] + else: + words += platform_globs(env["PLATFORM_DIR"]) + files = expand(" ".join(env[name] for name in names if name in env)) + if "EXCLUDE_PLATFORM" in env: + files = [f for f in files if not in_platform(f, env["PLATFORM_DIR"])] + words += [ + f"{env['UTILS_DIR']}/def2stream.py", + run_me_script, + f"{vars_basename}.sh", + f"{vars_basename}.tcl", + f"{vars_basename}.gdb", + ] + return sorted(set(files + expand(" ".join(words)))) + + +def is_yosys_step(script): + with open(script) as f: + return YOSYS_SCRIPT.search(f.read()) is not None + + +def archive_root_from_run_me(work_home, vars_basename): + """Where run-me changes to, relative to its own directory, and the vars + file's path from there: the archive's root, where the vars' paths + start. run-me is at the root when WORK_HOME is absolute (its path is + stripped from the members) or the flow directory; a relative WORK_HOME + keeps its place under the root, spelled as tar was given it, and + run-me climbs back from it. Both paths follow that spelling, not the + directory a symlink in it resolves to, as the member names do.""" + work = os.path.normpath(work_home) + if os.path.isabs(work) or work == ".": + return None, f"./{os.path.basename(vars_basename)}.sh" + root = os.path.join(*[".."] * len(work.split(os.sep))) + return root, f"./{os.path.normpath(vars_basename)}.sh" + + +def run_me_text(env, issue_target, vars_basename, yosys): + """The run-me script: it changes to the archive's root, sources the + vars file from there and runs the step's script.""" + root, vars_path = archive_root_from_run_me( + env.get("WORK_HOME") or ".", vars_basename + ) + run_me_dir = '"$(dirname "$0")"' if root is None else f'"$(dirname "$0")/{root}"' + lines = [ + "#!/usr/bin/env bash", + f"cd {run_me_dir}", + f"source {vars_path}", + ] + script = "${SCRIPTS_DIR}/" + issue_target + ".tcl" + if yosys: + lines.append(f"yosys {env.get('YOSYS_FLAGS', '')} -c {script}") + else: + threads = env.get("NUM_CORES") or "1" + openroad = f"openroad -no_init -threads {threads} {script}" + lines += [ + "if [[ ! -z ${GDB+x} ]]; then", + f" gdb --args {openroad}", + "else", + f" {openroad}", + "fi", + ] + return "\n".join(lines) + "\n" + + +def write_executable(path, text): + with open(path, "w") as f: + f.write(text) + umask = os.umask(0) + os.umask(umask) + os.chmod(path, os.stat(path).st_mode | (0o111 & ~umask)) + + +def compressor(): + """pigz compresses in parallel; gzip when it is not installed.""" + return "pigz" if shutil.which("pigz") else "gzip" + + +def tar_transforms(issue_name, flow_home, work_home): + """Member names under the issue's directory, with the FLOW_HOME and + WORK_HOME prefixes stripped, so files generated outside FLOW_HOME (a + CI workspace) land at the archive's root instead of recreating the + absolute path. Both the literal and the symlink-resolved WORK_HOME + may appear in member names.""" + work_root = os.path.realpath(work_home) + transforms = [ + f"s|^|{issue_name}/|S", + f"s|^{issue_name}{flow_home}/|{issue_name}/|S", + f"s|^{issue_name}{work_root}//*|{issue_name}/|S", + ] + literal = work_home.rstrip("/") + if work_home.startswith("/") and literal != work_root: + transforms.append(f"s|^{issue_name}{literal}//*|{issue_name}/|S") + return ["--transform=" + t for t in transforms] + + +def design_platform_files(env): + if "FULL_ISSUE" in env: + return expand(f"{env['DESIGN_DIR']} {env['PLATFORM_DIR']}") + return expand(f"{env['DESIGN_CONFIG']} {env['PLATFORM_DIR']}/config*.mk") + + +def tar_command(env, tar_name, issue_name, files): + return ( + [ + "tar", + f"--use-compress-program={compressor()}", + "--ignore-failed-read", + "-chf", + tar_name, + ] + + tar_transforms(issue_name, env["FLOW_HOME"], env.get("WORK_HOME") or ".") + + design_platform_files(env) + + expand( + " ".join( + env[name] + for name in [ + "LOG_DIR", + "OBJECTS_DIR", + "REPORTS_DIR", + "RESULTS_DIR", + "SCRIPTS_DIR", + ] + ) + ) + + files + ) + + +def exclude_platform_library(tar_name, transforms, design_library): + """Drops the liberty and LEF files from the archive: the platform's + own, and the copies the flow keeps of them among its objects and + results. The design's, which a file variable names, are put back.""" + tar = tar_name[: -len(".gz")] + subprocess.run(["gunzip", "-f", tar_name], check=True) + members = subprocess.run( + ["tar", "--list", "--file", tar], + check=True, + stdout=subprocess.PIPE, + universal_newlines=True, + ).stdout.splitlines() + library = sorted({m for m in members if PLATFORM_LIBRARY.search(m)}) + if library: + subprocess.run(["tar", "--delete", "--file", tar] + library, check=True) + if design_library: + subprocess.run( + ["tar", "--ignore-failed-read", "-rhf", tar] + transforms + design_library, + check=True, + ) + subprocess.run(["gzip", tar], check=True) + + +def make_issue(target, env): + issue_target = os.path.basename(target) + issue_dest = os.path.dirname(target) or "." + print(f"Creating issue for target {issue_target} in {issue_dest}", flush=True) + + date = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M") + issue_tag = env.get("ISSUE_TAG") or ( + f"{env['DESIGN_NICKNAME']}_{env['PLATFORM']}_{env['FLOW_VARIANT']}_{date}" + ) + flow_name = f"{env['DESIGN_NICKNAME']}-{env['PLATFORM']}-{env['FLOW_VARIANT']}" + vars_basename = f"{env['WORK_HOME']}/vars-{flow_name}" + run_me_script = f"{env['WORK_HOME']}/run-me-{flow_name}.sh" + + files = issue_files(env, vars_basename, run_me_script) + + yosys = is_yosys_step(f"{env['SCRIPTS_DIR']}/{issue_target}.tcl") + write_executable( + run_me_script, run_me_text(env, issue_target, vars_basename, yosys) + ) + + generate_vars.write_vars(vars_basename, env) + + issue_name = f"{issue_target}_{issue_tag}" + tar_name = f"{issue_dest}/{issue_name}.tar.gz" + print(f"Archiving issue to {tar_name}", flush=True) + print(f"Using {compressor()} to compress tar file", flush=True) + subprocess.run(tar_command(env, tar_name, issue_name, files), check=True) + + if "EXCLUDE_PLATFORM" in env: + exclude_platform_library( + tar_name, + tar_transforms(issue_name, env["FLOW_HOME"], env.get("WORK_HOME") or "."), + [f for f in files if PLATFORM_LIBRARY.search(f)], + ) + + if "COPY_ISSUE" in env: + os.makedirs(env["COPY_ISSUE"], exist_ok=True) + shutil.copy(tar_name, env["COPY_ISSUE"]) + return tar_name + + +def main(): + if len(sys.argv) != 2: + sys.exit(f"usage: {sys.argv[0]} /") + make_issue(sys.argv[1], dict(os.environ)) + + +if __name__ == "__main__": + main() diff --git a/flow/util/makeIssue.sh b/flow/util/makeIssue.sh deleted file mode 100755 index 27737516be..0000000000 --- a/flow/util/makeIssue.sh +++ /dev/null @@ -1,162 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -ISSUE_TARGET=$(basename $1) -ISSUE_DEST=$(dirname $1) - -echo "Creating issue for target ${ISSUE_TARGET} in ${ISSUE_DEST}" - -currentDate=$(date +"%Y-%m-%d_%H-%M") -ISSUE_TAG=${ISSUE_TAG:-"${DESIGN_NICKNAME}_${PLATFORM}_${FLOW_VARIANT}_${currentDate}"} -ISSUE_CP_DESIGN_FILE_VARS="SDC_FILE \ - VERILOG_FILES \ - SYNTH_NETLIST_FILES \ - FOOTPRINT_TCL \ - FOOTPRINT \ - SIG_MAP_FILE \ - IO_CONSTRAINTS \ - MACRO_PLACEMENT_TCL \ - MACRO_WRAPPERS \ - RTLMP_CONFIG_FILE \ - DFF_LIB_FILE " -ISSUE_CP_PLATFORM_FILE_VARS="LIB_FILES \ - SC_LEF \ - TECH_LEF \ - ADDITIONAL_FILES \ - ADDITIONAL_LEFS \ - CLKGATE_MAP_FILE \ - ADDER_MAP_FILE \ - LATCH_MAP_FILE \ - CDL_FILE \ - MAKE_TRACKS \ - POST_FLOORPLAN_TCL \ - TAPCELL_TCL \ - PDN_CFG \ - GLOBAL_CONNECT_TCL \ - PDN_TCL \ - POST_PDN_TCL \ - POST_CTS_TCL \ - PRE_GLOBAL_ROUTE_TCL \ - FASTROUTE_TCL \ - POST_DETAIL_ROUTE_TCL \ - RCX_RULES \ - FILL_CONFIG " -ISSUE_CP_FILE_VARS=$ISSUE_CP_DESIGN_FILE_VARS - -ISSUE_CP_FILES_PLATFORM="" -if [[ ! -v EXCLUDE_PLATFORM ]]; then - ISSUE_CP_FILE_VARS+=$ISSUE_CP_PLATFORM_FILE_VARS - ISSUE_CP_FILES_PLATFORM="$PLATFORM_DIR/*.tcl" - if ls $PLATFORM_DIR/*.sdc 1> /dev/null 2>&1; then - ISSUE_CP_FILES_PLATFORM="$ISSUE_CP_FILES_PLATFORM $PLATFORM_DIR/*.sdc" - fi - if ls $PLATFORM_DIR/*.cfg 1> /dev/null 2>&1; then - ISSUE_CP_FILES_PLATFORM="$ISSUE_CP_FILES_PLATFORM $PLATFORM_DIR/*.cfg" - fi -fi - -VARS_BASENAME=${WORK_HOME}/vars-$DESIGN_NICKNAME-$PLATFORM-$FLOW_VARIANT -RUN_ME_SCRIPT=${WORK_HOME}/run-me-$DESIGN_NICKNAME-$PLATFORM-$FLOW_VARIANT.sh - -for i in $ISSUE_CP_FILE_VARS ; do - if [ -v ${i} ]; then - filename=$i - ISSUE_CP_FILES+="${!filename} " - fi -done - -ISSUE_CP_FILES+="${ISSUE_CP_FILES_PLATFORM} \ - $UTILS_DIR/def2stream.py \ - ${RUN_ME_SCRIPT} \ - $VARS_BASENAME.sh \ - $VARS_BASENAME.tcl \ - $VARS_BASENAME.gdb" - -ISSUE_SCRIPT=${SCRIPTS_DIR}/${ISSUE_TARGET}.tcl -if grep -q -E "synth_preamble|yosys -import" "${ISSUE_SCRIPT}"; then - IS_YOSYS=1 -else - IS_YOSYS=0 -fi - -# Source the vars file relative to the run-me script itself, so the -# reproducible works out of the box wherever the tarball is extracted -# (WORK_HOME is an absolute CI path that does not exist elsewhere). -if [ "$IS_YOSYS" -eq 1 ]; then -cat > ${RUN_ME_SCRIPT} < ${RUN_ME_SCRIPT} < /dev/null; then - COMPRESS=pigz -else - COMPRESS=gzip -fi - -echo "Using $COMPRESS to compress tar file" - -# Save all files inside design and platform folders -if [ -v FULL_ISSUE ]; then - DESIGN_PLATFORM_FILES="$DESIGN_DIR $PLATFORM_DIR" -else - DESIGN_PLATFORM_FILES="$DESIGN_CONFIG $PLATFORM_DIR/config*.mk" -fi - -# Strip the WORK_HOME prefix as well, so files generated outside FLOW_HOME -# (vars, run-me, logs, ... when WORK_HOME points at a CI workspace) land at -# the tarball root instead of recreating the absolute path (e.g. tmp/...). -# Both the literal and the symlink-resolved form may appear in member names. -WORK_ROOT=$(realpath "${WORK_HOME:-.}") -WORK_HOME_TRANSFORMS=(--transform="s|^${ISSUE_TARGET}_${ISSUE_TAG}${WORK_ROOT}//*|${ISSUE_TARGET}_${ISSUE_TAG}/|S") -if [[ "${WORK_HOME:-.}" == /* && "${WORK_HOME%/}" != "${WORK_ROOT}" ]]; then - WORK_HOME_TRANSFORMS+=(--transform="s|^${ISSUE_TARGET}_${ISSUE_TAG}${WORK_HOME%/}//*|${ISSUE_TARGET}_${ISSUE_TAG}/|S") -fi -tar --use-compress-program=${COMPRESS} \ - --ignore-failed-read -chf ${TAR_NAME} \ - --transform="s|^|${ISSUE_TARGET}_${ISSUE_TAG}/|S" \ - --transform="s|^${ISSUE_TARGET}_${ISSUE_TAG}${FLOW_HOME}/|${ISSUE_TARGET}_${ISSUE_TAG}/|S" \ - "${WORK_HOME_TRANSFORMS[@]}" \ - $DESIGN_PLATFORM_FILES \ - $LOG_DIR \ - $OBJECTS_DIR \ - $REPORTS_DIR \ - $RESULTS_DIR \ - $SCRIPTS_DIR \ - $(for f in $ISSUE_CP_FILES; do echo $f; done | sort | uniq) - -if [ -v EXCLUDE_PLATFORM ]; then - # Remove liberty and lef files from tar file - gunzip -f ${TAR_NAME} - tar --list --file ${ISSUE_TARGET}_${ISSUE_TAG}.tar | grep -iE "*.(lib|lef|tlef)$" | xargs -r tar --delete --file ${ISSUE_TARGET}_${ISSUE_TAG}.tar - gzip ${ISSUE_TARGET}_${ISSUE_TAG}.tar -fi - -if [ ! -z ${COPY_ISSUE+x} ]; then - mkdir -p ${COPY_ISSUE} ; - cp ${TAR_NAME} ${COPY_ISSUE} ; -fi diff --git a/flow/util/utils.mk b/flow/util/utils.mk index 15c20df73d..eace791043 100644 --- a/flow/util/utils.mk +++ b/flow/util/utils.mk @@ -166,7 +166,7 @@ endef .PHONY: $(foreach script,$(ISSUE_SCRIPTS),$(script)_issue) $(foreach script,$(ISSUE_SCRIPTS),$(script)_issue): %_issue : - $(UTILS_DIR)/makeIssue.sh $(WORK_HOME)/$* + $(PYTHON_EXE) $(UTILS_DIR)/makeIssue.py $(WORK_HOME)/$* .PHONY: clean_issues clean_issues: