modified edk2/BaseTools/BuildEnv:
authorjljusten <jljusten@de2fecce-e211-0410-80a6-f3fac2684e05>
Tue, 11 Dec 2007 09:03:30 +0000 (09:03 +0000)
committerjljusten <jljusten@de2fecce-e211-0410-80a6-f3fac2684e05>
Tue, 11 Dec 2007 09:03:30 +0000 (09:03 +0000)
deleted  edk2/BaseTools/BuildEnv.py:
  Resolve https://edk2.tianocore.org/servlets/Scarab/id/EDKT557
    "All code in the edk2 tree must not require third party tools
     for running the provided tools."
  which refers to the usage of python by BuildEnv.py.

  /sigh

git-svn-id: https://edk2.tianocore.org/svn/edk2/trunk@4386 de2fecce-e211-0410-80a6-f3fac2684e05

edk2/BaseTools/BuildEnv
edk2/BaseTools/BuildEnv.py [deleted file]

index 08a84d4..8e7343a 100644 (file)
 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
+#
 # Setup the environment for unix-like systems running a bash-like shell.
 # This file must be "sourced" not merely executed. For example: ". edksetup.sh"
+#
 
-if [ ! -e ./BaseTools/BuildEnv.py ]
-then
-  echo Run this script from the base of your tree.  For example:
-  echo "  cd /Path/To/Edk/Root"
-  echo "  . BaseTools/BuildEnv"
-  return
-fi
+SetWorkspace() {
 
-#
-# First, we run a python tool that will ask the user to configure
-# the environment in a (relatively) user friendly manner.
-#
-python ./BaseTools/BuildEnv.py $*
+  #
+  # If WORKSPACE is already set, then we can return right now
+  #
+  if [ -n "$WORKSPACE" ]
+  then
+    return 0
+  fi
+
+  if [ ! ${BASH_SOURCE[0]} -ef ./BaseTools/BuildEnv ]
+  then
+    echo Run this script from the base of your tree.  For example:
+    echo "  cd /Path/To/Edk/Root"
+    echo "  . BaseTools/BuildEnv"
+    return -1
+  fi
+
+  #
+  # Set $WORKSPACE
+  #
+  export WORKSPACE=`pwd`
+
+  return 0
+
+}
+
+RestorePreviousConfiguration() {
+  #
+  # Restore previous configuration
+  #
+  PREVIOUS_CONF_FILE=Conf/BuildEnv.sh2
+  if [ -e $PREVIOUS_CONF_FILE ]
+  then
+    echo Loading previous configuration from \$WORKSPACE/$PREVIOUS_CONF_FILE
+    . $WORKSPACE/$PREVIOUS_CONF_FILE
+  fi
+}
+
+GenerateShellCodeToSetVariable() {
+  VARIABLE=$1
+  OUTPUT_FILE=$2
+  VAR_VALUE="echo \${${VARIABLE}}"
+  VAR_VALUE=`eval $VAR_VALUE`
+  echo "if [ -z \"\$${VARIABLE}\" ]"             >> $OUTPUT_FILE
+  echo "then"                                    >> $OUTPUT_FILE
+  echo "  export ${VARIABLE}=${VAR_VALUE}"       >> $OUTPUT_FILE
+  echo "fi"                                      >> $OUTPUT_FILE
+}
+
+GenerateShellCodeToUpdatePath() {
+  OUTPUT_FILE=$1
+  echo "if [ -e $EDK_TOOLS_PATH_BIN ]"                        >> $OUTPUT_FILE
+  echo "then"                                                 >> $OUTPUT_FILE
+  echo "  if [ "\${PATH/$EDK_TOOLS_PATH_BIN/}" == "\$PATH" ]" >> $OUTPUT_FILE
+  echo "  then"                                               >> $OUTPUT_FILE
+  echo "    export PATH=$EDK_TOOLS_PATH_BIN:\$PATH"           >> $OUTPUT_FILE
+  echo "  fi"                                                 >> $OUTPUT_FILE
+  echo "fi"                                                   >> $OUTPUT_FILE
+}
+
+StoreCurrentConfiguration() {
+  #
+  # Write configuration to a shell script to allow for configuration to be
+  # easily reloaded.
+  #
+  OUTPUT_FILE=Conf/BuildEnv.sh2
+  #echo Storing current configuration into \$WORKSPACE/$OUTPUT_FILE
+  OUTPUT_FILE=$WORKSPACE/$OUTPUT_FILE
+  echo "# Auto-generated by ${BASH_SOURCE[0]}" > $OUTPUT_FILE
+  GenerateShellCodeToSetVariable WORKSPACE $OUTPUT_FILE
+  GenerateShellCodeToSetVariable EDK_TOOLS_PATH $OUTPUT_FILE
+  GenerateShellCodeToUpdatePath $OUTPUT_FILE
+}
+
+SetEdkToolsPath() {
+
+  #
+  # If EDK_TOOLS_PATH is already set, then we can return right now
+  #
+  if [ -n "$EDK_TOOLS_PATH" ]
+  then
+    return 0
+  fi
+
+  #
+  # Figure out a uniq directory name from the uname command
+  #
+  UNAME_DIRNAME=`uname -sm`
+  UNAME_DIRNAME=${UNAME_DIRNAME// /-}
+  UNAME_DIRNAME=${UNAME_DIRNAME//\//-}
+
+  #
+  # Try $WORKSPACE/Conf/EdkTools
+  #
+  if [ -e $WORKSPACE/Conf/EdkTools ]
+  then
+    export EDK_TOOLS_PATH=$WORKSPACE/Conf/EdkTools
+    return 0
+  fi
+
+  #
+  # Try $WORKSPACE/Conf/BaseToolsSource
+  #
+  if [ -e $WORKSPACE/Conf/BaseToolsSource ]
+  then
+    export EDK_TOOLS_PATH=$WORKSPACE/Conf/BaseToolsSource
+    return 0
+  fi
+
+  #
+  # Try $WORKSPACE/BaseTools/Bin/$UNAME_DIRNAME
+  #
+  if [ -e $WORKSPACE/BaseTools/Bin/$UNAME_DIRNAME ]
+  then
+    export EDK_TOOLS_PATH=$WORKSPACE/BaseTools
+    return 0
+  fi
+
+  echo "Unable to determine EDK_TOOLS_PATH"
+  echo
+  echo "You may need to download the 'BaseTools' from buildtools.tianocore.org."
+  echo "After downloading, either create a symbolic link to the source at"
+  echo "\$WORKSPACE/Conf/BaseToolsSource, or set the EDK_TOOLS_PATH environment"
+  echo "variable."
+
+}
+
+GetBaseToolsBinSubDir() {
+  #
+  # Figure out a uniq directory name from the uname command
+  #
+  UNAME_DIRNAME=`uname -sm`
+  UNAME_DIRNAME=${UNAME_DIRNAME// /-}
+  UNAME_DIRNAME=${UNAME_DIRNAME//\//-}
+  echo $UNAME_DIRNAME
+}
+
+GetEdkToolsPathBinDirectory() {
+  #
+  # Figure out a uniq directory name from the uname command
+  #
+  BIN_SUB_DIR=`GetBaseToolsBinSubDir`
+
+  if [ -e $EDK_TOOLS_PATH/PseudoBin/$BIN_SUB_DIR ]
+  then
+    EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/PseudoBin/$BIN_SUB_DIR
+  else
+    EDK_TOOLS_PATH_BIN=$EDK_TOOLS_PATH/Bin/$BIN_SUB_DIR
+  fi
+
+  echo $EDK_TOOLS_PATH_BIN
+}
+
+AddEdkToolsToPath() {
+
+  #
+  # If EDK_TOOLS_PATH is not set, then we cannot update PATH
+  #
+  if [ -z "$EDK_TOOLS_PATH" ]
+  then
+    return -1
+  fi
+
+  EDK_TOOLS_PATH_BIN=`GetEdkToolsPathBinDirectory`
+
+  if [ ! -e $EDK_TOOLS_PATH_BIN ]
+  then
+    echo "Unable to find expected bin path under \$EDK_TOOLS_PATH!"
+    echo "> $EDK_TOOLS_PATH_BIN"
+    return -1
+  fi
+
+  if [ "${PATH/$EDK_TOOLS_PATH_BIN/}" == "$PATH" ]
+  then
+    export PATH=$EDK_TOOLS_PATH_BIN:$PATH
+    return 0
+  fi
+
+}
+
+CopySingleTemplateFile() {
+
+  SRC_FILENAME=BaseTools/Conf/$1.template
+  DST_FILENAME=Conf/$1.txt
+
+  if [ -e $WORKSPACE/$DST_FILENAME ]
+  then
+    return
+  fi
+
+  echo "Copying \$WORKSPACE/$SRC_FILENAME"
+  echo "     to \$WORKSPACE/$DST_FILENAME"
+  SRC_FILENAME=$WORKSPACE/$SRC_FILENAME
+  DST_FILENAME=$WORKSPACE/$DST_FILENAME
+  cp $SRC_FILENAME $DST_FILENAME
+
+}
+
+CopyTemplateFiles() {
+
+  CopySingleTemplateFile build_rule
+  CopySingleTemplateFile FrameworkDatabase
+  CopySingleTemplateFile tools_def
+  CopySingleTemplateFile target
+
+}
+
+ScriptMain() {
+
+  SetWorkspace
+  if [ -z $WORKSPACE ]
+  then
+    echo "Failure setting WORKSPACE"
+    return -1
+  fi
+
+  RestorePreviousConfiguration
+
+  SetEdkToolsPath
+  if [ -z $EDK_TOOLS_PATH ]
+  then
+    return -1
+  fi
+
+  AddEdkToolsToPath
+  if [ $? -ne 0 ]
+  then
+    echo "Failure adding EDK Tools into PATH!"
+    return -1
+  fi
+
+  StoreCurrentConfiguration
+
+  echo WORKSPACE: $WORKSPACE
+  echo EDK_TOOLS_PATH: $EDK_TOOLS_PATH
+
+  CopyTemplateFiles
+
+}
 
 #
-# The python tool will write ./Conf/BuildEnv.sh to actually configure
-# the environment.
+# Run the main function
 #
-if [ -e ./Conf/BuildEnv.sh ]
-then
-  . ./Conf/BuildEnv.sh
-else
-  echo There was a failure while trying to setup the environment!
-fi
-
+ScriptMain
 
diff --git a/edk2/BaseTools/BuildEnv.py b/edk2/BaseTools/BuildEnv.py
deleted file mode 100755 (executable)
index b065861..0000000
+++ /dev/null
@@ -1,287 +0,0 @@
-## @file BuildEnv.py\r
-# Initialize Environment for building\r
-#\r
-#  Copyright (c) 2007, Intel Corporation\r
-#\r
-#  All rights reserved. This program and the accompanying materials\r
-#  are licensed and made available under the terms and conditions of the BSD License\r
-#  which accompanies this distribution.  The full text of the license may be found at\r
-#  http://opensource.org/licenses/bsd-license.php\r
-#\r
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-#\r
-\r
-##\r
-# Import Modules\r
-#\r
-import os\r
-import os.path\r
-import pickle\r
-import shutil\r
-import sys\r
-\r
-from optparse import OptionParser\r
-\r
-# Version and Copyright\r
-VersionNumber = "0.01"\r
-__version__ = "%prog Version " + VersionNumber\r
-__copyright__ = "Copyright (c) 2007, Intel Corporation  All rights reserved."\r
-\r
-class SetupBuildEnvironmentApp:\r
-\r
-  def __init__(self):\r
-    (self.Opt, self.Args) = self.ProcessCommandLine()\r
-    self.SetupDefaults()\r
-    self.DetermineEnvironment()\r
-    self.DeleteEnvironmentConfigurationScript()\r
-    self.CopyTemplates()\r
-    self.WriteEnvironmentConfigurationScript()\r
-\r
-  def SetupDefaults(self):\r
-    self.itemsToConfigure = (\r
-      'compiler',\r
-      #'compiler-prefix',\r
-      'templates',\r
-      )\r
-\r
-    self.defaults = {\r
-      'compiler': {\r
-        'options': ('gcc', 'icc'),\r
-        'default': 'gcc',\r
-        },\r
-      'compiler-prefix': {\r
-        'options': ('/usr/bin', '/usr/bin/x86_64-pc-mingw32-'),\r
-        'freeform': True,\r
-        },\r
-      'templates': {\r
-        'description': 'templates and Conf directory',\r
-        'options': (\r
-          'copy once (no-overwrite)',\r
-          'copy with overwrite',\r
-          'symlink to templates',\r
-          'do nothing',\r
-          ),\r
-        'default': 'copy once (no-overwrite)',\r
-        },\r
-      }\r
-\r
-  def ProcessCommandLine(self):\r
-    Parser = OptionParser(description=__copyright__,version=__version__,prog="BaseTools/BuildEnv")\r
-    Parser.add_option("-q", "--quiet", action="store_true", type=None, help="Disable all messages except FATAL ERRORS.")\r
-    Parser.add_option("-v", "--verbose", action="store_true", type=None, help="Turn on verbose output with informational messages printed, "\\r
-                                                                               "including library instances selected, final dependency expression, "\\r
-                                                                               "and warning messages, etc.")\r
-    Parser.add_option("-d", "--debug", action="store", type="int", help="Enable debug messages at specified level.")\r
-\r
-    if os.environ.has_key('WORKSPACE'):\r
-      default = os.environ['WORKSPACE']\r
-    else:\r
-      default = os.getcwd()\r
-    Parser.add_option("--workspace", action="store", type="string", help="Base director of tree to configure", default=default)\r
-\r
-    (Opt, Args)=Parser.parse_args()\r
-    Parser.print_version()\r
-\r
-    return (Opt, Args)\r
-\r
-  def DetermineEnvironment(self):\r
-    confFilename = os.path.join(os.path.expanduser('~'), '.edk-build-env.pickle')\r
-    try:\r
-      confFile = open(confFilename, 'r')\r
-      conf = pickle.load(confFile)\r
-      confFile.close()\r
-    except Exception:\r
-      conf = {}\r
-    self.conf = conf\r
-\r
-    for item in self.itemsToConfigure:\r
-      if not conf.has_key(item):\r
-        self.AskForValueOfOption(item)\r
-\r
-    while True:\r
-      self.SummarizeCurrentState()\r
-\r
-      if not self.Opt.quiet:\r
-        response = raw_input('Would you like to change anything? (default=no): ')\r
-        response = response.strip()\r
-      else:\r
-        response = ''\r
-\r
-      if response.lower() in ('', 'n', 'no'):\r
-        break\r
-\r
-      for item in self.itemsToConfigure:\r
-        self.AskForValueOfOption(item)\r
-\r
-    confFile = open(confFilename, 'w')\r
-    pickle.dump(conf, confFile)\r
-    confFile.close()\r
-\r
-  def AskForValueOfOption(self, option):\r
-\r
-    options = self.defaults[option]['options']\r
-\r
-    if self.defaults[option].has_key('default'):\r
-      default = self.defaults[option]['default']\r
-    else:\r
-      default = None\r
-\r
-    if self.defaults[option].has_key('freeform'):\r
-      freeform = self.defaults[option]['freeform']\r
-    else:\r
-      freeform = False\r
-\r
-    if self.defaults[option].has_key('description'):\r
-      description = self.defaults[option]['description']\r
-    else:\r
-      description = option\r
-\r
-    conf = self.conf\r
-    if conf.has_key(option):\r
-      default = conf[option]\r
-    options = list(options) # in case options came in as a tuple\r
-    assert((default == '') or (default is None) or ('' not in options))\r
-    if (default is not None) and (default not in options):\r
-      options.append(default)\r
-    if (freeform and ('' not in options)):\r
-      options.append('')\r
-    options.sort()\r
-    while True:\r
-      print\r
-      if len(options) > 0:\r
-        print 'Options for', description\r
-        for i in range(len(options)):\r
-          print '  %d.' % (i + 1),\r
-          if options[i] != '':\r
-            print options[i],\r
-          else:\r
-            print '(empty string)',\r
-          if options[i] == default:\r
-            print '(default)'\r
-          else:\r
-            print\r
-\r
-      if len(options) > 0:\r
-        prompt = 'Select number or type value: '\r
-      else:\r
-        prompt = 'Type value: '\r
-      response = raw_input(prompt)\r
-      response = response.strip()\r
-\r
-      if response.isdigit():\r
-        response = int(response)\r
-        if response > len(options):\r
-          print 'ERROR: Invalid number selection!'\r
-          continue\r
-        response = options[response - 1]\r
-      elif (response == '') and (default is not None):\r
-        response = default\r
-\r
-      if (not freeform) and (response not in options):\r
-        print 'ERROR: Invalid selection! (must be from list)'\r
-        continue\r
-\r
-      break\r
-\r
-    conf[option] = response\r
-    print 'Using', conf[option], 'for', description\r
-\r
-  def SummarizeCurrentState(self):\r
-    print\r
-    print 'Current configuration:'\r
-    conf = self.conf\r
-    for item in self.itemsToConfigure:\r
-      value = conf[item]\r
-      if value == '': value = '(empty string)'\r
-      print ' ', item, '->', value\r
-\r
-  def CopyTemplates(self):\r
-    todo = self.conf['templates']\r
-    workspace = os.path.realpath(self.Opt.workspace)\r
-    templatesDir = \\r
-      os.path.join(workspace, 'BaseTools', 'Conf')\r
-    confDir = \\r
-      os.path.join(workspace, 'Conf')\r
-    print\r
-    print 'Templates & Conf directory'\r
-    print '  Templates dir:', self.RelativeToWorkspace(templatesDir)\r
-    for filename in os.listdir(templatesDir):\r
-      if not filename.endswith('.template'): continue\r
-\r
-      srcFilename = os.path.join(templatesDir, filename)\r
-      destFilename = os.path.join(confDir, filename[:-len('template')] + 'txt')\r
-      print ' ', self.RelativeToWorkspace(destFilename),\r
-\r
-      if todo == 'copy once (no-overwrite)':\r
-        if os.path.exists(destFilename):\r
-          print '[skipped, already exists]'\r
-        else:\r
-          shutil.copy(srcFilename, destFilename)\r
-          print '[copied]'\r
-      elif todo == 'copy with overwrite':\r
-        overwrite = ''\r
-        if os.path.exists(destFilename):\r
-          os.remove(destFilename)\r
-          overwrite = ', overwritten'\r
-        shutil.copy(srcFilename, destFilename)\r
-        print '[copied' + overwrite + ']'\r
-      elif todo == 'symlink to templates':\r
-        if os.path.islink(destFilename) or os.path.exists(destFilename):\r
-          if not os.path.islink(destFilename):\r
-            raise Exception, '%s is not a symlink! (remove file if you want to start using symlinks)' % \\r
-                             (self.RelativeToWorkspace(destFilename))\r
-          os.remove(destFilename)\r
-        os.symlink(os.path.join('..', self.RelativeToWorkspace(srcFilename)), destFilename)\r
-        print '[symlinked]'\r
-      elif todo == 'do nothing':\r
-        print '[skipped by user request]'\r
-      else:\r
-        raise Exception, 'Unknown action for templates&conf: %s' % todo\r
-\r
-  def DeleteEnvironmentConfigurationScript(self):\r
-    workspace = os.path.realpath(self.Opt.workspace)\r
-    scriptFilename = os.path.join(workspace, 'Conf', 'BuildEnv.sh')\r
-    if os.path.exists(scriptFilename):\r
-      os.remove(scriptFilename)\r
-\r
-  def WriteEnvironmentConfigurationScript(self):\r
-    workspace = os.path.realpath(self.Opt.workspace)\r
-    scriptFilename = os.path.join(workspace, 'Conf', 'BuildEnv.sh')\r
-    print\r
-    print 'Storing environment configuration into',\r
-    print   self.RelativeToWorkspace(scriptFilename)\r
-    script = open(scriptFilename, 'w')\r
-\r
-    print >> script, 'export WORKSPACE="%s"' % workspace\r
-    print >> script, 'export TOOLCHAIN="%s"' % self.conf['compiler']\r
-    #print >> script, 'export COMPILER_SUITE_PATH_PREFIX="%s"' % self.conf['compiler-prefix']\r
-\r
-    EDK_TOOLS_PATH = os.path.join(workspace, 'BaseTools')\r
-    print >> script, 'if [ $EDK_TOOLS_PATH=="" ]'\r
-    print >> script, 'then'\r
-    print >> script, '  export EDK_TOOLS_PATH="%s"' % EDK_TOOLS_PATH\r
-    print >> script, 'fi'\r
-\r
-    #\r
-    # Change PATH variable\r
-    #\r
-    newPath = os.environ['PATH'].split(os.path.pathsep)\r
-    binDir = \\r
-      os.path.join(workspace, 'BaseTools', 'Bin', sys.platform.title())\r
-    if binDir not in newPath:\r
-      newPath.append(binDir)\r
-    newPath = os.path.pathsep.join(newPath)\r
-    print >> script, 'export PATH=%s' % newPath\r
-\r
-    script.close()\r
-\r
-  def RelativeToWorkspace(self, path):\r
-    workspace = os.path.realpath(self.Opt.workspace)\r
-    for prefix in (workspace + os.path.sep, workspace):\r
-      if path.startswith(prefix):\r
-        return path[len(prefix):]\r
-\r
-if __name__ == '__main__':\r
-  SetupBuildEnvironmentApp()\r
-\r