Skip to content

Commit

Permalink
hermetic builds (#1160)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cc10512 authored Oct 29, 2024
1 parent 5216071 commit bad0d6b
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 18 deletions.
6 changes: 4 additions & 2 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ add_custom_command(
COMMAND
${Python_EXECUTABLE} ${SCRIPTS_DIR}/diagnostic_gen.py --outDir
${CMAKE_CURRENT_BINARY_DIR} --docs --slangBin $<TARGET_FILE:slang::driver>
--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
Expand Down
3 changes: 3 additions & 0 deletions include/slang/diagnostics/DiagArgFormatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#pragma once

#include <any>
#include <string>

#include "slang/slang_export.h"

namespace slang {

Expand Down
1 change: 1 addition & 0 deletions include/slang/util/BumpAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <cstring>
#include <new>
#include <span>
#include <type_traits>

#include "slang/util/Util.h"

Expand Down
4 changes: 4 additions & 0 deletions include/slang/util/CopyPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
//------------------------------------------------------------------------------
#pragma once

#include <cstddef>
#include <ostream>
#include <utility>

namespace slang {

/// A smart pointer that allocates its pointee on the heap and provides value copy
Expand Down
2 changes: 2 additions & 0 deletions include/slang/util/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
//------------------------------------------------------------------------------
#pragma once

#include <cstddef>
#include <cstdint>
#include <type_traits>

namespace slang {

Expand Down
1 change: 1 addition & 0 deletions include/slang/util/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//------------------------------------------------------------------------------
#pragma once

#include <algorithm>
#include <array>
#include <functional>
#include <random>
Expand Down
1 change: 1 addition & 0 deletions include/slang/util/SmallVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include <algorithm>
#include <iterator>
#include <limits>
#include <memory>
#include <span>
Expand Down
17 changes: 7 additions & 10 deletions scripts/diagnostic_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import shlex
import subprocess
import sys


def writefile(path, contents):
Expand All @@ -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 = []
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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():
Expand Down
10 changes: 7 additions & 3 deletions scripts/syntax_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -765,6 +766,9 @@ def generateSyntax(builddir, alltypes, kindmap):
//------------------------------------------------------------------------------
#pragma once
#include <ostream>
#include "slang/slang_export.h"
namespace std { class type_info; }
namespace slang::syntax {
Expand Down
5 changes: 3 additions & 2 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tools/netlist/include/DirectedGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Node {
return *this;
}
Node<NodeType, EdgeType>& operator=(Node<NodeType, EdgeType>&& node) noexcept {
edges = std::move(node.Edges);
edges = std::move(node.edges);
return *this;
}

Expand Down

0 comments on commit bad0d6b

Please sign in to comment.