Skip to content

Commit fcfb080

Browse files
committed
Added GetTimeString. Refactored File Creation utilities into separate tcl source file
1 parent 814384b commit fcfb080

File tree

4 files changed

+162
-102
lines changed

4 files changed

+162
-102
lines changed

OsvvmScriptsCore.tcl

Lines changed: 6 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#
2121
# Revision History:
2222
# Date Version Description
23-
# 7/2024 2024.07 Updated LocalInclude to better restore state if it fails
23+
# 1/2025 2025.01 Added GetTimeString
24+
# 7/2024 2024.07 Updated LocalInclude to better restore state if the include fails
2425
# Fixed settings in SetLogSignals.
2526
# 5/2024 2024.05 Updated for refactor of Simulate2Html. Renamed in prep for breaking file into smaller chunks.
2627
# 3/2024 2024.03 Updated CreateOsvvmScriptSettingsPkg and added FindOsvvmSettingsDirectory
@@ -2011,7 +2012,7 @@ proc SimulateDoneMoveTestCaseFiles {} {
20112012
# file rename -force ${TranscriptFile} ${TranscriptDestFile}
20122013
file copy -force ${TranscriptFile} ${TranscriptDestFile}
20132014
if {[catch {file delete -force ${TranscriptFile}} err]} {
2014-
puts "ScriptError: Cannot delete ${TranscriptFile}. Simulation crashed and did not close it. SimulationInteractive is $::osvvm::SimulateInteractive so cannot EndSimulation"
2015+
puts "ScriptWarning: Simulation did not close ${TranscriptFile}. Will EndSimulation to close it if SimulationInteractive is false. SimulationInteractive = $::osvvm::SimulateInteractive"
20152016
# end simulation to try to free locks on the file, and try to delete again - in the event the test case forgot TranscriptClose
20162017
if {!$::osvvm::SimulateInteractive} {
20172018
EndSimulation
@@ -2111,110 +2112,17 @@ proc TimeIt {args} {
21112112
puts "Time: [ElapsedTimeMs $StartTimeMs]"
21122113
}
21132114

2114-
# -------------------------------------------------
2115-
# CreateOsvvmScriptSettingsPkg
2116-
# do an operation on a list of items
2117-
#
2118-
proc FindOsvvmSettingsDirectory {} {
2119-
if {$::osvvm::SettingsAreRelativeToSimulationDirectory} {
2120-
set SettingsDirectory [file join ${::osvvm::CurrentSimulationDirectory} ${::osvvm::OsvvmSettingsSubDirectory}]
2121-
} else {
2122-
set SettingsDirectory [file join ${::osvvm::OsvvmHomeDirectory} "osvvm" ${::osvvm::OsvvmSettingsSubDirectory}]
2123-
}
2124-
CreateDirectory $SettingsDirectory
2125-
# set RelativeSettingsDirectory [::fileutil::relative [pwd] $SettingsDirectory]
2126-
# return $RelativeSettingsDirectory
2127-
# Needs to be a normalized path
2128-
return $SettingsDirectory
2129-
}
2130-
2131-
proc CreateOsvvmScriptSettingsPkg {SettingsDirectory} {
2132-
set OsvvmScriptSettingsPkgFile [file join ${SettingsDirectory} "OsvvmScriptSettingsPkg_generated.vhd"]
2133-
set NewFileName [file join ${SettingsDirectory} "OsvvmScriptSettingsPkg_new.vhd"]
2134-
2135-
set WriteCode [catch {set FileHandle [open $NewFileName w]} WriteErrMsg]
2136-
if {$WriteCode} {
2137-
puts "Not able to open OsvvmScriptSettingsPkg_generated.vhd. Using defaults instead"
2138-
return ""
2139-
}
2140-
puts $FileHandle "-- This file is autogenerated by CreateOsvvmScriptSettingsPkg"
2141-
puts $FileHandle "package body OsvvmScriptSettingsPkg is"
2142-
puts $FileHandle " constant OSVVM_HOME_DIRECTORY : string := \"[file normalize ${::osvvm::OsvvmHomeDirectory}]\" ;"
2143-
if {${::osvvm::OsvvmTemporaryOutputDirectory} eq ""} {
2144-
puts $FileHandle " constant OSVVM_RAW_OUTPUT_DIRECTORY : string := \"\" ;"
2145-
} else {
2146-
puts $FileHandle " constant OSVVM_RAW_OUTPUT_DIRECTORY : string := \"${::osvvm::OsvvmTemporaryOutputDirectory}/\" ;"
2147-
}
2148-
if {${::osvvm::OutputBaseDirectory} eq ""} {
2149-
puts $FileHandle " constant OSVVM_BASE_OUTPUT_DIRECTORY : string := \"\" ;"
2150-
} else {
2151-
puts $FileHandle " constant OSVVM_BASE_OUTPUT_DIRECTORY : string := \"${::osvvm::OutputBaseDirectory}/\" ;"
2152-
}
2153-
puts $FileHandle " constant OSVVM_BUILD_YAML_FILE : string := \"${::osvvm::OsvvmBuildYamlFile}\" ;"
2154-
puts $FileHandle " constant OSVVM_TRANSCRIPT_YAML_FILE : string := \"${::osvvm::TranscriptYamlFile}\" ;"
2155-
puts $FileHandle " constant OSVVM_REVISION : string := \"${::osvvm::OsvvmVersion}\" ;"
2156-
puts $FileHandle " constant OSVVM_SETTINGS_REVISION : string := \"${::osvvm::OsvvmVersionCompatibility}\" ;"
2157-
puts $FileHandle "end package body OsvvmScriptSettingsPkg ;"
2158-
close $FileHandle
2159-
if {[FileDiff $OsvvmScriptSettingsPkgFile $NewFileName]} {
2160-
file rename -force $NewFileName $OsvvmScriptSettingsPkgFile
2161-
} else {
2162-
file delete -force $NewFileName
2163-
}
2164-
return $OsvvmScriptSettingsPkgFile
2165-
}
2166-
2167-
# AutoGenerateFile
2168-
# Extract from FileName everything up to and including the pattern in the string
2169-
# Write Extracted contents to NewFileName
2170-
# Example call: set ErrorCode [catch {AutoGenerateFile $FileName $NewFileName "--!! Autogenerated:"} errmsg]
2171-
proc AutoGenerateFile {FileName NewFileName AutoGenerateMarker} {
2172-
set ReadCode [catch {set ReadFile [open $FileName r]} ReadErrMsg]
2173-
if {$ReadCode} { return }
2174-
set LinesOfFile [split [read $ReadFile] \n]
2175-
close $ReadFile
2176-
2177-
set WriteCode [catch {set WriteFile [open $NewFileName w]} WriteErrMsg]
2178-
if {$WriteCode} { return }
2179-
foreach OneLine $LinesOfFile {
2180-
puts $WriteFile $OneLine
2181-
if { [regexp ${AutoGenerateMarker} $OneLine] } {
2182-
break
2183-
}
2184-
}
2185-
close $WriteFile
2186-
}
2187-
21882115
proc SetArgv {} {
21892116
set ::argv0 0
21902117
set ::argv 0
21912118
set ::argc 0
21922119
}
21932120

2194-
2195-
proc FileDiff {File1 File2} {
2196-
set ReadFile1Code [catch {set FileHandle1 [open $File1 r]} ReadErrMsg]
2197-
if {$ReadFile1Code} {return "true"}
2198-
set LinesOfFile1 [split [read $FileHandle1] \n]
2199-
close $FileHandle1
2200-
set LengthOfFile1 [llength $$LinesOfFile1]
2201-
2202-
set ReadFile2Code [catch {set FileHandle2 [open $File2 r]} ReadErrMsg]
2203-
if {$ReadFile2Code} {return "true"}
2204-
set LinesOfFile2 [split [read $FileHandle2] \n]
2205-
close $FileHandle2
2206-
set LengthOfFile2 [llength $$LinesOfFile2]
2207-
2208-
if {$LengthOfFile1 != $LengthOfFile2} {return "true"}
2209-
2210-
for {set i 0} {$i < $LengthOfFile1} {incr i} {
2211-
if {[lindex $LinesOfFile1 $i] ne [lindex $LinesOfFile2 $i]} {return "true"}
2212-
}
2213-
return "false"
2121+
proc GetTimeString {} {
2122+
return [GetIsoTime [clock seconds]]
22142123
}
22152124

22162125

2217-
22182126
# Don't export the following due to conflicts with Tcl built-ins
22192127
# map
22202128

@@ -2246,9 +2154,9 @@ namespace export MergeCoverage
22462154
namespace export OsvvmLibraryPath
22472155
namespace export JoinWorkingDirectory ChangeWorkingDirectory
22482156
namespace export EndSimulation
2249-
namespace export CreateOsvvmScriptSettingsPkg FindOsvvmSettingsDirectory
22502157
namespace export FindLibraryPathByName CoSim
22512158
namespace export OpenBuildHtml
2159+
namespace export GetTimeString
22522160

22532161
# Exported only for tesing purposes
22542162
namespace export FindLibraryPath CreateLibraryPath FindExistingLibraryPath TimeIt FindIncludeFile UnsetLibraryVars

OsvvmScriptsFileCreate.tcl

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# File Name: OsvvmScriptsFileCreate.tcl
2+
# Purpose: Scripts for running simulations
3+
# Revision: OSVVM MODELS STANDARD VERSION
4+
#
5+
# Maintainer: Jim Lewis email: jim@synthworks.com
6+
# Contributor(s):
7+
# Jim Lewis email: jim@synthworks.com
8+
# Markus Ferringer Patterns for error handling and callbacks, ...
9+
#
10+
# Description
11+
# Tcl procedures to Autogenerate Files
12+
#
13+
# Developed by:
14+
# SynthWorks Design Inc.
15+
# VHDL Training Classes
16+
# OSVVM Methodology and Model Library
17+
# 11898 SW 128th Ave. Tigard, Or 97223
18+
# http://www.SynthWorks.com
19+
#
20+
# Revision History:
21+
# Date Version Description
22+
# 1/2025 2025.01 Initial
23+
#
24+
#
25+
# This file is part of OSVVM.
26+
#
27+
# Copyright (c) 2025 by SynthWorks Design Inc.
28+
#
29+
# Licensed under the Apache License, Version 2.0 (the "License");
30+
# you may not use this file except in compliance with the License.
31+
# You may obtain a copy of the License at
32+
#
33+
# https://www.apache.org/licenses/LICENSE-2.0
34+
#
35+
# Unless required by applicable law or agreed to in writing, software
36+
# distributed under the License is distributed on an "AS IS" BASIS,
37+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38+
# See the License for the specific language governing permissions and
39+
# limitations under the License.
40+
#
41+
42+
43+
namespace eval ::osvvm {
44+
45+
# -------------------------------------------------
46+
# CreateOsvvmScriptSettingsPkg
47+
# do an operation on a list of items
48+
#
49+
proc FindOsvvmSettingsDirectory {} {
50+
if {$::osvvm::SettingsAreRelativeToSimulationDirectory} {
51+
set SettingsDirectory [file join ${::osvvm::CurrentSimulationDirectory} ${::osvvm::OsvvmSettingsSubDirectory}]
52+
} else {
53+
set SettingsDirectory [file join ${::osvvm::OsvvmHomeDirectory} "osvvm" ${::osvvm::OsvvmSettingsSubDirectory}]
54+
}
55+
CreateDirectory $SettingsDirectory
56+
# set RelativeSettingsDirectory [::fileutil::relative [pwd] $SettingsDirectory]
57+
# return $RelativeSettingsDirectory
58+
# Needs to be a normalized path
59+
return $SettingsDirectory
60+
}
61+
62+
proc CreateOsvvmScriptSettingsPkg {SettingsDirectory} {
63+
set OsvvmScriptSettingsPkgFile [file join ${SettingsDirectory} "OsvvmScriptSettingsPkg_generated.vhd"]
64+
set NewFileName [file join ${SettingsDirectory} "OsvvmScriptSettingsPkg_new.vhd"]
65+
66+
set WriteCode [catch {set FileHandle [open $NewFileName w]} WriteErrMsg]
67+
if {$WriteCode} {
68+
puts "Not able to open OsvvmScriptSettingsPkg_generated.vhd. Using defaults instead"
69+
return ""
70+
}
71+
puts $FileHandle "-- This file is autogenerated by CreateOsvvmScriptSettingsPkg"
72+
puts $FileHandle "package body OsvvmScriptSettingsPkg is"
73+
puts $FileHandle " constant OSVVM_HOME_DIRECTORY : string := \"[file normalize ${::osvvm::OsvvmHomeDirectory}]\" ;"
74+
if {${::osvvm::OsvvmTemporaryOutputDirectory} eq ""} {
75+
puts $FileHandle " constant OSVVM_RAW_OUTPUT_DIRECTORY : string := \"\" ;"
76+
} else {
77+
puts $FileHandle " constant OSVVM_RAW_OUTPUT_DIRECTORY : string := \"${::osvvm::OsvvmTemporaryOutputDirectory}/\" ;"
78+
}
79+
if {${::osvvm::OutputBaseDirectory} eq ""} {
80+
puts $FileHandle " constant OSVVM_BASE_OUTPUT_DIRECTORY : string := \"\" ;"
81+
} else {
82+
puts $FileHandle " constant OSVVM_BASE_OUTPUT_DIRECTORY : string := \"${::osvvm::OutputBaseDirectory}/\" ;"
83+
}
84+
puts $FileHandle " constant OSVVM_BUILD_YAML_FILE : string := \"${::osvvm::OsvvmBuildYamlFile}\" ;"
85+
puts $FileHandle " constant OSVVM_TRANSCRIPT_YAML_FILE : string := \"${::osvvm::TranscriptYamlFile}\" ;"
86+
puts $FileHandle " constant OSVVM_REVISION : string := \"${::osvvm::OsvvmVersion}\" ;"
87+
puts $FileHandle " constant OSVVM_SETTINGS_REVISION : string := \"${::osvvm::OsvvmVersionCompatibility}\" ;"
88+
puts $FileHandle "end package body OsvvmScriptSettingsPkg ;"
89+
close $FileHandle
90+
if {[FileDiff $OsvvmScriptSettingsPkgFile $NewFileName]} {
91+
file rename -force $NewFileName $OsvvmScriptSettingsPkgFile
92+
} else {
93+
file delete -force $NewFileName
94+
}
95+
return $OsvvmScriptSettingsPkgFile
96+
}
97+
98+
# AutoGenerateFile
99+
# Extract from FileName everything up to and including the pattern in the string
100+
# Write Extracted contents to NewFileName
101+
# Example call: set ErrorCode [catch {AutoGenerateFile $FileName $NewFileName "--!! Autogenerated:"} errmsg]
102+
proc AutoGenerateFile {FileName NewFileName AutoGenerateMarker} {
103+
set ReadCode [catch {set ReadFile [open $FileName r]} ReadErrMsg]
104+
if {$ReadCode} { return }
105+
set LinesOfFile [split [read $ReadFile] \n]
106+
close $ReadFile
107+
108+
set WriteCode [catch {set WriteFile [open $NewFileName w]} WriteErrMsg]
109+
if {$WriteCode} { return }
110+
foreach OneLine $LinesOfFile {
111+
puts $WriteFile $OneLine
112+
if { [regexp ${AutoGenerateMarker} $OneLine] } {
113+
break
114+
}
115+
}
116+
close $WriteFile
117+
}
118+
119+
120+
proc FileDiff {File1 File2} {
121+
set ReadFile1Code [catch {set FileHandle1 [open $File1 r]} ReadErrMsg]
122+
if {$ReadFile1Code} {return "true"}
123+
set LinesOfFile1 [split [read $FileHandle1] \n]
124+
close $FileHandle1
125+
set LengthOfFile1 [llength $$LinesOfFile1]
126+
127+
set ReadFile2Code [catch {set FileHandle2 [open $File2 r]} ReadErrMsg]
128+
if {$ReadFile2Code} {return "true"}
129+
set LinesOfFile2 [split [read $FileHandle2] \n]
130+
close $FileHandle2
131+
set LengthOfFile2 [llength $$LinesOfFile2]
132+
133+
if {$LengthOfFile1 != $LengthOfFile2} {return "true"}
134+
135+
for {set i 0} {$i < $LengthOfFile1} {incr i} {
136+
if {[lindex $LinesOfFile1 $i] ne [lindex $LinesOfFile2 $i]} {return "true"}
137+
}
138+
return "false"
139+
}
140+
141+
142+
143+
# Don't export the following due to conflicts with Tcl built-ins
144+
# map
145+
146+
namespace export CreateOsvvmScriptSettingsPkg FindOsvvmSettingsDirectory
147+
148+
149+
150+
# end namespace ::osvvm
151+
}

OsvvmSettingsRequired.tcl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#
3333
# This file is part of OSVVM.
3434
#
35-
# Copyright (c) 2022 - 2024 by SynthWorks Design Inc.
35+
# Copyright (c) 2022 - 2025 by SynthWorks Design Inc.
3636
#
3737
# Licensed under the Apache License, Version 2.0 (the "License");
3838
# you may not use this file except in compliance with the License.
@@ -56,9 +56,9 @@
5656

5757
namespace eval ::osvvm {
5858

59-
variable OsvvmVersion 2024.11
60-
variable OsvvmBuildYamlVersion 2024.11
61-
variable OsvvmTestCaseYamlVersion 2024.11
59+
variable OsvvmVersion 2025.01
60+
variable OsvvmBuildYamlVersion 2025.01
61+
variable OsvvmTestCaseYamlVersion 2025.01
6262
# The following are set in VHDL code. Either need to pass these or have it directly in the VHDL Code.
6363
variable OsvvmAlertYamlVersion InVhdlCodeVersionTbd
6464
variable OsvvmCoverageYamlVersion InVhdlCodeVersionTbd

StartUpShared.tcl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ variable OsvvmLibraries $::osvvm::OsvvmHomeDirectory
7272
# Load Base OSVVM Project Scripts and Vendor Specific Scripts
7373
source ${::osvvm::OsvvmScriptDirectory}/OsvvmScriptsCreateYamlReports.tcl
7474
source ${::osvvm::OsvvmScriptDirectory}/OsvvmScriptsCore.tcl
75+
source ${::osvvm::OsvvmScriptDirectory}/OsvvmScriptsFileCreate.tcl
7576
namespace eval ::osvvm {
7677
source ${::osvvm::OsvvmScriptDirectory}/VendorScripts_${::osvvm::ScriptBaseName}.tcl
7778
}

0 commit comments

Comments
 (0)