diff --git a/cores/copy_source_files.py b/cores/copy_source_files.py index 09c28c4d0156f20179cd5a514e4bcd8738110dc2..0d92f0d4313ae2abc602313a6275fd555f788be1 100644 --- a/cores/copy_source_files.py +++ b/cores/copy_source_files.py @@ -11,6 +11,7 @@ import os from shutil import copyfile +import sys """ Recursively find occurences of fname in dirname, returns them as list. @@ -30,34 +31,40 @@ def find_files(fname, dirname): ############################################################################### if __name__== '__main__': + arg_lib = None + if len(sys.argv)>1: + arg_lib = sys.argv[0] + for hdllib_file in find_files('hdllib.cfg', '.') : - # Set the current target path (hdllib.cfg dir) - target_path = os.path.abspath(os.path.dirname(hdllib_file))+'/' - - # Read the hdllib.cfg file into a list - with open(hdllib_file) as f: - lines = f.readlines() - - # Get the paths to the required .VHD files - for line in lines: - if '.vhd' in line: - vhd_file = line.strip('\n').strip(' ') - - # Find the VHD file in the horizontal RadioHDL libraries - found_files = find_files(vhd_file, os.environ['RADIOHDL']+'/libraries') - - # Copy the VHD file here - if len(found_files)>1: - print 'Warning: multiple files found:' - print vhd_file, found_files - - try: - print 'Copying', found_files[0], 'to', target_path+vhd_file - copyfile(found_files[0], target_path+vhd_file) - except: - print 'Warning: could not copy', vhd_file, found_files, 'to', target_path - + core_lib = os.path.dirname(hdllib_file).split('/')[-1]+'_lib' + if core_lib==arg_lib or arg_lib==None: + # Set the current target path (hdllib.cfg dir) + target_path = os.path.abspath(os.path.dirname(hdllib_file))+'/' + + # Read the hdllib.cfg file into a list + with open(hdllib_file) as f: + lines = f.readlines() + + # Get the paths to the required .VHD files + for line in lines: + if '.vhd' in line: + vhd_file = line.strip('\n').strip(' ') + + # Find the VHD file in the horizontal RadioHDL libraries + found_files = find_files(vhd_file, os.environ['RADIOHDL']+'/libraries') + + # Copy the VHD file here + if len(found_files)>1: + print 'Warning: multiple files found:' + print vhd_file, found_files + + try: + print 'Copying', found_files[0], 'to', target_path+vhd_file + copyfile(found_files[0], target_path+vhd_file) + except: + print 'Warning: could not copy', vhd_file, found_files, 'to', target_path + diff --git a/cores/edit_source_files.py b/cores/edit_source_files.py index bbe54c491725c8004de8c6d134812c2c28984533..0cc91602ac60e8eef8421931b294f246fa4ee5c7 100644 --- a/cores/edit_source_files.py +++ b/cores/edit_source_files.py @@ -10,6 +10,7 @@ from copy_source_files import find_files import os +import sys REPLACE_LIST = [ @@ -74,61 +75,68 @@ REPLACE_LIST = [ for vhd_file in find_files('*.vhd', '.'): core_lib = os.path.dirname(vhd_file).split('/')[-1]+'_lib' - print 'Editing', vhd_file - - # Read the VHDL file into a list - with open(vhd_file) as f: - lines = f.readlines() - newlines= [] - - # Remove strings from VHDL file - for line in lines: - newline = line - for item in REPLACE_LIST: - replace=True - if 'work.' in line: - libname=item[1].split('.')[0] - if libname==core_lib: - replace=False - if replace==True: - newline = newline.replace(item[0], item[1]) - - newlines.append(newline) - - # find all lines with '_lib' - lib_lines = [] - for line in newlines: - if '_lib' in line: - lib_lines.append(line) - # extract full library name from that line - libs = [] - for line in lib_lines: - if 'USE' in line: - libname = line.split('.')[0].strip('USE ') - if not libname==core_lib: # don't add the work lib as dependency - libs.append(libname) - elif 'ENTITY' in line: - libname = line.split('.')[0].split(' ')[-1] - if not libname==core_lib: # don't add the work lib as dependency - libs.append(libname) - - unique_libs = list(set(libs)) - lib_str = str(unique_libs).strip('[]').replace("'", '') - - # Replace the LIBRARY declaration with an updated, complete one - final_lines = [] - for line in newlines: - final_line = line - if 'LIBRARY' in line and len(unique_libs)>0: - final_line = 'LIBRARY IEEE, '+ lib_str + ';\n' - - final_lines.append(final_line.replace('\r', '')) - - - with open(vhd_file, 'wb') as f: - f.writelines(final_lines) - f.close() - + arg_lib = None + + if len(sys.argv)>1: + arg_lib = sys.argv[0] + + if core_lib==arg_lib or arg_lib==None: + + print 'Editing', vhd_file + + # Read the VHDL file into a list + with open(vhd_file) as f: + lines = f.readlines() + newlines= [] + + # Remove strings from VHDL file + for line in lines: + newline = line + for item in REPLACE_LIST: + replace=True + if 'work.' in line: + libname=item[1].split('.')[0] + if libname==core_lib: + replace=False + if replace==True: + newline = newline.replace(item[0], item[1]) + + newlines.append(newline) + # find all lines with '_lib' + lib_lines = [] + for line in newlines: + if '_lib' in line: + lib_lines.append(line) + # extract full library name from that line + libs = [] + for line in lib_lines: + if 'USE' in line: + libname = line.split('.')[0].strip('USE ') + if not libname==core_lib: # don't add the work lib as dependency + libs.append(libname) + elif 'ENTITY' in line: + libname = line.split('.')[0].split(' ')[-1] + if not libname==core_lib: # don't add the work lib as dependency + libs.append(libname) + + unique_libs = list(set(libs)) + lib_str = str(unique_libs).strip('[]').replace("'", '') + + # Replace the LIBRARY declaration with an updated, complete one + final_lines = [] + for line in newlines: + final_line = line + if 'LIBRARY' in line and len(unique_libs)>0: + final_line = 'LIBRARY IEEE, '+ lib_str + ';\n' + + final_lines.append(final_line.replace('\r', '')) + + + with open(vhd_file, 'wb') as f: + f.writelines(final_lines) + + f.close() + diff --git a/cores/readme.txt b/cores/readme.txt index e6c81efd58fa6e4b000217f6b5d627d9556e5db8..9bcbce3a953f557cd08f28fee3cec65c1bd993bb 100644 --- a/cores/readme.txt +++ b/cores/readme.txt @@ -3,9 +3,13 @@ Summary ======= This directory contains vertically grouped versions of the horizontal RadioHDL -HDL libraries, intended to be uploaded to OpenCores. It cannot harm the current -horizontal libraries, yet it syncs the vertical libs with the horizontal ones, -and provides a clean migration possibility. +HDL libraries, stored on an external OpenCores repository. It cannot harm the +current horizontal libraries, yet it syncs our vertical RadioHDL libs with +the vertical 'cores': + +$RADIOHDL/libraries : untouched +$RADIOHDL/cores : Cores from Opencores repo = modified copies of + $RADIOHDL/libraries source files. Introduction ============ @@ -23,19 +27,53 @@ organized differently: The original horizontal organization is however still maintained as directory structure; e.g. all vertical 'dp' cores are in the 'dp' directory. -copy_source_files.py -==================== +copy_source_files.py [library] +============================== This script copies the source files from the horizontal RadioHDL repository, with the purpose of: 1) Keeping this 'cores' library in sync with our 'official' RadioHDL library, without risk of doing damage to it. 2) Provide option to migrate to this vertical for by calling 'svn move' +If no argument is passed, it will copy/overwrite ALL source files listed in the +hdllib.cfg files. +Pass a library name to copy only the source files for a specific library (e.g. +common_pkg). -edit_source_files.py -==================== +edit_source_files.py [library] +============================== This script edits the copied files such that: 1) the included horizontal libraries at the top are replaced by vertical ones; 2) the horizontal libraries named in the instantiations are replaced with vertical ones. +If no argument is passed, it will edit/overwrite ALL source files listed in the +hdllib.cfg files. +Pass a library name to edit only the source files for a specific library (e.g. +common_pkg). + +How this is organized in SVN +============================ +The actual 'core' directories (such as base/common/common_pkg) don't exist on +our own RADIOHDL SVN server. They are pulled in from the OpenCores repository. +An example command to set this up in SVN is shown below (svn propset). + +How to add a new 'core' +======================= +1) Go to OpenCores.org, log in, create new project with name 'my_project'. +2) After it is approved, include it in our RADIOHDL repository by defining + an external repo by running the following command in the desired parent + directory: + + $ svn propset svn:externals -F svn_propset_file . + + For this project, add the following line to svn_propset_file: + + my_project https://opencores.org/ocsvn/my_project/my_project/trunk/ + The svn_propset_files are in SVN in their respective folders. +3) Commit this SVN folder setting +4) SVN update; you will now get the project folder from the OpenCore repo. +5) Add an hdllib.cfg file to the project dir, add source files (without path). +6) Run: $ copy_source_files my_project +7) Run: $ edit_source_files my_project +8) Try the project in simulation, if it works: SVN commit to to OpenCores.