From 15a11c47ea46a309cfee25fb114ab44252982951 Mon Sep 17 00:00:00 2001 From: Petr Hodina Date: Tue, 17 Oct 2017 08:20:59 +0200 Subject: [PATCH 1/2] Fixed file generation on Windows platfrom. Added support for .cpp files. Refactored argument parsing. --- .gitignore | 1 + cmake.py | 27 ++++++++++++++------------- converter.py | 11 +++++++---- 3 files changed, 22 insertions(+), 17 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/cmake.py b/cmake.py index 847c951..25ebfa1 100644 --- a/cmake.py +++ b/cmake.py @@ -60,7 +60,7 @@ class CMake (object): cmake['ass']=[] for file in self.project['srcs']: - if file.endswith('.c') or file.endswith('.h'): + if file.endswith('.c') or file.endswith('.h') or file.endswith('.cpp'): cmake['files'].append({'path': file,'var':'SRC_FILE' + str(i)}) i = i+1 @@ -69,7 +69,7 @@ class CMake (object): cmake['ass'].append({'path': file}) cmake['files'].append({'path': file,'var':'SRC_FILE' + str(i)}) i = i+1 - + cmake['cxx'] = 'false' cmake['c_flags'] = '-g -Wextra -Wshadow -Wimplicit-function-declaration -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes -fno-common -ffunction-sections -fdata-sections -MD -Wall -Wundef -mthumb ' + core + ' ' + fpu @@ -91,10 +91,11 @@ class CMake (object): cmake['libs'] = [] self.context['cmake'] = cmake - - self.generateFile('CMakeLists.txt',os.path.join(self.path,'CMakeLists.txt')) + + abspath = os.path.abspath(os.path.join(self.path,'CMakeLists.txt')) + self.generateFile('CMakeLists.txt', abspath) - print ('Created file CMakeLists.txt') + print ('Created file CMakeLists.txt [{}]'.format(abspath)) # def generateFile (self, pathSrc, pathDst='', author='Pegasus', version='v1.0.0', licence='licence.txt', template_dir='../PegasusTemplates'): def generateFile (self, pathSrc, pathDst='', author='Pegasus', version='v1.0.0', licence='licence.txt', template_dir='.'): @@ -113,15 +114,15 @@ class CMake (object): generated_code = template.render(self.context) - if platform.system() == 'Window': + if platform.system() == 'Windows': - with open(pathDst, 'wb') as f: + with open(pathDst, 'w') as f: f.write(generated_code) elif platform.system() == 'Linux': - with open(pathDst, 'wb') as f: - f.write(str.encode(generated_code)) + with open(pathDst, 'w') as f: + f.write(generated_code) else: # Different OS than Windows or Linux pass @@ -141,15 +142,15 @@ class CMake (object): generated_code = template.render(self.context) - if platform.system() == 'Window': + if platform.system() == 'Windows': - with open(pathDst, 'wb') as f: + with open(pathDst, 'w') as f: f.write(generated_code) elif platform.system() == 'Linux': - with open(pathDst, 'wb') as f: - f.write(str.encode(generated_code)) + with open(pathDst, 'w') as f: + f.write(generated_code) else: # Different OS than Windows or Linux pass diff --git a/converter.py b/converter.py index 6040ccf..16668ca 100644 --- a/converter.py +++ b/converter.py @@ -27,13 +27,14 @@ if __name__ == '__main__': """ Parses params and calls the right conversion""" parser = argparse.ArgumentParser() + parser.add_argument("format", choices=("ewp", "uvprojx")) parser.add_argument("path", type=str, help="Root directory of project") - parser.add_argument("--ewp", help="Search for *.EWP file in project structure", action='store_true') - parser.add_argument("--uvprojx", help="Search for *.UPROJX file in project structure", action='store_true') + #"--ewp", help="Search for *.EWP file in project structure", action='store_true') + #parser.add_argument("--uvprojx", help="Search for *.UPROJX file in project structure", action='store_true') args = parser.parse_args() if os.path.isdir(args.path): - if args.ewp: + if args.format == 'ewp': print('Looking for *.ewp file in ' + args.path) filename = find_file(args.path, '.ewp') if len(filename): @@ -45,7 +46,7 @@ if __name__ == '__main__': cmakefile.populateCMake() else: print('No project *.ewp file found') - elif args.uvprojx: + elif args.format == 'uvprojx': print('Looking for *.uvprojx file in ' + args.path) filename = find_file(args.path, '.uvprojx') if len(filename): @@ -58,5 +59,7 @@ if __name__ == '__main__': cmakefile.populateCMake() else: print('No project *.uvprojx file found') + else: + print ('No format specified') else: print('Not a valid file path') From b3c43ebc52b3fbc8dc595f4b0ef77cf455a532f1 Mon Sep 17 00:00:00 2001 From: Petr Hodina Date: Tue, 17 Oct 2017 08:34:01 +0200 Subject: [PATCH 2/2] Added Readme & License. --- License.txt | 19 +++++++++++++++++++ Readme.txt | 31 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 License.txt create mode 100644 Readme.txt diff --git a/License.txt b/License.txt new file mode 100644 index 0000000..3814c34 --- /dev/null +++ b/License.txt @@ -0,0 +1,19 @@ +Copyright (c) 2017 Petr Hodina + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/Readme.txt b/Readme.txt new file mode 100644 index 0000000..7478ffb --- /dev/null +++ b/Readme.txt @@ -0,0 +1,31 @@ +# Project converter + +Simple modular python script to convert existing projects from IAR's ewp and ARM's KEIL uvprojx project formats to cmake and linker file using GCC compiler. + +## Module description + +cmake.py - Cmake and linker file generation +converter.py - Argument parsing +ewpproject.py - Parser for IAR's ewp file format +uvprojx.py - Parser for ARM's KEIL uvprojx file format + +## Usage + +Run in output dir. + +Convert project from IAR: + + converter.py ewp + +Convert project from ARM's KEIL: + + converter.py uvprojx + +## TODO + +[] Seperate templates into submodule +[] Support generation of Makefile +[] Support additional compilers +[] Test on MAC OSX +[] Arg to specify build directory +[] Add Tests \ No newline at end of file