From d8a3a03210e502ebbaa60589aa1c130763875c6b Mon Sep 17 00:00:00 2001 From: Sungho Park Date: Mon, 27 Feb 2012 21:24:32 +0900 Subject: [PATCH 1/1] Initialize --- AUTHORS | 5 + LICENSE | 202 ++++++++++++ Makefile | 84 +++++ NOTICE | 1 + build-package_linux.sh | 31 ++ build-package_mac.sh | 31 ++ build-package_win.sh | 40 +++ libxml2/build_win.sh | 16 + libxml2/patch/mingw.patch | 13 + package/build.linux | 31 ++ package/build.windows | 35 ++ package/pkginfo.manifest | 17 + package/remove.linux | 3 + package/remove.windows | 4 + package_upload.sh | 45 +++ sbi-build.bat | 24 ++ src/cmdline_interpreter.c | 745 ++++++++++++++++++++++++++++++++++++++++++ src/cmdline_interpreter.h | 31 ++ src/config_common.c | 198 +++++++++++ src/config_common.h | 46 +++ src/execute.c | 476 +++++++++++++++++++++++++++ src/execute.h | 69 ++++ src/execute_input.c | 155 +++++++++ src/execute_input.h | 60 ++++ src/plugin.c | 371 +++++++++++++++++++++ src/plugin.h | 92 ++++++ src/plugin_mgt.c | 161 +++++++++ src/plugin_mgt.h | 42 +++ src/rootstrap.c | 187 +++++++++++ src/rootstrap.h | 58 ++++ src/rootstrap_mgt.c | 291 +++++++++++++++++ src/rootstrap_mgt.h | 53 +++ src/sbi.c | 83 +++++ src/sbi_build.c | 374 +++++++++++++++++++++ src/sbi_config.c | 476 +++++++++++++++++++++++++++ src/sbi_config.h | 77 +++++ src/sbi_error.c | 310 ++++++++++++++++++ src/sbi_error.h | 28 ++ src/sbi_types.c | 130 ++++++++ src/sbi_types.h | 49 +++ src/sbi_util.c | 424 ++++++++++++++++++++++++ src/sbi_util.h | 62 ++++ src/sbi_xml.c | 259 +++++++++++++++ src/sbi_xml.h | 46 +++ src/target.c | 157 +++++++++ src/target.h | 49 +++ src/target_mgt.c | 334 +++++++++++++++++++ src/target_mgt.h | 63 ++++ src/tool.c | 126 +++++++ src/tool.h | 48 +++ src/toolchain.c | 392 ++++++++++++++++++++++ src/toolchain.h | 80 +++++ src/toolchain_action.c | 191 +++++++++++ src/toolchain_action.h | 59 ++++ src/toolchain_mgt.c | 406 +++++++++++++++++++++++ src/toolchain_mgt.h | 64 ++++ test/create_target_1.test | 5 + test/create_target_2.test | 4 + test/create_target_3.test | 4 + test/create_target_4.test | 4 + test/create_target_5.test | 4 + test/create_target_6.test | 4 + test/create_target_7.test | 4 + test/create_target_8.test | 4 + test/create_target_9.test | 4 + test/list.txt | 28 ++ test/list_information_1.test | 5 + test/list_information_2.test | 4 + test/list_information_3.test | 4 + test/list_information_4.test | 4 + test/list_information_6.test | 4 + test/new_list.txt | 28 ++ test/pre_test | 6 + test/regression.rb | 151 +++++++++ test/remove_target_1.test | 5 + test/remove_target_2.test | 4 + test/remove_target_3.test | 4 + test/remove_target_4.test | 5 + test/show_information_1.test | 5 + test/show_information_10.test | 4 + test/show_information_2.test | 5 + test/show_information_3.test | 5 + test/show_information_4.test | 4 + test/show_information_5.test | 4 + test/show_information_6.test | 4 + test/show_information_7.test | 5 + test/show_information_8.test | 4 + test/show_information_9.test | 4 + test/test_execute | 1 + 89 files changed, 8238 insertions(+) create mode 100644 AUTHORS create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 NOTICE create mode 100755 build-package_linux.sh create mode 100755 build-package_mac.sh create mode 100755 build-package_win.sh create mode 100755 libxml2/build_win.sh create mode 100644 libxml2/patch/mingw.patch create mode 100755 package/build.linux create mode 100755 package/build.windows create mode 100644 package/pkginfo.manifest create mode 100644 package/remove.linux create mode 100644 package/remove.windows create mode 100755 package_upload.sh create mode 100644 sbi-build.bat create mode 100644 src/cmdline_interpreter.c create mode 100644 src/cmdline_interpreter.h create mode 100644 src/config_common.c create mode 100644 src/config_common.h create mode 100644 src/execute.c create mode 100644 src/execute.h create mode 100644 src/execute_input.c create mode 100644 src/execute_input.h create mode 100644 src/plugin.c create mode 100644 src/plugin.h create mode 100644 src/plugin_mgt.c create mode 100644 src/plugin_mgt.h create mode 100644 src/rootstrap.c create mode 100644 src/rootstrap.h create mode 100644 src/rootstrap_mgt.c create mode 100644 src/rootstrap_mgt.h create mode 100644 src/sbi.c create mode 100644 src/sbi_build.c create mode 100644 src/sbi_config.c create mode 100644 src/sbi_config.h create mode 100644 src/sbi_error.c create mode 100644 src/sbi_error.h create mode 100644 src/sbi_types.c create mode 100644 src/sbi_types.h create mode 100644 src/sbi_util.c create mode 100644 src/sbi_util.h create mode 100644 src/sbi_xml.c create mode 100644 src/sbi_xml.h create mode 100644 src/target.c create mode 100644 src/target.h create mode 100644 src/target_mgt.c create mode 100644 src/target_mgt.h create mode 100644 src/tool.c create mode 100644 src/tool.h create mode 100644 src/toolchain.c create mode 100644 src/toolchain.h create mode 100644 src/toolchain_action.c create mode 100644 src/toolchain_action.h create mode 100644 src/toolchain_mgt.c create mode 100644 src/toolchain_mgt.h create mode 100755 test/create_target_1.test create mode 100755 test/create_target_2.test create mode 100755 test/create_target_3.test create mode 100755 test/create_target_4.test create mode 100755 test/create_target_5.test create mode 100755 test/create_target_6.test create mode 100755 test/create_target_7.test create mode 100755 test/create_target_8.test create mode 100755 test/create_target_9.test create mode 100755 test/list.txt create mode 100755 test/list_information_1.test create mode 100755 test/list_information_2.test create mode 100755 test/list_information_3.test create mode 100755 test/list_information_4.test create mode 100755 test/list_information_6.test create mode 100755 test/new_list.txt create mode 100755 test/pre_test create mode 100755 test/regression.rb create mode 100755 test/remove_target_1.test create mode 100755 test/remove_target_2.test create mode 100755 test/remove_target_3.test create mode 100755 test/remove_target_4.test create mode 100755 test/show_information_1.test create mode 100755 test/show_information_10.test create mode 100755 test/show_information_2.test create mode 100755 test/show_information_3.test create mode 100755 test/show_information_4.test create mode 100755 test/show_information_5.test create mode 100755 test/show_information_6.test create mode 100755 test/show_information_7.test create mode 100755 test/show_information_8.test create mode 100755 test/show_information_9.test create mode 100755 test/test_execute diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..9589ae0 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,5 @@ +DongHee Yang +Taejun Ha +Jiil Hyoun +Donghyuk Yang +HyunGoo Kang diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a937f5a --- /dev/null +++ b/Makefile @@ -0,0 +1,84 @@ +CC = gcc +CFLAGS = -g -Wall +LDFLAGS = +OS=$(shell uname -s) + +ifeq ($(OS),Darwin) +OS = Linux +endif + +ifeq ($(OS),Linux) +XMLCFLAGS = `xml2-config --cflags` +XMLLDFLAGS = `xml2-config --libs` +else +XMLCFLAGS = `./libxml2/usr/bin/xml2-config --cflags` +XMLLDFLAGS = `./libxml2/usr/bin/xml2-config --libs` +endif + +CFLAGS += $(XMLCFLAGS) + +COMMON_OBJS = bin/sbi_types.o bin/target_mgt.o bin/target.o bin/rootstrap_mgt.o bin/rootstrap.o bin/toolchain_mgt.o bin/toolchain.o bin/tool.o bin/toolchain_action.o bin/execute.o bin/execute_input.o bin/config_common.o bin/sbi_util.o bin/sbi_config.o bin/sbi_error.o +all: prebuild bin/sbi bin/sbi_build + +prebuild: + mkdir -p bin +ifneq ($(OS),Linux) + cd libxml2 ; ./build_win.sh +endif + +bin/sbi_build: bin/sbi_build.o $(COMMON_OBJS) bin/plugin_mgt.o bin/plugin.o + $(CC) $(LDFLAGS) -o $@ bin/sbi_build.o $(COMMON_OBJS) bin/plugin_mgt.o bin/plugin.o $(XMLLDFLAGS) +bin/sbi_build.o: ./src/sbi_build.c + $(CC) $(CFLAGS) -c -o $@ ./src/sbi_build.c +bin/sbi: bin/sbi.o bin/cmdline_interpreter.o $(COMMON_OBJS) bin/plugin_mgt.o bin/plugin.o + $(CC) $(LDFLAGS) -o $@ bin/sbi.o $(COMMON_OBJS) bin/cmdline_interpreter.o bin/plugin_mgt.o bin/plugin.o $(XMLLDFLAGS) +bin/sbi.o: ./src/sbi.c + $(CC) $(CFLAGS) $(XMLCFLAGS) -c -o $@ ./src/sbi.c +bin/cmdline_interpreter.o: ./src/cmdline_interpreter.c ./src/cmdline_interpreter.h + $(CC) $(CFLAGS) -c -o $@ ./src/cmdline_interpreter.c +bin/sbi_types.o: ./src/sbi_types.c ./src/sbi_types.h + $(CC) $(CFLAGS) -c -o $@ ./src/sbi_types.c +bin/target_mgt.o: ./src/target_mgt.c ./src/target_mgt.h + $(CC) $(CFLAGS) $(XMLCFLAGS) -c -o $@ ./src/target_mgt.c +bin/target.o: ./src/target.c ./src/target.c + $(CC) $(CFLAGS) -c -o $@ ./src/target.c +bin/rootstrap_mgt.o: ./src/rootstrap_mgt.c ./src/rootstrap_mgt.h + $(CC) $(CFLAGS) $(XMLCFLAGS) -c -o $@ ./src/rootstrap_mgt.c +bin/rootstrap.o: ./src/rootstrap.c ./src/rootstrap.h + $(CC) $(CFLAGS) -c -o $@ ./src/rootstrap.c +bin/toolchain_mgt.o: ./src/toolchain_mgt.c ./src/toolchain_mgt.h + $(CC) $(CFLAGS) $(XMLCFLAGS) -c -o $@ ./src/toolchain_mgt.c +bin/toolchain.o: ./src/toolchain.c ./src/toolchain.h + $(CC) $(CFLAGS) -c -o $@ ./src/toolchain.c +bin/tool.o: ./src/tool.c ./src/tool.h + $(CC) $(CFLAGS) -c -o $@ ./src/tool.c +bin/toolchain_action.o: ./src/toolchain_action.c ./src/toolchain_action.h + $(CC) $(CFLAGS) -c -o $@ ./src/toolchain_action.c +bin/execute.o: ./src/execute.c ./src/execute.h + $(CC) $(CFLAGS) $(XMLCFLAGS) -c -o $@ ./src/execute.c +bin/execute_input.o: ./src/execute_input.c ./src/execute_input.h + $(CC) $(CFLAGS) -c -o $@ ./src/execute_input.c +bin/sbi_error.o: ./src/sbi_error.c ./src/sbi_error.h + $(CC) $(CFLAGS) -c -o $@ ./src/sbi_error.c +bin/sbi_util.o: ./src/sbi_util.c ./src/sbi_util.h + $(CC) $(CFLAGS) -c -o $@ ./src/sbi_util.c +bin/config_common.o: ./src/config_common.c ./src/config_common.h + $(CC) $(CFLAGS) -c -o $@ ./src/config_common.c +bin/sbi_config.o: ./src/sbi_config.c ./src/sbi_config.h + $(CC) $(CFLAGS) -c -o $@ ./src/sbi_config.c +bin/plugin_mgt.o: ./src/plugin_mgt.c ./src/plugin_mgt.h + $(CC) $(CFLAGS) $(XMLCFLAGS) -c -o $@ ./src/plugin_mgt.c +bin/plugin.o: ./src/plugin.c ./src/plugin.h + $(CC) $(CFLAGS) $(XMLCFLAGS) -c -o $@ ./src/plugin.c + +clean: + rm -rf ./bin/* + rm -f ./lib/* + +test: all + mkdir -p regression_test/build-system/bin/ + cp -f bin/sbi regression_test/build-system/bin/ + + #pre test + cd regression_test; ./pre_test; ./regression.rb + diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..4297ee3 --- /dev/null +++ b/NOTICE @@ -0,0 +1 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. diff --git a/build-package_linux.sh b/build-package_linux.sh new file mode 100755 index 0000000..2695da6 --- /dev/null +++ b/build-package_linux.sh @@ -0,0 +1,31 @@ +#!/bin/sh -e +CURDIR=`pwd` + +rm -rf $CURDIR/package +mkdir -p $CURDIR/package + +#pkginfo file copy +cp $CURDIR/pkginfo.manifest $CURDIR/package/pkginfo.manifest +#copy remove script +cp $CURDIR/remove.sh $CURDIR/package/remove.sh +#add remove script section for pkginfo.manifest +echo "Remove-script : remove.sh" >> $CURDIR/package/pkginfo.manifest + +VERSION=`cat $CURDIR/package/pkginfo.manifest | grep Version | cut -d ':' -f2 | tr -d ' ' ` + +#init +rm -rf *.zip + +rm -rf $CURDIR/package/data +mkdir -p $CURDIR/package/data/SDK/build-system/bin +mkdir -p $CURDIR/package/data/SDK/build-system/plugins/ + +make clean ; make + +#copy +cp $CURDIR/bin/sbi $CURDIR/package/data/SDK/build-system/bin/ +cp $CURDIR/bin/sbi_build $CURDIR/package/data/SDK/build-system/bin/ + +#packaging +cd $CURDIR/package +zip -r -y $CURDIR/smart-build-interface_${VERSION}_linux.zip * diff --git a/build-package_mac.sh b/build-package_mac.sh new file mode 100755 index 0000000..e91ca24 --- /dev/null +++ b/build-package_mac.sh @@ -0,0 +1,31 @@ +#!/bin/sh -e +CURDIR=`pwd` + +rm -rf $CURDIR/package +mkdir -p $CURDIR/package + +#pkginfo file copy +cp $CURDIR/pkginfo.manifest $CURDIR/package/pkginfo.manifest +#copy remove script +cp $CURDIR/remove.sh $CURDIR/package/remove.sh +#add remove script section for pkginfo.manifest +echo "Remove-script : remove.sh" >> $CURDIR/package/pkginfo.manifest + +VERSION=`cat $CURDIR/package/pkginfo.manifest | grep Version | cut -d ':' -f2 | tr -d ' ' ` + +#init +rm -rf *.zip + +rm -rf $CURDIR/package/data +mkdir -p $CURDIR/package/data/SDK/build-system/bin +mkdir -p $CURDIR/package/data/SDK/build-system/plugins/ + +make clean ; make + +#copy +cp $CURDIR/bin/sbi $CURDIR/package/data/SDK/build-system/bin/ +cp $CURDIR/bin/sbi_build $CURDIR/package/data/SDK/build-system/bin/ + +#packaging +cd $CURDIR/package +zip -r -y $CURDIR/smart-build-interface_${VERSION}_mac.zip * diff --git a/build-package_win.sh b/build-package_win.sh new file mode 100755 index 0000000..b86f03d --- /dev/null +++ b/build-package_win.sh @@ -0,0 +1,40 @@ +#!/bin/sh -x +if [ "$WORKSPACE" ] +then + CURDIR=$WORKSPACE/smart-build-interface + CURDIR="`echo $CURDIR | tr '\\' '/' | sed 's/C:/\/c/'`" + echo $CURDIR + cd $CURDIR +else + CURDIR=`pwd` +fi + +rm -rf $CURDIR/package +mkdir -p $CURDIR/package + +#pkginfo file copy +cp $CURDIR/pkginfo.manifest $CURDIR/package/pkginfo.manifest +#copy remove script +cp $CURDIR/remove.bat $CURDIR/package/remove.bat +#add remove script section for pkginfo.manifest +echo "Remove-script : remove.bat" >> $CURDIR/package/pkginfo.manifest + +VERSION=`cat "$CURDIR"/package/pkginfo.manifest | grep Version | cut -d ':' -f2 | tr -d ' ' ` + +#init +rm -rf *.zip +rm -rf "$CURDIR"/package/data +mkdir -p "$CURDIR"/package/data/SDK/build-system/bin +mkdir -p "$CURDIR"/package/data/SDK/build-system/plugins + +make clean ; make + +#copy +cp "$CURDIR"/bin/sbi.exe $CURDIR/package/data/SDK/build-system/bin/ +cp "$CURDIR"/bin/sbi_build.exe $CURDIR/package/data/SDK/build-system/bin/ +cp "$CURDIR"/libxml2/usr/bin/*.dll $CURDIR/package/data/SDK/build-system/bin/ +cp "$CURDIR"/sbi-build.bat $CURDIR/package/data/SDK/build-system/bin/ + +#packaging +cd "$CURDIR"/package +zip -r "$CURDIR"/smart-build-interface_${VERSION}_windows.zip * diff --git a/libxml2/build_win.sh b/libxml2/build_win.sh new file mode 100755 index 0000000..80cde4f --- /dev/null +++ b/libxml2/build_win.sh @@ -0,0 +1,16 @@ +#!/bin/sh -e +CURDIR=`pwd` + +#extract +rm -rf libxml2-2.7.8 +tar xvf libxml2-2.7.8.tar.gz + +#patch if windows +cd $CURDIR/libxml2-2.7.8 +patch -p1 < ../patch/mingw.patch + +#build & install +mkdir -p $CURDIR/usr +./configure --prefix=$CURDIR/usr +make +make install diff --git a/libxml2/patch/mingw.patch b/libxml2/patch/mingw.patch new file mode 100644 index 0000000..4f43f11 --- /dev/null +++ b/libxml2/patch/mingw.patch @@ -0,0 +1,13 @@ +diff -urN libxml2-2.7.8/testThreads.c libxml2-2.7.8_modified/testThreads.c +--- libxml2-2.7.8/testThreads.c 2010-10-12 15:25:32 +0900 ++++ libxml2-2.7.8_modified/testThreads.c 2011-09-20 10:25:51 +0900 +@@ -107,7 +107,8 @@ + + for (i = 0; i < num_threads; i++) { + results[i] = NULL; +- tid[i] = (pthread_t) -1; ++ /*tid[i] = (pthread_t) -1;*/ ++ memset(&tid[i], 0xff, sizeof(tid[i]) ); + } + + for (i = 0; i < num_threads; i++) { diff --git a/package/build.linux b/package/build.linux new file mode 100755 index 0000000..afdea35 --- /dev/null +++ b/package/build.linux @@ -0,0 +1,31 @@ +#!/bin/sh -xe +# clean +clean() +{ + make clean + rm -rf $SRCDIR/*.zip + rm -rf $SRCDIR/*.tar.gz + rm -rf $SRCDIR/bin +} + +# build +build() +{ + make +} + +# install +install() +{ + BIN_DIR=$SRCDIR/package/smart-build-interface.package.linux/data/SDK/build-system/bin + mkdir -p $BIN_DIR + PLUGINS_DIR=$SRCDIR/package/smart-build-interface.package.linux/data/SDK/build-system/plugins + mkdir -p $PLUGINS_DIR + cp $SRCDIR/bin/sbi $BIN_DIR/ + cp $SRCDIR/bin/sbi_build $BIN_DIR/ +} + +[ "$1" = "clean" ] && clean +[ "$1" = "build" ] && build +[ "$1" = "install" ] && install +echo "success" diff --git a/package/build.windows b/package/build.windows new file mode 100755 index 0000000..1b9d1f5 --- /dev/null +++ b/package/build.windows @@ -0,0 +1,35 @@ +#!/bin/sh -xe +# clean +clean() +{ + make clean + rm -rf $SRCDIR/*.zip + rm -rf $SRCDIR/*.tar.gz + rm -rf $SRCDIR/bin + rm -rf $SRCDIR/libxml2/usr + rm -rf $SRCDIR/libxml2/libxml2-2.7.8 + rm -rf $SRCDIR/libxml2/libxml2-2.7.8.tar.gz +} + +# build +build() +{ + cp $ROOTDIR/libxml2-2.7.8.tar.gz $SRCDIR/libxml2/ + make +} + +# install +install() +{ + BIN_DIR=$SRCDIR/package/smart-build-interface.package.windows/data/SDK/build-system/bin + mkdir -p $BIN_DIR + PLUGINS_DIR=$SRCDIR/package/smart-build-interface.package.windows/data/SDK/build-system/plugins + mkdir -p $PLUGINS_DIR + cp $SRCDIR/bin/sbi $BIN_DIR/ + cp $SRCDIR/bin/sbi_build $BIN_DIR/ +} + +[ "$1" = "clean" ] && clean +[ "$1" = "build" ] && build +[ "$1" = "install" ] && install +echo "success" diff --git a/package/pkginfo.manifest b/package/pkginfo.manifest new file mode 100644 index 0000000..6682350 --- /dev/null +++ b/package/pkginfo.manifest @@ -0,0 +1,17 @@ +Package : smart-build-interface +Version : 0.20.16 +Maintainer : Taejun Ha , Jiil Hyoun , Donghyuk Yang , Donghee Yang +Description : smart build interface for Tizen SDK +OS : linux +Build-host-os : linux +Source : smart-build-interface + +Package : smart-build-interface +Version : 0.20.16 +Maintainer : Taejun Ha , Jiil Hyoun , Donghyuk Yang , Donghee Yang +Description : smart build interface for Tizen SDK +OS : windows +Build-host-os : windows +Install-dependency : +Source-dependency : libxml2-2.7.8.tar.gz [windows] +Source : smart-build-interface diff --git a/package/remove.linux b/package/remove.linux new file mode 100644 index 0000000..9d9f481 --- /dev/null +++ b/package/remove.linux @@ -0,0 +1,3 @@ +#!/bin/sh + +rm -f ${INSTALLED_PATH}/SDK/build-system/plugins/*_* diff --git a/package/remove.windows b/package/remove.windows new file mode 100644 index 0000000..e044d80 --- /dev/null +++ b/package/remove.windows @@ -0,0 +1,4 @@ +:: delims is a TAB followed by a space + +SET installed_path=%INSTALLED_PATH% +DEL %installed_path%\SDK\build-system\plguins\*_* diff --git a/package_upload.sh b/package_upload.sh new file mode 100755 index 0000000..024c519 --- /dev/null +++ b/package_upload.sh @@ -0,0 +1,45 @@ +# Script by TaeYoung Son +if [ $# -lt 1 ] +then + echo "Usage: package_upload {linux|windows|inhouse}" + exit 1 +fi + + +platform=$1 +case $1 in +linux) +upload_platform_name=LINUX_PUBLIC +platform=linux +package_file_list=`ls *_${platform}.zip` +;; +windows) +upload_platform_name=WINDOWS +platform=windows +package_file_list=`ls *_${platform}.zip` +;; +inhouse) +upload_platform_name=LINUX_INHOUSE +platform=linux +package_file_list=`ls *_${platform}.zip|grep -v rootstrap` +;; +*) +echo "${platform} is not supported yet." +exit 1 +;; +esac + +cupload_patform_name=$1 +current_date=`date +%Y%m%d` +upload_server=172.21.111.180 +upload_directory=/packages/${current_date}_PACKAGES_${upload_platform_name} +upload_user=core +upload_password=tmaxcore + +echo "Upload to server..." +for package_file in ${package_file_list} +do +echo "ncftpput -u ${upload_user} -p ${upload_password} ${upload_server} ${upload_directory} ${package_file}" +ncftpput -u ${upload_user} -p ${upload_password} ${upload_server} ${upload_directory} ${package_file} +done +echo "Upload SUCCESS" diff --git a/sbi-build.bat b/sbi-build.bat new file mode 100644 index 0000000..abd1a02 --- /dev/null +++ b/sbi-build.bat @@ -0,0 +1,24 @@ +@ECHO OFF + +IF "%1" == "/?" ( + echo Usage: sbi-build.bat [configuration name] + goto exit +) + +set msyspath=MinGW\msys\1.0\bin +set mingwpath=MinGW\bin +@set key=TIZEN_SDK_INSTALLED_PATH + +@FOR /F "tokens=1,2 delims==" %%i IN (%localappdata%\.TizenSDK\tizensdkpath) DO @if %%i==%key% (set installed_path=%%j) + +echo install_path : %installed_path% + +path=%installed_path%\%mingwpath%;%installed_path%\%msyspath%;%path% + +IF "%1" == "" ( + start /b %installed_path%\SDK\build-system\bin\sbi_build.exe +) ELSE ( + start /b %installed_path%\SDK\build-system\bin\sbi_build.exe -config %1 +) + +:exit diff --git a/src/cmdline_interpreter.c b/src/cmdline_interpreter.c new file mode 100644 index 0000000..0b26730 --- /dev/null +++ b/src/cmdline_interpreter.c @@ -0,0 +1,745 @@ +/* + * cmdline_interpreter.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +#include +#include +#include +#include +#include +#include "cmdline_interpreter.h" +#include "sbi_util.h" +#include "target_mgt.h" +#include "rootstrap_mgt.h" +#include "toolchain_mgt.h" +#include "sbi_config.h" +#include "sbi_error.h" + +typedef enum { + CMD_CREATE, + CMD_REMOVE, + CMD_SELECT, + CMD_SHOW, + CMD_LIST, + CMD_ACTION, + CMD_QUERY +} sbi_command_id; + + +/* sbi command structure */ +typedef struct _sbi_command +{ + sbi_command_id cmd_id; + string* rootstrap_id; + string* toolchain_id; + string* target_name; + string* extra_cmd_name; + string_list* extra_arguments; +} sbi_command; + + +static sbi_command* create_sbi_command( sbi_command_id cmd_id, + const char* rootstrap_id, const char* toolchain_id, + const char* target_name, const char* extra_cmd_name, + string_list* extra_arguments ) +{ + string* arg; + sbi_command* new_command = malloc( sizeof( sbi_command )); + new_command->cmd_id = cmd_id; + new_command->rootstrap_id = create_string( rootstrap_id ); + new_command->toolchain_id = create_string( toolchain_id ); + new_command->target_name = create_string( target_name ); + new_command->extra_cmd_name = create_string( extra_cmd_name ); + if (extra_arguments != NULL) { + new_command->extra_arguments = create_string(extra_arguments->str); + for ( arg = extra_arguments->next; arg != NULL; arg=arg->next ) + { + new_command->extra_arguments = append_string_to_list( new_command->extra_arguments,arg->str ); + } + } else { + new_command->extra_arguments = NULL; + } + + return new_command; +} + + +static void remove_sbi_command( sbi_command* cmd ) +{ + if ( cmd->rootstrap_id != NULL ) + remove_string( cmd->rootstrap_id ); + if ( cmd->toolchain_id != NULL ) + remove_string( cmd->toolchain_id ); + if ( cmd->target_name != NULL ) + remove_string( cmd->target_name ); + if ( cmd->extra_cmd_name != NULL ) + remove_string( cmd->extra_cmd_name ); + if ( cmd->extra_arguments != NULL ) + remove_string_list( cmd->extra_arguments ); + + free( cmd ); +} + + +static sbi_command* parse_command_line(int argc, char* argv[]); +static int execute_sbi_command( sbi_command* cmd ); + + +static sbi_command* parse_create_cmd(int argc, char* argv[]); +static int execute_create_cmd( sbi_command* cmd ); +static sbi_command* parse_remove_cmd(int argc, char* argv[]); +static int execute_remove_cmd( sbi_command* cmd ); +static sbi_command* parse_select_cmd(int argc, char* argv[]); +static int execute_select_cmd( sbi_command* cmd ); +static sbi_command* parse_show_cmd(int argc, char* argv[]); +static int execute_show_cmd( sbi_command* cmd ); +static sbi_command* parse_list_cmd(int argc, char* argv[]); +static int execute_list_cmd( sbi_command* cmd ); +static sbi_command* parse_action_cmd(int argc, char* argv[]); +static int execute_action_cmd( sbi_command* cmd ); +static sbi_command* parse_query_cmd(int argc, char* argv[]); +static int execute_query_cmd( sbi_command* cmd ); + + + +/* create the environment for interpreting */ +static void create_interpret_environment() +{ + /* initialize management module */ + initialize_rootstrap_mgt(); + initialize_toolchain_mgt(); + initialize_target_mgt(); +} + + +/* destroy the environment */ +static void destroy_interpret_environment() +{ + /* free management module */ + finalize_target_mgt(); + finalize_toolchain_mgt(); + finalize_rootstrap_mgt(); +} + + +/* Command line interpreter */ +int interpret_command_line( int argc, char* argv[] ) +{ + int ret; + sbi_command* cmd = NULL; + + /* create env */ + create_interpret_environment(); + + /* parse command line */ + cmd = parse_command_line( argc - 1, argv + 1 ); + if ( cmd == NULL ) + { + ret = -1; + goto fini; + } + + /* execute sbi command */ + ret = execute_sbi_command( cmd ); + + /* destroy cmd */ + remove_sbi_command( cmd ); + +fini: + destroy_interpret_environment(); + + return ret; +} + + +/* parse command line input and return command object */ +static sbi_command* parse_command_line( int argc, char* argv[] ) +{ + sbi_command* ret; + + if (argc < 1) + { + print_usage(USAGE_ALL); + ret = NULL; + } + else if (strncmp(argv[0], "create", 6) == 0 && strlen(argv[0]) == 6) + { + ret = parse_create_cmd(argc, argv); + } + else if (strncmp(argv[0], "remove", 6) == 0 && strlen(argv[0]) == 6) + { + ret = parse_remove_cmd(argc, argv); + } + else if (strncmp(argv[0], "select", 6) == 0 && strlen(argv[0]) == 6) + { + ret = parse_select_cmd(argc, argv); + } + else if (strncmp(argv[0], "list", 4) == 0 && strlen(argv[0]) == 4) + { + ret = parse_list_cmd(argc, argv); + } + else if (strncmp(argv[0], "show", 4) == 0 && strlen(argv[0]) == 4) + { + ret = parse_show_cmd(argc, argv); + } + else if (strncmp(argv[0], "action", 6) == 0 && strlen(argv[0]) == 6) + { + ret = parse_action_cmd(argc, argv); + } + else if (strncmp(argv[0], "query", 5) == 0 && strlen(argv[0]) == 5) + { + ret = parse_query_cmd(argc, argv); + } + else + { + print_usage(USAGE_ALL); + ret = NULL; + } + + return ret; +} + + +/* execute command object, and return its result */ +static int execute_sbi_command( sbi_command* cmd ) +{ + int result = 0; + + switch( cmd->cmd_id ) + { + case CMD_CREATE: + result = execute_create_cmd( cmd ); + break; + case CMD_REMOVE: + result = execute_remove_cmd( cmd ); + break; + case CMD_SELECT: + result = execute_select_cmd( cmd ); + break; + case CMD_SHOW: + result = execute_show_cmd( cmd ); + break; + case CMD_LIST: + result = execute_list_cmd( cmd ); + break; + case CMD_ACTION: + result = execute_action_cmd( cmd ); + break; + case CMD_QUERY: + result = execute_query_cmd( cmd ); + break; + default: + result = -1; + break; + } + + return result; +} + + + +/* + * Create new sbi target + * sbi create -root -tool + * */ +static sbi_command* parse_create_cmd(int argc, char* argv[]) +{ + static struct option long_options[] = + { + { "root", required_argument, 0, 'r' }, + { "tool", required_argument, 0, 't' }, + { 0, 0, 0, 0 } }; + + char target_id[MAX_NAME]; + char root_id[MAX_NAME]; + char tool_id[MAX_NAME]; + + int op; + int option_index = 0; + + strcpy(target_id, ""); + strcpy(root_id, ""); + strcpy(tool_id, ""); + + while ((op = getopt_long_only(argc, argv, "r:t:", long_options, + &option_index)) != -1) + { + + switch (op) + { + case 0: + break; + case 'r': + strncpy(root_id, optarg, MAX_NAME); + break; + case 't': + strncpy(tool_id, optarg, MAX_NAME); + break; + default: + sbi_error(2, "create", 1); + break; + } + } + + /* get target_id, target_id is last element in argv[] */ + if (argc > optind) + strncpy(target_id, argv[optind++], MAX_NAME); + else + sbi_error(2, "create", 1); + + /* error check */ + if (optind != argc) + sbi_error(2, "create", 1); + + if (strlen(root_id) == 0) + sbi_error(2, "create", 1); + + if (strlen(tool_id) == 0) + sbi_error(2, "create", 1); + + if (strlen(target_id) == 0) + sbi_error(2, "create", 1); + + return create_sbi_command( CMD_CREATE, root_id, tool_id, target_id, NULL, NULL ); +} + + +static int execute_create_cmd( sbi_command* cmd ) +{ + int result; + char* target_id = cmd->target_name->str; + char* rootstrap_id = cmd->rootstrap_id->str; + char* toolchain_id = cmd->toolchain_id->str; + + /* if rootstrap is not available, error */ + if (!is_rootstrap_available(rootstrap_id)) + sbi_error(3, rootstrap_id, 1); + + /* if toolchain is not available, error */ + if (!is_toolchain_available(toolchain_id)) + sbi_error(4, toolchain_id, 1); + + /* if the target already exists, error */ + if (is_target_available(target_id)) + sbi_error(1, target_id, 1); + + /* create target xml file */ + result = create_new_target(target_id,rootstrap_id ,toolchain_id ); + if (result != 0 ) + { + /* if fail, remove */ + remove_target_xml(target_id); + sbi_error(17, target_id, 1); + } + + /* execute "create" action, if predefined action is defined */ + if ( is_target_predefined_action_available( target_id, "create" ) ) + { + sbi_command* new_cmd = create_sbi_command(CMD_ACTION, NULL, NULL, target_id, "create", NULL ); + + result = execute_action_cmd( new_cmd ); + + remove_sbi_command( new_cmd ); + } + + return result; +} + + + +/* + * Remove SBI target + * sbi remove + * */ +sbi_command* parse_remove_cmd(int argc, char* argv[]) +{ + char target_id[MAX_NAME]; + + strcpy(target_id, ""); + /* get target_id, target_id is last element in argv[] */ + if (argc > 1) + strncpy(target_id, argv[1], MAX_NAME); + else + /* if argc is 1 then argument does not inlcude target name */ + sbi_error(2, "remove", 1); + + if (strlen(target_id) == 0) + sbi_error(2, "remove", 1); + + return create_sbi_command( CMD_REMOVE, NULL, NULL, target_id, NULL, NULL ); +} + + +static int execute_remove_cmd( sbi_command* cmd ) +{ + int result; + char* target_id = cmd->target_name->str; + + /* if the target is not available, error */ + if (!is_target_available(target_id)) + sbi_error(7, target_id, 1); + + /* remove target xml */ + remove_target_xml(target_id); + + /* change default target */ + if (is_default_target(target_id)) + reset_default_target(); + + /* execute "remove" action, if predefined action is defined */ + if ( is_target_predefined_action_available( target_id, "remove" ) ) + { + sbi_command* new_cmd = create_sbi_command(CMD_ACTION, NULL, NULL, target_id, "remove", NULL ); + + result = execute_action_cmd( new_cmd ); + + remove_sbi_command( new_cmd ); + } + + return 0; +} + + +/* + * Select the target as default target + * sbi select + * */ +static sbi_command* parse_select_cmd(int argc, char* argv[]) +{ + char target_id[MAX_NAME]; + + strcpy(target_id, ""); + + /* get target_name, target_name is last element in argv[] */ + if (argc > 1) + strncpy(target_id, argv[1], MAX_NAME); + else + sbi_error(2, "select", 1); + + if (strlen(target_id) == 0) + sbi_error(2, "select", 1); + + return create_sbi_command( CMD_SELECT, NULL, NULL, target_id, NULL, NULL ); +} + + +static int execute_select_cmd( sbi_command* cmd ) +{ + char* target_id = cmd->target_name->str; + + /* if the target is not available, error */ + if (!is_target_available(target_id)) + sbi_error(7, target_id, 1); + + /* set default */ + set_default_target(target_id); + + return 0; +} + + +/* + * Show information + * sbi show [|target |tool |root ] + * */ +sbi_command* parse_show_cmd(int argc, char* argv[]) +{ + sbi_command* cmd = NULL; + + if (argc == 1) + { + cmd = create_sbi_command( CMD_SHOW, NULL, NULL, NULL, NULL, NULL ); + } + else if (argc == 2) + { + cmd = create_sbi_command( CMD_SHOW, NULL, NULL, argv[1], NULL, NULL ); + } + else if (argc == 3) + { + if (strncmp(argv[1], "target", 6) == 0 && strlen(argv[1]) == 6) + cmd = create_sbi_command( CMD_SHOW, NULL, NULL, argv[2], NULL, NULL ); + else if (strncmp(argv[1], "tool", 4) == 0 && strlen(argv[1]) == 4) + cmd = create_sbi_command( CMD_SHOW, NULL, argv[2], NULL, NULL, NULL ); + else if (strncmp(argv[1], "root", 4) == 0 && strlen(argv[1]) == 4) + cmd = create_sbi_command( CMD_SHOW, argv[2], NULL, NULL, NULL, NULL ); + else + sbi_error(2, "show", 1); + } + else + sbi_error(2, "show", 1); + + return cmd; +} + + + +static int execute_show_cmd( sbi_command* cmd ) +{ + char* target_id = cmd->target_name->str; + char* rootstrap_id = cmd->rootstrap_id->str; + char* toolchain_id = cmd->toolchain_id->str; + + /* if no argument specified, use default target */ + if ( target_id == NULL && rootstrap_id == NULL && toolchain_id == NULL ) + { + if (does_default_target_exist()) + display_target_info( get_default_target() ); + else + sbi_error(8, NULL, 1); + } + else if ( target_id != NULL ) + { + /* if target is not available, error */ + if ( !is_target_available( target_id ) ) + sbi_error(24, target_id, 1); + + display_target_info( target_id ); + } + else if ( toolchain_id != NULL ) + { + /* if toolchain is not available, error */ + if (!is_toolchain_available(toolchain_id)) + sbi_error(4, toolchain_id, 1); + + display_toolchain_info( toolchain_id ); + } + else if ( rootstrap_id != NULL ) + { + /* if rootstrap is not available, error */ + if (!is_rootstrap_available(rootstrap_id)) + sbi_error(3, rootstrap_id, 1); + + display_rootstrap_info( rootstrap_id ); + } + + return 0; +} + + + +/* + * List up + * sbi list [target|tool|root|*all] + * */ +sbi_command* parse_list_cmd(int argc, char* argv[]) +{ + sbi_command* cmd = NULL; + + /* input is just 'sbi list' then default value is all */ + if (argc == 1) + { + cmd = create_sbi_command( CMD_LIST, "YES", "YES", "YES", NULL, NULL ); + } + else if (argc == 2) + { + if (strncmp(argv[1], "all", 3) == 0 && strlen(argv[1]) == 3) + { + cmd = create_sbi_command( CMD_LIST, "YES", "YES", "YES", NULL, NULL ); + } + else if (strncmp(argv[1], "target", 6) == 0 && strlen(argv[1]) == 6) + cmd = create_sbi_command( CMD_LIST, NULL, NULL, "YES", NULL, NULL ); + else if (strncmp(argv[1], "root", 4) == 0 && strlen(argv[1]) == 4) + cmd = create_sbi_command( CMD_LIST, "YES", NULL, NULL, NULL, NULL ); + else if (strncmp(argv[1], "tool", 4) == 0 && strlen(argv[1]) == 4) + cmd = create_sbi_command( CMD_LIST, NULL, "YES", NULL, NULL, NULL ); + else + { + sbi_error(2, "list", 1); + } + } + else + sbi_error(2, "list", 1); + + return cmd; +} + + +static int execute_list_cmd( sbi_command* cmd ) +{ + char* target_id = cmd->target_name->str; + char* rootstrap_id = cmd->rootstrap_id->str; + char* toolchain_id = cmd->toolchain_id->str; + + if ( target_id == NULL && rootstrap_id == NULL && toolchain_id == NULL ) + { + display_target_list(); + display_rootstrap_list(); + display_toolchain_list(); + } + + if (target_id != NULL) + { + display_target_list(); + } + if ( toolchain_id != NULL ) + { + display_toolchain_list(); + } + if ( rootstrap_id != NULL ) + { + display_rootstrap_list(); + } + + return 0; +} + + + +/* + * Execute action + * sbi action [target_name] -- action_cmd key1=value1 key2=value2 ... + * */ + +sbi_command* parse_action_cmd(int argc, char* argv[]) +{ + sbi_command* cmd = NULL; + char action_name[MAX_NAME]; + char target_id[MAX_NAME]; + string_list* arguments = NULL; + int cnt = 0; + int i = 0; + + strcpy(action_name, ""); + strcpy(target_id, ""); + + if ( argc > 3 && (strcmp(argv[0], "action") == 0) && (strcmp(argv[2], "--") == 0 ) ) + { + strncpy( target_id, argv[1], MAX_NAME); + strncpy( action_name, argv[3], MAX_NAME); + cnt = 4; + } + else + sbi_error(2, "action", 1); + + i = cnt; + if ( i < argc ) + { + arguments = create_string_list( argv[i] ); + i++; + } + + for (; i < argc ; i++) + { + assert( arguments != NULL ); + append_string_to_list( arguments, argv[i] ); + } + + cmd = create_sbi_command( CMD_ACTION, NULL, NULL, target_id, action_name, arguments ); + + /* clean up */ + if( arguments != NULL ) + remove_string_list( arguments ); + + return cmd; +} + + +static int execute_action_cmd( sbi_command* cmd ) +{ + int ret = 0; + char* target_id = cmd->target_name->str; + char* action_cmd = cmd->extra_cmd_name->str; + string_list* action_arguments = cmd->extra_arguments; + + /* if target is not available , error */ + if (!is_target_available(target_id)) + sbi_error(7, target_id, 1); + + /* if the action is not available , error */ + if ( !is_target_action_available( target_id, action_cmd) ) + sbi_error(29, action_cmd, 1); + + /* ececute action */ + ret = execute_target_action( target_id, action_cmd, action_arguments ); + + return ret; +} + + +/* + * Query action information + * sbi query [target_name] [action_cmd] + * */ +sbi_command* parse_query_cmd(int argc, char* argv[]) +{ + sbi_command* cmd = NULL; + char action_name[MAX_NAME]; + char target_id[MAX_NAME]; + + strcpy(target_id, ""); + strcpy(action_name, ""); + + switch(argc) + { + case 1: + sbi_error(2, "query", 1); + break; + case 2: + strncpy( target_id, argv[1], MAX_NAME); + cmd = create_sbi_command( CMD_QUERY, NULL, NULL, target_id, NULL, NULL ); + break; + + case 3: + strncpy( target_id, argv[1], MAX_NAME); + strncpy( action_name, argv[2], MAX_NAME); + cmd = create_sbi_command( CMD_QUERY, NULL, NULL, target_id, action_name, NULL ); + + break; + default: + sbi_error(2, "query", 1); + break; + } + + return cmd; +} + + +static int execute_query_cmd( sbi_command* cmd ) +{ + char* target_id = cmd->target_name->str; + char* action_cmd = cmd->extra_cmd_name->str; + + /* if target is not available , error */ + if (!is_target_available(target_id)) + sbi_error(7, target_id, 1); + + if( action_cmd != NULL ) + { + /* if the action is not available , error */ + if ( !is_target_action_available( target_id, action_cmd) ) + sbi_error(29, action_cmd, 1); + + print_target_action_variables( target_id, action_cmd ); + } + else + { + print_target_action_list(target_id); + } + + return 0; +} + diff --git a/src/cmdline_interpreter.h b/src/cmdline_interpreter.h new file mode 100644 index 0000000..9049d24 --- /dev/null +++ b/src/cmdline_interpreter.h @@ -0,0 +1,31 @@ +/* + * cmdline_interpreter.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +/* interpret command line input and return its result */ +int interpret_command_line( int argc, char* argv[] ); + + diff --git a/src/config_common.c b/src/config_common.c new file mode 100644 index 0000000..b4bc57a --- /dev/null +++ b/src/config_common.c @@ -0,0 +1,198 @@ +/* + * config_common.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include + +#include "config_common.h" +#include "sbi_util.h" +#include "sbi_error.h" + + +#define MAX_CONFIG_ITEM 255 +#define MAX_KEY_LENGTH 30 +#define MAX_VALUE_LENGTH 255 +#define MAX_CONFIG_LINE_LENGTH (MAX_KEY_LENGTH + MAX_VALUE_LENGTH + 10) + +typedef struct _config_item +{ + char key[MAX_KEY_LENGTH + 1]; + char value[MAX_VALUE_LENGTH + 1]; +} config_item_t; + +static config_item_t config_list[MAX_CONFIG_ITEM]; +static int config_size; + +void initialize_config(void) +{ + config_size = 0; +} + +int read_config_file(const char* path) +{ + FILE *fp = NULL; + char line[MAX_CONFIG_LINE_LENGTH + 1] = ""; + char msg[255]; + + /* open config file */ + fp = fopen(path, "r"); + if (fp == NULL) + { + sprintf(msg, "can't open config file : %s", path); + sbi_error(99, msg, 1); + return -1; + } + + config_size = 0; + + while (fgets(line, MAX_CONFIG_LINE_LENGTH, fp) != NULL) + { + char *key, *value; + + /* comment */ + if (line[0] == '#') + { + continue; + } + + /* get key */ + key = strtok(line, "="); + if (key == NULL) + { + continue; + } + key = trim(key); + + /* get value */ + value = strtok(NULL, "="); + if (value != NULL) + { + set_key_value_string(key, trim(value)); + } + else + { + set_key_value_string(key, ""); + } + } + + /* close */ + fclose(fp); + + return 0; +} + +int write_config_file(const char* path) +{ + FILE *fp = NULL; + int i; + char msg[255]; + + /* open config file */ + fp = fopen(path, "w"); + if (fp == NULL) + { + sprintf(msg, "can't open config file path : %s", path); + sbi_error(99, msg, 1); + return -1; + } + + /* write */ + for (i = 0; i < config_size; i++) + { + fprintf(fp, "%s=%s\n", config_list[i].key, config_list[i].value); + } + + /* close */ + fclose(fp); + + return 0; +} + +void set_key_value_string(const char* key, const char* value) +{ + int i; + + for (i = 0; i < config_size; i++) + { + if (strcmp(config_list[i].key, key) == 0) + { + strcpy(config_list[i].value, value); + break; + } + } + + if (i == config_size) + { + strcpy(config_list[i].key, key); + strcpy(config_list[i].value, value); + config_size++; + } +} + +char* get_key_value_string(const char* key) +{ + int i; + + for (i = 0; i < config_size; i++) + { + if (strcmp(config_list[i].key, key) == 0) + { + return trim(config_list[i].value); + } + } + + return NULL; +} + +int get_config_size() +{ + return config_size; +} + +char* get_key_string(int idx) +{ + if (idx < config_size) + { + return trim(config_list[idx].key); + } + else + { + return NULL; + } +} + +char* get_value_string(int idx) +{ + if (idx < config_size) + { + return trim(config_list[idx].value); + } + else + { + return NULL; + } +} diff --git a/src/config_common.h b/src/config_common.h new file mode 100644 index 0000000..09f3858 --- /dev/null +++ b/src/config_common.h @@ -0,0 +1,46 @@ +/* + * config_common.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +#ifndef _CONFIG_COMMON_H +#define _CONFIG_COMMON_H + +/* init */ +void initialize_config(void); + +/* i/o */ +int read_config_file(const char* path); +int write_config_file(const char* path); + +/* access */ +char* get_key_value_string(const char* key); +void set_key_value_string(const char* key, const char* value); +int get_config_size(); +char* get_key_string(int idx); +char* get_value_string(int idx); + +#endif diff --git a/src/execute.c b/src/execute.c new file mode 100644 index 0000000..589d0f5 --- /dev/null +++ b/src/execute.c @@ -0,0 +1,476 @@ +/* + * execute.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include +#include +#include +#include "execute.h" +#include "plugin_mgt.h" +#include "sbi_config.h" +#include "sbi_error.h" +#include "sbi_util.h" + + +static char* load_script_contents_from_plugin( plugin_tag* execute_tag ); + + +execute* create_execute_binary_path( char* binary_path, char* description ) +{ + execute *newr = (execute*)malloc( sizeof(execute ) ); + + newr->binary_path = strdup( binary_path ); + newr->script_name = NULL; + newr->script = NULL; + newr->input_list = NULL; + + if ( description != NULL ) + newr->description = (char*)strdup(description); + else + newr->description = NULL; + + newr->next = NULL; + + return newr; +} + + +execute* create_execute_script( char* script_name, char* description, char* script ) +{ + execute *newr = (execute*)malloc( sizeof(execute ) ); + + newr->binary_path = NULL; + newr->script_name = strdup( script_name ) ; + newr->script = strdup( script ); + newr->input_list = NULL; + + if ( description != NULL ) + newr->description = (char*)strdup(description); + else + newr->description = NULL; + + newr->next = NULL; + + return newr; +} + + +void set_execute_input( execute* dst, execute_input* input ) +{ + dst->input_list = input ; +} + + +execute* append_execute_list( execute* list, execute* src ) +{ + execute* r = list; + while( r->next != NULL ) + r=r->next; + + r->next = src; + + return list; +} + + +void remove_execute_list( execute* list ) +{ + execute* r = list; + while( r != NULL ) + { + execute* prev = r ; + r=r->next; + if ( prev->binary_path != NULL ) free( prev->binary_path ); + if ( prev->script_name != NULL ) free( prev->script_name ); + if ( prev->script != NULL ) free( prev->script ); + if ( prev->description != NULL ) free( prev->description ); + if ( prev->input_list != NULL ) remove_execute_input_list( prev->input_list ); + free( prev ); + } +} + +static execute_env* create_execute_env( char* key, char* value ) +{ + execute_env *newr = (execute_env*)malloc( sizeof(execute_env ) ); + + newr->key = strdup( key ); + newr->value = strdup( value ); + newr->next = NULL; + + return newr; +} + + +static execute_env* append_execute_env( execute_env* list, execute_env* src ) +{ + execute_env* r = list; + while( r->next != NULL ) + r=r->next; + + r->next = src; + + return list; +} + + +execute_env* parse_execute_env( string_list* arguments ) +{ + execute_env* result = NULL; + char* key_st = NULL; + char* key_end = NULL; + char* value_st = NULL; + char* value_end = NULL; + string_list* arg = NULL; + + if( arguments == NULL ) + return result; + + arg = arguments; + for ( ; arg ; arg=arg->next ) + { + char key[MAX_KEY_LENGTH]; + char value[MAX_VALUE_LENGTH]; + execute_env* newr; + + assert(arg->str != NULL); + + if ( *arg->str != '-' ) + { + sbi_error(25, arg->str, 0); + break; + } + + key_st = arg->str + 1; + value_end = key_st + strlen(arg->str); + key_end = strchr(arg->str, '='); + + if ( key_end == NULL ) + { + sbi_error(26, arg->str, 0); + break; + } + + value_st = key_end + 1; + + strncpy( key, key_st, key_end - key_st ); + key[key_end - key_st ] = '\0'; + strncpy( value, value_st, value_end - value_st); + value[value_end - value_st ] = '\0'; + + newr = create_execute_env( key, value ); + if ( result != NULL ) + append_execute_env( result, newr ); + else + result = newr; + + key_st = NULL; + key_end = NULL; + value_st = NULL; + value_end = NULL; + } + + return result; +} + + +void remove_execute_env( execute_env* list ) +{ + execute_env* r = list; + while( r != NULL ) + { + execute_env* prev = r ; + r=r->next; + free( prev->key ); + free( prev->value ); + free( prev ); + } +} + + + +execute* load_execute_list_from_plugin( plugin_tag* action_tag ) +{ + plugin_tag_list* tag_list = get_plugin_subtag_list( action_tag, "execute" ); + plugin_tag_list* plugin_tag = NULL; + execute* execute_list = NULL; + + if ( tag_list == NULL ) + return NULL; + + for( plugin_tag = tag_list; plugin_tag ; plugin_tag=plugin_tag->next ) + { + char *binary_path, *script_name, *desc; + execute* e = NULL; + + binary_path = get_plugin_tag_attribute( plugin_tag->tag, "binaryPath" ); + script_name = get_plugin_tag_attribute( plugin_tag->tag, "script" ); + desc = get_plugin_tag_attribute( plugin_tag->tag, "description" ); + + /* if binary */ + if ( binary_path != NULL ) + { + e = create_execute_binary_path( binary_path, desc ); + } + /* if script */ + else if ( script_name != NULL) + { + char* script_contents = load_script_contents_from_plugin( plugin_tag->tag ); + + if (script_contents != NULL) + { + e = create_execute_script( script_name, desc, script_contents ); + free( script_contents ); + } + else + e = NULL; + } + else + e = NULL; + + /* if creation is successful */ + if ( e != NULL ) + { + /* create/set execute input */ + set_execute_input( e, load_execute_input_list_from_plugin( plugin_tag->tag ) ); + + /* append it to list */ + if ( execute_list != NULL ) + append_execute_list( execute_list, e ); + else + execute_list = e; + } + + /* remove dynamically allocated string */ + free( binary_path ); + free( script_name ); + free( desc ); + } + + /* clean up */ + remove_plugin_tag_list(tag_list); + + return execute_list; +} + + +static char* load_script_contents_from_plugin( plugin_tag* execute_tag ) +{ + plugin_tag_list* ptag = get_plugin_subtag_list( execute_tag, "script" ); + char *script = NULL; + + if ( ptag == NULL ) + return NULL; + + /* get contents */ + script = get_plugin_tag_value( ptag->tag ); + + /* clean up */ + remove_plugin_tag_list(ptag); + + return script; +} + + + +/* resolve input argument and append to command*/ +static void append_arguments( char* cmd, execute_input* input_list , execute_env * env ) +{ + execute_input *input = input_list; + char* value; + + while( input ) + { + if ( strcmp( input->type , "tag" ) == 0 ) + { + execute_tag_value* v = parse_tag_value( input ); + v->id = tag_checker(v->id); + if( (value = search_tag(v->id, v->name, v->attr, v->attr_value, v->find_attr)) != 0 ) + { + value = tag_checker(value); + strcat( cmd, " \""); + strcat( cmd, value); + strcat( cmd, "\""); + } + else + { + strcat( cmd," \"\""); + } + } + else if ( strcmp( input->type, "variable") == 0 ) + { + execute_env* e = env; + while( e ) + { + if ( strcmp( e->key, input->value ) == 0 ) + { + /* don't need to wrap the value */ + strcat( cmd, " "); + strcat( cmd, e->value ); + break; + } + + e = e->next; + } + if ( e == NULL ) + sbi_error(27, input->value, 0); + } + else if ( strcmp( input->type, "string") == 0 ) + { + strcat( cmd, " \""); + strcat( cmd, input->value ); + strcat( cmd, "\""); + } + else + sbi_error(28, input->type, 0); + + /* get next */ + input = input->next; + } + +} +char* write_script(char* program, char* script) +{ + FILE *fp = NULL; + char msg[255]; + char *filename = get_script_file(); + + /* open config file */ + + //fp = fopen(get_script_file(), "w"); + fp = fopen(filename, "w"); + if (fp == NULL) + { + //sprintf(msg, "can't open script file path : %s", get_script_file()); + sprintf(msg, "can't open script file path : %s", filename); + sbi_error(99, msg, 1); + } + + /* write */ + fprintf(fp, "#!%s\n", program); + fprintf(fp, "\n%s\n", script); + + /* close */ + fclose(fp); + +#ifndef WIN32 + //chmod(get_script_file(), S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP); + chmod(filename, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP); +#endif + + return filename; +} + + +/* execute */ +static int execute_step( execute* ex , execute_env * env) +{ + char cmd[MAX_CMD_LENGTH + 1]; + int ret; + char* script_path = NULL; + + /* if binary_path is specified, call it */ + if ( ex->binary_path != NULL ) + { + /* set command */ + sprintf(cmd, "%s", ex->binary_path); + } + /* if script is specified, write it and execute it */ + else if ( ex->script_name != NULL ) + { + /* write script */ + script_path = write_script( ex->script_name, ex->script ); + + /* make cmd */ + sprintf(cmd, "sh \"%s\"", script_path); + } + else + { + sbi_error(0, "execute tag is wrong.\n", 1); + } + + /* append argunemt */ + append_arguments( cmd, ex->input_list , env); + + /* execute */ + SBI_PRINTF( 2, "CMD : %s\n", cmd ); + ret = system(cmd); + SBI_PRINTF( 2, "return : %d\n", ret ); + + /* if script file is written, remove it */ + if ( script_path != NULL ) + { + remove_file(script_path); + } + + return ret; +} + + +/* get variable */ +string_list* get_input_variable_list( execute* exe ) +{ + execute_input* input = exe->input_list; + string_list *list = NULL; + + if( input == NULL ) + return NULL; + + for( ; input; input = input->next ) + { + if( strcmp(input->type,"variable")==0 ) + { + if ( list != NULL ) + append_string_to_list( list, input->value ); + else + list = create_string( input->value ); + } + } + + return list; +} + + +/* execute all step defined in a action */ +int execute_all_steps( execute* ex_list, execute_env * env ) +{ + execute* ex = ex_list; + + while( ex ) + { + int ret = execute_step( ex, env ); + if ( ret != 0 ) + { + /* TODO error handling */ + return ret; + //break; + } + ex = ex->next; + } + + return 0; +} diff --git a/src/execute.h b/src/execute.h new file mode 100644 index 0000000..90bb936 --- /dev/null +++ b/src/execute.h @@ -0,0 +1,69 @@ +/* + * execute.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#ifndef EXECUTION_H_ +#define EXECUTION_H_ +#include "execute_input.h" +#include "sbi_types.h" +#include "plugin.h" + +typedef struct _execute { + char* binary_path; + char* script_name; + char* script; + execute_input *input_list; + char* description; + struct _execute *next; +} execute; + +/* structure */ +execute* create_execute_binary_path( char* binary_path, char* description ); +execute* create_execute_script( char* script_name, char* description, char* script ); +void set_execute_input( execute* dst, execute_input* input ); +execute* append_execute_list( execute* list, execute* src ); +void remove_execute_list( execute* t ); + +/* execute environment */ +typedef struct _execute_env { + char* key; + char* value; + struct _execute_env * next; +} execute_env; + +execute_env* parse_execute_env( string_list* argument ); +void remove_execute_env( execute_env* t ); + +/* load */ +execute* load_execute_list_from_plugin( plugin_tag* action_tag ); + +/* get variable */ +string_list* get_input_variable_list( execute* exe ); + +/* execute */ +int execute_all_steps( execute* ex_list, execute_env * env ); + +#endif /* EXECUTION_H_ */ diff --git a/src/execute_input.c b/src/execute_input.c new file mode 100644 index 0000000..5bda67d --- /dev/null +++ b/src/execute_input.c @@ -0,0 +1,155 @@ +/* + * execute_input.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include "execute_input.h" + +execute_input* create_execute_input( char* type, char* value ) +{ + execute_input *newr = (execute_input*)malloc( sizeof(execute_input ) ); + + newr->type = (char*)strdup(type); + newr->value = (char*)strdup( value ); + newr->next = NULL; + + return newr; +} + + +execute_input* append_execute_input_list( execute_input* list, execute_input* src ) +{ + execute_input* r = list; + while( r->next != NULL ) + r=r->next; + + r->next = src; + + return list; + +} + + +void remove_execute_input_list( execute_input* list ) +{ + execute_input* r = list; + while( r != NULL ) + { + execute_input* prev = r ; + r=r->next; + free( prev->type ); + free( prev->value ); + free( prev ); + } +} + + + + +execute_input* load_execute_input_list_from_plugin( plugin_tag* execute_tag ) +{ + plugin_tag_list* tag_list = get_plugin_subtag_list( execute_tag, "input" ); + plugin_tag_list* ptag = NULL; + execute_input* input_list = NULL; + + if ( tag_list == NULL ) + return NULL; + + for( ptag = tag_list; ptag ; ptag=ptag->next ) + { + execute_input* ei = NULL; + char *type, *value; + + /* create */ + type = get_plugin_tag_attribute( ptag->tag, "type" ); + value = get_plugin_tag_attribute( ptag->tag, "value" ); + ei = create_execute_input( type, value ); + + /* if valid, append it */ + if ( ei != NULL ) + { + if ( input_list != NULL) + append_execute_input_list( input_list, ei ); + else + input_list = ei; + } + + /* remove dynamically allocated string */ + free( type ); + free( value ); + } + + /* clean up */ + remove_plugin_tag_list(tag_list); + + return input_list; +} + + +execute_tag_value* parse_tag_value( execute_input* input ) +{ + execute_tag_value* newr = malloc( sizeof ( execute_tag_value ) ); + + char* val_st; + char* val_end; + char val[5][256] = {"", "", "", "", ""}; + char* copy = strdup( input->value ); + int i = 0; + + val_st = copy; + val_end = strchr(val_st, ':'); + + while ( val_end != NULL ) + { + strncpy(val[i], val_st, val_end - val_st); + val_st = val_end + 1; + val_end = strchr(val_st, ':'); + i++; + } + + if ( *val_st != '\0' ) + strcpy( val[i], val_st ); + + newr->id = (strcmp(val[0], "") == 0) ? NULL : strdup(val[0]); + newr->name = (strcmp(val[1], "") == 0) ? NULL : strdup(val[1]); + newr->attr = (strcmp(val[2], "") == 0) ? NULL : strdup(val[2]); + newr->attr_value = (strcmp(val[3], "") == 0) ? NULL : strdup(val[3]); + newr->find_attr = (strcmp(val[4], "") == 0) ? NULL : strdup(val[4]); + + return newr; +} + + +void remove_execute_tag_value( execute_tag_value* value ) +{ + free( value->name ); + free( value->attr ); + free( value->attr_value ); + free( value->find_attr ); + free( value ); +} + diff --git a/src/execute_input.h b/src/execute_input.h new file mode 100644 index 0000000..5c58de5 --- /dev/null +++ b/src/execute_input.h @@ -0,0 +1,60 @@ +/* + * execute_input.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#ifndef EXECUTE_INPUT_H_ +#define EXECUTE_INPUT_H_ + +#include "plugin.h" + +typedef struct _execute_input { + char* type; + char* value; + struct _execute_input *next; +} execute_input; + + +execute_input* create_execute_input( char* type, char* value ); +execute_input* append_execute_input_list( execute_input* list, execute_input* src ); +void remove_execute_input_list( execute_input* t ); + +execute_input* load_execute_input_list_from_plugin( plugin_tag* execute_tag ); + +/* for parsing tag value */ +/* plugin_id:tag_name:tag_attr:tag_attr_value:tag_find_attr */ +typedef struct _tag_value { + char* id; + char* name; + char* attr; + char* attr_value; + char* find_attr; +} execute_tag_value; + + +execute_tag_value* parse_tag_value( execute_input* input ); +void remove_execute_tag_value( execute_tag_value* value ); + +#endif /* EXECUTE_INPUT_H_ */ diff --git a/src/plugin.c b/src/plugin.c new file mode 100644 index 0000000..16bd97b --- /dev/null +++ b/src/plugin.c @@ -0,0 +1,371 @@ +/* + * plugin.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include + +#include "sbi_util.h" +#include "plugin.h" + + +static char* query_tag_loop(xmlNode* node, char* name, xmlChar * attr, char* attr_value, xmlChar* find_attr); + +plugin* create_plugin( char* file_name ) +{ + + char plugin_id[MAX_FILE_PATH + 1]; + char* ext; + xmlDoc* doc = NULL; + plugin* ret = malloc(sizeof(plugin)); + + /* file name validation*/ + if(!does_file_exist(file_name)) + { + return NULL; + } + + /* extension id validation*/ + doc = xmlReadFile(file_name, NULL, 0); + ret->extension_id = query_tag(doc,"extension",NULL,NULL,"point"); + if (ret->extension_id == NULL) + { + xmlFreeDoc(doc); + free(ret->extension_id); + free(ret); + return NULL; + } + + /* return plugin */ + strcpy(plugin_id,file_name); + ext = strrchr(plugin_id,'.'); + ext = '\0'; + ret->id = strdup(plugin_id); + ret->doc = doc; + ret->next = NULL; + return ret; +} + + +plugin* append_plugin( plugin* list, plugin* src ) +{ + plugin* node = list; + + if(node == NULL) + { + return src; + } + + while(node->next != NULL) + { + node = node->next; + } + + node->next = src; + return list; +} + + +void remove_plugin( plugin* list ) +{ + plugin* node = list; + plugin* prev; + + while(node != NULL) + { + prev = node; + node = node->next; + if(prev->extension_id != NULL) + { + free(prev->extension_id); + } + if(prev->id != NULL) + { + free(prev->id); + } + if(prev->doc != NULL) + { + xmlFreeDoc(prev->doc); + } + free(prev); + } +} + +plugin_tag_list* create_plugin_tag_list(plugin_tag* tag, char* tag_name) +{ + plugin_tag_list* list; + + list = malloc( sizeof(plugin_tag_list) ); + list->tag = xmlCopyNode(tag,1); + list->tag_name = strdup(tag_name); + list->next = NULL; + return list; +} + + +plugin_tag_list* append_plugin_tag_list(plugin_tag_list* list, plugin_tag_list* src) +{ + plugin_tag_list* node; + + if(list == NULL) + { + return src; + } + + node = list; + while(node->next != NULL) + { + node = node->next; + } + node->next = src; + + return list; +} + + +void remove_plugin_tag_list(plugin_tag_list* list) +{ + plugin_tag_list* node; + plugin_tag_list* pre; + + node = list; + while(node != NULL) + { + pre = node; + node = node->next; + if(pre->tag != NULL) + { + xmlFreeNodeList(pre->tag); + } + if(pre->tag_name != NULL) + { + free(pre->tag_name); + } + free(pre); + } +} + +plugin_tag* search_plugin_first_tag(plugin_tag* tag, const char* tag_name) +{ + plugin_tag* node; + plugin_tag* ret; + + if( strcmp( (const char*)tag->name,tag_name) == 0) + { + return tag; + } + + node = xmlFirstElementChild(tag); + if(node != NULL) + { + ret = search_plugin_first_tag(node,tag_name); + if(ret != NULL) + { + return ret; + } + } + + node = xmlNextElementSibling(tag); + if(node != NULL) + { + return search_plugin_first_tag(node, tag_name); + } + + return NULL; +} + +plugin_tag* get_plugin_tag( plugin* plg, char* tag_name ) +{ + plugin_tag* node; + + node = xmlDocGetRootElement(plg->doc); + if(node == NULL) + { + return NULL; + } + + return search_plugin_first_tag(node, tag_name); +} + +plugin_tag_list* get_plugin_subtag_list( plugin_tag* parent_tag, char* tag_name ) +{ + plugin_tag_list* list = NULL; + plugin_tag* node; + + node = xmlFirstElementChild(parent_tag); + while( node != NULL) + { + if(strcmp( (const char*)node->name,tag_name) == 0) + { + list = append_plugin_tag_list(list, create_plugin_tag_list(node,tag_name)); + } + node = xmlNextElementSibling(node); + } + return list; +} + +char* get_plugin_tag_attribute( plugin_tag* ptag, const char* attr ) +{ + xmlChar * value; + char* string; + + value = xmlGetProp(ptag, (const xmlChar *)attr); + if(value != NULL ) + { + string = strdup((char*)value); + xmlFree(value); + return string; + } + return NULL; +} + +char* get_plugin_tag_value( plugin_tag*ptag ) +{ + xmlChar * value; + char* string; + + value = xmlNodeGetContent(ptag); + if(value != NULL) + { + string = strdup((char*)value); + xmlFree(value); + return string; + } + return NULL; +} + +plugin_tag* get_plugin_sub_tags( plugin_tag* ptag) +{ + return xmlFirstElementChild(ptag); +} + +plugin_writer* create_writer(plugin_doc** doc) +{ + return xmlNewTextWriterDoc(doc,0); +} + +int start_write_doc(plugin_writer* writer) +{ + return xmlTextWriterStartDocument(writer,NULL,NULL,NULL); +} + +int start_write_elm(plugin_writer* writer, const char * name) +{ + return xmlTextWriterStartElement(writer,(const xmlChar *)name); +} + +int write_attr(plugin_writer* writer, const char * name, const char * constant) +{ + return xmlTextWriterWriteAttribute(writer,(const xmlChar *)name,(const xmlChar *)constant); +} + +int write_string(plugin_writer* writer, const char * content) +{ + return xmlTextWriterWriteString(writer,(const xmlChar *)content); +} + +int end_write_elm(plugin_writer* writer) +{ + return xmlTextWriterEndElement(writer); +} + +int end_write_doc(plugin_writer* writer) +{ + return xmlTextWriterEndDocument(writer); +} + +void free_writer(plugin_writer* writer) +{ + return xmlFreeTextWriter(writer); +} + +void free_doc(plugin_doc* doc) +{ + return xmlFreeDoc(doc); +} + +int save_doc_file(plugin_doc* doc,const char* filename) +{ + return xmlSaveFile(filename,doc); +} + +static char* query_tag_loop(xmlNode* node, char* name, xmlChar * attr, char* attr_value, xmlChar * find_attr ) +{ + xmlNode *cur_node = NULL; + xmlChar* result; + char* ret; + char* tmp; + char temp[MAX_CMD_LENGTH + 1]; + + for (cur_node = node; cur_node; cur_node = xmlNextElementSibling(cur_node)) + { + if(strcmp((const char*)cur_node->name, name) == 0) + { + if( ( attr == NULL && attr_value == NULL ) || + ( (tmp = (char*)xmlGetProp(cur_node,attr)) != NULL && strcmp(attr_value,tmp) == 0)) + { + /* find attr is needed */ + if( find_attr == NULL ) + { + return NULL; + } + + result = xmlGetProp(cur_node,find_attr); + if(result == NULL) + { + return NULL; + } + + ret = strdup((char*)result); + if(strchr(ret,' ') != NULL) + { + sprintf(temp,"\"%s\"",ret); + free(ret); + ret=strdup(temp); + } + + xmlFree(result); + return ret; + } + } + ret = query_tag_loop(cur_node->children, name, attr, attr_value, find_attr); + if(ret != NULL) + return ret; + } + return NULL; +} + +char* query_tag(xmlDoc* doc, char* name, char* attr, char* attr_value, char* find_attr ) +{ + xmlNode *root = NULL; + + if (doc == NULL) + return NULL; + + root = xmlDocGetRootElement(doc); + return query_tag_loop(root, name, (xmlChar*)attr, attr_value, (xmlChar*)find_attr); +} diff --git a/src/plugin.h b/src/plugin.h new file mode 100644 index 0000000..e617d58 --- /dev/null +++ b/src/plugin.h @@ -0,0 +1,92 @@ +/* + * plugin.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#ifndef PLUGIN_H_ +#define PLUGIN_H_ + +#include +#include +#include + +#define MAX_NAME 512 +#define MAX_VER_LENGTH 512 +#define MAX_FILE_PATH 1024 +#define MAX_REPOSITORY_LENGTH 512 +#define MAX_DATE_LENGTH 512 +#define MAX_PLUGIN_CMD_LENGTH 1024 +#define MAX_LINE_LENGTH 1024 +#define MAX_CMD_LENGTH 2048 + +typedef struct _plugin { + char* id; + char* extension_id; + struct _plugin *next; + xmlDoc* doc; +} plugin; +typedef plugin plugin_list; + +plugin* create_plugin( char* file_name ); +plugin* append_plugin( plugin* list, plugin* src ); +void remove_plugin( plugin* ); + +typedef xmlNode plugin_tag; +typedef xmlDoc plugin_doc; +typedef xmlTextWriter plugin_writer; + +typedef struct _plugin_tag_list{ + char* tag_name; + struct _plugin_tag_list *next; + plugin_tag* tag; +}plugin_tag_list; + + +plugin_tag_list* create_plugin_tag_list(plugin_tag* tag, char* tag_name); +plugin_tag_list* append_plugin_tag_list(plugin_tag_list* list, plugin_tag_list* src); +void remove_plugin_tag_list(plugin_tag_list* list); + +plugin_tag* search_plugin_first_tag(plugin_tag* plg, const char* tag_name); +plugin_tag* get_plugin_tag( plugin* plg, char* tag_name ); +plugin_tag_list* get_plugin_subtag_list( plugin_tag* parent_tag, char* tag_name ); +char* get_plugin_tag_attribute( plugin_tag*, const char* attr ); +char* get_plugin_tag_value( plugin_tag* ); +plugin_tag* get_plugin_sub_tags( plugin_tag* ); + +/* XML writing */ +plugin_writer* create_writer(plugin_doc** doc); +int start_write_doc(plugin_writer* writer); +int start_write_elm(plugin_writer* writer, const char * name); +int write_attr(plugin_writer* writer, const char * name, const char * constant); +int write_string(plugin_writer* writer, const char * content); +int end_write_elm(plugin_writer* writer); +int end_write_doc(plugin_writer* writer); +void free_writer(plugin_writer* writer); +void free_doc(plugin_doc* doc); +int save_doc_file(plugin_doc* doc,const char* filename); + +char* query_tag(xmlDoc* doc, char* name, char* attr, char* attr_value, char* find_attr); + +#endif /* PLUGIN_H_ */ diff --git a/src/plugin_mgt.c b/src/plugin_mgt.c new file mode 100644 index 0000000..fb9c8c3 --- /dev/null +++ b/src/plugin_mgt.c @@ -0,0 +1,161 @@ +/* + * plugin_mgt.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include + +#include "plugin_mgt.h" +#include "sbi_util.h" + + +static plugin* plugins = NULL; +static char* plugin_base_dir; + +void initialize_plugins(char* plugin_dir) +{ + DIR* dir; + struct dirent *entry; + //char* plugin_base_dir; + char xml_path[MAX_FILE_PATH + 1]; + //plugin_base_dir = get_plugin_base_dir(); + plugin_base_dir = plugin_dir; + + dir = opendir(plugin_base_dir); + if ( dir == NULL ) + return; + + while ( (entry = readdir(dir)) != NULL ) + { + int d_name_size; + + d_name_size = strlen( entry->d_name ); + if ( strcmp( entry->d_name + ( d_name_size - 4 ), ".xml" ) != 0 ) + { + continue; + } +#ifdef WIN32 + sprintf( xml_path, "%s\\%s", plugin_base_dir, entry->d_name); +#else + sprintf( xml_path, "%s/%s", plugin_base_dir, entry->d_name); +#endif + if (!is_directory(xml_path)) + { + plugins = append_plugin(plugins, create_plugin(xml_path)); + } + } + closedir(dir); +} + + +plugin* get_plugin_list(char* extention_pid ) +{ + plugin* node = plugins; + plugin* reta = NULL; + + while (node != NULL) + { + if (strcmp(node->extension_id, extention_pid ) == 0) + { + plugin* retp = malloc(sizeof(plugin)); + memcpy(retp, node, sizeof(plugin)); + retp->next = NULL; + if (reta == NULL) + reta = retp; + else + append_plugin(reta, retp); + } + node = node->next; + } + + return reta; +} + +void remove_plugin_list(plugin_list* list) +{ + plugin_list* node; + plugin_list* temp; + node = list; + while(node != NULL) + { + temp = node; + node = node->next; + free(temp); + } +} + +char* search_tag(char* plugin_id, char* tag_name, char* attr, char* attr_val, char* find_attr) +{ + plugin* p; + char* ret; + char xml_path[MAX_FILE_PATH +1]; + + // sprintf(xml_path,"%s/%s.xml",get_plugin_base_dir(),tag_checker(plugin_id)); +#ifdef WIN32 + sprintf(xml_path,"%s\\%s.xml", plugin_base_dir, plugin_id); +#else + sprintf(xml_path,"%s/%s.xml", plugin_base_dir, plugin_id); +#endif + p = get_plugin(xml_path); + if(p == NULL) + { + return NULL; + } + ret = query_tag(p->doc,tag_name,attr,attr_val,find_attr); + //ret = tag_checker(ret); + + return ret; +} + +plugin* get_plugin(char* plugin_id ) +{ + plugin* node = plugins; + while( node ) + { + if ( strcmp( node->id, plugin_id ) == 0 ) + return node; + node = node->next; + } + return NULL; +} + +void add_new_plugin( plugin* new_plugin ) +{ + plugins = append_plugin(plugins, new_plugin); +} + + +void add_target(char* target_xml_path) +{ + plugins = append_plugin(plugins, create_plugin(target_xml_path)); +} + + + +void finalize_plugins() +{ + remove_plugin(plugins); +} diff --git a/src/plugin_mgt.h b/src/plugin_mgt.h new file mode 100644 index 0000000..5ab247b --- /dev/null +++ b/src/plugin_mgt.h @@ -0,0 +1,42 @@ +/* + * plugin_mgt.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#ifndef PLUGIN_MGT_H_ +#define PLUGIN_MGT_H_ +#include "plugin.h" + +void initialize_plugins(); +plugin* get_plugin_list(char* extention_pid ); +void remove_plugin_list(plugin_list* list); +plugin* get_plugin(char* plugin_id ); +void add_new_plugin( plugin* new_plugin ); +void add_target(char* target_xml_path); +char* search_tag(char* plugin_id, char* tag_name, char* attr, char* attr_val, char* find_attr); +void finalize_plugins(); + + +#endif /* PLUGIN_MGT_H_ */ diff --git a/src/rootstrap.c b/src/rootstrap.c new file mode 100644 index 0000000..0a934d5 --- /dev/null +++ b/src/rootstrap.c @@ -0,0 +1,187 @@ +/* + * rootstrap.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include +#include "rootstrap.h" + + +static rootstrap_property* create_rootstrap_property( char* key, char* value ) +{ + rootstrap_property *newr = (rootstrap_property*)malloc( sizeof(rootstrap_property ) ); + + newr->key = (char*)strdup(key); + newr->value = (char*)strdup(value); + newr->next = NULL; + + return newr; +} + + +static rootstrap_property* append_rootstrap_property_list( rootstrap_property* list, rootstrap_property* src ) +{ + rootstrap_property* r = list; + while( r->next != NULL ) + r=r->next; + + r->next = src; + + return list; +} + + +static void remove_rootstrap_property_list( rootstrap_property* list ) +{ + rootstrap_property* r = list; + rootstrap_property* prev; + while( r != NULL ) + { + prev = r; + r=r->next; + if(prev->key != NULL) + { + free(prev->key); + } + if(prev->value != NULL) + { + free(prev->value); + } + free(prev); + } +} + + +rootstrap* create_rootstrap( char* id, char* name, char* version, char* architecture, char* path, char* toolchain_type) +{ + rootstrap *newr = (rootstrap*)malloc( sizeof(rootstrap ) ); + + newr->id = (char*)strdup(id); + + if ( name != NULL ) newr->name = (char*)strdup(name); + else newr->name = (char*)strdup(id); + + if ( version != NULL ) newr->version = (char*)strdup(version); + else newr->version = (char*)strdup("1.0"); + + if ( architecture != NULL ) newr->architecture = (char*)strdup( architecture ); + else newr->architecture = NULL; + if ( path != NULL ) newr->path = (char*)strdup( path ); + else newr->path = NULL; + if ( toolchain_type != NULL ) newr->support_toolchain_type = (char*)strdup( toolchain_type ); + else newr->support_toolchain_type = NULL; + newr->property_list = NULL; + newr->next = NULL; + + return newr; +} + + +rootstrap* append_rootstrap_list( rootstrap* list, rootstrap* src ) +{ + rootstrap* r = list; + while( r->next != NULL ) + r=r->next; + + r->next = src; + + return list; +} + + +void remove_rootstrap_list( rootstrap* list ) +{ + rootstrap* r = list; + while( r != NULL ) + { + rootstrap* prev = r ; + r=r->next; + if(prev->id != NULL) free( prev->id ); + if(prev->name != NULL) free( prev->name ); + if(prev->version != NULL) free( prev->version ); + if(prev->architecture != NULL) free( prev->architecture ); + if(prev->path != NULL) free( prev->path ); + if(prev->support_toolchain_type != NULL) free( prev->support_toolchain_type ); + remove_rootstrap_property_list(prev->property_list); + free( prev ); + } +} + + +void add_rootstrap_property( rootstrap* r, char* key, char* value ) +{ + rootstrap_property* newr = create_rootstrap_property( key, value ); + + if ( r->property_list != NULL ) + append_rootstrap_property_list( r->property_list, newr ); + else + r->property_list = newr; +} + + +/* load from plugin */ +rootstrap* load_rootstrap_from_plugin( plugin* p ) +{ + rootstrap* new_rootstrap = NULL; + char *id, *name, *version, *architecture, *path, *toolchain_type; + plugin_tag_list* prop_tag; + plugin_tag_list* tag_list; + plugin_tag* tag = get_plugin_tag( p, "rootstrap" ); + + assert( tag != NULL ); + + /* read */ + id = get_plugin_tag_attribute( tag, "id" ); + name = get_plugin_tag_attribute( tag, "name" ); + version = get_plugin_tag_attribute( tag, "version" ); + architecture = get_plugin_tag_attribute( tag, "architecture" ); + toolchain_type = get_plugin_tag_attribute( tag, "supportToolchainType" ); + path = get_plugin_tag_attribute( tag, "path" ); + + /* create */ + new_rootstrap = create_rootstrap( id, name, version, architecture, path, toolchain_type ); + + tag_list = get_plugin_subtag_list( tag, "property"); + prop_tag = tag_list; + for( ; prop_tag; prop_tag = prop_tag->next ) + { + char* key = get_plugin_tag_attribute( prop_tag->tag, "key" ); + char* value = get_plugin_tag_attribute( prop_tag->tag, "value" ); + add_rootstrap_property( new_rootstrap, key, value ); + free( key ); + free( value); + } + remove_plugin_tag_list(tag_list); + + free( id ); + free( name ); + free( architecture ); + free( path ); + free( toolchain_type ); + + return new_rootstrap; +} diff --git a/src/rootstrap.h b/src/rootstrap.h new file mode 100644 index 0000000..dfd7303 --- /dev/null +++ b/src/rootstrap.h @@ -0,0 +1,58 @@ +/* + * rootstrap.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#ifndef ROOTSTRAP_H_ +#define ROOTSTRAP_H_ +#include "plugin.h" + +typedef struct _rootstrap_property { + char* key; + char* value; + struct _rootstrap_property* next; +} rootstrap_property; + + +typedef struct _rootstrap { + char* id; + char* name; + char* version; + char* architecture; + char* path; + char* support_toolchain_type; + rootstrap_property* property_list; + struct _rootstrap *next; +} rootstrap; + +rootstrap* create_rootstrap( char* id, char* name, char* version, char* architecture, char* path, char* toolchain_type); +rootstrap* append_rootstrap_list( rootstrap* list, rootstrap* src ); +void add_rootstrap_property( rootstrap* r, char* key, char* value ); +void remove_rootstrap_list( rootstrap* t ); + +/* load from plugin */ +rootstrap* load_rootstrap_from_plugin( plugin* p ); + +#endif /* ROOTSTRAP_H_ */ diff --git a/src/rootstrap_mgt.c b/src/rootstrap_mgt.c new file mode 100644 index 0000000..6077612 --- /dev/null +++ b/src/rootstrap_mgt.c @@ -0,0 +1,291 @@ +/* + * rootstrap_mgt.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include + +#include "rootstrap_mgt.h" +#include "rootstrap.h" +#include "plugin_mgt.h" +#include "plugin.h" +#include "sbi_util.h" + +static rootstrap* rootstrap_list = NULL; + +/* init fini */ +void initialize_rootstrap_mgt( ) +{ + plugin* list = get_plugin_list("rootstrapDefinition"); + plugin* p = list; + + for( ; p ; p = p->next ) + { + rootstrap* r = load_rootstrap_from_plugin( p ); + + if ( r != NULL ) + { + if ( rootstrap_list != NULL ) + append_rootstrap_list( rootstrap_list, r ); + else + rootstrap_list = r; + } + } + remove_plugin_list(list); +} + + +void finalize_rootstrap_mgt( ) +{ + remove_rootstrap_list( rootstrap_list ); +} + + +/* list up all target */ +string_list* get_all_available_rootstrap_ids( ) +{ + string_list *new_list = NULL; + rootstrap * t = rootstrap_list; + + for( ; t ; t=t->next ) + { + if ( new_list != NULL ) + append_string_to_list( new_list, t->id ); + else + new_list = create_string_list( t->id ); + } + + return new_list; +} + + +string_list* get_all_available_rootstrap_names( ) +{ + string_list *new_list = NULL; + rootstrap * t = rootstrap_list; + + for( ; t ; t=t->next ) + { + if ( new_list != NULL ) + append_string_to_list( new_list, t->name ); + else + new_list = create_string_list( t->name ); + } + + return new_list; +} + + +/* find */ +static rootstrap* find_rootstrap( char* rootstrap_id ) +{ + rootstrap * t = rootstrap_list; + + for( ; t ; t=t->next ) + { + if ( strcmp( t->id, rootstrap_id ) == 0 ) + return t; + } + + return NULL; +} + + +/* rootstrap */ +char* get_rootstrap_name( char* rootstrap_id ) +{ + rootstrap * t = find_rootstrap( rootstrap_id ); + + if ( t != NULL ) + return strdup( t->name ); + else + return NULL; +} + + +char* get_rootstrap_version( char* rootstrap_id ) +{ + rootstrap * t = find_rootstrap( rootstrap_id ); + + if ( t != NULL ) + return strdup( t->version ); + else + return NULL; +} + + + +char* get_rootstrap_architecture( char* rootstrap_id ) +{ + rootstrap * t = find_rootstrap( rootstrap_id ); + + if ( t != NULL ) + { + if(t->architecture != NULL) + return strdup( t->architecture ); + else + return NULL; + } + else + { + return NULL; + } +} + + +char* get_rootstrap_path( char* rootstrap_id ) +{ + rootstrap * t = find_rootstrap( rootstrap_id ); + + if ( t != NULL ) + return strdup( t->path ); + else + return NULL; +} + + +char* get_rootstrap_support_toolchain_type( char* rootstrap_id ) +{ + rootstrap * t = find_rootstrap( rootstrap_id ); + + if ( t != NULL ) + { + if(t->support_toolchain_type != NULL) + return strdup( t->support_toolchain_type ); + else + return NULL; + } + else + { + return NULL; + } +} + +string_list* get_rootstrap_property_list( char* rootstrap_id ) +{ + rootstrap * t = find_rootstrap( rootstrap_id ); + rootstrap_property* r = t->property_list; + string_list * list= NULL; + + for( ; r; r = r -> next ) + { + if ( list != NULL ) + append_string_to_list( list, r->key ); + else + list = create_string_list( r->key); + } + + return list; +} + + + +char* get_rootstrap_property_value( char* rootstrap_id, char* key ) +{ + rootstrap * t = find_rootstrap( rootstrap_id ); + rootstrap_property* r = t->property_list; + + for( ; r; r = r -> next ) + { + if ( strcmp( r-> key , key) == 0 ) + return strdup( r->value ); + } + + return NULL; +} + + +int is_rootstrap_available( char* rootstrap_id ) +{ + rootstrap * t = find_rootstrap( rootstrap_id ); + + if ( t != NULL ) + return 1; + else + return 0; +} + +void display_rootstrap_list() +{ + string_list* list = get_all_available_rootstrap_ids(); + string_list* id = list; + + /* + SBI_PRINTF(1, "\nAvailable Rootstrap List\n"); + SBI_PRINTF(1, "------------------------\n"); + */ + while ( id != NULL ) + { + SBI_PRINTF(1, "%s\n", id->str ); + id=id->next; + } + + /* remove allocated string */ + if ( list != NULL ) remove_string_list( list ); +} + +void display_rootstrap_info( char* rootstrap_id ) +{ + if(is_rootstrap_available(rootstrap_id)) + { + char* name = get_rootstrap_name( rootstrap_id ) ; + char* version = get_rootstrap_version( rootstrap_id ) ; + char* architecture = get_rootstrap_architecture( rootstrap_id ) ; + char* path = tag_checker( get_rootstrap_path( rootstrap_id ) ); + char* toolchain_type = get_rootstrap_support_toolchain_type( rootstrap_id ) ; + string_list* key_origin; + string_list* key; + char* value; + + SBI_PRINTF(1, "NAME=%s\n", name); + SBI_PRINTF(1, "VERSION=%s\n", version); + SBI_PRINTF(1, "ARCHITECTURE=%s\n", architecture ); + SBI_PRINTF(1, "SYSROOT_PATH=%s\n", path ); + SBI_PRINTF(1, "SUPPORT_TOOLCHAIN_TYPE=%s\n", toolchain_type ); + + /* other properties */ + key_origin = get_rootstrap_property_list( rootstrap_id ); + key = key_origin; + for( ; key; key = key->next ) + { + value = tag_checker( get_rootstrap_property_value( rootstrap_id, key->str) ); + SBI_PRINTF(1, "%s=%s\n", key->str, value); + free(value); + } + remove_string_list(key_origin); + + free( name ); + free( version ); + free( architecture ); + free( path ); + free( toolchain_type ); + } + else + { + SBI_PRINTF(1, "%s rootstrap name is not available",rootstrap_id); + } +} diff --git a/src/rootstrap_mgt.h b/src/rootstrap_mgt.h new file mode 100644 index 0000000..4dab511 --- /dev/null +++ b/src/rootstrap_mgt.h @@ -0,0 +1,53 @@ +/* + * rootstrap_mgt.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#ifndef _SBI_ROOT_H +#define _SBI_ROOT_H + +#include "sbi_config.h" +#include "sbi_types.h" + +/* init fini */ +void initialize_rootstrap_mgt( ); +void finalize_rootstrap_mgt( ); + +/* list up all target */ +string_list* get_all_available_rootstrap_ids( ); +string_list* get_all_available_rootstrap_names( ); + +/* rootstrap */ +char* get_rootstrap_name( char* rootstrap_id ); +char* get_rootstrap_version( char* rootstrap_id ); +char* get_rootstrap_architecture( char* rootstrap_id ); +char* get_rootstrap_support_toolchain_type( char* rootstrap_id ); +char* get_rootstrap_path( char* rootstrap_id ); +string_list* get_rootstrap_property_list( char* rootstrap_id ); +char* get_rootstrap_property_value( char* rootstrap_id, char* key ); +int is_rootstrap_available( char* rootstrap_id ); +void display_rootstrap_list(); +void display_rootstrap_info( char* rootstrap_id ); +#endif diff --git a/src/sbi.c b/src/sbi.c new file mode 100644 index 0000000..0ba6dfe --- /dev/null +++ b/src/sbi.c @@ -0,0 +1,83 @@ +/* + * sbi.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include "sbi_config.h" +#include "sbi_util.h" +#include "rootstrap_mgt.h" +#include "plugin_mgt.h" +#include "cmdline_interpreter.h" + + +static int initialize_sbi(const char*); +static void finalize_sbi(void); + + +int main(int argc, char* argv[]) +{ + int ret = 0; /* return value */ + + /* initialize SBI. If failed, return -1 */ + if ( initialize_sbi(argv[0]) != 0 ) + exit(-1); + + /* interpret command line input */ + ret = interpret_command_line( argc , argv ); + + /* finalize SBI */ + finalize_sbi(); + + /* if interpreting failed, return -1 */ + if (ret != 0) + exit(-1); + + exit(0); + + return ret; +} + + +/* initialize SBI */ +static int initialize_sbi(const char* exec_path) +{ + /* sbi configuration*/ + initialize_sbi_configuration(exec_path); + + /* initialize plugins */ + initialize_plugins(get_plugin_base_dir()); + + return 0; +} + + +/* finish SBI */ +static void finalize_sbi() +{ + /* finalize plugins */ + finalize_plugins(); +} + diff --git a/src/sbi_build.c b/src/sbi_build.c new file mode 100644 index 0000000..0f4f7a3 --- /dev/null +++ b/src/sbi_build.c @@ -0,0 +1,374 @@ +/* + * sbi_build.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include +#include +#include +#include "sbi_config.h" +#include "sbi_types.h" +#include "sbi_util.h" + +#define BUILDDATA_FILE ".build_data" +#define USAGE_SBIBUILD "sbi_build [-config ]" +#define CONFIG_PREFIX "CB" +#define DEFAULT_MODE "buildpackage" +#define MAX_BUF_SIZE 20000 + +char* get_default_configuration(FILE *fin); +int ready_configuration(FILE* fin, char* selected_config, string_list** exec_list, char* mode); +void make_directories(char* pdir_start); +void make_dir(char* path); +string_list* create_makefile(FILE *fin, char* config, char* config_dir, char* mode); +void execute_command(string_list* exec, char* config_dir); +void print_sbibuild_usage(); +void print_sbibuild_error(char* msg); + +int main(int argc, char* argv[]) +{ + FILE *fin; + + char config[MAX_NAME] = {0,}; + char mode[MAX_NAME] = {0,}; + char *pconfig; + + int use_default_configuration = 0; + int available_config = 0; + int arg_count = 1; + + string_list *exec_list; + + /* initialize configuration */ + initialize_sbi_configuration(argv[0]); + + /* check arguments */ + while (arg_count <= argc) { + if (strncmp(argv[arg_count - 1], "-config", 7) == 0 && strlen(argv[arg_count - 1]) == 7) { + if (arg_count + 1 <= argc) { + strcat(config, argv[arg_count]); + arg_count = arg_count + 2; + } else { + print_sbibuild_usage(); + return -1; + } + } else if (strncmp(argv[arg_count -1], "-mode", 5) == 0 && strlen(argv[arg_count - 1]) == 5) { + if (arg_count + 1 <= argc) { + strcat(mode, argv[arg_count]); + arg_count = arg_count + 2; + } else { + print_sbibuild_usage(); + return -1; + } + } else { + arg_count++; + } + } + + if (!strcmp(config, "")) { + use_default_configuration = 1; + } + + + /* open and read ".build_data" file */ + fin = fopen(BUILDDATA_FILE, "r"); + + if (fin == NULL) { + print_sbibuild_error("There is no \".build_data\" file"); + return -1; + } + + /* if useDefault is set, the first configuration is default configuration */ + if (use_default_configuration) { + pconfig = get_default_configuration(fin); + strncat(config, pconfig, strlen(pconfig)); + fclose(fin); + fin = fopen(BUILDDATA_FILE, "r"); + } + + if (!strcmp(mode, "")) { + strcat(mode, DEFAULT_MODE); + } + + printf("[info] config = %s\n", config); + printf("[info] mode = %s\n", mode); + + if (!strcmp(config, "") && use_default_configuration) { + print_sbibuild_error("Default configuration does not exist"); + return -1; + } + + /* ready to build configuration */ + available_config = ready_configuration(fin, config, &exec_list, mode); + + /* close ".build_data" file */ + fclose(fin); + + if (!available_config) { + print_sbibuild_error("The configuration does not exist"); + return -1; + } + + /* execute commands */ + execute_command(exec_list, config); + + return 0; +} + +/* ready to build configuration (make configuration directory and create makefile) */ +int ready_configuration(FILE* fin, char* config, string_list** exec_list, char* mode) +{ + char buf[MAX_LINE_LENGTH] = {0,}; + char config_path[MAX_NAME] = {0,}; + char selected_config[MAX_NAME] = {0,}; + int available_config = 0; + + sprintf(selected_config, "[%s]\n", config); + + while (fgets(buf, sizeof(buf), fin) != NULL) { + if (!strcmp(buf, selected_config)) { + available_config = 1; + sprintf(config_path, "%s_%s", CONFIG_PREFIX, config); + if (is_directory(config_path)) { + remove_directory(config_path); + } + make_dir(config_path); + + /* create_makefile() function returns execution command list */ + *exec_list = create_makefile(fin, config, config_path, mode); + } + } + + return available_config; +} + +/* execute commands */ +void execute_command(string_list* exec, char* config) +{ + char cmd[MAX_CMD_LENGTH] = {0,}; + char sbi_path[MAX_FILE_PATH] = {0,}; + char config_absolute_path[MAX_FILE_PATH] = {0,}; + char config_path[MAX_NAME] = {0,}; + char current_path[MAX_FILE_PATH] = {0,}; + char *pstr; + + sprintf(sbi_path, "%s/bin/sbi", get_install_dir()); + sprintf(config_path, "%s_%s", CONFIG_PREFIX, config); + sprintf(current_path, "%s", get_current_path()); + sprintf(config_absolute_path, "%s/%s", current_path, config_path); + +#ifdef WIN32 + pstr = &config_absolute_path[0]; + while (*pstr != '\0') { + if(*pstr == '\\') { + *pstr = '/'; + } + pstr++; + } +#endif + + for ( ; exec != NULL ; exec = exec->next ) { + memset(cmd, 0, MAX_CMD_LENGTH); + pstr = (char*)replaceStr(exec->str, "$(SBI_PATH)", sbi_path); + pstr = (char*)replaceStr(pstr, "$(CONFIG_PATH)", config_path); + SBI_PRINTF( 2, "CMD : %s\n", pstr ); + int ret = system(pstr); + SBI_PRINTF( 2, "return : %d\n", ret ); + free(pstr); + } +} + +/* get default configuration name from ".build_data" file */ +char* get_default_configuration(FILE *fin) +{ + char config[MAX_NAME] = {0,}; + char buf[MAX_LINE_LENGTH] = {0,}; + char *pStr; + int len = 0; + + while (fgets(buf, sizeof(buf), fin) != NULL) { + if (buf[0] == '[') { + pStr = strstr(buf, "]\n"); + if (pStr != NULL) { + len = pStr-&buf[1]; + strncat(config, &buf[1], len); + break; + } + } + } + + return strdup(config); +} + +/* create "makefile" file */ +string_list* create_makefile(FILE *fin, char* config, char* config_path, char* mode) +{ + int file_content = 0; + int execution_command = 0; + int len = 0; + + char buf[MAX_BUF_SIZE] = {0,}; + char relative_file_path[MAX_FILE_PATH] = {0,}; + char absolute_file_path[MAX_FILE_PATH] = {0,}; + char project_path[MAX_FILE_PATH] = {0,}; + char makefile_variable_project_path[MAX_FILE_PATH] = {0,}; + char makefile_variable_rootstrap_path[MAX_FILE_PATH] = {0,}; + char makefile_variable_config_path[MAX_FILE_PATH] = {0,}; + char end_config[MAX_NAME] = {0,}; + char end_tag[MAX_NAME] = {0,}; + char start_execute_str[MAX_NAME] = {0,}; + + char *pfile_start, *ptag_end, *pexecute_start; + + string_list* exec_list = NULL; + FILE *fout; + + sprintf(project_path, "%s", get_current_path()); + sprintf(makefile_variable_rootstrap_path, "ROOTSTRAP_BASE_PATH := %s/rootstraps\n", get_install_dir()); + sprintf(makefile_variable_project_path, "PROJECT_PATH := %s\n", project_path); + sprintf(makefile_variable_config_path, "CONFIG_PATH := %s/%s\n", project_path, config_path); + sprintf(end_config, "[/%s]\n", config); + sprintf(start_execute_str, "", mode); + + while ((fgets(buf, sizeof(buf), fin) != NULL) && strcmp(buf, end_config)) { + + pfile_start = NULL; + ptag_end = NULL; + pexecute_start = NULL; + + pfile_start = strstr(buf, "" tag */ + if (pfile_start != NULL) { + fout = NULL; + len = strlen(buf) - 9; + + memset(relative_file_path, 0, MAX_FILE_PATH); + memset(absolute_file_path, 0, MAX_FILE_PATH); + memset(end_tag, 0, MAX_NAME); + + strncpy(relative_file_path, &pfile_start[7], len); + relative_file_path[len] = '\0'; + sprintf(absolute_file_path, "%s/%s", config_path, relative_file_path); + + chdir(config_path); + /* make directories */ + make_directories(relative_file_path); + chdir(project_path); + + fout = fopen(absolute_file_path, "w"); + /* if file is "makefile", write additional variables */ + if (!strcmp(relative_file_path, "makefile")) { + fputs(makefile_variable_rootstrap_path, fout); + fputs(makefile_variable_project_path, fout); + fputs(makefile_variable_config_path, fout); + } + + sprintf(end_tag, "", relative_file_path); + file_content = 1; + + /* in case of "" tag */ + } else if (pexecute_start != NULL) { + memset(end_tag, 0, MAX_NAME); + execution_command = 1; + sprintf(end_tag, "", mode); + + /* in case of "" or "" tag */ + } else if (ptag_end != NULL) { + if (file_content) { + file_content = 0; + fclose(fout); + } else if (execution_command) { + execution_command = 0; + } + + /* in case of file content */ + } else if (file_content) { + fputs(buf, fout); + + /* in case of execution command */ + } else if (execution_command) { + if (exec_list != NULL) { + append_string_to_list(exec_list, buf); + } else { + exec_list = create_string_list(buf); + } + } + memset(buf, 0, sizeof(buf)); + } + + return exec_list; +} + +/* create directory structure */ +void make_directories(char* pdir_start) +{ + char* pdir_end; + char dir[MAX_FILE_PATH] = {0,}; + + while ((pdir_end = strstr(pdir_start, "/")) != NULL) { + memset(dir, 0, MAX_FILE_PATH); + strncpy(dir, pdir_start, pdir_end - pdir_start); + make_dir(dir); + chdir(dir); + if (pdir_end + 1 != NULL) { + pdir_start = pdir_end + 1; + } else { + break; + } + } +} + +/* create directory */ +void make_dir(char* path) +{ + if (path == NULL) { + return; + } + +#ifdef WIN32 + mkdir(path); +#else + mkdir(path, S_IRWXU | S_IRWXO | S_IRWXG); +#endif + +} + +/* print usage of sbi_build command */ +void print_sbibuild_usage() +{ + SBI_PRINTF(1, "Usage: %s\n", USAGE_SBIBUILD); +} + +/* print error message of sbi_build command */ +void print_sbibuild_error(char* msg) +{ + SBI_PRINTF(1, "Error: %s\n", msg); +} diff --git a/src/sbi_config.c b/src/sbi_config.c new file mode 100644 index 0000000..8ed5f9a --- /dev/null +++ b/src/sbi_config.c @@ -0,0 +1,476 @@ +/* + * sbi_config.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +#include +#include +#include +#include +#include + +#include "sbi_config.h" +#include "config_common.h" +#include "sbi_util.h" +#include "sbi_error.h" + + +#ifdef WIN32 +char* SBI = "sbi.exe"; +#else +char* SBI = "sbi"; +#endif +typedef struct _sbi_cfg +{ + char default_target[MAX_NAME + 1]; + int print_level; +} SBI_CFG; + +static SBI_CFG sbi_cfg; +static char* get_sbi_config_path(void); +static int read_sbi_config(void); + +static char* global_target_id = NULL; +static char* global_toolchain_id = NULL; +static char* global_rootstrap_id = NULL; + +char* get_install_bin_dir() +{ + char* path = getenv("PATH"); + char vpath[MAX_FILE_PATH]; + char* tok = NULL; + char realpath[MAX_FILE_PATH]; + + if (path == NULL) + { + return NULL; + } + strcpy(vpath, path); + tok = strtok(vpath, ":"); + sprintf(realpath, "%s/%s", tok, SBI); + if (does_file_exist(realpath)) + { + return tok; + } + + while ( (tok = strtok(NULL, ":") ) != NULL ) + { + sprintf(realpath, "%s/%s", tok, SBI); + if (does_file_exist(realpath)) + { + return tok; + } + } + return NULL; +} + +char* dirname(char** name) +{ + char* tok1; + char* tok2; + + tok1 = strrchr(*name, '/'); + tok2 = strrchr(*name, '\\'); + if (tok1 == NULL && tok2 == NULL) + { + return NULL; + } + + if (tok1 > tok2) + { + *tok1 = '\0'; + } + else + { + *tok2 = '\0'; + } + return *name; +} + +/* set install base dir to SBI_INSTALL path */ +static void set_install_base_dir_from_execute_path(const char* execute_path) +{ + char cwd[255]; + char path[255]; + char* basename; + char bin_dir[255]; + basename = path; + strcpy(path, execute_path); + + if (dirname(&basename) != NULL) + { + strcpy(bin_dir, basename); + } + else + { + if (does_file_exist(SBI)) + { + strcpy(bin_dir, "./"); + } + else + { + strcpy(bin_dir, get_install_bin_dir()); + } + } + + sprintf(path, "%s/..", bin_dir); + getcwd(cwd,255); + chdir(path); + getcwd(path,255); + set_install_base_dir(path); + chdir(cwd); + +} + +void set_install_base_dir(char* absolue_path) +{ + strcpy(sbi_install_base_dir, absolue_path); +} + +char* get_install_dir(void) +{ + return sbi_install_base_dir; +} + +char* get_target_base_dir(void) +{ + static char sbi_target_base_dir[MAX_FILE_PATH + 1]; + + sprintf(sbi_target_base_dir, "%s/targets", sbi_install_base_dir); + + return sbi_target_base_dir; +} + +char* get_toolchain_base_dir(void) +{ + static char sbi_toolchain_base_dir[MAX_FILE_PATH + 1]; + + sprintf(sbi_toolchain_base_dir, "%s/toolchains", sbi_install_base_dir); + + return sbi_toolchain_base_dir; +} + +char* get_rootstrap_base_dir(void) +{ + static char sbi_rootstrap_base_dir[MAX_FILE_PATH + 1]; + + sprintf(sbi_rootstrap_base_dir, "%s/rootstraps", sbi_install_base_dir); + + return sbi_rootstrap_base_dir; +} + +char* get_plugin_base_dir(void) +{ + static char sbi_plugin_base_dir[MAX_FILE_PATH + 1]; + +#ifdef WIN32 + sprintf(sbi_plugin_base_dir, "%s\\plugins", sbi_install_base_dir); +#else + sprintf(sbi_plugin_base_dir, "%s/plugins", sbi_install_base_dir); +#endif + return sbi_plugin_base_dir; +} + + +char* get_script_file(void) +{ + char filename[100] = {0,}; + int ran = 0; + static char sbi_script_file[MAX_FILE_PATH + 1]; + srand(time(NULL)); + ran = rand(); + sprintf(filename, "%d", ran); +#ifdef WIN32 + sprintf(sbi_script_file, "%s\\%s",sbi_install_base_dir, filename); +#else + ///sprintf(sbi_script_file, "%s/.script",sbi_install_base_dir); + sprintf(sbi_script_file, "%s/%s",sbi_install_base_dir, filename); +#endif + return sbi_script_file; +} + +/* default target */ +int set_default_target(char* target_id) +{ + strcpy(sbi_cfg.default_target, target_id); + + /* write config */ + initialize_config(); + + /* set */ + set_key_value_string("SBI_DEFAULT_TARGET", target_id); + + /* write */ + write_config_file(get_sbi_config_path()); + + return 0; +} + +char* get_default_target(void) +{ + if (read_sbi_config() == -1) + strcpy(sbi_cfg.default_target, ""); + + return sbi_cfg.default_target; +} + +int get_print_level(void) +{ + if (read_sbi_config() == -1) + { + /* if can't read config file then print_level's default value is 1 */ + sbi_cfg.print_level = 1; + } + + return sbi_cfg.print_level; +} + +int reset_default_target(void) +{ + strcpy(sbi_cfg.default_target, ""); + + /* write config */ + initialize_config(); + + /* set default target */ + set_key_value_string("SBI_DEFAULT_TARGET", ""); + + /* set default print level */ + set_key_value_string("SBI_PRINT_LEVEL ", "1"); + + /* write */ + write_config_file(get_sbi_config_path()); + + return 0; +} + +int is_default_target(char* target_id) +{ + if (strcmp(target_id, get_default_target()) == 0) + return 1; + else + return 0; +} + +int does_default_target_exist(void) +{ + if (strlen(get_default_target()) == 0) + return 0; + else + return 1; +} + +static int read_sbi_config(void) +{ + char* path; + char *value; + static int is_loaded = 0; + + /* if already loaded, skip */ + if (is_loaded) + { + return 0; + } + else + { + is_loaded = 1; + } + + /* get tool config path */ + path = get_sbi_config_path(); + + /* read config file */ + if (read_config_file(path) == -1) + { + sbi_error(99, "can't read sbi config file", 0); + return -1; + } + + /* SBI_DEFAULT_TARGET */ + value = get_key_value_string("SBI_DEFAULT_TARGET"); + if (value != NULL) + { + strncpy(sbi_cfg.default_target, trim(value), MAX_NAME); + } + else + { + sbi_error(99, "can't read sbi config default target", 0); + } + + /* SBI_PRINT_LEVEL */ + value = get_key_value_string("SBI_PRINT_LEVEL"); + if (value != NULL) + { + /* get print level from sbi.config file */ + char print_level[MAX_NAME]; + strncpy(print_level, trim(value), MAX_NAME); + sbi_cfg.print_level = atoi(print_level); + } + else + { + /* default print level is 1 */ + sbi_cfg.print_level = 1; + } + + return 0; +} + +static char* get_sbi_config_path(void) +{ + static char sbi_config_path[MAX_FILE_PATH + 1]; + + sprintf(sbi_config_path, "%s/sbi.cfg", get_install_dir()); + + return sbi_config_path; +} + +void initialize_sbi_configuration(const char*exec_path) +{ + /* find/set base directory from execute path */ + set_install_base_dir_from_execute_path(exec_path); + + /* check sbi.cfg file exist , if not make default sbi.cfg file */ + if (!does_file_exist(get_sbi_config_path())) + { + reset_default_target(); + } +} + + +void set_target_id(char* id) +{ + global_target_id = strdup(id); +} + +void set_rootstrap_id(char* id) +{ + global_rootstrap_id = strdup(id); +} + +void set_toolchain_id(char* id) +{ + global_toolchain_id = strdup(id); +} + +void free_toolchain_id(void) +{ + if(global_toolchain_id != NULL) + { + free(global_toolchain_id); + } +} + +void free_rootstrap_id(void) +{ + if(global_rootstrap_id != NULL) + { + free(global_rootstrap_id); + } +} + +void free_target_id(void) +{ + if(global_target_id != NULL) + { + free(global_target_id); + } +} + +char* tag_checker(char* tag) +{ + char* ret; + char* points; + char* pointe; + char* value ; + char temp[MAX_CMD_LENGTH +1]; + + ret = tag; + if(ret != NULL) + { + points = ret; + value = NULL; + while( (points = strchr(points,'#')) != NULL) + { + if(points[1] == '{' && (pointe = strchr(points, '}')) != NULL) + { + strncpy(temp,points + 2,pointe-points-2); + temp[pointe-points-2] = '\0'; + if(strcmp(temp,"SBI_HOME")==0) + { + value = get_unix_path( get_install_dir() ); + if(value == NULL || strcmp(value,"")==0) + { + points = pointe; + continue; + } + } + else if(strcmp(temp,"ROOTSTRAP")==0) + { + value = global_rootstrap_id; + if(value == NULL || strcmp(value,"")==0) + { + points = pointe; + continue; + } + } + else if(strcmp(temp,"TOOLCHAIN")==0) + { + value = global_toolchain_id; + if(value == NULL || strcmp(value,"")==0) + { + points = pointe; + continue; + } + } + else if(strcmp(temp,"TARGET")==0) + { + value = global_target_id; + if(value == NULL || strcmp(value,"")==0) + { + points = pointe; + continue; + } + } + else + { + points = pointe; + continue; + } + + strncpy(temp,ret,points-ret); + strncpy(temp + (points-ret),value,strlen(value)); + strncpy(temp + (points-ret) + strlen(value),pointe +1,strlen(pointe+1)); + (temp + (points-ret) + strlen(value))[strlen(pointe+1)] = '\0'; + free(ret); + ret = strdup(temp); + points = ret; + value = NULL; + } + } + } + return ret; +} + diff --git a/src/sbi_config.h b/src/sbi_config.h new file mode 100644 index 0000000..ca0a824 --- /dev/null +++ b/src/sbi_config.h @@ -0,0 +1,77 @@ +/* + * sbi_config.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#ifndef _SBI_CONFIG_H +#define _SBI_CONFIG_H + +#define MAX_NAME 512 +#define MAX_VER_LENGTH 512 +#define MAX_FILE_PATH 1024 +#define MAX_REPOSITORY_LENGTH 512 +#define MAX_DATE_LENGTH 512 +#define MAX_PLUGIN_CMD_LENGTH 1024 +#define MAX_LINE_LENGTH 1024 +#define MAX_CMD_LENGTH 2048 +#define MAX_KEY_LENGTH 512 +#define MAX_VALUE_LENGTH 1024 + +typedef enum _EMULATE_MODE +{ + EMUL_BUILD = 0, EMUL_EMULATE = 1 +} EMUL_MODE; + +char sbi_install_base_dir[MAX_FILE_PATH]; +void set_install_base_dir(char* absolue_path); + +/* directory */ +char* get_install_dir(void); +char* get_target_base_dir(void); +char* get_toolchain_base_dir(void); +char* get_rootstrap_base_dir(void); +char* get_plugin_base_dir(void); + +char* get_script_file(void); + +/* default target */ +int set_default_target(char* target_name); +char* get_default_target(void); +int get_print_level(void); +int reset_default_target(void); +int is_default_target(char* target_name); +int does_default_target_exist(void); +void initialize_sbi_configuration(const char* exec_path); + +void set_target_id(char* id); +void set_rootstrap_id(char* id); +void set_toolchain_id(char* id); +void free_toolchain_id(void); +void free_rootstrap_id(void); +void free_target_id(void); + +char* tag_checker(char* tag); + +#endif diff --git a/src/sbi_error.c b/src/sbi_error.c new file mode 100644 index 0000000..3c1de5e --- /dev/null +++ b/src/sbi_error.c @@ -0,0 +1,310 @@ +/* + * sbi_error.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include +#include "sbi_error.h" +#include "target_mgt.h" +#include "toolchain_mgt.h" +#include "rootstrap_mgt.h" +#include "sbi_util.h" + +void sbi_error(int no, char* arg, int quit) +{ + + USAGE_TYPE type; + + switch (no) + { + case 1: + SBI_PRINTF(1, "ERR001: Target already exists\n"); + if (quit) + { + exit(1); + } + break; + case 2: + + if (strcmp(arg, "all") == 0) + { + type = USAGE_ALL; + } + else if (strcmp(arg, "create") == 0) + { + type = USAGE_CREATE; + } + else if (strcmp(arg, "remove") == 0) + { + type = USAGE_REMOVE; + } + else if (strcmp(arg, "list") == 0) + { + type = USAGE_LIST; + } + else if (strcmp(arg, "select") == 0) + { + type = USAGE_SELECT; + } + else if (strcmp(arg, "show") == 0) + { + type = USAGE_SHOW; + } + else if (strcmp(arg, "action") == 0) + { + type = USAGE_ACTION; + } + else if (strcmp(arg, "query") == 0) + { + type = USAGE_QUERY; + } + else + { + SBI_PRINTF(1, "INTERNAL ERROR.\n"); + exit(1); + } + + SBI_PRINTF(1, "ERR002: Invalid command options. See next usage.\n"); + print_usage(type); + if (quit) + { + exit(1); + } + break; + case 3: + SBI_PRINTF(1, + "ERR003: The target rootstrap \"%s\" does not exist. See following avaiable target rootstraps.\n", arg); + display_rootstrap_list(); + + if (quit) + { + exit(1); + } + break; + case 4: + SBI_PRINTF(1, + "ERR004: The toolchain \"%s\" does not exist. See next avaiable toolchain names.\n", arg); + display_toolchain_list(); + if (quit) + exit(1); + break; + case 5: + SBI_PRINTF(1, + "ERR005: Invalid target rootstrap configuration. Upgrade is needed.\n"); + if (quit) + { + exit(1); + } + break; + case 6: + SBI_PRINTF(1, "ERR006: Invalid toolchain configuration. Upgrade is needed.\n"); + if (quit) + { + exit(1); + } + break; + case 7: + SBI_PRINTF(1, + "ERR007: The target \"%s\" does not exist. See next avaiable target names.\n", arg); + display_target_list(); + if (quit) + { + exit(1); + } + break; + case 8: + SBI_PRINTF(1, "ERR008: No default target is selected.\n"); + if (quit) + { + exit(1); + } + break; + case 9: + SBI_PRINTF(1, "ERR009: Invalid execution path used.\n"); + if (quit) + { + exit(1); + } + break; + case 10: + SBI_PRINTF(1, "ERR010: Invalild project path.\n"); + if (quit) + { + exit(1); + } + break; + case 11: + SBI_PRINTF(1, "ERR011: Project must be configured first.\n"); + if (quit) + { + exit(1); + } + break; + case 12: + SBI_PRINTF(1, "ERR012: Package does not exist in the target.\n"); + if (quit) + { + exit(1); + } + break; + case 13: + SBI_PRINTF(1, "ERR013: Excutable files does not exist.\n"); + if (quit) + { + exit(1); + } + break; + case 14: + SBI_PRINTF(1, "ERR014: Invalid mode is used. Use \"emulate\" or \"build\"\n"); + if (quit) + { + exit(1); + } + break; + case 15: + SBI_PRINTF(1, "ERR015: Tool plugin type can't support Rootstrap plugin type\n"); + if (quit) + { + exit(1); + } + break; + case 16: + SBI_PRINTF(1, + "ERR016: Target name must start with alphabet and name only include (alphabet, number, ., _, - )\n"); + if (quit) + { + exit(1); + } + break; + case 17: + SBI_PRINTF(1, "ERR017: Target \"%s\" generate is failed\n", arg); + if (quit) + { + exit(1); + } + break; + case 18: + SBI_PRINTF(1, "ERR018: Project name does not exist in .project file\n"); + if (quit) + { + exit(1); + } + break; + case 19: + SBI_PRINTF(1, "ERR019: %s file does not exist in parent director\n", arg); + if (quit) + { + exit(1); + } + break; + case 20: + SBI_PRINTF(1, "ERR020: %s file can not open\n", arg); + if (quit) + { + exit(1); + } + break; + case 21: + SBI_PRINTF(1, "ERR021: Plugin execution failed\n"); + if (quit) + { + exit(1); + } + break; + case 22: + SBI_PRINTF(1, "ERR022: %s Directory does not exist\n", arg); + if (quit) + { + exit(1); + } + break; + case 23: + SBI_PRINTF(1, "ERR023: %s file does not exist\n", arg); + if (quit) + { + exit(1); + } + break; + case 24: + SBI_PRINTF(1, "ERR024 : plugin \"%s\" is not exist\n", arg); + if (quit) + { + exit(1); + } + break; + case 25: + SBI_PRINTF(1, "WARNING : arguments start with '-' character. (%s)\n", arg); + if (quit) + { + exit(1); + } + break; + case 26: + SBI_PRINTF(1, "WARNING : \"%s\" option does not have value.\n", arg); + if (quit) + { + exit(1); + } + break; + case 27: + SBI_PRINTF(1, "WARNING : this action needs \"%s\" argument.\n", arg); + if (quit) + { + exit(1); + } + break; + case 28: + SBI_PRINTF(1, "WARNING : \"%s\" input type is not supported.\n", arg); + if (quit) + { + exit(1); + } + break; + case 29: + SBI_PRINTF(1, "ERR029 : \"%s\" action is not defined.\n", arg); + if (quit) + { + exit(1); + } + break; + case 30: + SBI_PRINTF(1, "WARNING : there is an action tag which does not have \"name\" attribute.\n"); + if (quit) + { + exit(1); + } + break; + default: + SBI_PRINTF(1, "INTERNAL ERROR %s\n", arg); + if (quit) + { + exit(1); + } + break; + } + +} diff --git a/src/sbi_error.h b/src/sbi_error.h new file mode 100644 index 0000000..874dba1 --- /dev/null +++ b/src/sbi_error.h @@ -0,0 +1,28 @@ +/* + * sbi_error.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +void sbi_error(int no, char* arg, int exit); diff --git a/src/sbi_types.c b/src/sbi_types.c new file mode 100644 index 0000000..7ab66c6 --- /dev/null +++ b/src/sbi_types.c @@ -0,0 +1,130 @@ +/* + * sbi_types.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include +#include "sbi_types.h" + +string_list* create_string_list( const char* str ) +{ + string_list* new_list = malloc( sizeof( string_list )); + if (str == NULL) { + new_list->str = NULL; + new_list->next = NULL; + } else { + new_list->str = strdup( str ); + new_list->next = NULL; + } + + return new_list; +} + + +string_list* append_string_to_list( string_list* old_list, const char* str ) +{ + string_list* list; + assert ( old_list != NULL ); + + list = old_list; + while( list->next != NULL ) + list = list->next; + + list->next = create_string_list( str ); + + return old_list; +} + + +void remove_string_list( string_list * old_list ) +{ + string_list* list; + assert ( old_list != NULL ); + + list = old_list; + while( list->next != NULL ) + { + string_list *prev = list; + list = list->next; + + free( prev->str ); + free( prev ); + } + + free( list->str ); + free( list ); +} + + + +string_list* append_string_list_to_list(string_list* old_list, string_list* new_list ) +{ + string* old_entry; + string* new_entry; + + assert ( old_list != NULL ); + + if ( new_list == NULL ) + return old_list; + + for( new_entry = new_list; new_entry; new_entry = new_entry->next ) + { + old_entry = old_list; + while( old_entry->next != NULL ) + { + if ( strcmp( old_entry->str, new_entry->str ) == 0 ) + break; + + old_entry = old_entry->next; + } + + /* already exist, skip */ + if ( old_entry->next != NULL) + continue; + + old_entry->next = create_string_list( new_entry->str ); + } + + return old_list; +} + + +string_list* clone_string_list( string_list* list ) +{ + string_list* new_list = NULL; + string* src; + + for( src = list; src; src = src->next ) + { + if ( new_list != NULL ) + append_string_to_list( new_list, src->str ); + else + new_list = create_string( src->str ); + } + + return new_list; +} diff --git a/src/sbi_types.h b/src/sbi_types.h new file mode 100644 index 0000000..046c37c --- /dev/null +++ b/src/sbi_types.h @@ -0,0 +1,49 @@ +/* + * sbi_types.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#ifndef SBI_TYPES_H_ +#define SBI_TYPES_H_ + +/* for return */ +typedef struct _string_list { + char* str; + struct _string_list *next; +} string_list; + +string_list* create_string_list( const char* ); +string_list* append_string_to_list( string_list*, const char* ); +void remove_string_list( string_list * ); + +typedef string_list string; +#define create_string create_string_list +#define remove_string remove_string_list + +/* list manipulation */ +string_list* append_string_list_to_list(string_list* old_list, string_list* new_list ); +string_list* clone_string_list( string_list* new_list ); + +#endif /* SBI_TYPES_H_ */ diff --git a/src/sbi_util.c b/src/sbi_util.c new file mode 100644 index 0000000..0ad5f96 --- /dev/null +++ b/src/sbi_util.c @@ -0,0 +1,424 @@ +/* + * sbi_util.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "sbi_util.h" +#include "sbi_config.h" +#include "sbi_error.h" + + +char current_path[MAX_FILE_PATH]; +char* create_usage = + "sbi create -root -tool "; +char* remove_usage = + "sbi remove {all|}"; +char* select_usage = + "sbi select "; +char* list_usage = + "sbi list [target|tool|root|*all]"; +char* show_usage = + "sbi show [|target |tool |root ]"; +char* action_usage = + "sbi action -- "; +char* query_usage = + "sbi query "; + +void print_usage(USAGE_TYPE usage_type) +{ + SBI_PRINTF(1, "usage\n"); + + switch (usage_type) + { + case USAGE_ALL: + SBI_PRINTF(1, "%s\n", create_usage); + SBI_PRINTF(1, "%s\n", remove_usage); + SBI_PRINTF(1, "%s\n", select_usage); + SBI_PRINTF(1, "%s\n", list_usage); + SBI_PRINTF(1, "%s\n", show_usage); + SBI_PRINTF(1, "%s\n", action_usage); + break; + case USAGE_CREATE: + SBI_PRINTF(1, "%s\n", create_usage); + break; + case USAGE_REMOVE: + SBI_PRINTF(1, "%s\n", remove_usage); + break; + case USAGE_SELECT: + SBI_PRINTF(1, "%s\n", select_usage); + break; + case USAGE_LIST: + SBI_PRINTF(1, "%s\n", list_usage); + break; + case USAGE_SHOW: + SBI_PRINTF(1, "%s\n", show_usage); + break; + case USAGE_ACTION: + SBI_PRINTF(1, "%s\n", action_usage); + break; + case USAGE_QUERY: + SBI_PRINTF(1, "%s\n", query_usage); + break; + default: + sbi_error(99, "unknown usage", 1); + break; + } + + exit(1); +} + +char* get_current_path() +{ + return getcwd(current_path, MAX_FILE_PATH); +} + +char* trim(char* str) +{ + char* str_begin = str; + int i; + for (i = strlen(str); i > 0; i--) + { + if (str[i] != ' ' && str[i] != '\t' && str[i] != '\n' && str[i] != '\0') + { + str[i + 1] = '\0'; + break; + } + } + + if (str[i] == ' ' || str[i] == '\t' || str[i] == '\n') + { + str[i] = '\0'; + } + + for (i = 0; i < strlen(str); i++) + { + if (str[i] != ' ' && str[i] != '\t') + { + str_begin = str + i; + break; + } + } + return str_begin; +} + +void remove_extension(char* file_name, char* file_name2) +{ + int i; + + sprintf(file_name2, "%s", file_name); + for (i = strlen(file_name2); i > 0; i--) + { + if (file_name2[i - 1] == '.') + { + file_name2[i - 1] = '\0'; + return; + } + } + + return; +} + +int does_file_exist(char* path) +{ + struct stat sb; + + if (stat(path, &sb) != 0) + { + return 0; + } + + return 1; +} + +int is_directory(char* path) +{ + struct stat fstat; + + stat(path, &fstat); +#ifdef WIN32 + if(S_ISDIR(fstat.st_mode) ) + { + return 1; + } +#else + if (S_ISDIR(fstat.st_mode) && !S_ISLNK(fstat.st_mode)) + { + return 1; + } +#endif + + return 0; +} + +void make_directory(char* path) +{ + char copy_path[MAX_FILE_PATH]; + char new_path[MAX_FILE_PATH]; + char* dir; + + strcpy(copy_path, path); + strcpy(new_path, ""); + dir = strtok(copy_path, "/"); + + while (dir) + { + sprintf(new_path, "%s/%s", new_path, dir); + + if (!does_file_exist(new_path)) + { +#ifdef WIN32 + mkdir( new_path ); +#else + mkdir(new_path, S_IRWXU); +#endif + } + + dir = strtok(NULL, "/"); + if (dir == NULL) + break; + } +} + +/* + static int remove_path( char* path ); + */ + +int remove_directory(char* path) +{ + char cmd[255]; + +#ifdef WIN32 + sprintf(cmd, "rmdir \"%s\" /s/q", path ); + SBI_PRINTF( 2, "CMD : %s\n", cmd ); + int ret = system(cmd); + SBI_PRINTF( 2, "return : %d\n", ret ); + return ret; +#else + sprintf(cmd, "rm -rf \"%s\"", path); + + SBI_PRINTF( 2, "CMD : %s\n", cmd ); + int ret = system(cmd); + SBI_PRINTF( 2, "return : %d\n", ret ); + + return ret; +#endif +} + +int remove_file(char* path) +{ + char cmd[255]; + +#ifdef WIN32 + sprintf(cmd, "del \"%s\" /f/q", path ); + SBI_PRINTF( 2, "CMD : %s\n", cmd ); + int ret = system(cmd); + SBI_PRINTF( 2, "return : %d\n", ret ); + return ret; +#else + sprintf(cmd, "rm -rf \"%s\"", path); + SBI_PRINTF( 2, "CMD : %s\n", cmd ); + int ret = system(cmd); + SBI_PRINTF( 2, "return : %d\n", ret ); + return ret; +#endif +} + +#if 0 +static int remove_path( char* path ) +{ + if( is_directory( path ) ) + { + DIR* dir = opendir(path); + struct dirent *entry; + + /* remove child */ + while( entry=readdir( dir ) ) + { + char new_path[MAX_FILE_PATH]; + + if( strcmp( entry->d_name, "." ) == 0 || + strcmp( entry->d_name, ".." ) == 0 ) + { + continue; + } + + sprintf(new_path,"%s/%s",path, entry->d_name ); + if ( remove_path( new_path ) != 0 ) + { + return -1; + } + } + + /* remove me */ + if( remove( path ) != 0 ) + { + return -1; + } + } + else + { + remove( path ); + } + + return 0; +} +#endif + +int is_full_path(char* path) +{ +#ifdef WIN32 + /* if path is full path then path is c: or d: ... then check second byte */ + if ( path[1] == ':' ) + { + return 1; + } + else + { + return 0; + } +#else + if (path[0] == '/') + { + return 1; + } + else + { + return 0; + } +#endif +} + +void get_tool_full_path(char* full_path, char* src_path) +{ + if (is_full_path(src_path)) + { + sprintf(full_path, "%s", src_path); + } + else + { + sprintf(full_path, "%s/%s", get_toolchain_base_dir(), src_path); + } +} + +int get_base_dir(char* path, char* base_dir) +{ + char* tok = NULL; + char buf[MAX_FILE_PATH]; + + strcpy(buf, path); + + tok = strrchr(buf, '/'); + if (tok != NULL) + { + *(tok) = '\0'; + } + + strcpy(base_dir, buf); + + return 0; +} + + +char* get_unix_path( char* absolue_path ) +{ + static char buf[ 1024 ]; + int i; + + strcpy( buf, absolue_path ); + + /* change "X:" -> "/X" for windows support*/ + if( buf[1] == ':' ) + { + buf[1]=buf[0]; + buf[0]='/'; + } + + /* change "\" -> "/" for windows support*/ + for( i=0; i < strlen( buf ); i++ ) + { + if ( buf[i] == '\\' ) + buf[i] = '/'; + } + + return buf; +} + +char* replaceStr(char* org, char* src, char* dst) +{ + char* pSearch = NULL; + char *pStartStr = org; + char *pEndStr = NULL; + char buf[1024] = {0,}; + char buf2[1024] = {0,}; + int dstlen = strlen(dst); + int srclen = strlen(src); + + strncpy(buf, pStartStr, sizeof(pStartStr)); + + pSearch = strstr(pStartStr, src); + + while (pSearch != NULL) { + + memset(buf, 0, sizeof(buf)); + + pEndStr = pSearch+srclen; + strncpy(buf, pStartStr, pSearch-pStartStr); + strncat(buf, dst, dstlen); + strncat(buf, pEndStr, strlen(pEndStr)); + + memset(buf2, 0, sizeof(buf2)); + strcpy(buf2, buf); + + pStartStr = buf2; + pSearch = strstr(pStartStr, src); + } + + return strdup(pStartStr); +} + +void SBI_PRINTF(int level, const char *fmt, ...) +{ + /* if config file's print level is bigger then level */ + /* print level + * 1 : SBI result message + * 2 : more information + */ + if( get_print_level() >= level ) + { + va_list arg; + va_start(arg, fmt); + vprintf(fmt, arg); + va_end(arg); + } +} diff --git a/src/sbi_util.h b/src/sbi_util.h new file mode 100644 index 0000000..a47812b --- /dev/null +++ b/src/sbi_util.h @@ -0,0 +1,62 @@ +/* + * sbi_util.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#ifndef _SBI_UTIL_H +#define _SBI_UTIL_H + +typedef enum _USAGE_TYPE +{ + USAGE_ALL = 0, + USAGE_CREATE = 1, + USAGE_REMOVE = 2, + USAGE_SELECT = 3, + USAGE_LIST = 4, + USAGE_SHOW = 5, + USAGE_ACTION = 6, + USAGE_QUERY = 7 +} USAGE_TYPE; + +void print_usage(USAGE_TYPE usage_type); + +char* get_current_path(); +char* trim(char* str); +void remove_extension(char* file_name, char* file_name2); + +/* directory/file */ +int does_file_exist(char* path); +int is_dir(char* path); +int is_directory(char* path); +void make_directory(char* path); +int remove_directory(char* path); +int remove_file(char* path); +int is_full_path(char* path); +int get_base_dir(char* path, char* base_dir); +char* get_unix_path( char* absolue_path ); +char* replaceStr(char* org, char* src, char* dst); +void SBI_PRINTF(int level, const char *fmt, ...); + +#endif diff --git a/src/sbi_xml.c b/src/sbi_xml.c new file mode 100644 index 0000000..6026d34 --- /dev/null +++ b/src/sbi_xml.c @@ -0,0 +1,259 @@ +/* + * sbi_xml.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "sbi_util.h" +#include "sbi_config.h" +#include "sbi_xml.h" + +#ifdef LIBXML_READER_ENABLED + +// internal function +static char* query_tag_loop(xmlNode* node, char* name, xmlChar * attr, + char* attr_value, xmlChar * find_attr); +static char* query_tag(xmlDoc* doc, char* name, char* attr, + char* attr_value, xmlChar * find_attr); + +int sbi_list_using_xml(int list_type) +{ + char plugin_base_dir[MAX_FILE_PATH + 1]; + char target_base_dir[MAX_FILE_PATH + 1]; + char xml_path[MAX_FILE_PATH + 1]; + struct dirent *entry; + DIR* dir; + int i; + int target_cnt = 0; + int toolchain_cnt = 0; + int rootstrap_cnt = 0; + int buildsystem_cnt = 0; + char* target_list[100]; + char* toolchain_list[100]; + char* rootstrap_list[100]; + char* buildsystem_list[100]; + + if (list_type == LIST_ALL || list_type == LIST_TARGET) + { + char* target_name; + sprintf( target_base_dir, "%s", get_target_base_dir()); + + if (!is_directory(target_base_dir)) + { + /* target base dir is not directory */ + return -1; + } + + dir = opendir(target_base_dir); + while ( (entry = readdir(dir)) != NULL ) + { + int d_name_size; + char* ext; + + d_name_size = strlen( entry->d_name ); + if ( strcmp( entry->d_name + ( d_name_size - 4 ), ".xml" ) != 0 ) + continue; + + target_name = malloc( 100 ); + strcpy(target_name, entry->d_name); + target_name[strlen(target_name) -4] = '\0'; + target_list[target_cnt++] = target_name; + } + } + + if (list_type != LIST_TARGET) + { + sprintf( plugin_base_dir, "%s", get_plugin_base_dir()); + + if (!is_directory(plugin_base_dir)) + { + /* plugin base dir is not directory */ + return -1; + } + + dir = opendir(plugin_base_dir); + while ( (entry = readdir(dir)) != NULL ) + { + int d_name_size; + char* ext; + + d_name_size = strlen( entry->d_name ); + if ( strcmp( entry->d_name + ( d_name_size - 4 ), ".xml" ) != 0 ) + continue; + + sprintf( xml_path, "%s/%s", plugin_base_dir, entry->d_name); + if (!is_directory(xml_path)) + { + char* extension_id = NULL; + char* list_id = NULL; + + xmlDoc *doc = NULL; + doc = xmlReadFile(xml_path, NULL, 0); + + extension_id = query_tag( doc, "extension" , NULL, NULL, "point" ); + + if( extension_id == NULL ) + { + continue; + } + + if( (list_type == LIST_ALL || list_type == LIST_ROOT ) && + strcmp( extension_id, "rootstrapDefinition" ) == 0) + { + list_id = query_tag( doc, "rootstrap", NULL, NULL, "id" ); + + rootstrap_list[rootstrap_cnt] = list_id; + rootstrap_cnt++; + } + else if ( (list_type == LIST_ALL || list_type == LIST_TOOL ) && + strcmp( extension_id, "toolchainDefinition" ) == 0) + { + list_id = query_tag( doc, "toolchain", NULL, NULL, "id" ); + + toolchain_list[toolchain_cnt] = list_id; + toolchain_cnt++; + } + else if ( (list_type == LIST_ALL || list_type == LIST_BUILD_SYSTEM ) && + strcmp( extension_id, "buildSystemDefinition" ) == 0) + { + list_id = query_tag( doc, "buildSystem", NULL, NULL, "id" ); + + toolchain_list[toolchain_cnt] = list_id; + toolchain_cnt++; + } + } + } + } + + if( (list_type == LIST_ALL || list_type == LIST_TARGET ) ) + { + SBI_PRINTF(1, "\nAvailable Target List\n"); + SBI_PRINTF(1, "------------------------\n"); + for ( i = 0 ; i < target_cnt ; i++ ) + { + SBI_PRINTF(1, "%s\n", target_list[i] ); + free(target_list[i]); + } + } + + if( (list_type == LIST_ALL || list_type == LIST_ROOT ) ) + { + SBI_PRINTF(1, "\nAvailable Rootstrap List\n"); + SBI_PRINTF(1, "------------------------\n"); + for ( i = 0 ; i < rootstrap_cnt ; i++ ) + { + SBI_PRINTF(1, "%s\n", rootstrap_list[i] ); + } + } + + + if( (list_type == LIST_ALL || list_type == LIST_TOOL ) ) + { + SBI_PRINTF(1, "\nAvailable Tool List\n"); + SBI_PRINTF(1, "------------------------\n"); + for ( i = 0 ; i < toolchain_cnt ; i++ ) + { + SBI_PRINTF(1, "%s\n", toolchain_list[i] ); + } + } + + if( (list_type == LIST_ALL || list_type == LIST_BUILD_SYSTEM ) ) + { + SBI_PRINTF(1, "\nAvailable Build System List\n"); + SBI_PRINTF(1, "------------------------\n"); + for ( i = 0 ; i < buildsystem_cnt ; i++ ) + { + SBI_PRINTF(1, "%s\n", buildsystem_list[i] ); + } + } + + return 1; +} + + +static char* query_tag_loop(xmlNode* node, char* name, char* attr, xmlChar * attr_value, char* find_attr ) +{ + xmlNode *cur_node = NULL; + xmlChar* result; + char* ret; + char* tmp; + char temp[MAX_CMD_LENGTH + 1]; + + for (cur_node = node; cur_node; cur_node = xmlNextElementSibling(cur_node)) + { + if(strcmp(cur_node->name, name) == 0) + { + if( ( attr == NULL && attr_value == NULL ) || + ( (tmp = xmlGetProp(cur_node,attr)) != NULL && strcmp(attr_value,tmp) == 0)) + { + /* find attr is needed */ + if( find_attr == NULL ) + { + return NULL; + } + + result = xmlGetProp(cur_node,find_attr); + if(result == NULL) + { + return NULL; + } + + ret = strdup(result); + if(strchr(ret,' ') != NULL) + { + sprintf(temp,"\"%s\"",ret); + free(ret); + ret=strdup(temp); + } + + xmlFree(result); + return ret; + } + } + ret = query_tag_loop(cur_node->children, name, attr, attr_value, find_attr); + if(ret != NULL) + return ret; + } + return NULL; +} + +static char* query_tag(xmlDoc* doc, char* name, char* attr, char* attr_value, xmlChar * find_attr ) +{ + xmlNode *root = NULL; + + if (doc == NULL) + return NULL; + + root = xmlDocGetRootElement(doc); + return query_tag_loop(root, name, attr, attr_value, find_attr); +} +#endif diff --git a/src/sbi_xml.h b/src/sbi_xml.h new file mode 100644 index 0000000..612930c --- /dev/null +++ b/src/sbi_xml.h @@ -0,0 +1,46 @@ +/* + * sbi_xml.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#ifndef _SBI_XML_H +#define _SBI_XML_H +#include + +typedef enum _SHOW_OPTION +{ + SHOW_TARGET = 1, SHOW_ROOT = 2, SHOW_TOOL = 3 +} SHOW_OP; + +typedef enum _LIST_OPTION +{ + LIST_ALL = 0, LIST_TARGET = 1, LIST_ROOT = 2, LIST_TOOL = 3, LIST_BUILD_SYSTEM = 4 +} LIST_OP; + +// external api +int sbi_list_using_xml(int list_type); + +char* query_tag(xmlDoc* doc, char* name, char* attr, char* attr_value, char* find_attr); +#endif diff --git a/src/target.c b/src/target.c new file mode 100644 index 0000000..8a3712f --- /dev/null +++ b/src/target.c @@ -0,0 +1,157 @@ +/* + * target.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include +#include "target.h" +#include "sbi_config.h" +#include "toolchain_mgt.h" +#include "rootstrap_mgt.h" + +target* create_target( char* id, char* name, char* rootstrap_id, char* toolchain_id ) +{ + target *new_target = (target*)malloc( sizeof(target ) ); + + new_target->id = strdup( id ); + if ( name != NULL ) + new_target->name = (char*)strdup(name); + else + new_target->name = (char*)strdup(id); + + new_target->rootstrap_id = (char*)strdup( rootstrap_id ); + new_target->toolchain_id = (char*)strdup( toolchain_id ); + new_target->next = NULL; + + return new_target; +} + + +target* append_target( target* list, target* src ) +{ + target* t = list; + while( t->next != NULL ) + t=t->next; + + t->next = src; + + return list; +} + + +void remove_target( target* list ) +{ + target* t = list; + while( t != NULL ) + { + target* prev = t; + t=t->next; + free( prev->id ); + free( prev->name ); + free( prev->rootstrap_id ); + free( prev->toolchain_id ); + free( prev ); + } +} + + +/* save to plugin */ +plugin * create_target_plugin( target* t ) +{ + plugin* new_plugin = NULL; + plugin_doc *doc = NULL; + int rc; + char target_xml_path[MAX_FILE_PATH + 1]; + + /* create writer */ + plugin_writer* writer = create_writer(&doc); + + rc = start_write_doc(writer); + rc = start_write_elm(writer, "extension"); + rc = write_attr(writer, "point", "targetDefinition"); + rc = start_write_elm(writer, "target"); + rc = write_attr(writer, "id", t->id); + rc = write_attr(writer, "name", t->name); + rc = write_attr(writer, "rootstrapId", t->rootstrap_id); + rc = write_attr(writer, "toolchainId", t->toolchain_id); + rc = end_write_elm(writer); + rc = end_write_elm(writer); + rc = end_write_doc(writer); + + /* free writer */ + free_writer(writer); + + /* save plugin file */ + sprintf( target_xml_path, "%s/%s.xml", get_plugin_base_dir(), t->id); + rc = save_doc_file(doc, target_xml_path); + free_doc(doc); + + /* create */ + new_plugin = create_plugin(target_xml_path); + + return new_plugin; +} + + +/* load from plugin */ +target* load_target_from_plugin( plugin* p ) +{ + target* new_target = NULL; + char *id, *name, *rootstrap_id, *toolchain_id; + plugin_tag* tag = get_plugin_tag( p, "target" ); + + assert( tag != NULL ); + + id = get_plugin_tag_attribute( tag, "id" ); + name = get_plugin_tag_attribute( tag, "name" ); + rootstrap_id = get_plugin_tag_attribute( tag, "rootstrapId" ); + toolchain_id = get_plugin_tag_attribute( tag, "toolchainId" ); + + /* id name */ + if (id == NULL || name == NULL ) + return NULL; + + /* check toolchain */ + if (toolchain_id == NULL || !is_toolchain_available(toolchain_id)) + return NULL; + + /* check rootstrap */ + if (rootstrap_id == NULL || !is_rootstrap_available(rootstrap_id) ) + return NULL; + + /* create */ + new_target = create_target( id, name, rootstrap_id, toolchain_id ); + + /* clean up */ + free( id ); + free( name ); + free( rootstrap_id ); + free( toolchain_id ); + + return new_target; +} + diff --git a/src/target.h b/src/target.h new file mode 100644 index 0000000..23610e1 --- /dev/null +++ b/src/target.h @@ -0,0 +1,49 @@ +/* + * target.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#ifndef TARGET_H_ +#define TARGET_H_ +#include "plugin.h" + +typedef struct _target { + char* id; + char* name; /* display */ + char* rootstrap_id; + char* toolchain_id; + struct _target *next; +} target; + +target* create_target( char* id, char* name, char* rootstrap_id, char* toolchain_id ); +target* append_target( target* list, target* src ); +void remove_target( target* t ); + +/* save to plugin */ +plugin * create_target_plugin( target* t ); +/* load from plugin */ +target* load_target_from_plugin( plugin* p ); + +#endif /* TARGET_H_ */ diff --git a/src/target_mgt.c b/src/target_mgt.c new file mode 100644 index 0000000..a593f91 --- /dev/null +++ b/src/target_mgt.c @@ -0,0 +1,334 @@ +/* + * target_mgt.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include +#include +#include "target_mgt.h" +#include "toolchain_mgt.h" +#include "rootstrap_mgt.h" +#include "plugin_mgt.h" +#include "plugin.h" +#include "target.h" +#include "sbi_util.h" + + +static target* target_list = NULL; + +static target* search_target_id( char* target_id ); + +void initialize_target_mgt( ) +{ + plugin* list = get_plugin_list("targetDefinition"); + plugin* p = list; + + for( ; p ; p = p->next ) + { + target* t = load_target_from_plugin( p ); + + if ( t != NULL ) + { + if ( target_list != NULL ) + append_target( target_list, t ); + else + target_list = t; + } + } + remove_plugin_list(list); +} + +/* list up all target */ +string_list* get_all_available_target_ids( ) +{ + string_list *new_list = NULL; + target * t = target_list; + + for( ; t ; t=t->next ) + { + if ( new_list != NULL ) + append_string_to_list( new_list, t->id ); + else + new_list = create_string_list( t->id ); + } + + return new_list; +} + + + +string_list* get_all_available_target_names( ) +{ + string_list *new_list = NULL; + target * t = target_list; + + for( ; t ; t=t->next ) + { + if ( new_list != NULL ) + append_string_to_list( new_list, t->name ); + else + new_list = create_string_list( t->name ); + } + + return new_list; +} + +char* get_rootstrap_id( char* target_id ) +{ + char* rootstrap_id = NULL; + target* t = search_target_id(target_id); + + if ( t != NULL) + rootstrap_id = strdup(t->rootstrap_id); + + return rootstrap_id; +} + +char* get_toolchain_id( char* target_id ) +{ + char* toolchain_id = NULL; + target* t = search_target_id(target_id); + + if ( t != NULL) + toolchain_id = strdup(t->toolchain_id); + + return toolchain_id; +} + +char* get_target_name( char* target_id ) +{ + char* target_name = NULL; + target* t = search_target_id(target_id); + + if ( t != NULL) + target_name = strdup(t->name); + + return target_name; +} + + +int create_new_target( char* target_id, char* rootstrap_id, char* toolchain_id ) +{ + target* new_target = NULL; + plugin* p = NULL; + + assert( target_id != NULL && !is_target_available( target_id ) ); + assert( rootstrap_id != NULL && is_rootstrap_available( rootstrap_id ) ); + assert( toolchain_id != NULL && is_toolchain_available( toolchain_id ) ); + + /* create target */ + new_target = create_target( target_id, target_id, rootstrap_id, toolchain_id ); + + /* create target */ + p = create_target_plugin( new_target ); + if ( p == NULL ) + return -1; + + add_new_plugin( p ); + if ( target_list != NULL ) { + append_target( target_list, new_target); + } else { + target_list = new_target; + } + + return 0; +} + + +int remove_target_xml( char* target_id ) +{ + // check child xmls + + // remove target xml file + char filepath[MAX_FILE_PATH]; +#ifdef WIN32 + sprintf(filepath, "%s\\%s.xml", get_plugin_base_dir(), target_id); +#else + sprintf(filepath, "%s/%s.xml", get_plugin_base_dir(), target_id); +#endif + return remove_file(filepath); +} + + +static target* search_target_id( char* target_id ) +{ + target* t = target_list; + target* result_searching = NULL; + + for( ; t ; t=t->next ) + { + if ( !strcmp(t->id, target_id) ) + { + result_searching = t; + break; + } + } + + return result_searching; +} + +int is_target_available( char* target_id ) +{ + target* t = search_target_id(target_id); + int result = 0; + + if ( t != NULL) + result = 1; + + return result; +} + +void finalize_target_mgt( ) +{ + remove_target( target_list ); +} + +void display_target_list() +{ + string_list* list = get_all_available_target_ids(); + string_list* id = list; + + /* + SBI_PRINTF(1, "\nAvailable Target List\n"); + SBI_PRINTF(1, "------------------------\n"); + */ + while ( id != NULL ) + { + SBI_PRINTF(1, "%s\n", id->str ); + id=id->next; + } + + /* remove allocated string */ + if ( list != NULL ) remove_string_list( list ); +} + +void display_target_info( char* target_id ) +{ + char* name = get_target_name( target_id ); + char* rootstrap_id = get_rootstrap_id( target_id ); + char* toolchain_id = get_toolchain_id( target_id ); + + SBI_PRINTF(1, "NAME=%s\n", name ); + SBI_PRINTF(1, "ROOTSTRAP_ID=%s\n", rootstrap_id ); + SBI_PRINTF(1, "TOOLCHAIN_ID=%s\n", toolchain_id ); + + free( name ); + free( rootstrap_id ); + free( toolchain_id ); + /* TODO: must display project dependent info */ +} + + +/* action */ +int is_target_predefined_action_available( char* target_id, char* action_name ) +{ + int ret = 0; + char* toolchain_id = get_toolchain_id( target_id ); + + if ( toolchain_id != NULL && is_toolchain_action_available( toolchain_id, action_name, 1 ) ) + ret = 1; + + if ( toolchain_id != NULL ) + free( toolchain_id ); + + return ret; +} + + +int is_target_action_available( char* target_id, char* action_cmd ) +{ + int ret = 0; + char* toolchain_id = get_toolchain_id( target_id ); + + if ( toolchain_id != NULL && ( + is_toolchain_action_available( toolchain_id, action_cmd, 1 ) || + is_toolchain_action_available( toolchain_id, action_cmd, 0 ) ) ) + ret = 1; + + if ( toolchain_id != NULL ) + free( toolchain_id ); + + return ret; +} + + + +int execute_target_action( char* target_id, char* action_cmd, string_list* arguments ) +{ + int ret = 0; + char* toolchain_id = get_toolchain_id( target_id ); + char* rootstrap_id = get_rootstrap_id(target_id); + + /* check */ + if ( !is_target_action_available( target_id, action_cmd ) ) + return -1; + + /* set basic action environment */ + set_target_id(target_id); + set_toolchain_id(toolchain_id); + set_rootstrap_id(rootstrap_id); + + /* execute */ + ret = execute_toolchain_action( toolchain_id, action_cmd, arguments ); + + /* release environment */ + free_toolchain_id(); + free_rootstrap_id(); + free_target_id(); + + /* free */ + free( toolchain_id ); + free( rootstrap_id ); + + return ret; +} + + +void print_target_action_variables( char* target_id, char* action_name ) +{ + char* toolchain_id = get_toolchain_id( target_id ); + + /* print */ + print_toolchain_action_variable_list( toolchain_id, action_name ); + + /* free */ + free( toolchain_id ); +} + + +void print_target_action_list(char* target_id) +{ + char*toolchain_id = get_toolchain_id(target_id); + + /* print */ + print_toolchain_action_list(toolchain_id); + + /* free */ + free( toolchain_id ); +} + + diff --git a/src/target_mgt.h b/src/target_mgt.h new file mode 100644 index 0000000..e551403 --- /dev/null +++ b/src/target_mgt.h @@ -0,0 +1,63 @@ +/* + * target_mgt.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +#ifndef _SBI_TARGET_H +#define _SBI_TARGET_H + +#include "sbi_types.h" + +/* init fini */ +void initialize_target_mgt( ); +void finalize_target_mgt( ); + +/* list up all target */ +string_list* get_all_available_target_ids( ); +string_list* get_all_available_target_names( ); + +/* create/remove target xml */ +int create_new_target( char* target_id, char* rootstrap_id, char* toolchain_id ); +int remove_target_xml( char* target_id ); + +/* getting functions */ +char* get_target_name( char* target_id ); +char* get_rootstrap_id( char* target_id ); +char* get_toolchain_id( char* target_id ); + +/* functions */ +void display_target_list(); +void display_target_info( char* target_id ); +int is_target_available( char* target_id ); + +/* action */ +int is_target_predefined_action_available( char* target_id, char* action_cmd ); +int is_target_action_available( char* target_id, char* action_cmd ); +int execute_target_action( char* target_id, char* action_cmd, string_list* arguments ); +void print_target_action_variables( char*target_id, char*action_name ); +void print_target_action_list(char*target_id); + +#endif diff --git a/src/tool.c b/src/tool.c new file mode 100644 index 0000000..cc3a88b --- /dev/null +++ b/src/tool.c @@ -0,0 +1,126 @@ +/* + * tool.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include "tool.h" + +tool* create_tool( char* name, char* path, char* version, char* desc ) +{ + tool *newr = (tool*)malloc( sizeof(tool ) ); + + if ( name != NULL ) + newr->name = (char*)strdup(name); + else + newr->name = (char*)strdup(name); + + newr->path = (char*)strdup( path ); + if ( version != NULL ) + newr->version = (char*)strdup( version ); + else + newr->version = (char*)strdup( " " ); + if ( desc != NULL ) + newr->description = (char*)strdup( desc ); + else + newr->description = (char*)strdup( " "); + newr->next = NULL; + + return newr; +} + + +tool* append_tool_list( tool* list, tool* src ) +{ + tool* r = list; + while( r->next != NULL ) + r=r->next; + + r->next = src; + + return list; +} + + +void remove_tool_list( tool* list ) +{ + tool* r = list; + while( r != NULL ) + { + tool* prev = r ; + r=r->next; + free( prev->name ); + free( prev->path ); + free( prev->version ); + free( prev->description ); + free( prev ); + } +} + + + +tool* load_tool_list_from_plugin( plugin_tag* toolchain_tag ) +{ + plugin_tag_list* tag_list = get_plugin_subtag_list( toolchain_tag, "tool" ); + plugin_tag_list* plugin_tag = NULL; + tool* tool_list = NULL; + + if ( tag_list == NULL ) + return NULL; + + for( plugin_tag =tag_list ; plugin_tag ; plugin_tag=plugin_tag->next ) + { + tool* t = NULL; + char *name, *ver, *path, *desc; + + /* create tool */ + name = get_plugin_tag_attribute( plugin_tag->tag, "name" ); + ver = get_plugin_tag_attribute( plugin_tag->tag, "version" ); + path = get_plugin_tag_attribute( plugin_tag->tag, "path" ); + desc = get_plugin_tag_attribute( plugin_tag->tag, "description" ); + t = create_tool( name, path, ver, desc ); + + /* append to list */ + if ( t != NULL ) + { + if ( tool_list != NULL ) + append_tool_list( tool_list, t ); + else + tool_list = t; + } + + /* remove dynamically allocated string */ + free( name ); + free( ver ); + free( path ); + free( desc ); + } + + /* clean up */ + remove_plugin_tag_list(tag_list); + + return tool_list; +} diff --git a/src/tool.h b/src/tool.h new file mode 100644 index 0000000..813c498 --- /dev/null +++ b/src/tool.h @@ -0,0 +1,48 @@ +/* + * tool.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#ifndef TOOL_H_ +#define TOOL_H_ + +#include "plugin.h" + +typedef struct _tool { + char* name; + char* path; + char* version; + char* description; + struct _tool * next; +} tool; + +tool* create_tool( char* name, char* path, char* version, char* desc ); +tool* append_tool_list( tool* list, tool* src ); +void remove_tool_list( tool* t ); + +tool* load_tool_list_from_plugin( plugin_tag* toolchain_tag ); + + +#endif /* TOOL_H_ */ diff --git a/src/toolchain.c b/src/toolchain.c new file mode 100644 index 0000000..e34c516 --- /dev/null +++ b/src/toolchain.c @@ -0,0 +1,392 @@ +/* + * toolchain.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include +#include "toolchain.h" +#include "toolchain_action.h" +#include "sbi_error.h" +#include "sbi_util.h" + + +toolchain* create_toolchain( char* id, char* name, char* version, char* architecture, char* path, char* toolchain_type ) +{ + toolchain *newr = (toolchain*)malloc( sizeof(toolchain ) ); + + newr->id = strdup( id ); + + if ( name != NULL ) newr->name = (char*)strdup(name); + else newr->name = (char*)strdup(id); + + if ( version != NULL ) newr->version = (char*)strdup(version); + else newr->version = (char*)strdup("1.0"); + + if( architecture != NULL ) newr->architecture = (char*)strdup( architecture ); + else newr->architecture = NULL; + if( path != NULL ) newr->path = (char*)strdup( path ); + else newr->path = NULL; + if( toolchain_type != NULL ) newr->toolchain_type = (char*)strdup( toolchain_type ); + else newr->toolchain_type = NULL; + newr->property_list = NULL; + newr->tool_list = NULL; + newr->action_list = NULL; + newr->next = NULL; + + return newr; +} + + +toolchain* append_toolchain_list( toolchain* list, toolchain* src ) +{ + toolchain* r = list; + while( r->next != NULL ) + r=r->next; + + r->next = src; + + return list; +} + +void remove_toolchain_property_list( toolchain_property* list ) +{ + toolchain_property* t = list; + toolchain_property* prev; + while( t != NULL ) + { + prev = t; + t=t->next; + if(prev->key != NULL) + { + free(prev->key); + } + if(prev->value != NULL) + { + free(prev->value); + } + free(prev); + } +} + +void remove_toolchain_list( toolchain* list ) +{ + toolchain* r = list; + while( r != NULL ) + { + toolchain* prev = r ; + r=r->next; + if(prev->id != NULL) + { + free( prev->id ); + } + if(prev->name != NULL) + { + free( prev->name ); + } + if(prev->version != NULL) + { + free( prev->version ); + } + if(prev->architecture != NULL) + { + free( prev->architecture ); + } + if(prev->path != NULL) + { + free( prev->path ); + } + if(prev->toolchain_type != NULL) + { + free( prev->toolchain_type ); + } + if(prev->property_list != NULL) + { + remove_toolchain_property_list(prev->property_list); + } + if(prev->tool_list != NULL) + { + remove_tool_list( prev->tool_list ); + } + if(prev->action_list != NULL) + { + remove_toolchain_action_list( prev->action_list ); + } + free( prev ); + } +} + +static toolchain_property* create_toolchain_property( char* key, char* value ) +{ + toolchain_property *newr = (toolchain_property*)malloc( sizeof(toolchain_property ) ); + + newr->key = (char*)strdup(key); + newr->value = (char*)strdup(value); + newr->next = NULL; + + return newr; +} + +static toolchain_property* append_toolchain_property_list( toolchain_property* list, toolchain_property* src ) +{ + toolchain_property* t = list; + while( t->next != NULL ) + t=t->next; + + t->next = src; + + return list; +} + +void add_toolchain_property( toolchain* t, char* key, char* value ) +{ + toolchain_property* newr = create_toolchain_property( key, value ); + + if ( t->property_list != NULL ) + append_toolchain_property_list( t->property_list, newr ); + else + t->property_list = newr; +} + + + +void set_tool_list( toolchain*tc, tool* t ) +{ + tc->tool_list = t; +} + + +string_list* get_tool_list( toolchain*tc ) +{ + string_list* list = NULL; + tool* t = NULL; + + for( t = tc->tool_list; t != NULL; t = t->next ) + { + string_list* newl = create_string_list( t->name ); + + if ( list != NULL ) + { + append_string_to_list( list, newl->str); + remove_string_list(newl); + } + else + list = newl; + } + + return list; +} + + +char* get_tool_path( toolchain*tc, char* tool_name ) +{ + tool* t = NULL; + + for(t = tc->tool_list; t != NULL; t = t->next ) + { + if ( strcmp( t->name, tool_name ) == 0 ) + return t->path; + } + + return NULL; +} + + +char* get_tool_version( toolchain*tc, char* tool_name ) +{ + tool* t = NULL; + + for(t = tc->tool_list; t != NULL; t = t->next ) + { + if ( strcmp( t->name, tool_name ) == 0 ) + return t->version; + } + + return NULL; +} + + + +void set_toolchain_action_list( toolchain*tc, toolchain_action* t ) +{ + tc->action_list = t; +} + + +static toolchain_action* find_toolchain_action( toolchain*tc, char* action_name ) +{ + toolchain_action* action = tc->action_list; + + while( action ) + { + if ( strcmp( action->name, action_name ) == 0 ) + { + return action; + } + action = action->next; + } + + return NULL; +} + + + +/* call action */ +int perform_toolchain_action( toolchain*tc, char* action_name, string_list *argument ) +{ + toolchain_action* action = find_toolchain_action( tc, action_name ); + + if ( action != NULL ) + { + return execute_action( action, argument ); + } + else + { + sbi_error(29, action_name, 0); + return -1; + } +} + + +/* print action list */ +void print_action_list( toolchain* t ) +{ + toolchain_action* action; + + if ( t == NULL ) + { + return; + } + action = t->action_list; + while(action != NULL) + { + string_list *var_list = NULL; + string *var = NULL; + + /* ignore predefined */ + if(action->predefined == 1 ) + { + /* skip current */ + action = action->next; + continue; + } + + /* get */ + var_list = get_toolchain_action_variable_list( action ); + + /* print */ + SBI_PRINTF(1, "%s", action->name ); + for( var = var_list; var; var = var->next ) + { + SBI_PRINTF(1, " %s", var->str ); + } + SBI_PRINTF(1, "\n"); + + /* clean up */ + if ( var_list != NULL ) + remove_string_list( var_list ); + + /* get next */ + action = action->next; + } +} + + +/* print action variables */ +void print_action_variable_list( toolchain* t, char* action_cmd ) +{ + toolchain_action* action = find_toolchain_action( t, action_cmd ); + string_list *var_list = NULL; + string *var = NULL; + + if ( action == NULL ) + return; + + /* get */ + var_list = get_toolchain_action_variable_list( action ); + + for( var = var_list; var; var = var->next ) + { + SBI_PRINTF(1, " %s", var->str ); + } + SBI_PRINTF(1, "\n"); +} + + +/* load from plugin */ +toolchain* load_toolchain_from_plugin( plugin* p ) +{ + toolchain* tc = NULL; + char *id, *name, *version,*architecture,*path,*toolchain_type; + tool* tool_list = NULL; + toolchain_action* action_list = NULL; + + /* create toolchain */ + plugin_tag* tag = get_plugin_tag( p, "toolchain" ); + assert( tag != NULL ); + id = get_plugin_tag_attribute( tag, "id" ); + name = get_plugin_tag_attribute( tag, "name" ); + version = get_plugin_tag_attribute( tag, "version" ); + architecture = get_plugin_tag_attribute( tag, "architecture" ); + path = get_plugin_tag_attribute( tag, "path" ); + toolchain_type = get_plugin_tag_attribute( tag, "toolchainType" ); + tc = create_toolchain( id, name, version, architecture, path, toolchain_type ); + + if ( tc != NULL ) + { + plugin_tag_list* tag_list = get_plugin_subtag_list( tag, "property"); + plugin_tag_list* prop_tag = NULL; + + for( prop_tag = tag_list; prop_tag; prop_tag = prop_tag->next ) + { + char* key = get_plugin_tag_attribute( prop_tag->tag, "key" ); + char* value = get_plugin_tag_attribute( prop_tag->tag, "value" ); + add_toolchain_property( tc, key, value ); + free( key ); + free( value); + } + remove_plugin_tag_list(tag_list); + + /* create tool list & set it */ + tool_list = load_tool_list_from_plugin( tag ); + set_tool_list ( tc, tool_list ); + + /* create action list & set it */ + action_list = load_toolchain_action_list_from_plugin( tag ); + set_toolchain_action_list( tc, action_list ); + } + + /* remove dynamically allocated string */ + free( id ); + free( name ); + free( architecture ); + free( path ); + free( toolchain_type ); + + return tc; +} + + diff --git a/src/toolchain.h b/src/toolchain.h new file mode 100644 index 0000000..25b3c12 --- /dev/null +++ b/src/toolchain.h @@ -0,0 +1,80 @@ +/* + * toolchain.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + + +#ifndef TOOLCHAIN_H_ +#define TOOLCHAIN_H_ +#include "tool.h" +#include "toolchain_action.h" +#include "sbi_types.h" +#include "plugin.h" + + +typedef struct _toolchain_property { + char* key; + char* value; + struct _toolchain_property* next; +} toolchain_property; + + +typedef struct _toolchain { + char* id; + char* name; + char* version; + char* architecture; + char* path; + char* toolchain_type; + toolchain_property* property_list; + tool* tool_list; + toolchain_action* action_list; + struct _toolchain* next; +} toolchain; + +void add_toolchain_property( toolchain* r, char* key, char* value ); + +toolchain* create_toolchain( char* id, char* name, char* version, char* architecture, char* path, char* toolchain_type); +toolchain* append_toolchain_list( toolchain* list, toolchain* src ); +void remove_toolchain_list( toolchain* t ); + +void set_tool_list( toolchain*tc, tool* t ); +string_list* get_tool_list( toolchain*tc ); +char* get_tool_path( toolchain*tc, char* tool_name ); +char* get_tool_version( toolchain*tc, char* tool_name ); + +void set_toolchain_action_list( toolchain*tc, toolchain_action* a ); + +/* load from plugin */ +toolchain* load_toolchain_from_plugin( plugin* p ); + +/* perform action */ +int perform_toolchain_action( toolchain*tc, char* action_name, string_list *argument ); + +/* print */ +void print_action_list( toolchain* t ); +void print_action_variable_list( toolchain* t, char* action_cmd ); + +#endif /* TOOLCHAIN_H_ */ diff --git a/src/toolchain_action.c b/src/toolchain_action.c new file mode 100644 index 0000000..d8ca657 --- /dev/null +++ b/src/toolchain_action.c @@ -0,0 +1,191 @@ +/* + * toolchain_action.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include +#include "toolchain_action.h" +#include "sbi_error.h" + + +toolchain_action* create_toolchain_action( char* name, char* predefined, char* description ) +{ + toolchain_action *newr = (toolchain_action*)malloc( sizeof(toolchain_action ) ); + + if ( name != NULL ) + newr->name = (char*)strdup(name); + else + { + sbi_error(30, "", 0); + free(newr); + return NULL; + } + + if ( predefined != NULL ) + { + if ( strcmp(predefined, "YES") == 0) + newr->predefined = 1; + else + newr->predefined = 0; + } + else + { + newr->predefined = 0; + } + + if ( description != NULL ) + newr->description = (char*)strdup( description ); + else + newr->description = (char*)strdup( " " ); + + newr->next = NULL; + + return newr; +} + +void set_execute( toolchain_action* dst, execute* list ) +{ + dst->exec_list = list ; +} + +toolchain_action* append_toolchain_action_list( toolchain_action* list, toolchain_action* src ) +{ + toolchain_action* r = list; + while( r->next != NULL ) + r=r->next; + + r->next = src; + + return list; +} + + +void remove_toolchain_action_list( toolchain_action* list ) +{ + toolchain_action* r = list; + while( r != NULL ) + { + toolchain_action* prev = r ; + r=r->next; + free( prev->name ); + free( prev->description ); + remove_execute_list( prev->exec_list ); + free( prev ); + } +} + + +/* load from plugin */ +toolchain_action* load_toolchain_action_list_from_plugin( plugin_tag* toolchain_tag ) +{ + plugin_tag_list* tag_list = get_plugin_subtag_list( toolchain_tag, "action" ); + plugin_tag_list* plugin_tag = NULL; + toolchain_action* action_list = NULL; + + if ( tag_list == NULL ) + return NULL; + + for( plugin_tag=tag_list ; plugin_tag ; plugin_tag=plugin_tag->next ) + { + toolchain_action* action = NULL; + char *name, *predefined, *desc; + + /* create toolchain action */ + name = get_plugin_tag_attribute( plugin_tag->tag, "name" ); + predefined = get_plugin_tag_attribute( plugin_tag->tag, "predefined" ); + desc = get_plugin_tag_attribute( plugin_tag->tag, "description" ); + action = create_toolchain_action( name, predefined, desc ); + + /* create execute list & set it & append the action to list */ + if (action != NULL) + { + execute* execute_list = load_execute_list_from_plugin ( plugin_tag->tag ); + set_execute( action, execute_list ); + + if ( action_list != NULL ) + append_toolchain_action_list( action_list, action ); + else + action_list = action; + } + + /* remove dynamically allocated string */ + free( name ); + free( predefined ); + free( desc ); + } + + /* clean up */ + remove_plugin_tag_list(tag_list); + + return action_list; +} + + +/* get action variable list */ +string_list* get_toolchain_action_variable_list( toolchain_action* action ) +{ + execute* exe = action->exec_list; + string_list* result_list = NULL; + + for( ; exe; exe = exe->next ) + { + string_list* var_list = get_input_variable_list( exe ); + + if ( var_list != NULL ) + { + if ( result_list != NULL ) + append_string_list_to_list( result_list, var_list ); + else + result_list = clone_string_list( var_list ); + + remove_string_list( var_list ); + } + } + + return result_list; +} + + +/* call action */ +int execute_action( toolchain_action* act, string_list *arguments ) +{ + int ret; + + /* create action environment */ + execute_env* env = parse_execute_env( arguments ); + + /* execute action */ + SBI_PRINTF(2, "## Executing Action : %s\n", act->name ); + ret = execute_all_steps( act->exec_list , env ); + + /* remove action environment */ + remove_execute_env( env ); + + return ret; +} + + diff --git a/src/toolchain_action.h b/src/toolchain_action.h new file mode 100644 index 0000000..5bd4036 --- /dev/null +++ b/src/toolchain_action.h @@ -0,0 +1,59 @@ +/* + * toolchain_action.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#ifndef TOOLCHAIN_ACTION_H_ +#define TOOLCHAIN_ACTION_H_ + +#include "execute.h" +#include "sbi_types.h" +#include "sbi_util.h" +#include "plugin.h" + +typedef struct _toolchain_action { + char* name; + int predefined; + char* description; + execute* exec_list; + struct _toolchain_action* next; +} toolchain_action; + + +toolchain_action* create_toolchain_action( char* name, char* predefined, char* description ); +void set_execute( toolchain_action* dst, execute* list ); +toolchain_action* append_toolchain_action_list( toolchain_action* list, toolchain_action* src ); +void remove_toolchain_action_list( toolchain_action* t ); + +/* load from plugin */ +toolchain_action* load_toolchain_action_list_from_plugin( plugin_tag* toolchain_tag ); + +/* get action variable list */ +string_list* get_toolchain_action_variable_list( toolchain_action* action ); + +/* call action */ +int execute_action( toolchain_action* act, string_list *argument ); + +#endif /* TOOLCHAIN_ACTION_H_ */ diff --git a/src/toolchain_mgt.c b/src/toolchain_mgt.c new file mode 100644 index 0000000..98386e0 --- /dev/null +++ b/src/toolchain_mgt.c @@ -0,0 +1,406 @@ +/* + * toolchain_mgt.c + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#include +#include +#include + +#include "toolchain_mgt.h" +#include "toolchain.h" +#include "sbi_util.h" +#include "plugin_mgt.h" +#include "plugin.h" +#include "sbi_error.h" + + +static toolchain* toolchain_list = NULL; + + +/* init fini */ +void initialize_toolchain_mgt( ) +{ + plugin* list = get_plugin_list("toolchainDefinition"); + plugin* p = list; + + for( ; p ; p = p->next ) + { + toolchain* tc = load_toolchain_from_plugin( p ); + + if ( tc != NULL ) + { + if ( toolchain_list != NULL ) + append_toolchain_list( toolchain_list, tc ); + else + toolchain_list = tc; + } + } + remove_plugin_list(list); +} + + +void finalize_toolchain_mgt( ) +{ + remove_toolchain_list( toolchain_list ); +} + + +/* list up all target */ +string_list* get_all_available_toolchain_ids( ) +{ + string_list *new_list = NULL; + toolchain * t = toolchain_list; + + for( ; t ; t=t->next ) + { + if ( new_list != NULL ) + append_string_to_list( new_list, t->id ); + else + new_list = create_string_list( t->id ); + } + + return new_list; +} + + +string_list* get_all_available_toolchain_names( ) +{ + string_list *new_list = NULL; + toolchain * t = toolchain_list; + + for( ; t ; t=t->next ) + { + if ( new_list != NULL ) + append_string_to_list( new_list, t->name ); + else + new_list = create_string_list( t->name ); + } + + return new_list; +} + + +/* find */ +static toolchain* find_toolchain( char* toolchain_id ) +{ + toolchain * t = toolchain_list; + + for( ; t ; t=t->next ) + { + if ( strcmp( t->id, toolchain_id ) == 0 ) + return t; + } + + return NULL; +} + + +/* toolchain */ +char* get_toolchain_name( char* toolchain_id ) +{ + toolchain * t = find_toolchain( toolchain_id ); + + if ( t != NULL ) + return strdup( t->name ); + else + return NULL; +} + + +char* get_toolchain_version( char* toolchain_id ) +{ + toolchain * t = find_toolchain( toolchain_id ); + + if ( t != NULL ) + return strdup( t->version ); + else + return NULL; +} + + +char* get_toolchain_architecture( char* toolchain_id ) +{ + toolchain * t = find_toolchain( toolchain_id ); if ( t != NULL ) + return strdup( t->architecture ); + else + return NULL; +} + +char* get_toolchain_path( char* toolchain_id ) +{ + toolchain * t = find_toolchain( toolchain_id ); + + if ( t != NULL ) + return strdup( t->path ); + else + return NULL; +} + +char* get_toolchain_toolchain_type( char* toolchain_id ) +{ + toolchain * t = find_toolchain( toolchain_id ); + + if ( t != NULL ) + { + if(t->toolchain_type != NULL) + { + return strdup( t->toolchain_type ); + } + else + { + return NULL; + } + } + else + { + return NULL; + } +} + +string_list* get_toolchain_property_list( char* toolchain_id ) +{ + toolchain * t = find_toolchain( toolchain_id ); + toolchain_property* r; + string_list * list= NULL; + if(t != NULL) + { + r = t->property_list; + for( ; r; r = r -> next ) + { + if ( list != NULL ) + append_string_to_list( list, r->key ); + else + list = create_string_list( r->key); + } + + return list; + } + return NULL; +} + +char* get_toolchain_property_value( char* toolchain_id, char* key ) +{ + toolchain * t = find_toolchain( toolchain_id ); + toolchain_property* r; + if(t != NULL) + { + r = t->property_list; + for( ; r; r = r -> next ) + { + if ( strcmp( r->key , key) == 0 ) + return strdup( r->value ); + } + } + return NULL; +} + +int is_toolchain_available( char* toolchain_id ) +{ + toolchain * t = find_toolchain( toolchain_id ); + + if ( t != NULL ) + return 1; + else + return 0; +} + +int is_toolchain_action_available( char* toolchain_id, char* action_name, int predefined) +{ + if ( !is_toolchain_available( toolchain_id) ) + { + sbi_error(4, toolchain_id, 0); + return 0; + } + + toolchain* t = find_toolchain( toolchain_id ); + assert(t != NULL); + + toolchain_action* list = t->action_list; + for ( ; list ; list = list->next) + { + if ( (strcmp(list->name, action_name) == 0) + && (list->predefined == predefined) ) + return 1; + } + + return 0; +} + + +string_list* get_toolchain_tool_list( char* toolchain_id ) +{ + toolchain * t = find_toolchain( toolchain_id ); + + return get_tool_list( t ); +} + + + + +char* get_toolchain_tool_path( char* toolchain_id, char* tool_name ) +{ + toolchain * t = find_toolchain( toolchain_id ); + + return strdup( get_tool_path( t , tool_name ) ); +} + + +char* get_toolchain_tool_version( char* toolchain_id, char* tool_name ) +{ + toolchain * t = find_toolchain( toolchain_id ); + + return strdup( get_tool_version( t , tool_name ) ); +} + + + +/* call action */ +int execute_toolchain_action( char* toolchain_id, char* action_name, string_list *argument ) +{ + int ret; + toolchain * t = find_toolchain( toolchain_id ); + + /* if not found, error */ + if ( t == NULL ) + return -1; + + /* execute */ + ret = perform_toolchain_action( t, action_name, argument ); + + return ret; +} + +/* query action */ +void print_toolchain_action_variable_list( char* toolchain_id, char* action_name ) +{ + toolchain * t = find_toolchain( toolchain_id ); + + /* if not found, error */ + if ( t == NULL ) + return; + + /* execute */ + print_action_variable_list( t, action_name ); + + return; +} + + +void print_toolchain_action_list( char* toolchain_id ) +{ + toolchain * t = find_toolchain( toolchain_id ); + + /* if not found, error */ + if ( t == NULL ) + return; + + /* execute */ + print_action_list( t ); + + return; +} + + +void display_toolchain_list() +{ + string_list* list = get_all_available_toolchain_ids(); + string_list* id = list; + + /* + SBI_PRINTF(1, "\nAvailable Toolchain List\n"); + SBI_PRINTF(1, "------------------------\n"); + */ + while ( id != NULL ) + { + SBI_PRINTF(1, "%s\n", id->str ); + id=id->next; + } + + if ( list != NULL ) remove_string_list( list ); +} + + +void display_toolchain_info( char* toolchain_id ) +{ + if(is_toolchain_available(toolchain_id)) + { + char* name = get_toolchain_name( toolchain_id ) ; + char* version = get_toolchain_version( toolchain_id ) ; + char* architecture = get_toolchain_architecture( toolchain_id ) ; + char* path = get_toolchain_path( toolchain_id ) ; + char* toolchain_type = get_toolchain_toolchain_type( toolchain_id ) ; + char* value; + string_list* tool_origin; + string_list* tool; + string_list* key_origin; + string_list* key; + + SBI_PRINTF(1, "NAME=%s\n", name); + SBI_PRINTF(1, "VERSION=%s\n", version); + SBI_PRINTF(1, "ARCHITECTURE=%s\n", architecture ); + SBI_PRINTF(1, "TOOLCHAIN_PATH=%s\n", path ); + SBI_PRINTF(1, "TOOLCHAIN_TYPE=%s\n", toolchain_type ); + + /* other properties */ + key_origin = get_toolchain_property_list( toolchain_id ); + key = key_origin; + for( ; key; key = key->next ) + { + value = tag_checker( get_toolchain_property_value( toolchain_id, key->str) ); + SBI_PRINTF(1, "%s=%s\n", key->str, value ); + if(value !=NULL) + free(value); + } + if(key_origin != NULL) + remove_string_list(key_origin); + + /* display tools */ + tool_origin = get_toolchain_tool_list( toolchain_id ); + tool = tool_origin; + for( ; tool != NULL; tool = tool->next ) + { + char* path = tag_checker( get_toolchain_tool_path( toolchain_id, tool->str ) ); + char* t_version = get_toolchain_tool_version( toolchain_id, tool->str ); + + SBI_PRINTF(1, "TOOL_%s_PATH=%s\n", tool->str, path ); + SBI_PRINTF(1, "TOOL_%s_VERSION=%s\n", tool->str, t_version ); + free( path ); + free( t_version ); + } + if(tool_origin != NULL) + remove_string_list(tool_origin); + + free( name ); + free( version ); + free( architecture ); + free( path ); + free( toolchain_type ); + } + else + { + SBI_PRINTF(1, "%s is not available toolchain name\n",toolchain_id ); + } +} diff --git a/src/toolchain_mgt.h b/src/toolchain_mgt.h new file mode 100644 index 0000000..6312b30 --- /dev/null +++ b/src/toolchain_mgt.h @@ -0,0 +1,64 @@ +/* + * toolchain_mgt.h + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Taejun Ha + * Jiil Hyoun + * Donghyuk Yang + * DongHee Yang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + */ + +#ifndef _SBI_TOOL_H +#define _SBI_TOOL_H + +#include "sbi_config.h" +#include "sbi_types.h" + +#define MAX_TOOLS 50 + +/* init fini */ +void initialize_toolchain_mgt( ); +void finalize_toolchain_mgt( ); + +/* list up all target */ +string_list* get_all_available_toolchain_ids( ); +string_list* get_all_available_toolchain_names( ); + +/* toolchain */ +char* get_toolchain_name( char* toolchain_id ); +char* get_toolchain_version( char* toolchain_id ); +char* get_toolchain_architecture( char* toolchain_id ); +char* get_toolchain_path( char* toolchain_id ); +char* get_toolchain_toolchain_type( char* toolchain_id ); +int is_toolchain_available( char* toolchain_id ); +void display_toolchain_list(); +void display_toolchain_info( char* toolchain_id ); + +string_list* get_toolchain_tool_list( char* toolchain_id ); +char* get_toolchain_tool_path( char* toolchain_id, char* tool_name ); +char* get_toolchain_tool_version( char* toolchain_id, char* tool_name ); + +/* call action */ +int is_toolchain_action_available( char* toolchain_id, char* action_name, int predefined); +int execute_toolchain_action( char* toolchain_id, char* action_name, string_list *argument ); +void print_toolchain_action_variable_list( char* toolchain_id, char* action_name ); +void print_toolchain_action_list(char* toolchain_id); + +#endif diff --git a/test/create_target_1.test b/test/create_target_1.test new file mode 100755 index 0000000..fa0a0d4 --- /dev/null +++ b/test/create_target_1.test @@ -0,0 +1,5 @@ +#testCaseName = create target 1 +#result_check = regression_target1 +#result_cmd_count = 2 +"build-system/bin/sbi" create -root $root_name -tool $tool_name regression_target1 +"build-system/bin/sbi" list target diff --git a/test/create_target_2.test b/test/create_target_2.test new file mode 100755 index 0000000..e2b9aad --- /dev/null +++ b/test/create_target_2.test @@ -0,0 +1,4 @@ +#testCaseName = create target 2 +#result_check = ERR001 +#result_cmd_count = 1 +"build-system/bin/sbi" create -root $root_name -tool $tool_name regression_target1 diff --git a/test/create_target_3.test b/test/create_target_3.test new file mode 100755 index 0000000..7d4d657 --- /dev/null +++ b/test/create_target_3.test @@ -0,0 +1,4 @@ +#testCaseName = create target 3 +#result_check = ERR002 +#result_cmd_count = 1 +"build-system/bin/sbi" create -option_error $root_name -tool $tool_name regression_target_no_exist diff --git a/test/create_target_4.test b/test/create_target_4.test new file mode 100755 index 0000000..ebe1041 --- /dev/null +++ b/test/create_target_4.test @@ -0,0 +1,4 @@ +#testCaseName = create target 4 +#result_check = ERR003 +#result_cmd_count = 1 +"build-system/bin/sbi" create -root root_name_not_exist -tool $tool_name regression_target_no_exist diff --git a/test/create_target_5.test b/test/create_target_5.test new file mode 100755 index 0000000..173c3d9 --- /dev/null +++ b/test/create_target_5.test @@ -0,0 +1,4 @@ +#testCaseName = create target 5 +#result_check = ERR005 +#result_cmd_count = 1 +"build-system/bin/sbi" create -root $root_name_error -tool $tool_name regression_target_no_exist diff --git a/test/create_target_6.test b/test/create_target_6.test new file mode 100755 index 0000000..15d7bd5 --- /dev/null +++ b/test/create_target_6.test @@ -0,0 +1,4 @@ +#testCaseName = create target 6 +#result_check = ERR004 +#result_cmd_count = 1 +"build-system/bin/sbi" create -root $root_name -tool $tool_name_not_exist regression_target_no_exist diff --git a/test/create_target_7.test b/test/create_target_7.test new file mode 100755 index 0000000..94b5073 --- /dev/null +++ b/test/create_target_7.test @@ -0,0 +1,4 @@ +#testCaseName = create target 7 +#result_check = ERR006 +#result_cmd_count = 1 +"build-system/bin/sbi" create -root $root_name -tool $tool_name_error regression_target_no_exist diff --git a/test/create_target_8.test b/test/create_target_8.test new file mode 100755 index 0000000..b0e2a73 --- /dev/null +++ b/test/create_target_8.test @@ -0,0 +1,4 @@ +#testCaseName = create target 8 +#result_check = ERR016 +#result_cmd_count = 1 +"build-system/bin/sbi" create -root $root_name -tool $tool_name 2wrong_target_name? diff --git a/test/create_target_9.test b/test/create_target_9.test new file mode 100755 index 0000000..aa17dd9 --- /dev/null +++ b/test/create_target_9.test @@ -0,0 +1,4 @@ +#testCaseName = create target 9 +#result_check = ERR015 +#result_cmd_count = 1 +"build-system/bin/sbi" create -root $root_name -tool tool_plugin_error regression_target_no_exist diff --git a/test/list.txt b/test/list.txt new file mode 100755 index 0000000..2dced86 --- /dev/null +++ b/test/list.txt @@ -0,0 +1,28 @@ +create_target_1 = YES +create_target_2 = YES +create_target_3 = YES +create_target_4 = YES +#create_target_5 = YES +create_target_6 = YES +#create_target_7 = YES +#create_target_8 = YES +#create_target_9 = YES +list_information_1 = YES +list_information_2 = YES +list_information_3 = YES +list_information_4 = YES +list_information_6 = YES +show_information_1 = YES +show_information_2 = YES +show_information_3 = YES +show_information_4 = YES +show_information_5 = YES +show_information_6 = YES +show_information_8 = YES +show_information_9 = YES +show_information_10 = YES +remove_target_1 = YES +remove_target_2 = YES +remove_target_3 = YES +show_information_7 = YES +remove_target_4 = YES diff --git a/test/list_information_1.test b/test/list_information_1.test new file mode 100755 index 0000000..64f4d3f --- /dev/null +++ b/test/list_information_1.test @@ -0,0 +1,5 @@ +#testCaseName = list information 1 +#result_check = regression_target1 +#result_cmd_count = 1 +"build-system/bin/sbi" list target +echo -n "TODO multi line check " >&2 diff --git a/test/list_information_2.test b/test/list_information_2.test new file mode 100755 index 0000000..e222f7f --- /dev/null +++ b/test/list_information_2.test @@ -0,0 +1,4 @@ +#testCaseName = list information 2 +#result_check = slp-device-1.0 +#result_cmd_count = 1 +"build-system/bin/sbi" list root diff --git a/test/list_information_3.test b/test/list_information_3.test new file mode 100755 index 0000000..21bb00f --- /dev/null +++ b/test/list_information_3.test @@ -0,0 +1,4 @@ +#testCaseName = list information 3 +#result_check = gcc-4.5.3-armel +#result_cmd_count = 1 +"build-system/bin/sbi" list tool diff --git a/test/list_information_4.test b/test/list_information_4.test new file mode 100755 index 0000000..a7809c1 --- /dev/null +++ b/test/list_information_4.test @@ -0,0 +1,4 @@ +#testCaseName = list information 4 +#result_check = slp-device-1.0 +#result_cmd_count = 1 +"build-system/bin/sbi" list all diff --git a/test/list_information_6.test b/test/list_information_6.test new file mode 100755 index 0000000..24756d5 --- /dev/null +++ b/test/list_information_6.test @@ -0,0 +1,4 @@ +#testCaseName = list information 6 +#result_check = ERR002: +#result_cmd_count = 1 +"build-system/bin/sbi" list invalid_option diff --git a/test/new_list.txt b/test/new_list.txt new file mode 100755 index 0000000..196d570 --- /dev/null +++ b/test/new_list.txt @@ -0,0 +1,28 @@ +create_target_1 = YES +create_target_2 = YES +create_target_3 = YES +create_target_4 = YES +create_target_5 = YES +create_target_6 = YES +create_target_7 = YES +create_target_8 = YES +create_target_9 = YES +list_information_1 = YES +list_information_2 = YES +list_information_3 = YES +list_information_4 = YES +list_information_6 = YES +show_information_1 = YES +show_information_2 = YES +show_information_3 = YES +show_information_4 = YES +show_information_5 = YES +show_information_6 = YES +show_information_8 = YES +show_information_9 = YES +show_information_10 = YES +remove_target_1 = YES +remove_target_2 = YES +remove_target_3 = YES +show_information_7 = YES +remove_target_4 = YES diff --git a/test/pre_test b/test/pre_test new file mode 100755 index 0000000..9c86b7c --- /dev/null +++ b/test/pre_test @@ -0,0 +1,6 @@ +#!/bin/sh +CURDIR=`pwd` +cp -r $CURDIR/plugins $CURDIR/build-system/ +export root_name=slp-device-1.0 +export tool_name=gcc-4.5.3-armel +echo success diff --git a/test/regression.rb b/test/regression.rb new file mode 100755 index 0000000..dca55b8 --- /dev/null +++ b/test/regression.rb @@ -0,0 +1,151 @@ +#!/usr/bin/ruby +testSuccessArray = Array.new +testFailArray = Array.new +testSkipArray = Array.new +testNotFoundArray = Array.new +testFileArray = Array.new +cmdList = Array.new + +testTotalCnt = 0 +testExt = "test" + +testCaseName = "" +resultCheck = "" +resultFlag = "" +resultCmdCount = 0 + +# check this file +root_name = "slp-device-1.0" +tool_name = "gcc-4.5.3-armel" + +# test execution +def testExecution(name, cmds, success, failArray, good, goodFlag, goodCnt) + stdout = "" + printf("#{name} ... ") + STDOUT.flush + + cmds.each do |cmd| + if cmd.strip.size != 0 + if cmds [goodCnt] == cmd + stdout = `#{cmd}` + else + `#{cmd}` + end + end + end + + if ( goodFlag == "true" and stdout.include? "#{good}" ) + puts "SUCCESS" + success.push("#{name}") + elsif ( goodFlag == "false" and ! stdout.include? "#{good}" ) + puts "SUCCESS" + success.push("#{name}") + else + puts "FAIL" + failArray.push("#{name}") + end + +cmds.clear +end + +#test_list file open +if (ARGV.size() == 0) + listFileName = "list.txt" +else + listFileName = ARGV.shift +end + +File.open( listFileName ) { |f| + f.each_line do |line| + testFileName = line.split('=')[0].strip + testFileNameFlag = line.split('=')[1].strip + + if testFileNameFlag == "YES" + testFileArray.push("#{testFileName}") + else + testSkipArray.push("#{testFileName}") + end + end +} + +puts +puts "Regression Test Start " +puts "==================================" + +#each file execution +testFileArray.each do |testFileName| + testFileFullName = "#{testFileName}" + "." + "#{testExt}" + + if File.exist?("#{testFileFullName}") + testTotalCnt = testTotalCnt + 1 + File.open("#{testFileFullName}") {|file| + + tempLine = file.gets + testCaseName = tempLine.split(' = ')[1].strip + + tempLine = file.gets + if tempLine[1].chr == "!" + resultFlag = "false" + else + resultFlag = "true" + end + resultCheck = tempLine.gsub(/\$root_name/, "#{root_name}") + resultCheck = tempLine.gsub(/\$tool_name/, "#{tool_name}") + resultCheck = tempLine.split(" = ")[1].strip + + tempLine = file.gets + resultCmdCount = Integer(tempLine.split(" = ")[1].strip) + resultCmdCount = resultCmdCount - 1 + + file.each_line do |line| + if ( line[0] != '*' and line[0] != "\#") + line = line.gsub(/\$root_name/, "#{root_name}") + line = line.gsub(/\$tool_name/, "#{tool_name}") + cmdList.push("#{line}") + end + end + } + + testExecution(testCaseName, cmdList, testSuccessArray, testFailArray, resultCheck, resultFlag, resultCmdCount) + else + testNotFoundArray.push("#{testFileFullName}") + end +end + +# print result +puts +puts "Regression Test Result" +puts "----------------------" +puts "Total Test Case : #{testTotalCnt} case" +puts "Skip Test Case : #{testSkipArray.size} case" +puts "Test Success : #{testSuccessArray.size} case" +puts "Test Errors : #{testFailArray.size} case" +puts + +if testSkipArray.size != 0 + puts "Test Skip Files : " + testSkipArray.each do |name| + printf("#{name} ") + end + puts + puts +end + +if testNotFoundArray.size != 0 + puts "Test Skip Files : " + testNotFoundArray.each do |name| + printf("#{name} ") + end + puts + puts +end + +if testFailArray.size != 0 + puts "Test Fail Files" + puts "---------------" + testFailArray.each do |name| + puts name + end + puts +end + diff --git a/test/remove_target_1.test b/test/remove_target_1.test new file mode 100755 index 0000000..da5a26d --- /dev/null +++ b/test/remove_target_1.test @@ -0,0 +1,5 @@ +#testCaseName = remove target 1 +#!result_check = regression_target1 +#result_cmd_count = 2 +"build-system/bin/sbi" remove regression_target1 +"build-system/bin/sbi" list diff --git a/test/remove_target_2.test b/test/remove_target_2.test new file mode 100755 index 0000000..aebbcbe --- /dev/null +++ b/test/remove_target_2.test @@ -0,0 +1,4 @@ +#testCaseName = remove target 2 +#result_check = ERR002: Invalid command options. See next usage +#result_cmd_count = 1 +"build-system/bin/sbi" remove diff --git a/test/remove_target_3.test b/test/remove_target_3.test new file mode 100755 index 0000000..1189e96 --- /dev/null +++ b/test/remove_target_3.test @@ -0,0 +1,4 @@ +#testCaseName = remove target 3 +#result_check = ERR007: The target +#result_cmd_count = 1 +"build-system/bin/sbi" remove remove_test3_not_exist_error_target diff --git a/test/remove_target_4.test b/test/remove_target_4.test new file mode 100755 index 0000000..2e95ed1 --- /dev/null +++ b/test/remove_target_4.test @@ -0,0 +1,5 @@ +#testCaseName = remove target 4 +#!result_check = D +#result_cmd_count = 2 +"build-system/bin/sbi" remove regression_target2 +"build-system/bin/sbi" list target diff --git a/test/show_information_1.test b/test/show_information_1.test new file mode 100755 index 0000000..80c3c43 --- /dev/null +++ b/test/show_information_1.test @@ -0,0 +1,5 @@ +#testCaseName = show information 1 +#result_check = CONFIG_BUILD_SYSTEM +#result_cmd_count = 1 +"build-system/bin/sbi" show regression_target1 +echo -n "TODO multi line chech " >&2 diff --git a/test/show_information_10.test b/test/show_information_10.test new file mode 100755 index 0000000..f3f1bc5 --- /dev/null +++ b/test/show_information_10.test @@ -0,0 +1,4 @@ +#testCaseName = show information 10 +#result_check = ERR004: +#result_cmd_count = 1 +"build-system/bin/sbi" show tool target_name_no_exist diff --git a/test/show_information_2.test b/test/show_information_2.test new file mode 100755 index 0000000..67b0c6b --- /dev/null +++ b/test/show_information_2.test @@ -0,0 +1,5 @@ +#testCaseName = show information 2 +#result_check = CONFIG_BUILD_SYSTEM +#result_cmd_count = 1 +"build-system/bin/sbi" show target regression_target1 +echo -n "TODO multi line check " >&2 diff --git a/test/show_information_3.test b/test/show_information_3.test new file mode 100755 index 0000000..2c022f6 --- /dev/null +++ b/test/show_information_3.test @@ -0,0 +1,5 @@ +#testCaseName = show information 3 +#result_check = ARCHITECTURE= +#result_cmd_count = 1 +"build-system/bin/sbi" show root $root_name +echo -n "TODO multi line check " >&2 diff --git a/test/show_information_4.test b/test/show_information_4.test new file mode 100755 index 0000000..9a1bebf --- /dev/null +++ b/test/show_information_4.test @@ -0,0 +1,4 @@ +#testCaseName = show information 4 +#result_check = COMPILER_PATH= +#result_cmd_count = 1 +"build-system/bin/sbi" show tool $tool_name diff --git a/test/show_information_5.test b/test/show_information_5.test new file mode 100755 index 0000000..6cf884e --- /dev/null +++ b/test/show_information_5.test @@ -0,0 +1,4 @@ +#testCaseName = show information 5 +#result_check = CONFIG_BUILD_SYSTEM +#result_cmd_count = 1 +"build-system/bin/sbi" show diff --git a/test/show_information_6.test b/test/show_information_6.test new file mode 100755 index 0000000..807cb7a --- /dev/null +++ b/test/show_information_6.test @@ -0,0 +1,4 @@ +#testCaseName = show information 6 +#result_check = ERR002: +#result_cmd_count = 1 +"build-system/bin/sbi" show invalid_option regression_target1 diff --git a/test/show_information_7.test b/test/show_information_7.test new file mode 100755 index 0000000..6232edc --- /dev/null +++ b/test/show_information_7.test @@ -0,0 +1,5 @@ +#testCaseName = show information 7 +#result_check = ERR008: +#result_cmd_count = 2 +echo -n "DEFAULT TARGET REMOVE NEEDED " >&2 +"build-system/bin/sbi" show diff --git a/test/show_information_8.test b/test/show_information_8.test new file mode 100755 index 0000000..fe1bc10 --- /dev/null +++ b/test/show_information_8.test @@ -0,0 +1,4 @@ +#testCaseName = show information 8 +#result_check = ERR007: +#result_cmd_count = 1 +"build-system/bin/sbi" show target regression_target_no_exist diff --git a/test/show_information_9.test b/test/show_information_9.test new file mode 100755 index 0000000..d09fac4 --- /dev/null +++ b/test/show_information_9.test @@ -0,0 +1,4 @@ +#testCaseName = show information 9 +#result_check = ERR003: +#result_cmd_count = 1 +"build-system/bin/sbi" show root root_name_no_exist diff --git a/test/test_execute b/test/test_execute new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/test/test_execute @@ -0,0 +1 @@ +#!/bin/sh -- 2.7.4