⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243527 in webkit


Ignore:
Timestamp:
Mar 26, 2019, 4:51:10 PM (7 years ago)
Author:
Keith Rollin
Message:

Update the way generate-xcfilelists returns strings from functions
https://bugs.webkit.org/show_bug.cgi?id=195975
<rdar://problem/49040807>

Reviewed by Dean Jackson.

There are places where generate-xcfilelists executes assignments with
statements like:

FOO=$(some_function)

where "some_function" return a string by echoing it. E.g.

some_function()
{

echo "Hello, World"

}

This is a common idiom, but it has a problem if "some_function" needs
to call "exit" in an attempt to halt the entire script right then and
there. Since "some_function" is called inside of $(), it's being
executed in a sub-shell. Calling exit in that sub-shell simply exits
that shell; it doesn't not exit the outer shell in which the main part
of the script is still running. As such, the main script keeps
executing when the intent was for the script to halt.

The solution to this is to use a different idiom for returning
strings. The one we now is to pass in the name of the variable to
receive the string result:

some_function()
{

variable_name=$1
eval $variable_name ="Hello, World"

}

The call site now looks like

some_function FOO

Because there's no invocation of a sub-shell, some_function can now
call "exit" if it wants to, and the entire script will exit at that
point.

  • Scripts/generate-xcfilelists:
Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r243523 r243527  
     12019-03-26  Keith Rollin  <krollin@apple.com>
     2
     3        Update the way generate-xcfilelists returns strings from functions
     4        https://bugs.webkit.org/show_bug.cgi?id=195975
     5        <rdar://problem/49040807>
     6
     7        Reviewed by Dean Jackson.
     8
     9        There are places where generate-xcfilelists executes assignments with
     10        statements like:
     11
     12            FOO=$(some_function)
     13
     14        where "some_function" return a string by echoing it. E.g.
     15
     16            some_function()
     17            {
     18                echo "Hello, World"
     19            }
     20
     21        This is a common idiom, but it has a problem if "some_function" needs
     22        to call "exit" in an attempt to halt the entire script right then and
     23        there. Since "some_function" is called inside of $(), it's being
     24        executed in a sub-shell. Calling exit in that sub-shell simply exits
     25        that shell; it doesn't not exit the outer shell in which the main part
     26        of the script is still running. As such, the main script keeps
     27        executing when the intent was for the script to halt.
     28
     29        The solution to this is to use a different idiom for returning
     30        strings. The one we now is to pass in the name of the variable to
     31        receive the string result:
     32
     33            some_function()
     34            {
     35                variable_name=$1
     36                eval $variable_name ="Hello, World"
     37            }
     38
     39        The call site now looks like
     40
     41            some_function FOO
     42
     43        Because there's no invocation of a sub-shell, some_function can now
     44        call "exit" if it wants to, and the entire script will exit at that
     45        point.
     46
     47        * Scripts/generate-xcfilelists:
     48
    1492019-03-26  Chris Dumez  <cdumez@apple.com>
    250
  • trunk/Tools/Scripts/generate-xcfilelists

    r243188 r243527  
    608608
    609609    local GX_PROVISIONAL_CONFIGURATION=$(echo "$1" | tr '[:upper:]' '[:lower:]')
    610 
    611     [[ "${GX_PROVISIONAL_CONFIGURATION}" == "" ]] && { echo ""; return; }
    612 
    613     [[ "${GX_PROVISIONAL_CONFIGURATION}" == "debug" ]] && { echo "Debug"; return; }
    614     [[ "${GX_PROVISIONAL_CONFIGURATION}" == "release" ]] && { echo "Release"; return; }
    615     [[ "${GX_PROVISIONAL_CONFIGURATION}" == "production" ]] && { echo "Production"; return; }
    616     [[ "${GX_PROVISIONAL_CONFIGURATION}" == "profiling" ]] && { echo "Profiling"; return; }
     610    local GX_RESULT=$2
     611
     612    [[ "${GX_PROVISIONAL_CONFIGURATION}" == "" ]]           && { eval $GX_RESULT=""; return; }
     613
     614    [[ "${GX_PROVISIONAL_CONFIGURATION}" == "debug" ]]      && { eval $GX_RESULT="Debug"; return; }
     615    [[ "${GX_PROVISIONAL_CONFIGURATION}" == "release" ]]    && { eval $GX_RESULT="Release"; return; }
     616    [[ "${GX_PROVISIONAL_CONFIGURATION}" == "production" ]] && { eval $GX_RESULT="Production"; return; }
     617    [[ "${GX_PROVISIONAL_CONFIGURATION}" == "profiling" ]]  && { eval $GX_RESULT="Profiling"; return; }
    617618
    618619    die "Unrecognized configuration: $1"
     
    625626
    626627    local GX_PROVISIONAL_PLATFORM_NAME=$(echo "$1" | tr '[:upper:]' '[:lower:]')
    627 
    628     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "" ]] && { echo ""; return; }
    629 
    630     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "ios" ]] && { echo "iphoneos"; return; }
    631     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "iphone" ]] && { echo "iphoneos"; return; }
    632     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "ipad" ]] && { echo "iphoneos"; return; }
    633     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "iphoneos" ]] && { echo "iphoneos"; return; }
    634     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "iphonesimulator" ]] && { echo "iphonesimulator"; return; }
    635 
    636     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "mac" ]] && { echo "macosx"; return; }
    637     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "osx" ]] && { echo "macosx"; return; }
    638     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "macos" ]] && { echo "macosx"; return; }
    639     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "macosx" ]] && { echo "macosx"; return; }
    640 
    641     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "tvos" ]] && { echo "appletvos"; return; }
    642     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "appletvos" ]] && { echo "appletvos"; return; }
    643     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "tvsimulator" ]] && { echo "appletvsimulator"; return; }
    644     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "appletvsimulator" ]] && { echo "appletvsimulator"; return; }
    645 
    646     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "watchos" ]] && { echo "watchos"; return; }
    647     [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "watchsimulator" ]] && { echo "watchsimulator"; return; }
     628    local GX_RESULT=$2
     629
     630    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "" ]]                   && { eval $GX_RESULT=""; return; }
     631
     632    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "ios" ]]                && { eval $GX_RESULT="iphoneos"; return; }
     633    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "iphone" ]]             && { eval $GX_RESULT="iphoneos"; return; }
     634    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "ipad" ]]               && { eval $GX_RESULT="iphoneos"; return; }
     635    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "iphoneos" ]]           && { eval $GX_RESULT="iphoneos"; return; }
     636    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "iphonesimulator" ]]    && { eval $GX_RESULT="iphonesimulator"; return; }
     637
     638    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "mac" ]]                && { eval $GX_RESULT="macosx"; return; }
     639    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "osx" ]]                && { eval $GX_RESULT="macosx"; return; }
     640    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "macos" ]]              && { eval $GX_RESULT="macosx"; return; }
     641    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "macosx" ]]             && { eval $GX_RESULT="macosx"; return; }
     642
     643    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "tvos" ]]               && { eval $GX_RESULT="appletvos"; return; }
     644    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "appletvos" ]]          && { eval $GX_RESULT="appletvos"; return; }
     645    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "tvsimulator" ]]        && { eval $GX_RESULT="appletvsimulator"; return; }
     646    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "appletvsimulator" ]]   && { eval $GX_RESULT="appletvsimulator"; return; }
     647
     648    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "watchos" ]]            && { eval $GX_RESULT="watchos"; return; }
     649    [[ "${GX_PROVISIONAL_PLATFORM_NAME}" == "watchsimulator" ]]     && { eval $GX_RESULT="watchsimulator"; return; }
    648650
    649651    die "Unrecognized platform name: $1"
     
    655657    log_callstack_and_parameters "$@"
    656658
    657     local GX_SDK=$(get_canonical_platform_name "$1")
     659    local GX_SDK=$1
     660    local GX_RESULT=$2
     661    get_canonical_platform_name "${GX_SDK}" GX_SDK
    658662    local GX_INTERNAL_SDK="${GX_SDK}.internal"
    659663
     
    662666    # Prefer an internal SDK if one exists.
    663667
    664     [[ " ${GX_SDKS[@]} " =~ " ${GX_INTERNAL_SDK} " ]] && { echo "${GX_INTERNAL_SDK}"; return; }
    665     [[ " ${GX_SDKS[@]} " =~ " ${GX_SDK} " ]] && { echo "${GX_SDK}"; return; }
     668    [[ " ${GX_SDKS[@]} " =~ " ${GX_INTERNAL_SDK} " ]]   && { eval $GX_RESULT="${GX_INTERNAL_SDK}"; return; }
     669    [[ " ${GX_SDKS[@]} " =~ " ${GX_SDK} " ]]            && { eval $GX_RESULT="${GX_SDK}"; return; }
    666670
    667671    die "Unsupported SDK: ${GX_SDK}."
     
    845849    (( ${GX_QUIET} )) && GX_ARGS+=("--quiet")
    846850
    847     local GX_SDK_NAME=$(get_sdk_name "${GX_PLATFORM_NAME}")
     851    local GX_SDK_NAME
     852    get_sdk_name "${GX_PLATFORM_NAME}" GX_SDK_NAME
    848853
    849854    log_debug "Sublaunching for: ${GX_PROJECT_TAG}/${GX_PLATFORM_NAME}/${GX_CONFIGURATION}"
     
    12331238
    12341239    [[ -z "${GX_PROJECT_TAG}" || ( " ${GX_PROJECT_TAGS[@]} " =~ " ${GX_PROJECT_TAG} " ) ]] || { die "Unrecognized project: ${GX_PROJECT_TAG}";  }
    1235     GX_PLATFORM_NAME=$(get_canonical_platform_name "${GX_PLATFORM_NAME}")
    1236     GX_CONFIGURATION=$(get_canonical_configuration "${GX_CONFIGURATION}")
     1240    get_canonical_platform_name "${GX_PLATFORM_NAME}" GX_PLATFORM_NAME
     1241    get_canonical_configuration "${GX_CONFIGURATION}" GX_CONFIGURATION
    12371242
    12381243    if (( ${GX_DO_GENERATE} ))
Note: See TracChangeset for help on using the changeset viewer.