From: jjin9 Date: Fri, 1 Sep 2006 09:21:38 +0000 (+0000) Subject: add ContextTool to workspace/Tools X-Git-Tag: edk2-stable201903~24447 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=c74c7a43020713e9d9e11098e3118472d920c2ff add ContextTool to workspace/Tools In directory: workspace/Tools/bin please type: ContextTool to see the usage help git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1427 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/Tools/Source/ContextTool/build.xml b/Tools/Source/ContextTool/build.xml new file mode 100644 index 0000000000..13567799b4 --- /dev/null +++ b/Tools/Source/ContextTool/build.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tools/Source/ContextTool/org/tianocore/context/ContextMain.java b/Tools/Source/ContextTool/org/tianocore/context/ContextMain.java new file mode 100644 index 0000000000..991d81a357 --- /dev/null +++ b/Tools/Source/ContextTool/org/tianocore/context/ContextMain.java @@ -0,0 +1,17 @@ +package org.tianocore.context; + +public class ContextMain { + + public static void main(String[] args) { + + if(ParseParameter.checkParameter(args) == false){ + System.exit(0); + } + + if (TargetFile.parsePath("target.txt") == false) { + System.exit(0); + } + + System.out.printf("%n%s", "Target.txt generate successfully!"); + } +} diff --git a/Tools/Source/ContextTool/org/tianocore/context/HelpInfo.java b/Tools/Source/ContextTool/org/tianocore/context/HelpInfo.java new file mode 100644 index 0000000000..09daf023b6 --- /dev/null +++ b/Tools/Source/ContextTool/org/tianocore/context/HelpInfo.java @@ -0,0 +1,109 @@ +package org.tianocore.context; + +public class HelpInfo { + + + /** + * output the tools usage guide + * @param no input parameter + * @return no return value + **/ + public static void outputUsageInfo() { + System.out.printf("\n%s", UsageInfoString); + System.out.printf("\n%s", DetailOfOptionString); + + for (int i = 0; i < 6; i++) { + outputSubUsageInfo(UsageString[i], UsageStringInfo[i]); + } + } + + /** + * output the usage info which bases on cmd option + * @param String str1 : the cmd option + * String str2 : the detail of cmd option + * @return no return value + **/ + private static void outputSubUsageInfo(String str1, String str2) { + splitString(str2); + if (substrnum > 0) { + System.out.printf("\n%4s %-30s %s", "", str1, substr[0]); + for (int i = 1; i < substrnum; i++) { + if (substr[i] != null) + System.out.printf("\n%4s %-30s %s", "", "", substr[i]); + } + substrnum = 0; + } else { + System.out.printf("\n%4s %-30s %s", "", str1, str2); + } + } + + /** + * according to the output width, split the detail info + * @param String str :the detail info + * @return no return value + **/ + private static void splitString(String str) { + int strlength = str.length(); + if (strlength > MaxSrtingLength) { + + //we should modify the array to list, for it is strange to + 2 + substrnum = strlength / MaxSrtingLength + 2; + String[] tokens = str.split("[ ]", 0); + substr = new String[substrnum]; + int templength = 0; + int j = 0; + int start = 0; + int end = 0; + for (int i = 0; i < tokens.length; i++) { + if ((templength = end + tokens[i].length() + 1) < (MaxSrtingLength + start)) { + end = templength; + } else { + substr[j++] = str.substring(start, end); + start = end; + i = i - 1; + } + } + substr[j] = str.substring(start, end - 1); + } + } + + private static String[] substr = null; + + private static int substrnum = 0; + + private static final int MaxSrtingLength = 40; + + private static final String UsageInfoString = "Usage: context [-option1] [args] [-option2] [args] ..."; + + private static final String DetailOfOptionString = "Where options include:"; + + private static final String HString = "-h"; + + private static final String HStringInfo = "print this help message"; + + private static final String AString = "-a "; + + private static final String AStringInfo = "what kind of architechure is the binary target, such as IA32, IA64, X64, EBC, or ARM. Multiple values can be specified on a single line, using space to separate the values."; + + private static final String CString = "-c "; + + private static final String CStringInfo = "Assign a txt file, which specify the tools to use for the build and must be located in the path: WORKSPACE/Tools/Conf/. If no file is specified, the default filename is \"tools_def.txt\""; + + private static final String NString = "-n "; + + private static final String NStringInfo = "Specify the TagName, such as GCC, MSFT, which are defined in the \"tool_definition_file.txt\""; + + private static final String PString = "-p <*.fpd>"; + + private static final String PStringInfo = "Specify the WORKSPACE relative Path and Filename of platform FPD file that will be used for the build."; + + private static final String TString = "-t "; + + private static final String TStringInfo = "What kind of the version is the binary target, such as DEBUG, RELEASE. Multiple values can be specified on a single line, using space to separate the values."; + + private static final String[] UsageString = { HString, AString, CString, + NString, PString, TString }; + + private static final String[] UsageStringInfo = { HStringInfo, AStringInfo, + CStringInfo, NStringInfo, PStringInfo, TStringInfo }; +} diff --git a/Tools/Source/ContextTool/org/tianocore/context/ParseParameter.java b/Tools/Source/ContextTool/org/tianocore/context/ParseParameter.java new file mode 100644 index 0000000000..d74801e279 --- /dev/null +++ b/Tools/Source/ContextTool/org/tianocore/context/ParseParameter.java @@ -0,0 +1,86 @@ +package org.tianocore.context; + +public class ParseParameter { + + + /** + * check the validity of user's input args + * @param args -- user's input + * @return true or false + **/ + public static boolean checkParameter(String[] args) { + + if(args.length == 0){ + HelpInfo.outputUsageInfo(); + return false; + } else { + if( args[0].charAt(0) != '-' ){ + HelpInfo.outputUsageInfo(); + return false; + } + for(int i=0; i ParseParameter.length) { + bw.write(ParseParameter.pstr); + } else { + bw.write(textLine); + } + bw.newLine(); + } else if (textLine.indexOf("TARGET_ARCH") != -1) { + if(ParseParameter.astr.length() > ParseParameter.length) { + bw.write(ParseParameter.astr); + } else { + bw.write(textLine); + } + bw.newLine(); + } else if (textLine.indexOf("TARGET") != -1) { + if(ParseParameter.tstr.length() > ParseParameter.length) { + bw.write(ParseParameter.tstr); + } else { + bw.write(textLine); + } + bw.newLine(); + } else if (textLine.indexOf("TOOL_CHAIN_CONF") != -1) { + if(ParseParameter.cstr.length() > ParseParameter.length) { + bw.write(ParseParameter.cstr); + } else { + bw.write(textLine); + } + bw.newLine(); + } else if (textLine.indexOf("TOOL_CHAIN_TAG") != -1) { + if(ParseParameter.nstr.length() > ParseParameter.length) { + bw.write(ParseParameter.nstr); + } else { + bw.write(textLine); + } + bw.newLine(); + } + } + } + } catch (IOException e) { + System.out.println("\n# read or write file error!"); + return false; + } + + try { + br.close(); + bw.close(); + } catch (IOException e) { + System.out + .println("\n# close BufferedReader&BufferedWriter error"); + return false; + } + + if (Fd.delete() == false) { + System.out.println("\n# delete file failed !"); + return false; + } + if (TempFd.renameTo(Fd) == false) { + System.out.println("\n# rename file failed !"); + return false; + } + + return true; + } + + /** + * according to user's input args, write the file directly + * @param File fd : the File of the target file + * @return true or false + **/ + private static boolean writeFile(File fd) { + + if (fd.canWrite() != true) + return false; + + FileOutputStream outputFile = null; + try { + outputFile = new FileOutputStream(fd); + } catch (FileNotFoundException e) { + System.out + .println("\n# can't find the file when open the output stream !"); + return false; + } + FileChannel outputChannel = outputFile.getChannel(); + + ByteBuffer[] buffers = new ByteBuffer[5]; + buffers[0] = ByteBuffer.allocate(ParseParameter.pstr.toString().length()); + buffers[1] = ByteBuffer.allocate(ParseParameter.tstr.toString().length()); + buffers[2] = ByteBuffer.allocate(ParseParameter.astr.toString().length()); + buffers[3] = ByteBuffer.allocate(ParseParameter.cstr.toString().length()); + buffers[4] = ByteBuffer.allocate(ParseParameter.nstr.toString().length()); + + buffers[0].put(ParseParameter.pstr.toString().getBytes()).flip(); + buffers[1].put(ParseParameter.tstr.toString().getBytes()).flip(); + buffers[2].put(ParseParameter.astr.toString().getBytes()).flip(); + buffers[3].put(ParseParameter.cstr.toString().getBytes()).flip(); + buffers[4].put(ParseParameter.nstr.toString().getBytes()).flip(); + + try { + ByteBuffer bufofCP = ByteBuffer.allocate(Copyright.length()); + bufofCP.put(Copyright.getBytes()).flip(); + outputChannel.write(bufofCP); + + ByteBuffer bufofFI = ByteBuffer.allocate(Fileinfo.length()); + bufofFI.put(Fileinfo.getBytes()).flip(); + outputChannel.write(bufofFI); + + ByteBuffer buffer0 = ByteBuffer.allocate(pusage.length()); + buffer0.put(pusage.getBytes()).flip(); + outputChannel.write(buffer0); + outputChannel.write(buffers[0]); + + ByteBuffer buffer1 = ByteBuffer.allocate(tusage.length()); + buffer1.put(tusage.getBytes()).flip(); + outputChannel.write(buffer1); + outputChannel.write(buffers[1]); + + ByteBuffer buffer2 = ByteBuffer.allocate(ausage.length()); + buffer2.put(ausage.getBytes()).flip(); + outputChannel.write(buffer2); + outputChannel.write(buffers[2]); + + ByteBuffer buffer3 = ByteBuffer.allocate(cusage.length()); + buffer3.put(cusage.getBytes()).flip(); + outputChannel.write(buffer3); + outputChannel.write(buffers[3]); + + ByteBuffer buffer4 = ByteBuffer.allocate(nusage.length()); + buffer4.put(nusage.getBytes()).flip(); + outputChannel.write(buffer4); + outputChannel.write(buffers[4]); + + outputFile.close(); + } catch (IOException e) { + System.out.println("\n# The operations of file failed !"); + return false; + } + return true; + } + + /// + /// point to target.txttmp, a temp file, which is created and deleted during the tool's runtime. + /// + private static File TempFd; + + /// + /// point to target.txt. + /// + private static File Fd; + + private static final String Copyright = "#\n" + + "# Copyright (c) 2006, Intel Corporation\n" + + "#\n" + + "# All rights reserved. This program and the accompanying materials\n" + + "# are licensed and made available under the terms and conditions of the BSD License\n" + + "# which accompanies this distribution. The full text of the license may be found at\n" + + "# http://opensource.org/licenses/bsd-license.php\n" + + "\n" + + "# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN \"AS IS\" BASIS,\n" + + "# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\n"; + + private static final String Fileinfo = "#\n" + + "# Filename: target.template\n" + + "#\n" + + "# ALL Paths are Relative to WORKSPACE\n" + + "\n" + + "# Separate multiple LIST entries with a SINGLE SPACE character, do not use comma characters.\n" + + "# Un-set an option by either commenting out the line, or not setting a value.\n"; + + private static final String pusage = "#\n" + + "# PROPERTY Type Use Description\n" + + "# ---------------- -------- -------- -----------------------------------------------------------\n" + + "# ACTIVE_PLATFORM Filename Recommended Specify the WORKSPACE relative Path and Filename\n" + + "# of the platform FPD file that will be used for the build\n" + + "# This line is required if and only if the current working\n" + + "# directory does not contain one or more FPD files.\n"; + + private static final String tusage = "\n\n" + + "# TARGET List Optional Zero or more of the following: DEBUG, RELEASE, \n" + + "# UserDefined; separated by a space character. \n" + + "# If the line is missing or no value is specified, all\n" + + "# valid targets specified in the FPD file will attempt \n" + + "# to be built. The following line will build all platform\n" + + "# targets.\n"; + + private static final String ausage = "\n\n" + + "# TARGET_ARCH List Optional What kind of architecture is the binary being target for.\n" + + "# One, or more, of the following, IA32, IA64, X64, EBC or ARM.\n" + + "# Multiple values can be specified on a single line, using \n" + + "# space charaters to separate the values. These are used \n" + + "# during the parsing of an FPD file, restricting the build\n" + + "# output target(s.)\n" + + "# The Build Target ARCH is determined by a logical AND of:\n" + + "# FPD BuildOptions: tag\n" + + "# If not specified, then all valid architectures specified \n" + + "# in the FPD file, for which tools are available, will be \n" + + "# built.\n"; + + private static final String cusage = "\n\n" + + "# TOOL_DEFINITION_FILE Filename Optional Specify the name of the filename to use for specifying \n" + + "# the tools to use for the build. If not specified, \n" + + "# tools_def.txt will be used for the build. This file \n" + + "# MUST be located in the WORKSPACE/Tools/Conf directory.\n"; + + private static final String nusage = "\n\n" + + "# TAGNAME List Optional Specify the name(s) of the tools_def.txt TagName to use.\n" + + "# If not specified, all applicable TagName tools will be \n" + + "# used for the build. The list uses space character separation.\n"; +} diff --git a/Tools/bin/ContextTool b/Tools/bin/ContextTool new file mode 100644 index 0000000000..3bd23112a8 --- /dev/null +++ b/Tools/bin/ContextTool @@ -0,0 +1,15 @@ +# +# Copyright (c) 2006, Intel Corporation +# All rights reserved. This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# + +export CLASSPATH=$CLASSPATH:$WORKSPACE/Tools/bin/ContextTool.jar + +# Run Framework Wizard +java org.tianocore.context.ContextMain diff --git a/Tools/bin/ContextTool.bat b/Tools/bin/ContextTool.bat new file mode 100644 index 0000000000..69ca4fc2e2 --- /dev/null +++ b/Tools/bin/ContextTool.bat @@ -0,0 +1,73 @@ +@REM +@REM Copyright (c) 2006, Intel Corporation +@REM All rights reserved. This program and the accompanying materials +@REM are licensed and made available under the terms and conditions of the BSD License +@REM which accompanies this distribution. The full text of the license may be found at +@REM http://opensource.org/licenses/bsd-license.php +@REM +@REM THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +@REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +@REM + +@echo off + +:check_java +if "%JAVA_HOME%"=="" goto no_jdk +:check_wks +if "%WORKSPACE%"=="" goto no_wks +:check_ant +if "%ANT_HOME%"=="" goto no_ant +:check_xmlbeans +if "%XMLBEANS_HOME%"=="" goto no_xmlbeans +:check_surfacearea +if not exist %WORKSPACE%\Tools\Jars\SurfaceArea.jar ( + goto no_surfacearea +) +:check_ContextTool +if not exist %WORKSPACE%\Tools\Jars\ContextTool.jar ( + goto no_ContextTool +) + +@REM Run Framework Wizard +call "java" -cp %CLASSPATH%;%WORKSPACE%\Tools\Jars\ContextTool.jar org.tianocore.context.ContextMain %* + +goto end + +:no_jdk +@echo. +@echo !!! Please set JAVA_HOME !!! +@echo. +goto check_wks + +:no_wks +@echo. +@echo !!! Please set WORKSPACE !!! +@echo. +goto check_ant + +:no_ant +@echo. +@echo !!! Please set ANT_HOME !!! +@echo. +goto check_xmlbeans + +:no_xmlbeans +@echo. +@echo !!! Please set XMLBEANS_HOME !!! +@echo. +goto end + +:no_surfacearea +@echo. +@echo !!! Please run edksetup.bat to build SurfaceArea.jar !!! +@echo. +goto end + +:no_ContextTool +@echo. +@echo !!! Please run edksetup.bat to build ContextTool.jar !!! +@echo. +goto end + +:end +@echo on diff --git a/Tools/build.xml b/Tools/build.xml index 9e07a3d5e3..06cc9211d7 100644 --- a/Tools/build.xml +++ b/Tools/build.xml @@ -39,6 +39,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Source/Cpptasks/build.xml Source/FrameworkWizard/build.xml Source/MigrationTools/build.xml + Source/ContextTool/build.xml "/> @@ -99,6 +100,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Source/SurfaceArea/build.xml Source/TianoTools/build.xml Source/MigrationTools/build.xml + Source/ContextTool/build.xml "/> @@ -131,6 +133,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Source/SurfaceArea/build.xml Source/TianoTools/build.xml Source/MigrationTools/build.xml + Source/ContextTool/build.xml "/>