From bad0d6ba3dec20355b0156c535bbddf2f926ab37 Mon Sep 17 00:00:00 2001 From: Calin Cascaval <3770874+cc10512@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:45:04 +1300 Subject: [PATCH] hermetic builds (#1160) Adds explicit arguments to the generator scripts to point to the input such that they can be used in a hermetic build where the scripts do not run from the source directory. Remaining inputs are assume to be in the same directory. --- bindings/CMakeLists.txt | 6 ++++-- docs/CMakeLists.txt | 1 + include/slang/diagnostics/DiagArgFormatter.h | 3 +++ include/slang/util/BumpAllocator.h | 1 + include/slang/util/CopyPtr.h | 4 ++++ include/slang/util/Function.h | 2 ++ include/slang/util/Random.h | 1 + include/slang/util/SmallVector.h | 1 + scripts/diagnostic_gen.py | 17 +++++++---------- scripts/syntax_gen.py | 10 +++++++--- source/CMakeLists.txt | 5 +++-- tools/netlist/include/DirectedGraph.h | 2 +- 12 files changed, 35 insertions(+), 18 deletions(-) diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt index caf708d44..0fe436e77 100644 --- a/bindings/CMakeLists.txt +++ b/bindings/CMakeLists.txt @@ -25,8 +25,10 @@ endif() # Generate bindings for syntax node types add_custom_command( - COMMAND ${Python_EXECUTABLE} ${SCRIPTS_DIR}/syntax_gen.py --dir - ${CMAKE_CURRENT_BINARY_DIR} --python-bindings + COMMAND + ${Python_EXECUTABLE} ${SCRIPTS_DIR}/syntax_gen.py --dir + ${CMAKE_CURRENT_BINARY_DIR} --python-bindings --syntax + ${SCRIPTS_DIR}/syntax.txt OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/PySyntaxBindings0.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySyntaxBindings1.cpp ${CMAKE_CURRENT_BINARY_DIR}/PySyntaxBindings2.cpp diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 4db315a05..d75e9368f 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -36,6 +36,7 @@ add_custom_command( COMMAND ${Python_EXECUTABLE} ${SCRIPTS_DIR}/diagnostic_gen.py --outDir ${CMAKE_CURRENT_BINARY_DIR} --docs --slangBin $ + --diagnostics ${SCRIPTS_DIR}/diagnostics.txt OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/warnings.dox DEPENDS ${SCRIPTS_DIR}/diagnostic_gen.py ${SCRIPTS_DIR}/diagnostics.txt ${SCRIPTS_DIR}/warning_docs.txt diff --git a/include/slang/diagnostics/DiagArgFormatter.h b/include/slang/diagnostics/DiagArgFormatter.h index 5c84c1385..aa87f543f 100644 --- a/include/slang/diagnostics/DiagArgFormatter.h +++ b/include/slang/diagnostics/DiagArgFormatter.h @@ -8,6 +8,9 @@ #pragma once #include +#include + +#include "slang/slang_export.h" namespace slang { diff --git a/include/slang/util/BumpAllocator.h b/include/slang/util/BumpAllocator.h index 75d8ac729..c6a1426bb 100644 --- a/include/slang/util/BumpAllocator.h +++ b/include/slang/util/BumpAllocator.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "slang/util/Util.h" diff --git a/include/slang/util/CopyPtr.h b/include/slang/util/CopyPtr.h index 0dab7512e..f7a0f4989 100644 --- a/include/slang/util/CopyPtr.h +++ b/include/slang/util/CopyPtr.h @@ -7,6 +7,10 @@ //------------------------------------------------------------------------------ #pragma once +#include +#include +#include + namespace slang { /// A smart pointer that allocates its pointee on the heap and provides value copy diff --git a/include/slang/util/Function.h b/include/slang/util/Function.h index d740c4406..4b47337d9 100644 --- a/include/slang/util/Function.h +++ b/include/slang/util/Function.h @@ -7,7 +7,9 @@ //------------------------------------------------------------------------------ #pragma once +#include #include +#include namespace slang { diff --git a/include/slang/util/Random.h b/include/slang/util/Random.h index 1bb019755..1f9015f14 100644 --- a/include/slang/util/Random.h +++ b/include/slang/util/Random.h @@ -7,6 +7,7 @@ //------------------------------------------------------------------------------ #pragma once +#include #include #include #include diff --git a/include/slang/util/SmallVector.h b/include/slang/util/SmallVector.h index 007db63a7..b1c6e9bf8 100644 --- a/include/slang/util/SmallVector.h +++ b/include/slang/util/SmallVector.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include #include diff --git a/scripts/diagnostic_gen.py b/scripts/diagnostic_gen.py index 453d5fbe2..401896ee6 100755 --- a/scripts/diagnostic_gen.py +++ b/scripts/diagnostic_gen.py @@ -8,6 +8,7 @@ import os import shlex import subprocess +import sys def writefile(path, contents): @@ -28,17 +29,13 @@ def main(): parser.add_argument("--srcDir", help="Source directory to search for usages") parser.add_argument("--incDir", help="Include directory to search for usages") parser.add_argument("--docs", action="store_true") + parser.add_argument("--diagnostics", help="path to diagnostics file") parser.add_argument("--slangBin") args = parser.parse_args() - ourdir = os.path.dirname(os.path.realpath(__file__)) - inf = open(os.path.join(ourdir, "diagnostics.txt")) - + inf = open(args.diagnostics) headerdir = os.path.join(args.outDir, "slang", "diagnostics") - try: - os.makedirs(headerdir) - except OSError: - pass + os.makedirs(headerdir, exist_ok=True) diags = {} groups = [] @@ -88,7 +85,7 @@ def parsegroup(elems): if args.docs: createdocs( args.outDir, - os.path.join(ourdir, "warning_docs.txt"), + os.path.join(os.path.dirname(args.diagnostics), "warning_docs.txt"), args.slangBin, diags, groups, @@ -280,7 +277,7 @@ def createallheader(path, diags): def createdocs(outDir, inpath, slangBin, diags, groups): inf = open(inpath) - curropt = None + curropt = [None, None, None, None, None] inexample = False exampleMap = {} @@ -310,7 +307,7 @@ def createdocs(outDir, inpath, slangBin, diags, groups): curropt[1] += " " curropt[1] += line - if curropt: + if curropt[0]: exampleMap[curropt[0]] = curropt for k, v in exampleMap.items(): diff --git a/scripts/syntax_gen.py b/scripts/syntax_gen.py index 154fd64cc..3b5d813f9 100755 --- a/scripts/syntax_gen.py +++ b/scripts/syntax_gen.py @@ -48,17 +48,18 @@ def main(): parser = argparse.ArgumentParser(description="Diagnostic source generator") parser.add_argument("--dir", default=os.getcwd(), help="Output directory") parser.add_argument("--python-bindings", action="store_true") + parser.add_argument("--syntax", help="full path to syntax file") args = parser.parse_args() - ourdir = os.path.dirname(os.path.realpath(__file__)) - alltypes, kindmap = loadalltypes(ourdir) + inputdir = os.path.dirname(args.syntax) + alltypes, kindmap = loadalltypes(inputdir) if args.python_bindings: generatePyBindings(args.dir, alltypes) else: generateSyntaxClone(args.dir, alltypes, kindmap) generateSyntax(args.dir, alltypes, kindmap) - generateTokenKinds(ourdir, args.dir) + generateTokenKinds(inputdir, args.dir) def loadalltypes(ourdir): @@ -765,6 +766,9 @@ def generateSyntax(builddir, alltypes, kindmap): //------------------------------------------------------------------------------ #pragma once +#include +#include "slang/slang_export.h" + namespace std { class type_info; } namespace slang::syntax { diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 0b1e9324a..58d55c95a 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -10,7 +10,8 @@ add_custom_command( COMMAND ${Python_EXECUTABLE} ${SCRIPTS_DIR}/diagnostic_gen.py --outDir ${CMAKE_CURRENT_BINARY_DIR} --srcDir ${CMAKE_CURRENT_SOURCE_DIR} --incDir - ${CMAKE_CURRENT_SOURCE_DIR}/../include/slang + ${CMAKE_CURRENT_SOURCE_DIR}/../include/slang --diagnostics + ${SCRIPTS_DIR}/diagnostics.txt OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/slang/diagnostics/AllDiags.h ${CMAKE_CURRENT_BINARY_DIR}/slang/diagnostics/CompilationDiags.h ${CMAKE_CURRENT_BINARY_DIR}/slang/diagnostics/ConstEvalDiags.h @@ -33,7 +34,7 @@ add_custom_command( # Generate syntax headers and sources add_custom_command( COMMAND ${Python_EXECUTABLE} ${SCRIPTS_DIR}/syntax_gen.py --dir - ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR} --syntax ${SCRIPTS_DIR}/syntax.txt OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/slang/syntax/AllSyntax.h ${CMAKE_CURRENT_BINARY_DIR}/AllSyntax.cpp ${CMAKE_CURRENT_BINARY_DIR}/SyntaxClone.cpp diff --git a/tools/netlist/include/DirectedGraph.h b/tools/netlist/include/DirectedGraph.h index 54acd850d..eea7ec307 100644 --- a/tools/netlist/include/DirectedGraph.h +++ b/tools/netlist/include/DirectedGraph.h @@ -79,7 +79,7 @@ class Node { return *this; } Node& operator=(Node&& node) noexcept { - edges = std::move(node.Edges); + edges = std::move(node.edges); return *this; }