Changeset 111323


Ignore:
Timestamp:
Sep 18, 2013, 11:11:02 PM (7 years ago)
Author:
marius@…
Message:

Merge from trunk.

Location:
branches/gsoc13-tests
Files:
3 deleted
63 edited
5 copied

Legend:

Unmodified
Added
Removed
  • branches/gsoc13-tests

  • branches/gsoc13-tests/ChangeLog

    r105003 r111323  
    44###
    55
    6 Release 2.2.0 (unreleased)
     6Release 2.2.1 (unreleased)
     7    - Provide choice of GCC version when compiling with DragonEgg.
     8      (larryv in r108040)
     9
     10    - Add Portfile options for setting OBJCXX, OBJCXXFLAGS, and
     11      universal architecture flags in OBJCFLAGS.
     12      (#38512, larryv in r107973, r107976, r107987)
     13
     14    - Add support for autostarting tasks with startupitems after installing.
     15      Useful for the certsync port. (#35474, cal in r106810, 109245)
     16
     17Release 2.2.0 (2013-07-23 by jmr)
     18    - Fixed ports sometimes being incorrectly cleaned after the unarchive
     19      target is run with newer archives. (jmr in r106717)
     20
     21    - When rebuilding an installed port, fixed the old copy being removed
     22      before the new copy has been built. (jmr in r106668)
     23
     24    - Support deleting selected files and directories before creating a pkg.
     25      (blair in r105575)
     26
    727    - Remove unsupported xpkg package type, xar-based format with XML.
    828      (afb in r105002)
    929
     30    - Support pattern matching in compiler.blacklist.
     31      (larryv in r104174, r104178)
     32
     33    - Workaround for some OS commands hanging on 10.8 when started from a root
     34      login shell. (#34221, jeremyhu in r104118)
     35
     36    - TMPDIR is now set to ${workpath}/.tmp while building ports, to avoid
     37      problems with using /tmp. (#37834, ryandesign in r103518)
     38
    1039    - Remove unimplemented 'port submit', remove XAR source packages.
    1140      (cal in r103400)
    1241
    13     - Remove dependency_libs information from libtool libraries (.la).
    14       (#38010, jmr in r102945)
     42    - Prevent overlinking by removing dependency_libs information from
     43      GNU Libtool (.la) files or by deleting the files entirely.
     44      (#38010; jmr in r102945; jeremyhu in r107465, r107527)
     45
     46    - Setting configure.compiler will now automatically add a dependency if
     47      the chosen compiler is provided by a port. (#32542, cal in r102932)
    1548
    1649    - Add 'port space --total' which displays the grand total only.
     
    2457    - Fixes bringing trace mode back to a working state. Improvements to reduce
    2558      the number of builds trace mode breaks.
    26       (cal in r100071-100073, r100077, r100126, r100221)
     59      (cal in r100071-100073, r100077, r100126, r100221, r106710)
    2760
    2861    - Began using sandbox-exec(1) on 10.5+ to prevent commands executed using
    2962      the 'system' procedure from writing files outside of the build directory
    3063      and selected other locations like /tmp. (jmr in r98156, r98193, etc.)
     64
     65    - Added ability to sync ports tree with git (jeremyhu in r92410)
    3166
    3267Release 2.1.3 (2013-01-31 by jmr)
  • branches/gsoc13-tests/Mk/macports.autoconf.mk.in

    r81642 r111323  
    88
    99CC                      = @CC@
    10 CFLAGS                  = @CFLAGS@ $(CFLAGS_QUICHEEATERS) $(CFLAGS_PEDANTIC) $(CFLAGS_WERROR)
     10CFLAGS                  = @CFLAGS@ -std=c99 $(CFLAGS_QUICHEEATERS) $(CFLAGS_PEDANTIC) $(CFLAGS_WERROR)
    1111OBJCFLAGS               = @OBJCFLAGS@ $(CFLAGS_QUICHEEATERS) $(CFLAGS_PEDANTIC) $(CFLAGS_WERROR)
    1212CPPFLAGS                = @CPPFLAGS@ @DEFS@ @INCLUDES@ @TCL_INCLUDES@
  • branches/gsoc13-tests/Mk/macports.tea.mk

    r66305 r111323  
    1111all:: ${SHLIB_NAME} pkgIndex.tcl
    1212
    13 $(SHLIB_NAME):: ${OBJS}
     13$(SHLIB_NAME): ${OBJS}
    1414        ${SHLIB_LD} ${OBJS} -o ${SHLIB_NAME} ${TCL_STUB_LIB_SPEC} ${SHLIB_LDFLAGS} ${LIBS}
    1515
  • branches/gsoc13-tests/config/RELEASE_URL

    r102343 r111323  
    1 https://svn.macports.org/repository/macports/tags/release_2_1_3/base
     1https://svn.macports.org/repository/macports/tags/release_2_2_0/base
  • branches/gsoc13-tests/config/macports_version

    r92788 r111323  
    1 2.1.99
     12.2.99
  • branches/gsoc13-tests/configure

    r111299 r111323  
    11#! /bin/sh
    22# Guess values for system-dependent variables and create Makefiles.
    3 # Generated by GNU Autoconf 2.69 for MacPorts 2.1.99.
     3# Generated by GNU Autoconf 2.69 for MacPorts 2.2.99.
    44#
    55# Report bugs to <macports-dev@lists.macosforge.org>.
     
    581581PACKAGE_NAME='MacPorts'
    582582PACKAGE_TARNAME='macports'
    583 PACKAGE_VERSION='2.1.99'
    584 PACKAGE_STRING='MacPorts 2.1.99'
     583PACKAGE_VERSION='2.2.99'
     584PACKAGE_STRING='MacPorts 2.2.99'
    585585PACKAGE_BUGREPORT='macports-dev@lists.macosforge.org'
    586586PACKAGE_URL=''
     
    662662MD5_LIBS
    663663READLINK_IS_NOT_P1003_1A
     664ac_cv_func_strlcat
    664665CPP
    665666UNIVERSAL_ARCHS
     
    841842with_tcl_sqlite3
    842843with_included_tclthread
    843 with_trace_sdk
    844844enable_shared
    845845'
     
    14131413  # This message is too long to be a string in the A/UX 3.1 sh.
    14141414  cat <<_ACEOF
    1415 \`configure' configures MacPorts 2.1.99 to adapt to many kinds of systems.
     1415\`configure' configures MacPorts 2.2.99 to adapt to many kinds of systems.
    14161416
    14171417Usage: $0 [OPTION]... [VAR=VALUE]...
     
    14791479if test -n "$ac_init_help"; then
    14801480  case $ac_init_help in
    1481      short | recursive ) echo "Configuration of MacPorts 2.1.99:";;
     1481     short | recursive ) echo "Configuration of MacPorts 2.2.99:";;
    14821482   esac
    14831483  cat <<\_ACEOF
     
    15261526  --with-included-tclthread
    15271527                          install included Thread package.
    1528   --with-trace-sdk=SDK    SDK for redirection in trace lib (for example
    1529                           MacOSX10.4u.sdk)
    15301528
    15311529Some influential environment variables:
     
    16251623if $ac_init_version; then
    16261624  cat <<\_ACEOF
    1627 MacPorts configure 2.1.99
     1625MacPorts configure 2.2.99
    16281626generated by GNU Autoconf 2.69
    16291627
     
    22942292running configure, to aid debugging if configure makes a mistake.
    22952293
    2296 It was created by MacPorts $as_me 2.1.99, which was
     2294It was created by MacPorts $as_me 2.2.99, which was
    22972295generated by GNU Autoconf 2.69.  Invocation command line was
    22982296
     
    27892787{ $as_echo "$as_me:${as_lineno-$LINENO}: checking MacPorts version" >&5
    27902788$as_echo_n "checking MacPorts version... " >&6; }
    2791 MACPORTS_VERSION=2.1.99
     2789MACPORTS_VERSION=2.2.99
    27922790{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MACPORTS_VERSION" >&5
    27932791$as_echo "$MACPORTS_VERSION" >&6; }
     
    29552953                  Please upgrade at http://store.apple.com/" "$LINENO" 5
    29562954    ;;
    2957   10.4.[0-9]|10.4.10|10.5.[0-7]|10.6.[0-7]|10.7.[0-4]|10.8.[0-1])
     2955  10.4.[0-9]|10.4.10|10.5.[0-7]|10.6.[0-7]|10.7.[0-4]|10.8.[0-3])
    29582956    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: This version of Mac OS X is out of date" >&5
    29592957$as_echo "$as_me: WARNING: This version of Mac OS X is out of date" >&2;}
     
    30093007    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: This version of Xcode Tools is not supported" >&5
    30103008$as_echo "$as_me: WARNING: This version of Xcode Tools is not supported" >&2;}
    3011     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Please upgrade at http://connect.apple.com/" >&5
    3012 $as_echo "$as_me: WARNING: Please upgrade at http://connect.apple.com/" >&2;}
     3009    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Please upgrade at https://developer.apple.com/downloads/" >&5
     3010$as_echo "$as_me: WARNING: Please upgrade at https://developer.apple.com/downloads/" >&2;}
    30133011    ;;
    30143012  2.[2-3]*|3.[0]*)
     
    87868784
    87878785for ac_header in limits.h paths.h sys/file.h crt_externs.h fcntl.h sys/fcntl.h sys/cdefs.h err.h sys/socket.h \
    8788         sys/sysctl.h readline/readline.h readline/history.h pwd.h sys/paths.h utime.h
     8786        sys/event.h sys/sysctl.h readline/readline.h readline/history.h pwd.h sys/paths.h utime.h
    87898787do :
    87908788  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
     
    88038801
    88048802# Checks for library functions.
    8805 for ac_func in bzero memset fgetln lockf flock setmode strcasecmp strncasecmp strlcpy copyfile clearenv sysctlbyname
     8803for ac_func in bzero memset fgetln lockf flock setmode strcasecmp strncasecmp strlcpy strlcat copyfile clearenv sysctlbyname kqueue
    88068804do :
    88078805  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
     
    88148812fi
    88158813done
     8814
     8815
    88168816
    88178817
     
    1000510005fi
    1000610006
    10007 
    10008 
    10009 # Check whether --with-trace-sdk was given.
    10010 if test "${with_trace_sdk+set}" = set; then :
    10011   withval=$with_trace_sdk; test -d ${DEVELOPER_DIR}/SDKs/$withval && cat >>confdefs.h <<_ACEOF
    10012 #define TRACE_SDK "${withval}"
    10013 _ACEOF
    10014 
    10015 fi
    10016 
    10017 
    1001810007# Allows building of shared libraries
    1001910008
     
    1010810097
    1010910098# Output
    10110 ac_config_files="$ac_config_files Doxyfile Makefile Mk/macports.autoconf.mk doc/base.mtree doc/prefix.mtree doc/macosx.mtree doc/macports.conf doc/pubkeys.conf portmgr/freebsd/Makefile src/Makefile src/machista1.0/Makefile src/macports1.0/macports_autoconf.tcl src/macports1.0/macports_test_autoconf.tcl src/port1.0/port_autoconf.tcl src/port1.0/port_test_autoconf.tcl src/package1.0/package_test_autoconf.tcl src/registry2.0/registry_autoconf.tcl src/programs/Makefile src/macports1.0/macports_fastload.tcl setupenv.bash"
     10099ac_config_files="$ac_config_files Doxyfile Makefile Mk/macports.autoconf.mk doc/base.mtree doc/macosx.mtree doc/macports.conf doc/prefix.mtree doc/pubkeys.conf portmgr/freebsd/Makefile setupenv.bash src/Makefile src/machista1.0/Makefile src/macports1.0/macports_autoconf.tcl src/macports1.0/macports_test_autoconf.tcl src/macports1.0/macports_fastload.tcl src/package1.0/package_test_autoconf.tcl src/pextlib1.0/Makefile src/port1.0/port_autoconf.tcl src/port1.0/port_test_autoconf.tcl src/programs/Makefile src/registry2.0/registry_autoconf.tcl"
    1011110100
    1011210101
     
    1062010609# values after options handling.
    1062110610ac_log="
    10622 This file was extended by MacPorts $as_me 2.1.99, which was
     10611This file was extended by MacPorts $as_me 2.2.99, which was
    1062310612generated by GNU Autoconf 2.69.  Invocation command line was
    1062410613
     
    1068210671ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
    1068310672ac_cs_version="\\
    10684 MacPorts config.status 2.1.99
     10673MacPorts config.status 2.2.99
    1068510674configured by $0, generated by GNU Autoconf 2.69,
    1068610675  with options \\"\$ac_cs_config\\"
     
    1081010799    "Mk/macports.autoconf.mk") CONFIG_FILES="$CONFIG_FILES Mk/macports.autoconf.mk" ;;
    1081110800    "doc/base.mtree") CONFIG_FILES="$CONFIG_FILES doc/base.mtree" ;;
    10812     "doc/prefix.mtree") CONFIG_FILES="$CONFIG_FILES doc/prefix.mtree" ;;
    1081310801    "doc/macosx.mtree") CONFIG_FILES="$CONFIG_FILES doc/macosx.mtree" ;;
    1081410802    "doc/macports.conf") CONFIG_FILES="$CONFIG_FILES doc/macports.conf" ;;
     10803    "doc/prefix.mtree") CONFIG_FILES="$CONFIG_FILES doc/prefix.mtree" ;;
    1081510804    "doc/pubkeys.conf") CONFIG_FILES="$CONFIG_FILES doc/pubkeys.conf" ;;
    1081610805    "portmgr/freebsd/Makefile") CONFIG_FILES="$CONFIG_FILES portmgr/freebsd/Makefile" ;;
     10806    "setupenv.bash") CONFIG_FILES="$CONFIG_FILES setupenv.bash" ;;
    1081710807    "src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;;
    1081810808    "src/machista1.0/Makefile") CONFIG_FILES="$CONFIG_FILES src/machista1.0/Makefile" ;;
    1081910809    "src/macports1.0/macports_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/macports1.0/macports_autoconf.tcl" ;;
    1082010810    "src/macports1.0/macports_test_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/macports1.0/macports_test_autoconf.tcl" ;;
     10811    "src/macports1.0/macports_fastload.tcl") CONFIG_FILES="$CONFIG_FILES src/macports1.0/macports_fastload.tcl" ;;
     10812    "src/package1.0/package_test_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/package1.0/package_test_autoconf.tcl" ;;
     10813    "src/pextlib1.0/Makefile") CONFIG_FILES="$CONFIG_FILES src/pextlib1.0/Makefile" ;;
    1082110814    "src/port1.0/port_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/port1.0/port_autoconf.tcl" ;;
    1082210815    "src/port1.0/port_test_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/port1.0/port_test_autoconf.tcl" ;;
    10823     "src/package1.0/package_test_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/package1.0/package_test_autoconf.tcl" ;;
     10816    "src/programs/Makefile") CONFIG_FILES="$CONFIG_FILES src/programs/Makefile" ;;
    1082410817    "src/registry2.0/registry_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/registry2.0/registry_autoconf.tcl" ;;
    10825     "src/programs/Makefile") CONFIG_FILES="$CONFIG_FILES src/programs/Makefile" ;;
    10826     "src/macports1.0/macports_fastload.tcl") CONFIG_FILES="$CONFIG_FILES src/macports1.0/macports_fastload.tcl" ;;
    10827     "setupenv.bash") CONFIG_FILES="$CONFIG_FILES setupenv.bash" ;;
    1082810818    "src/pkg_mkindex.sh") CONFIG_FILES="$CONFIG_FILES src/pkg_mkindex.sh" ;;
    1082910819
  • branches/gsoc13-tests/configure.ac

    r111299 r111323  
    3333                  Please upgrade at http://store.apple.com/])
    3434    ;;
    35   10.4.[[0-9]]|10.4.10|10.5.[[0-7]]|10.6.[[0-7]]|10.7.[[0-4]]|10.8.[[0-1]])
     35  10.4.[[0-9]]|10.4.10|10.5.[[0-7]]|10.6.[[0-7]]|10.7.[[0-4]]|10.8.[[0-3]])
    3636    AC_MSG_WARN([This version of Mac OS X is out of date])
    3737    AC_MSG_WARN([Please run Software Update to update it])
     
    8181  1.*|2.[[0-1]]*)
    8282    AC_MSG_WARN([This version of Xcode Tools is not supported])
    83     AC_MSG_WARN([Please upgrade at http://connect.apple.com/])
     83    AC_MSG_WARN([Please upgrade at https://developer.apple.com/downloads/])
    8484    ;;
    8585  2.[[2-3]]*|3.[[0]]*)
     
    239239AC_HEADER_SYS_WAIT
    240240AC_CHECK_HEADERS([limits.h paths.h sys/file.h crt_externs.h fcntl.h sys/fcntl.h sys/cdefs.h err.h sys/socket.h \
    241         sys/sysctl.h readline/readline.h readline/history.h pwd.h sys/paths.h utime.h])
     241        sys/event.h sys/sysctl.h readline/readline.h readline/history.h pwd.h sys/paths.h utime.h])
    242242
    243243INCLUDES="-I.. -I. $INCLUDES"
    244244
    245245# Checks for library functions.
    246 AC_CHECK_FUNCS([bzero memset fgetln lockf flock setmode strcasecmp strncasecmp strlcpy copyfile clearenv sysctlbyname])
     246AC_CHECK_FUNCS([bzero memset fgetln lockf flock setmode strcasecmp strncasecmp strlcpy strlcat copyfile clearenv sysctlbyname kqueue])
     247AC_SUBST(ac_cv_func_strlcat)
     248
    247249MP_CHECK_READLINK_IS_P1003_1A
    248250
     
    329331fi
    330332
    331 AH_TEMPLATE([TRACE_SDK], [SDK for SDK redirect in tracelib])
    332 AC_ARG_WITH(
    333         trace-sdk,
    334         AS_HELP_STRING([--with-trace-sdk=SDK],
    335                 [SDK for redirection in trace lib (for example MacOSX10.4u.sdk)]),
    336         [test -d ${DEVELOPER_DIR}/SDKs/$withval && AC_DEFINE_UNQUOTED([TRACE_SDK], "${withval}")], [])
    337 
    338333# Allows building of shared libraries
    339334SC_ENABLE_SHARED
     
    393388        Mk/macports.autoconf.mk
    394389        doc/base.mtree
    395         doc/prefix.mtree
    396390        doc/macosx.mtree
    397391        doc/macports.conf
     392        doc/prefix.mtree
    398393        doc/pubkeys.conf
    399394        portmgr/freebsd/Makefile
     395        setupenv.bash
    400396        src/Makefile
    401397        src/machista1.0/Makefile
    402398        src/macports1.0/macports_autoconf.tcl
    403399        src/macports1.0/macports_test_autoconf.tcl
     400        src/macports1.0/macports_fastload.tcl
     401        src/package1.0/package_test_autoconf.tcl
     402        src/pextlib1.0/Makefile
    404403        src/port1.0/port_autoconf.tcl
    405404        src/port1.0/port_test_autoconf.tcl
    406         src/package1.0/package_test_autoconf.tcl
     405        src/programs/Makefile
    407406        src/registry2.0/registry_autoconf.tcl
    408         src/programs/Makefile
    409         src/macports1.0/macports_fastload.tcl
    410         setupenv.bash
    411407])
    412408
  • branches/gsoc13-tests/doc/archive_sites.conf

    r91009 r111323  
    1 # Configuration for (binary) archive sources.
    21# $Id$
    32
    4 # Each entry is started by a name line. The only required values are name and
    5 # urls. Other fields are type, prefix, applications_dir and frameworks_dir,
    6 # which have the usual default values:
    7 #    type tbz2
    8 #    prefix /opt/local
    9 #    applications_dir /Applications/MacPorts
    10 #    frameworks_dir ${prefix}/Library/Frameworks
     3# MacPorts configuration file for binary archive sources.
     4
     5# Each source entry consists of one or more fields.
    116#
    12 # type can be any of: tgz, tar, tbz, tbz2, tlz, txz, xar, zip, cpgz, cpio
    13 # Note that some types require a corresponding tool to be installed, and
    14 # entries with an unsupported type will not be used.
     7#   name: A name for the archive source. This field always starts a new
     8#       entry. Required.
     9#
     10#   urls: A space- or tab-delimited list of the source's URLs. Defaults
     11#       to an empty list.
     12#
     13#   type: The filetype of the archives; valid values are "cpgz", "cpio",
     14#       "tar", "tbz", "tbz2", "tgz", "tlz", "txz", "xar", and "zip".
     15#       MacPorts handles each archive type with an appropriate external
     16#       executable; if it cannot find such an executable, or if the
     17#       specified type is invalid, the source is not used. Defaults to
     18#       "tbz2".
     19#
     20#   prefix: The prefix of the MacPorts installation used to create the
     21#       source's archives. This must match the value of "prefix" set in
     22#       macports.conf, or the source is not used. Defaults to
     23#       "/opt/local".
     24#
     25#   applications_dir: The applications directory of the MacPorts
     26#       installation used to create the source's archives. This must
     27#       match the value of "applications_dir" set in macports.conf, or
     28#       the source is not used. Defaults to "/Applications/MacPorts".
     29#
     30#   frameworks_dir: The frameworks directory of the MacPorts
     31#       installation used to create the source's archives. This must
     32#       match the value of "frameworks_dir" set in macports.conf, or the
     33#       source is not used. Defaults to "[prefix]/Library/Frameworks".
    1534
    16 # Example:
    17 #name                mysource
    18 #urls                http://example.com/ ftp://ftp.example.org/
    19 #type                tbz2
    20 #prefix              /opt/mysource
    21 #applications_dir    /opt/mysource/Applications
    22 #frameworks_dir      /opt/mysource/Library/Frameworks
     35# Example source:
     36#name                   My Source
     37#urls                   http://example.com/ ftp://ftp.example.com/packages/
     38#type                   zip
     39#prefix                 /opt/mysource
     40#applications_dir       /opt/mysource/Applications
    2341
    24 # If you want to disable use of the archive sites listed in the ports tree,
    25 # you could do this:
    26 #name                macports_archives
    27 #urls
     42# To disable the default archive source, uncomment the following dummy
     43# entry; it will shadow the one from the ports tree.
     44#name                   macports_archives
  • branches/gsoc13-tests/doc/macports.conf.in

    r105575 r111323  
    1 # MacPorts system wide configuration file
    21# $Id$
    32
    4 # Set the directory in which to install ports. Must match where MacPorts itself is installed.
    5 prefix                  @prefix_expanded@
     3# MacPorts system-wide configuration file.
     4# Commented-out values are defaults unless otherwise noted.
    65
    7 # Set the user to run MacPorts compiles, etc as when privileges are dropped during an install
    8 #macportsuser           @RUNUSR@
     6# Directory under which MacPorts should install ports. This must be
     7# where MacPorts itself is installed.
     8prefix                  @prefix_expanded@
    99
    10 # Where to store MacPorts working data
    11 portdbpath              @localstatedir_expanded@/macports
     10# User to run operations as when MacPorts drops privileges.
     11#macportsuser           @RUNUSR@
    1212
    13 # PATH settings that are used for external tools (configure, make, etc.) while
    14 # installing ports. The default paths are given in the example; it need not be
    15 # uncommented.  Customizing binpath is unsupported and is intended for
    16 # advanced users only.
    17 #binpath                @prefix_expanded@/bin:@prefix_expanded@/sbin:/bin:/sbin:/usr/bin:/usr/sbin
     13# Directory for MacPorts working data.
     14portdbpath              @localstatedir_expanded@/macports
    1815
    19 # Directory containing Xcode Tools (default is to ask xcode-select)
    20 #developer_dir          @DEVELOPER_DIR@
     16# Colon-delimited list of directories to search for external tools
     17# (make(1), pkg-config(1), etc.). While installing ports, MacPorts uses
     18# this list for PATH. Changing this setting is intended for advanced
     19# users only and is unsupported.
     20#binpath                @prefix_expanded@/bin:@prefix_expanded@/sbin:/bin:/sbin:/usr/bin:/usr/sbin
    2121
    22 # Path to PackageMaker.app
    23 # It may be necessary to set this with Xcode >= 4.3, as that version
    24 # requires PackageMaker to be installed manually from the Auxiliary Tools for
    25 # Xcode disk image. The default is /Applications/PackageMaker.app with Xcode
    26 # 4.3 and ${developer_dir}/Applications/Utilities/PackageMaker.app with older
    27 # versions.
    28 #packagemaker_path /Applications/PackageMaker.app
     22# Directory containing Xcode Tools. By default, MacPorts determines this
     23# using xcode-select(1).
     24#developer_dir          @DEVELOPER_DIR@
    2925
    30 # Directory containing Applications from ports.
    31 applications_dir        @MPAPPLICATIONSDIR@
     26# Location of PackageMaker. Defaults to
     27# "${developer_dir}/Applications/Utilities/PackageMaker.app" with Xcode
     28# 4.2 and earlier and "/Applications/PackageMaker.app" with 4.3 and later.
     29#packagemaker_path      /Applications/PackageMaker.app
    3230
    33 # Directory containing Frameworks from ports.
    34 frameworks_dir          @MPFRAMEWORKSDIR@
     31# Directory for application bundles installed by ports.
     32applications_dir        @MPAPPLICATIONSDIR@
    3533
    36 # Where to find the sources list.
    37 sources_conf            @MPCONFIGDIR_EXPANDED@/sources.conf
     34# Directory for frameworks installed by ports.
     35frameworks_dir          @MPFRAMEWORKSDIR@
    3836
    39 # Where to find global variants definition file (optional)
    40 variants_conf           @MPCONFIGDIR_EXPANDED@/variants.conf
     37# Location of the MacPorts sources list.
     38sources_conf            @MPCONFIGDIR_EXPANDED@/sources.conf
    4139
    42 # When to build ports from source. Default is 'ifneeded', which downloads an
    43 # archive if available or builds from source otherwise. 'always' has the same
    44 # effect as -s on the command line, and 'never' is likewise the same as -b.
    45 #buildfromsource        ifneeded
     40# Location of the MacPorts global variants definition file. Optional.
     41variants_conf           @MPCONFIGDIR_EXPANDED@/variants.conf
    4642
    47 # Type of archives to use for port images
    48 #
    49 # Supported types: tgz, tar, tbz, tbz2 (default), tlz, txz, xar, zip, cpgz, cpio
    50 #portarchivetype        tbz2
     43# When MacPorts should build ports from source.
     44# - ifneeded: Download binary archives if available; build from source
     45#   otherwise.
     46# - always: Always build from source; never try fetching archives.
     47# - never: Never build from source; try fetching archives and abort if
     48#   unavailable.
     49#buildfromsource        ifneeded
    5150
    52 # CPU architecture to compile for. Defaults to i386 or ppc on Mac OS X 10.5
    53 # and earlier, depending on the CPU type detected at runtime. On Mac OS X 10.6
    54 # the default is x86_64 if the CPU supports it, i386 otherwise.
    55 #build_arch             i386
     51# Type of archive to use for port images. Supported types are cpgz,
     52# cpio, tar, tbz, tbz2, tgz, tlz, txz, xar, zip.
     53#portarchivetype        tbz2
    5654
    57 # CPU architectures to use for Universal Binaries (+universal variant)
    58 universal_archs         @UNIVERSAL_ARCHS@
     55# CPU architecture to target. Supported values are "ppc", "ppc64",
     56# "i386", and "x86_64". Defaults to:
     57# - OS X 10.5 and earlier: "ppc" on PowerPC, otherwise "i386".
     58# - OS X 10.6 and later: "x86_64" on Intel 64, otherwise "i386".
     59#build_arch             i386
    5960
    60 # Use ccache (C/C++ compiler cache) - see http://ccache.samba.org/
    61 #configureccache        no
     61# Space-delimited list of CPU architectures to target when building
     62# universal. Defaults to "i386 ppc" on OS X 10.5 and earlier and
     63# "x64_64 i386" on OS X 10.6 and later.
     64universal_archs         @UNIVERSAL_ARCHS@
    6265
    63 # Location where ccache stores its files
    64 #ccache_dir             @localstatedir_expanded@/macports/build/.ccache
     66# Use ccache, a compiler cache for C, C++, Objective-C, and
     67# Objective-C++. (See http://ccache.samba.org.) The "ccache" executable
     68# must exist in one of the directories in binpath.
     69#configureccache        no
    6570
    66 # Maximum size ccache may use.
    67 # Use 'G', 'M', or 'K' suffix for giga-, mega- or kilobytes.
    68 #ccache_size            2G
     71# Directory for ccache's cached compiler output.
     72#ccache_dir             @localstatedir_expanded@/macports/build/.ccache
    6973
    70 # Use distcc (distributed compiler) - see http://distcc.samba.org/
    71 #configuredistcc        no
     74# Maximum size of files stored in ccache's cache. Append "G", "M", or
     75# "K" for gigabytes, megabytes, or kilobytes.
     76#ccache_size            2G
    7277
    73 # Use pipes rather than intermediate files when compiling C/C++/etc
    74 #configurepipe          yes
     78# Use distcc, a distributed compiler for C, C++, Objective-C, and
     79# Objective-C++. (See http://distcc.org.) The "distcc" executable must
     80# exist in one of the directories in binpath.
     81#configuredistcc        no
    7582
    76 # Lowered scheduling priority (0-20) to use for make when building ports
    77 #buildnicevalue         0
     83# Use pipes rather than temporary files for communication between the
     84# various stages of C, C++, Objective-C, and Objective-C++ compilation.
     85#configurepipe          yes
    7886
    79 # Number of simultaneous make jobs (commands) to use when building ports. This
    80 # value may be set to 0 so the number of simultaneous make jobs will be set to
    81 # the number of CPU cores that are automatically detected, or the number of GB
    82 # of physical memory plus one, whichever is less.
    83 #buildmakejobs          0
     87# Lowered scheduling priority to use for commands run during configure,
     88# build, and destroot. Accepted values are 0 (normal priority) through
     89# 20 (lowest priority).
     90#buildnicevalue         0
    8491
    85 # umask value to use when a port installs its files
    86 #destroot_umask         022
     92# Number of simultaneous make(1) jobs to use when building ports. If set
     93# to 0, the number of jobs will be the lesser of:
     94# - number of automatically-detected CPU cores
     95# - gigabytes of physical memory + 1
     96#buildmakejobs          0
    8797
    88 # Set whether to automatically execute "clean" after "install" of ports
    89 #portautoclean          yes
     98# umask value to use when a port installs its files.
     99#destroot_umask         022
    90100
    91 # Set to yes if you don't want logs to be deleted after successful builds
    92 #keeplogs               no
     101# Automatically execute "clean" after "install" of ports.
     102#portautoclean          yes
    93103
    94 # Rsync server to fetch MacPorts sources from. Note that this is only used
    95 # for selfupdate. The source(s) for the ports tree are set in sources.conf.
    96 # Known mirrors at time of writing (see https://trac.macports.org/wiki/Mirrors
    97 # for the current list):
    98 #   rsync.macports.org        - California, USA (master)
    99 #   trd.no.rsync.macports.org - Trondheim, Norway
    100 #rsync_server           rsync.macports.org
     104# Keep logs after successful installations.
     105#keeplogs               no
    101106
    102 # Rsync directory from which to pull the base/ component (infrastructure) of MacPorts
    103 # If this points to a .tar file, a signed .rmd160 must exist next to it
    104 # on the server and will be used to verify its integrity.
    105 #rsync_dir              release/tarballs/base.tar
     107# The rsync server for fetching MacPorts base during selfupdate. This
     108# setting is NOT used when downloading the ports tree; the sources for
     109# the ports tree are set in sources.conf. See
     110# https://trac.macports.org/wiki/Mirrors#MacPortsSource for a list of
     111# available servers.
     112#rsync_server           rsync.macports.org
    106113
    107 # Rsync options
    108 #rsync_options          -rtzv --delete-after
     114# Location of MacPorts base sources on rsync_server. If this references
     115# a .tar file, a signed .rmd160 file must exist in the same directory
     116# and will be used to verify its integrity. See
     117# https://trac.macports.org/wiki/Mirrors#MacPortsSource to find the
     118# correct rsync_dir for a particular rsync_server.
     119#rsync_dir              release/tarballs/base.tar
    109120
    110 # Options for generated startup items
    111 # startupitem_type may be "default", "systemstarter", "launchd", or "none";
    112 # if the option is empty or "default" then a startupitem type appropriate
    113 # to the platform will be chosen. Mac OS X 10.4 Tiger and above will default to
    114 # launchd, while older Mac OS X systems will default to systemstarter. If
    115 # option "none" is chosen, port startupitems are ignored and no startupitems
    116 # are installed.
    117 #startupitem_type       default
     121# Options to pass to rsync when fetching MacPorts base and the ports tree.
     122#rsync_options          -rtzv --delete-after
    118123
    119 # Option to install symlinks into /Library/LaunchAgents or /Library/LaunchDaemons
    120 # startupitem_install may be empty, "yes" or "no";
    121 # if the option is NOT "no" then a symlink for the startupitem will be created in
    122 # the appropriate system directory.
     124# Type of generated StartupItems.
     125# - launchd: Create StartupItems for use with launchd.
     126# - systemstarter: Create StartupItems for use with SystemStarter.
     127# - rcng: Create StartupItems for use with the rc.d system.
     128# - default: Create StartupItems for launchd on OS X and for rc.d on
     129#   other platforms.
     130# - none: Disable creation of StartupItems.
     131#startupitem_type       default
     132
     133# Create system-level symlinks to generated StartupItems. If set to
     134# "no", symlinks will not be created; otherwise, symlinks will be placed
     135# in /Library/LaunchDaemons or /Library/LaunchAgents as appropriate.
    123136#startupitem_install    yes
    124137
    125 # Extra environment variables to keep. Any variables listed here are added
    126 # to the list of variables that are not removed from the environment used
    127 # while processing ports. As with binpath, setting extra_env is intended for
    128 # advanced users and is unsupported.
    129 # extra_env             KEEP_THIS THIS_TOO
     138# Extra environment variables to keep. MacPorts sanitizes its
     139# environment while processing ports, keeping:
     140# - DISPLAY
     141# - DYLD_FALLBACK_FRAMEWORK_PATH, DYLD_FALLBACK_LIBRARY_PATH,
     142#   DYLD_FRAMEWORK_PATH, DYLD_INSERT_LIBRARIES, DYLD_LIBRARY_PATH
     143# - JAVA_HOME
     144# - ARCHIVE_SITE_LOCAL, MASTER_SITE_LOCAL, PATCH_SITE_LOCAL
     145# - PORTSRC
     146# - ALL_PROXY, FTP_PROXY, http_proxy, HTTPS_PROXY, NO_PROXY, RSYNC_PROXY
     147# - GROUP, USER
     148# - COLUMNS, LINES
     149# Variables listed in extra_env are added to this list. This has no
     150# default value; setting it is intended for advanced users and is
     151# unsupported. (Note that sudo(8) sanitizes its environment on OS X 10.5
     152# and later, so it may have to be configured to pass the desired
     153# variables to MacPorts.)
     154#extra_env              KEEP_THIS THIS_TOO
    130155
    131 # Proxy support
    132 # Precedence is: env, macports.conf, System Preferences
    133 # That is, if it's set in the environment, that will be used instead of
    134 # anything here or in System Preferences.  Setting proxy_override_env to yes
    135 # will cause any proxies set here (or in System Preferences if set there but
    136 # not here) to override what's in the environment.
    137 # Note that System Preferences doesn't have an rsync proxy definition.
    138 # Also note, on 10.5, sudo will clear many environment variables including
    139 # those for proxy support.
    140 # Equivalent environment variables: http_proxy, HTTPS_PROXY, FTP_PROXY,
    141 # RSYNC_PROXY, NO_PROXY
    142 #
    143 #proxy_override_env     yes
    144 # HTTP proxy:
    145 #proxy_http             hostname:12345
    146 # HTTPS proxy:
    147 #proxy_https            hostname:12345
    148 # FTP proxy:
    149 #proxy_ftp              hostname:12345
    150 # rsync proxy:
    151 #proxy_rsync            hostname:12345
    152 # hosts not to go through the proxy (comma-separated, applies to HTTP, HTTPS,
    153 # and FTP, but not rsync):
    154 #proxy_skip             internal1, internal2, internal3
     156# Override proxy-related environment variables. By default, MacPorts
     157# takes proxy settings from the environment, from the proxy_* options
     158# below, and from Network Preferences, in that order. If this is set to
     159# "yes", MacPorts uses proxy_*, then Network Preferences, then the
     160# environment. (Note that Network Preferences does not have a setting
     161# for rsync proxies. Also note that sudo(8) sanitizes its environment on
     162# OS X 10.5 and later, so it may have to be configured to pass desired
     163# variables to MacPorts.)
     164#proxy_override_env     no
    155165
    156 # Options 'host_blacklist' and 'preferred_hosts', used for indicating
    157 # space separated lists of download hosts that should not be used or
    158 # should be used preferentially, respectively. These override the usual
    159 # ping time check.
    160 #host_blacklist     badhost1.org badhost2.org
    161 #preferred_hosts    preferredhost1.org preferredhost2.org
     166# Proxies. These have no default values. The analogous environment
     167# variables are "http_proxy", "HTTPS_PROXY", "FTP_PROXY", and
     168# "RSYNC_PROXY".
     169#proxy_http             proxy1:12345
     170#proxy_https            proxy2:67890
     171#proxy_ftp              proxy3:02139
     172#proxy_rsync            proxy4:11377
    162173
    163 # Set whether to automatically run rev-upgrade after upgrading ports
    164 #revupgrade_autorun yes
    165 # Option controlling action taken by rev-upgrade, which checks for broken
    166 # linking and can rebuild affected ports. Possible values are
    167 #'rebuild' (default) or 'report'.
    168 #revupgrade_mode        rebuild
     174# Comma-delimited list of hosts that MacPorts should not access through
     175# the HTTP, HTTPS, and FTP proxies. This does not apply to rsync, and it
     176# has no default value.
     177#proxy_skip             host1, host2, host3
    169178
    170 # When creating a pkg, specify the files and/or directories in
    171 # ${prefix} to delete after the unarchive stage and before the
    172 # pkg is created.  If not set, nothing is deleted.
    173 #
    174 # Because mpkg's are built from pkg's, any mpkg's will also have
    175 # the specified files and/or directories omitted.
    176 #
    177 # For example
    178 #
    179 #   pkg_post_unarchive_deletions include share/doc share/man
    180 #
    181 # will delete ${prefix}/include, ${prefix}/share/doc and
    182 # ${prefix}/share/man.
    183 #
    184 # This feature is useful when one wants to shrink the size of the
    185 # pkg's and mpkg's for deployment to Macs that will not be used
    186 # for development.  One large mpkg was observed to shrink from
    187 # 504 MB to 271 MB.
    188 #
    189 #pkg_post_unarchive_deletions include share/doc share/man
     179# Space-delimited lists of download hosts that MacPorts should not use
     180# and that MacPorts should prefer, respectively, overriding the usual
     181# ping time checks. These have no default values.
     182#host_blacklist         badhost1 badhost2
     183#preferred_hosts        preferredhost1 preferredhost2
     184
     185# Whether MacPorts should automatically run rev-upgrade after upgrading
     186# ports.
     187#revupgrade_autorun     yes
     188
     189# Whether rev-upgrade should automatically rebuild ports with broken
     190# linking or merely report the breakage. Supported values are "report"
     191# and "rebuild".
     192#revupgrade_mode        rebuild
     193
     194# Space-delimited list of files and directories to delete after the
     195# unarchive stage and before creating a pkg. Paths are interpreted
     196# relative to prefix, and there is no default value. This is useful for
     197# removing unnecessary files and directories prior to pkg or mpkg
     198# deployment.
     199#pkg_post_unarchive_deletions   include share/doc share/man
  • branches/gsoc13-tests/doc/pubkeys.conf.in

    r68996 r111323  
    1 # Downloaded archives will only be used if they can be verified by a public
    2 # key listed here. Use full paths, one per line.
     1# $Id$
     2
     3# MacPorts system-wide public key configuration file.
     4
     5# Downloaded archives will only be used if they can be verified by one
     6# of the public keys listed here. Use absolute paths, one per line.
    37
    48@prefix_expanded@/share/macports/macports-pubkey.pem
    59
    6 # To distribute archives of your own, you need a key pair generated like so:
    7 # openssl genrsa -des3 -out privkey.pem 2048
    8 # openssl rsa -in privkey.pem -pubout -out pubkey.pem
    9 # Then sign the archives like this:
    10 # openssl dgst -ripemd160 -sign privkey.pem -out archive.tbz2.rmd160 archive.tbz2
     10# To distribute archives of your own, generate a key pair:
     11#   openssl genrsa -des3 -out privkey.pem 2048
     12#   openssl rsa -in privkey.pem -pubout -out pubkey.pem
     13#
     14# And sign the archives:
     15#   openssl dgst -ripemd160 -sign privkey.pem -out archive.tbz2.rmd160 archive.tbz2
  • branches/gsoc13-tests/doc/sources.conf

    r79599 r111323  
    1 #  MacPorts system wide sources configuration file
    2 #  $Id$
     1# $Id$
    32
    4 #  To setup a local ports repository, insert a "file://" entry following
    5 #  the example below that points to your local ports directory:
    6 #  Example: file:///Users/landonf/misc/MacPorts/ports
     3# MacPorts system-wide configuration file for ports tree sources.
     4#
     5# To change how MacPorts fetches base, see rsync_server and rsync_dir in
     6# macports.conf.
    77
    8 #  The default MacPorts repository should always be tagged [default]
    9 #  for proper functionality of various resources (port groups, mirror
    10 #  sites, etc).  If you switch it from the rsync:// URL, be sure to keep
    11 #  it tagged [default].
     8# To add a local source, add a "file://" entry.
     9#
     10#   Example: file:///Users/landonf/misc/MacPorts/ports
     11#
     12# To prevent a source from synchronizing when `port sync` is used,
     13# append "[nosync]" at the end.
     14#
     15#   Example: file:///Users/landonf/misc/MacPorts/ports [nosync]
     16#
     17# Note that MacPorts parses source URLs in order; when a port appears in
     18# multiple sources, it installs the first occurrence. For local sources
     19# to shadow remote ones, "file://" URLs must come before other URLs.
    1220
    13 #  To prevent a source from synchronizing when `port sync` is used,
    14 #  append [nosync] at the end as shown in this example:
    15 #  Example: file:///Users/landonf/misc/MacPorts/ports [nosync]
    16 
    17 #  NOTE: The port command parses source URLs in order and installs the
    18 #        first occurrance when a port appears in multiple repositories.
    19 #        So keep "file://" URLs above other URL types.
    20 
    21 
    22 #  To get the ports tree from the master MacPorts server in California, USA use:
    23 #      rsync://rsync.macports.org/release/ports/
    24 #  To get it from the mirror in Trondheim, Norway use:
    25 #      rsync://trd.no.rsync.macports.org/release/ports/
    26 #  A current list of mirrors is available at https://trac.macports.org/wiki/Mirrors
    27 
    28 # If an rsync URL points to a .tar file, a signed .rmd160 must exist next to
    29 # it on the server and will be used to verify its integrity.
     21# A list of rsync mirrors is available at
     22# https://trac.macports.org/wiki/Mirrors#Portfiles.
     23#
     24# If an "rsync://" URL points to a .tar file, a signed .rmd160 file must
     25# exist in the same directory on the server and will be used to verify
     26# its integrity.
     27#
     28# For proper functionality of various resources (port groups, mirror
     29# sites, etc.), the primary MacPorts source must always be tagged
     30# "[default]", even if switched from the default "rsync://" URL.
    3031
    3132rsync://rsync.macports.org/release/tarballs/ports.tar [default]
  • branches/gsoc13-tests/doc/variants.conf

    r63004 r111323  
    1 # To specify global variants to use for all port builds,
    2 # customize this file to list variant settings you want.
     1# $Id$
     2
     3# MacPorts system-wide global variants configuration file.
     4
     5# Any variants listed here are applied to all port builds. As on the
     6# command line, variants may be either enabled (+) or disabled (-), and
     7# unsupported variants are simply ignored.
    38#
    4 # Any variants specified here that are not supported by
    5 # a port will just be ignored. Multiple variants can be
    6 # specified per line, or one per line is also allowed.
     9# Each line must be a space- or tab-delimited list of zero or more
     10# variants.
    711#
    812# Example:
    9 # +ipv6 +no_x11
     13#   -x11 +no_x11 +quartz
     14#   +gcc48
     15#   +universal
  • branches/gsoc13-tests/portmgr/ReleaseProcess

    r95877 r111323  
    108108
    109109And finally we tag the entire directory as release_2_0_0-archive:
     110
     111FIXME: this doesn't seem to work any more. The base subdir in the tag ends up being from trunk.
    110112
    111113 cd ../../
     
    236238 * [http://www.macupdate.com/info.php/id/21309/macports MacUpdate] (submitter: ???)
    237239 * [http://twitter.com/macports twitter] (submitter: raimue@)
     240 * [https://plus.google.com/communities/110287630398071712872 Google+ Community] (submitter: raimue@)
    238241 * (Where else?)
    239242
  • branches/gsoc13-tests/portmgr/fedora/macports.spec

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/gsoc13-tests/portmgr/jobs/mprsyncup

    r96182 r111323  
    8989    exit 1
    9090fi
     91# cleanup up the working copy if it is locked
     92if [ -f ${RBASE}/.svn/lock ]; then
     93    ${CLEANUP} ${RBASE}
     94fi
    9195if [ -d ${RBASE}/.svn ]; then
    9296    ${SVN} switch ${RELEASE_URL} ${RBASE}
     
    114118# generate platform-specific indexes
    115119pushd ${PORTS} >> /dev/null
    116 # build MP trunk in a private location for indexing
    117 pushd ${TBASE} >> /dev/null
     120# build MP in a private location for indexing
     121pushd ${RBASE} >> /dev/null
    118122${MKDIR} -p ${TCLPKG}
    119123./configure \
     
    123127make
    124128make install
     129make distclean
    125130popd
    126131
  • branches/gsoc13-tests/portmgr/jobs/port_binary_distributable.tcl

    r99279 r111323  
    183183        if {!$any_good} {
    184184            if {$verbose} {
    185                 puts "'$portName' has license '$lic' which is not known to be distributable"
     185                puts "\"$portName\" is not distributable because its license \"$lic\" is not known to be distributable"
    186186            }
    187187            return 1
     
    244244            if {!$any_good} {
    245245                if {$verbose} {
    246                     puts "${portName}'s dependency '$aPort' has license '$lic' which is not known to be distributable"
     246                    puts "\"$portName\" is not distributable because its dependency \"$aPort\" has license \"$lic\" which is not known to be distributable"
    247247                }
    248248                return 1
     
    250250            if {!$any_compatible} {
    251251                if {$verbose} {
    252                     puts "dependency '$aPort' has license '$full_lic' which conflicts with license '$top_lic' from '$portName'"
     252                    puts "\"$portName\" is not distributable because its license \"$top_lic\" conflicts with license \"$full_lic\" of dependency \"$aPort\""
    253253                }
    254254                return 1
     
    270270
    271271    if {$verbose} {
    272         puts "$portName is distributable"
     272        puts "\"$portName\" is distributable"
    273273    }
    274274    return 0
  • branches/gsoc13-tests/src/Makefile.in

    r88376 r111323  
    11TCLPKG=         @OUR_INCLUDED_PACKAGES@ \
    22                        cregistry \
     3                        registry2.0 \
    34                        macports1.0 \
    45                        port1.0 \
    56                        package1.0 \
    67                        pextlib1.0 \
    7                         registry2.0 \
    8                         darwintracelib1.0 \
    98                        machista1.0
    109SUBDIR=         ${TCLPKG} port programs
     10
     11ifeq ($(shell uname),Darwin)
     12TCLPKG+= darwintracelib1.0
     13endif
    1114
    1215all::
  • branches/gsoc13-tests/src/config.h.in

    r88981 r111323  
    8484#undef HAVE_INTTYPES_H
    8585
     86/* Define to 1 if you have the `kqueue' function. */
     87#undef HAVE_KQUEUE
     88
    8689/* Define if you have the `crypto' library (-lcrypto). */
    8790#undef HAVE_LIBCRYPTO
     
    174177#undef HAVE_STRING_H
    175178
     179/* Define to 1 if you have the `strlcat' function. */
     180#undef HAVE_STRLCAT
     181
    176182/* Define to 1 if you have the `strlcpy' function. */
    177183#undef HAVE_STRLCPY
     
    189195   */
    190196#undef HAVE_SYS_DIR_H
     197
     198/* Define to 1 if you have the <sys/event.h> header file. */
     199#undef HAVE_SYS_EVENT_H
    191200
    192201/* Define to 1 if you have the <sys/fcntl.h> header file. */
     
    265274#undef STDC_HEADERS
    266275
    267 /* SDK for SDK redirect in tracelib */
    268 #undef TRACE_SDK
    269 
    270276/* Attribute to mark unused variables */
    271277#undef UNUSED
  • branches/gsoc13-tests/src/cregistry/entry.h

    r88441 r111323  
    6363        reg_error* errPtr);
    6464
     65sqlite_int64 reg_entry_owner_id(reg_registry* reg, char* path);
    6566int reg_entry_owner(reg_registry* reg, char* path, reg_entry** entry,
    6667        reg_error* errPtr);
  • branches/gsoc13-tests/src/cregistry/file.c

    r88874 r111323  
    9898 * @param [in] reg      registry to open entry in
    9999 * @param [in] id       port id in the dabatase
    100  * @param [in] path     file path in the database
     100 * @param [in] name     file path in the database
    101101 * @param [out] errPtr  on error, a description of the error that occures
    102102 * @return              the file if success, NULL if failure
  • branches/gsoc13-tests/src/cregistry/util.c

    r93815 r111323  
    124124 * @param [out] objects  the objects selected
    125125 * @param [in] fn        a function to convert sqlite3_stmts to the desired type
    126  * @param [inout] data  data passed along to the cast function
     126 * @param [in,out] castcalldata data passed along to the cast function
    127127 * @param [in] del       a function to delete the desired type of object
    128128 * @param [out] errPtr   on error, a description of the error that occurred
  • branches/gsoc13-tests/src/cregistry/vercomp.c

    r82291 r111323  
    5656 * @param [in] lengthA  length of first version string, or -1 to use strlen
    5757 * @param [in] versionB second version string, i.e. "1.4.2"
    58  * @param [in] lengthA  length of second version string, or -1 to use strlen
     58 * @param [in] lengthB  length of second version string, or -1 to use strlen
    5959 * @return              -1 if A < B; 0 if A = B; 1 if A > B
    6060 */
  • branches/gsoc13-tests/src/darwintracelib1.0/darwintrace.c

    r106639 r111323  
    88 *
    99 * @APPLE_BSD_LICENSE_HEADER_START@
    10  * 
     10 *
    1111 * Redistribution and use in source and binary forms, with or without
    1212 * modification, are permitted provided that the following conditions
    1313 * are met:
    14  * 
     14 *
    1515 * 1.  Redistributions of source code must retain the above copyright
    16  *     notice, this list of conditions and the following disclaimer. 
     16 *     notice, this list of conditions and the following disclaimer.
    1717 * 2.  Redistributions in binary form must reproduce the above copyright
    1818 *     notice, this list of conditions and the following disclaimer in the
    19  *     documentation and/or other materials provided with the distribution. 
     19 *     documentation and/or other materials provided with the distribution.
    2020 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
    2121 *     its contributors may be used to endorse or promote products derived
    22  *     from this software without specific prior written permission. 
    23  * 
     22 *     from this software without specific prior written permission.
     23 *
    2424 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
    2525 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     
    3232 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    3333 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    34  * 
     34 *
    3535 * @APPLE_BSD_LICENSE_HEADER_END@
    3636 */
     
    4343#include <sys/cdefs.h>
    4444#endif
     45
    4546#if defined(_DARWIN_FEATURE_64_BIT_INODE) && !defined(_DARWIN_FEATURE_ONLY_64_BIT_INODE)
    4647/* The architecture we're building for has multiple versions of stat.
     
    6162#endif
    6263
     64#include <ctype.h>
    6365#include <dirent.h>
    6466#include <dlfcn.h>
    6567#include <errno.h>
    6668#include <fcntl.h>
     69#include <pthread.h>
    6770#include <stdarg.h>
     71#include <stdbool.h>
     72#include <stdint.h>
    6873#include <stdio.h>
    6974#include <stdlib.h>
     
    7984#ifndef HAVE_STRLCPY
    8085/* Define strlcpy if it's not available. */
    81 size_t strlcpy(char* dst, const char* src, size_t size);
    82 size_t strlcpy(char* dst, const char* src, size_t size)
    83 {
     86size_t strlcpy(char *dst, const char *src, size_t size) {
    8487        size_t result = strlen(src);
    85         if (size > 0)
    86         {
     88        if (size > 0) {
    8789                size_t copylen = size - 1;
    88                 if (copylen > result)
    89                 {
     90                if (copylen > result) {
    9091                        copylen = result;
    9192                }
     
    9798#endif
    9899
    99 /*
    100  * Compile time options:
    101  * DARWINTRACE_SHOW_PROCESS: show the process id of every access
    102  * DARWINTRACE_LOG_CREATE: log creation of files as well.
    103  * DARWINTRACE_SANDBOX: control creation, deletion and writing to files and dirs.
    104  * DARWINTRACE_LOG_FULL_PATH: use F_GETPATH to log the full path.
    105  * DARWINTRACE_DEBUG_OUTPUT: verbose output of stuff to debug darwintrace.
    106  *
    107  * global variables (only checked when setup is first called)
     100#include "../pextlib1.0/strlcat.c"
     101
     102/* global variables (only checked when setup is first called)
    108103 * DARWINTRACE_LOG
    109104 *    path to the log file (no logging happens if it's unset).
     
    114109 */
    115110
    116 #ifndef DARWINTRACE_SHOW_PROCESS
    117 #define DARWINTRACE_SHOW_PROCESS 0
     111/*
     112 * DARWINTRACE_DEBUG: verbose output of operations to debug darwintrace
     113 */
     114#ifndef DARWINTRACE_DEBUG
     115#define DARWINTRACE_DEBUG (0)
    118116#endif
    119 #ifndef DARWINTRACE_LOG_CREATE
    120 #define DARWINTRACE_LOG_CREATE 0
     117
     118static inline int __darwintrace_strbeginswith(const char *str, const char *prefix);
     119static inline int __darwintrace_pathbeginswith(const char *str, const char *prefix);
     120static inline void __darwintrace_log_op(const char *op, const char *path, int fd);
     121static void __darwintrace_copy_env() __attribute__((constructor));
     122static void __darwintrace_setup_tls() __attribute__((constructor));
     123static inline char *__darwintrace_alloc_env(const char *varName, const char *varValue);
     124static inline char *const *__darwintrace_restore_env(char *const envp[]);
     125static inline void __darwintrace_setup();
     126static inline void __darwintrace_cleanup_path(char *path);
     127static char *__send(const char *buf, uint32_t len, int answer);
     128
     129/**
     130 * PID of the process darwintrace was last used in. This is used to detect
     131 * forking and opening a new connection to the control socket in the child
     132 * process. Not doing so would potentially cause two processes writing to the
     133 * same socket.
     134 */
     135static pid_t __darwintrace_pid = (pid_t) - 1;
     136
     137/**
     138 * pthread_key_ts for the pthread_t returned by pthread_self() and the
     139 * darwintrace socket to ensure the socket is only used from a single thread.
     140 */
     141static pthread_key_t tid_key;
     142static pthread_key_t sock_key;
     143
     144/**
     145 * Helper variable containing the number of the darwintrace socket, iff the
     146 * close(2) syscall should be allowed to close it. Used by \c
     147 * __darwintrace_close.
     148 */
     149static volatile int __darwintrace_close_sock = -1;
     150
     151/**
     152 * size of the communication buffer
     153 */
     154#define BUFFER_SIZE 1024
     155
     156/**
     157 * Variable holding the sandbox bounds in the following format:
     158 *  <filemap>       :: (<spec> '\0')+ '\0'
     159 *  <spec>          :: <path> '\0' <operation> <additional_data>?
     160 *  <operation>     :: '0' | '1' | '2'
     161 * where
     162 *  0: allow
     163 *  1: map the path to the one given in additional_data
     164 *  2: check for a dependency using the socket
     165 */
     166static char *filemap;
     167
     168enum {
     169    FILEMAP_ALLOW = 0,
     170    FILEMAP_REDIR = 1,
     171    FILEMAP_ASK   = 2
     172};
     173
     174/**
     175 * Copy of the DYLD_INSERT_LIBRARIES environment variable to restore it in
     176 * execve(2). DYLD_INSERT_LIBRARIES is needed to preload this library into any
     177 * process' address space.
     178 */
     179static char *__env_dyld_insert_libraries;
     180
     181/**
     182 * Copy of the DYLD_FORCE_FLAT_NAMESPACE environment variable to restore it in
     183 * execve(2). DYLD_FORCE_FLAT_NAMESPACE=1 is needed for the preload-based
     184 * sandbox to work.
     185 */
     186static char *__env_dyld_force_flat_namespace;
     187
     188/**
     189 * Copy of the DARWINTRACE_LOG environment variable to restore it in execve(2).
     190 * Contains the path to the unix socket used for communication with the
     191 * MacPorts-side of the sandbox.
     192 */
     193static char *__env_darwintrace_log;
     194
     195#if DARWINTRACE_DEBUG
     196#   if __STDC_VERSION__>=199901L
     197#       define debug_printf(format, ...) \
     198        fprintf(stderr, "darwintrace[%d]: " format, getpid(), __VA_ARGS__);
     199#   else
     200__attribute__((format(printf, 1, 2))) static inline void debug_printf(const char *format, ...) {
     201        va_list args;
     202        va_start(args, format);
     203        vfprintf(stderr, format, args);
     204        va_end(args);
     205}
     206#   endif
     207#else
     208#   define debug_printf(...)
    121209#endif
    122 #ifndef DARWINTRACE_SANDBOX
    123 #define DARWINTRACE_SANDBOX 1
    124 #endif
    125 #ifndef DARWINTRACE_DEBUG_OUTPUT
    126 #define DARWINTRACE_DEBUG_OUTPUT 0
    127 #endif
    128 #ifndef DARWINTRACE_LOG_FULL_PATH
    129 #define DARWINTRACE_LOG_FULL_PATH 1
    130 #endif
    131 
    132 #ifndef DEFFILEMODE
    133 #define DEFFILEMODE 0666
    134 #endif
     210
     211/**
     212 * Setup method called as constructor to set up thread-local storage for the
     213 * thread id and the darwintrace socket.
     214 */
     215static void __darwintrace_setup_tls() {
     216        if (0 != (errno = pthread_key_create(&tid_key, NULL))) {
     217                perror("darwintrace: pthread_key_create");
     218                abort();
     219        }
     220        if (0 != (errno = pthread_key_create(&sock_key, NULL))) {
     221                perror("darwintrace: pthread_key_create");
     222                abort();
     223        }
     224}
     225
     226/**
     227 * Convenience getter function for the thread-local darwintrace socket
     228 */
     229static inline FILE *__darwintrace_sock() {
     230        return (FILE *) pthread_getspecific(sock_key);
     231}
     232
     233/**
     234 * Convenience getter function for the thread ID
     235 */
     236static inline pthread_t __darwintrace_tid() {
     237        return (pthread_t) pthread_getspecific(tid_key);
     238}
     239
     240/**
     241 * Convenience setter function for the thread-local darwintrace socket
     242 */
     243static inline void __darwintrace_sock_set(FILE *stream) {
     244        if (0 != (errno = pthread_setspecific(sock_key, stream))) {
     245                perror("darwintrace: pthread_setspecific");
     246                abort();
     247        }
     248}
     249
     250/**
     251 * Convenience setter function for the thread-local darwintrace socket
     252 */
     253static inline void __darwintrace_tid_set() {
     254        if (0 != (errno = pthread_setspecific(tid_key, (const void *) pthread_self()))) {
     255                perror("darwintrace: pthread_setspecific");
     256                abort();
     257        }
     258}
     259
     260/**
     261 * Return 0 if str doesn't begin with prefix, 1 otherwise. Note that this is
     262 * not a simple string comparison, but works on a path component level.
     263 * A prefix of /var/tmp will not match a string of /var/tmpfoo.
     264 */
     265static inline int __darwintrace_pathbeginswith(const char *str, const char *prefix) {
     266        char s;
     267        char p;
     268
     269        /* '/' is the allow all wildcard */
     270        if (strcmp(prefix, "/") == 0) {
     271                return 1;
     272        }
     273
     274        do {
     275                s = *str++;
     276                p = *prefix++;
     277        } while (p && (p == s));
     278        return (p == 0 && (s == '/' || s == '\0'));
     279}
     280
     281/**
     282 * Return 0 if str doesn't begin with prefix, 1 otherwise.
     283 */
     284static inline int __darwintrace_strbeginswith(const char *str, const char *prefix) {
     285        char s;
     286        char p;
     287        do {
     288                s = *str++;
     289                p = *prefix++;
     290        } while (p && (p == s));
     291        return (p == 0);
     292}
    135293
    136294/*
    137  * Prototypes.
    138  */
    139 inline int __darwintrace_strbeginswith(const char* str, const char* prefix);
    140 inline void __darwintrace_log_op(const char* op, const char* path, int fd);
    141 void __darwintrace_copy_env() __attribute__((constructor));
    142 inline char* __darwintrace_alloc_env(const char* varName, const char* varValue);
    143 inline char* const* __darwintrace_restore_env(char* const envp[]);
    144 static inline void __darwintrace_setup();
    145 inline void __darwintrace_cleanup_path(char *path);
    146 static char * exchange_with_port(const char * buf, size_t len, int answer);
    147 
    148 static int __darwintrace_fd = -2;
    149 static FILE *__darwintrace_debug = NULL;
    150 static pid_t __darwintrace_pid = (pid_t) -1;
    151 #define BUFFER_SIZE     1024
    152 
    153 /**
    154  * filemap: path\0whattodo\0path\0whattodo\0\0
    155  * path: begin of path (for example /opt)
    156  * whattodo:
    157  *   0     -- allow
    158  *   1PATH -- map
    159  *   2     -- ask for allow
    160 **/
    161 static char * filemap=0;
    162 
    163 /* copy of the global variables */
    164 static char* __env_dyld_insert_libraries;
    165 static char* __env_dyld_force_flat_namespace;
    166 static char* __env_darwintrace_log;
    167 static char* __env_darwintrace_debug_log;
    168 
    169 #if DARWINTRACE_DEBUG_OUTPUT
    170 #if __STDC_VERSION__>=199901L
    171 #define debug_printf(format, ...) fprintf(stderr, "darwintrace[%d]: " format, getpid(), __VA_ARGS__); \
    172         if (__darwintrace_debug) { \
    173                 fprintf(__darwintrace_debug, "darwintrace: " format, __VA_ARGS__); \
    174         }
    175 #else
    176 __attribute__ ((format (printf, 1, 2)))
    177 static inline
    178 int debug_printf(const char *format, ...) {
    179     int ret;
    180     va_list args;
    181     va_start(args, format);
    182     ret = vfprintf(stderr, format, args);
    183     va_end(args);
    184     return ret;
    185 }
    186 #endif
    187 #else
    188 #define debug_printf(...)
    189 #endif
    190 
    191 /*
    192  * return 0 if str doesn't begin with prefix, 1 otherwise.
    193  */
    194 inline int __darwintrace_strbeginswith(const char* str, const char* prefix) {
    195         char theCharS;
    196         char theCharP;
    197         do {
    198                 theCharS = *str++;
    199                 theCharP = *prefix++;
    200         } while(theCharP && (theCharP == theCharS));
    201         return (theCharP == 0);
    202 }
    203 
    204 /*
    205  * Copy the environment variables, if they're defined.
    206  */
    207 void __darwintrace_copy_env() {
    208         char* theValue;
    209         theValue = getenv("DYLD_INSERT_LIBRARIES");
    210         if (theValue != NULL) {
    211                 __env_dyld_insert_libraries = strdup(theValue);
    212         } else {
    213                 __env_dyld_insert_libraries = NULL;
    214         }
    215         theValue = getenv("DYLD_FORCE_FLAT_NAMESPACE");
    216         if (theValue != NULL) {
    217                 __env_dyld_force_flat_namespace = strdup(theValue);
    218         } else {
    219                 __env_dyld_force_flat_namespace = NULL;
    220         }
    221         theValue = getenv("DARWINTRACE_LOG");
    222         if (theValue != NULL) {
    223                 __env_darwintrace_log = strdup(theValue);
    224         } else {
    225                 __env_darwintrace_log = NULL;
    226         }
    227         theValue = getenv("DARWINTRACE_DEBUG_LOG");
    228         if (theValue != NULL) {
    229                 __env_darwintrace_debug_log = strdup(theValue);
    230         } else {
    231                 __env_darwintrace_debug_log = NULL;
    232         }
    233 }
    234 
    235 /*
     295 * Copy the environment variables, if they're defined. This is run as
     296 * a constructor at startup.
     297 */
     298static void __darwintrace_copy_env() {
     299#define COPYENV(name, variable) \
     300        if (NULL != (val = getenv(#name))) {\
     301                if (NULL == (variable = strdup(val))) {\
     302                        perror("darwintrace: strdup");\
     303                        abort();\
     304                }\
     305        } else {\
     306                variable = NULL;\
     307        }
     308
     309        char *val;
     310        COPYENV(DYLD_INSERT_LIBRARIES,     __env_dyld_insert_libraries)
     311        COPYENV(DYLD_FORCE_FLAT_NAMESPACE, __env_dyld_force_flat_namespace)
     312        COPYENV(DARWINTRACE_LOG,           __env_darwintrace_log)
     313#undef COPYENV
     314}
     315
     316/**
    236317 * Allocate a X=Y string where X is the variable name and Y its value.
    237318 * Return the new string.
     
    239320 * If the value is NULL, return NULL.
    240321 */
    241 inline char* __darwintrace_alloc_env(const char* varName, const char* varValue) {
    242         char* theResult = NULL;
    243         if (varValue) {
    244                 int theSize = strlen(varName) + strlen(varValue) + 2;
    245                 theResult = (char*) malloc(theSize);
    246                 if (theResult) {
    247                     snprintf(theResult, theSize, "%s=%s", varName, varValue);
    248                     theResult[theSize - 1] = 0;
    249                 }
    250         }
    251        
    252         return theResult;
    253 }
    254 
    255 /*
     322static inline char *__darwintrace_alloc_env(const char *name, const char *val) {
     323        char *result = NULL;
     324
     325        if (val) {
     326                size_t size = strlen(name) + strlen(val) + 2;
     327                if (NULL == (result = malloc(size))) {
     328                        perror("darwintrace: malloc");
     329                        abort();
     330                }
     331                snprintf(result, size, "%s=%s", name, val);
     332                if (size > 0) {
     333                        result[size - 1] = '\0';
     334                }
     335        }
     336
     337        return result;
     338}
     339
     340/**
    256341 * This function checks that envp contains the global variables we had when the
    257342 * library was loaded and modifies it if it doesn't.
    258343 */
    259 __attribute__((always_inline))
    260 inline char* const* __darwintrace_restore_env(char* const envp[]) {
     344static inline char *const *__darwintrace_restore_env(char *const envp[]) {
    261345        /* allocate the strings. */
    262346        /* we don't care about the leak here because we're going to call execve,
    263      * which, if it succeeds, will get rid of our heap */
    264         char* dyld_insert_libraries_ptr =       
    265                 __darwintrace_alloc_env(
    266                         "DYLD_INSERT_LIBRARIES",
    267                         __env_dyld_insert_libraries);
    268         char* dyld_force_flat_namespace_ptr =   
    269                 __darwintrace_alloc_env(
    270                         "DYLD_FORCE_FLAT_NAMESPACE",
    271                         __env_dyld_force_flat_namespace);
    272         char* darwintrace_log_ptr =     
    273                 __darwintrace_alloc_env(
    274                         "DARWINTRACE_LOG",
    275                         __env_darwintrace_log);
    276         char* darwintrace_debug_log_ptr =       
    277                 __darwintrace_alloc_env(
    278                         "DARWINTRACE_DEBUG_LOG",
    279                         __env_darwintrace_debug_log);
    280 
    281         char* const * theEnvIter = envp;
    282         int theEnvLength = 0;
    283         char** theCopy;
    284         char** theCopyIter;
    285 
    286         while (*theEnvIter != NULL) {
    287                 theEnvLength++;
    288                 theEnvIter++;
    289         }
    290 
    291         /* 5 is sufficient for the four variables we copy and the terminator */
    292         theCopy = (char**) malloc(sizeof(char*) * (theEnvLength + 5));
    293         theEnvIter = envp;
    294         theCopyIter = theCopy;
    295 
    296         while (*theEnvIter != NULL) {
    297                 char* theValue = *theEnvIter;
    298                 if (__darwintrace_strbeginswith(theValue, "DYLD_INSERT_LIBRARIES=")) {
    299                         theValue = dyld_insert_libraries_ptr;
     347         * which, if it succeeds, will get rid of our heap */
     348        char *dyld_insert_libraries_ptr     = __darwintrace_alloc_env("DYLD_INSERT_LIBRARIES",     __env_dyld_insert_libraries);
     349        char *dyld_force_flat_namespace_ptr = __darwintrace_alloc_env("DYLD_FORCE_FLAT_NAMESPACE", __env_dyld_force_flat_namespace);
     350        char *darwintrace_log_ptr           = __darwintrace_alloc_env("DARWINTRACE_LOG",           __env_darwintrace_log);
     351
     352        char *const *enviter = envp;
     353        size_t envlen = 0;
     354        char **copy;
     355        char **copyiter;
     356
     357        while (*enviter != NULL) {
     358                envlen++;
     359                enviter++;
     360        }
     361
     362        /* 4 is sufficient for the three variables we copy and the terminator */
     363        copy = malloc(sizeof(char *) * (envlen + 4));
     364
     365        enviter  = envp;
     366        copyiter = copy;
     367
     368        while (*enviter != NULL) {
     369                char *val = *enviter;
     370                if (__darwintrace_strbeginswith(val, "DYLD_INSERT_LIBRARIES=")) {
     371                        val = dyld_insert_libraries_ptr;
    300372                        dyld_insert_libraries_ptr = NULL;
    301                 } else if (__darwintrace_strbeginswith(theValue, "DYLD_FORCE_FLAT_NAMESPACE=")) {
    302                         theValue = dyld_force_flat_namespace_ptr;
     373                } else if (__darwintrace_strbeginswith(val, "DYLD_FORCE_FLAT_NAMESPACE=")) {
     374                        val = dyld_force_flat_namespace_ptr;
    303375                        dyld_force_flat_namespace_ptr = NULL;
    304                 } else if (__darwintrace_strbeginswith(theValue, "DARWINTRACE_LOG=")) {
    305                         theValue = darwintrace_log_ptr;
     376                } else if (__darwintrace_strbeginswith(val, "DARWINTRACE_LOG=")) {
     377                        val = darwintrace_log_ptr;
    306378                        darwintrace_log_ptr = NULL;
    307                 } else if (__darwintrace_strbeginswith(theValue, "DARWINTRACE_DEBUG_LOG=")) {
    308                         theValue = darwintrace_debug_log_ptr;
    309                         darwintrace_debug_log_ptr = NULL;
    310                 }
    311                
    312                 if (theValue) {
    313                         *theCopyIter++ = theValue;
    314                 }
    315 
    316                 theEnvIter++;
    317         }
    318        
     379                }
     380
     381                if (val) {
     382                        *copyiter++ = val;
     383                }
     384
     385                enviter++;
     386        }
     387
    319388        if (dyld_insert_libraries_ptr) {
    320                 *theCopyIter++ = dyld_insert_libraries_ptr;
     389                *copyiter++ = dyld_insert_libraries_ptr;
    321390        }
    322391        if (dyld_force_flat_namespace_ptr) {
    323                 *theCopyIter++ = dyld_force_flat_namespace_ptr;
     392                *copyiter++ = dyld_force_flat_namespace_ptr;
    324393        }
    325394        if (darwintrace_log_ptr) {
    326                 *theCopyIter++ = darwintrace_log_ptr;
    327         }
    328         if (darwintrace_debug_log_ptr) {
    329                 *theCopyIter++ = darwintrace_debug_log_ptr;
    330         }
    331 
    332         *theCopyIter = 0;
    333        
    334         return theCopy;
    335 }
    336 
    337 static void ask_for_filemap()
    338 {
    339         filemap=exchange_with_port("filemap\t", sizeof("filemap\t"), 1);
    340         if(filemap==(char*)-1)
    341                 filemap=0;
    342 }
    343 
    344 __attribute__((always_inline))
     395                *copyiter++ = darwintrace_log_ptr;
     396        }
     397
     398        *copyiter = 0;
     399
     400        return copy;
     401}
     402
     403/*
     404 * Data structures and functions to iterate over the filemap received from
     405 * tracelib code.
     406 */
     407
     408/**
     409 * \c filemap_iterator_t is an (opaque) iterator type that keeps the state
     410 * required to iterate through the filemap. Create a new filemap_iterator_t on
     411 * stack, initialize it using \c __darwintrace_filemap_iterator_init and pass
     412 * it to \c __darwintrace_filemap_iter to iterate over the filemap.
     413 */
     414typedef struct filemap_iterator {
     415        char *next;
     416} filemap_iterator_t;
     417
     418/**
     419 * Initialize a given \c filemap_iterator_t. Calling this function again will
     420 * rewind the iterator.
     421 *
     422 * \param[in] it pointer to the iterator to be initialized
     423 */
     424static inline void __darwintrace_filemap_iterator_init(filemap_iterator_t *it) {
     425        it->next = filemap;
     426}
     427
     428/**
     429 * Iterate through the filemap passed from tracelib code. Call this multiple
     430 * times with the same iterator object until it returns \c NULL to iterate
     431 * through the filemap.
     432 *
     433 * \param[out] command location for the command specified for this filemap
     434 *                     entry
     435 * \param[out] replacement location for a replacement path, if any. This field
     436 *                         is only valid if the command field indicates
     437 *                         a replacement path is being used.
     438 * \param[in]  it pointer to a \c filemap_iterator_t keeping the state of this
     439 *                iteration
     440 * \return string containing the path this filemap entry corresponds to, or \c
     441 *         NULL if the end of the filemap was reached
     442 */
     443static inline char *__darwintrace_filemap_iter(char *command, char **replacement, filemap_iterator_t *it) {
     444        enum { PATH, COMMAND, REPLACEPATH, DONE } state = PATH;
     445        char *t;
     446        char *path;
     447
     448        if (it == NULL || it->next == NULL || *it->next == '\0') {
     449                return NULL;
     450        }
     451
     452        path = t = it->next;
     453
     454        /* advance the cursor: if the number after the string is not 1, there's no
     455         * path behind it and we can advance by strlen(t) + 3. If it is 1, make
     456         * sure to skip the path, too.
     457         */
     458        state = PATH;
     459        while (state != DONE) {
     460                switch (state) {
     461                        case DONE:
     462                                fprintf(stderr, "darwintrace: illegal state in dfa in " __FILE__ ":%d\n", __LINE__);
     463                                abort();
     464                                break;
     465                        case PATH:
     466                                if (!*t) {
     467                                        state = COMMAND;
     468                                }
     469                                break;
     470                        case COMMAND:
     471                                *command = *t;
     472                                if (*t == 1) {
     473                                        state = REPLACEPATH;
     474                                        *replacement = t + 1;
     475                                } else {
     476                                        state = DONE;
     477                                        /* the byte after the status code is 0, if the status
     478                                         * code isn't 1 */
     479                                        t++;
     480                                }
     481                                break;
     482                        case REPLACEPATH:
     483                                if (!*t) {
     484                                        state = DONE;
     485                                }
     486                                break;
     487                }
     488                t++;
     489        }
     490
     491        it->next = t;
     492        return path;
     493}
     494
     495/**
     496 * Request sandbox boundaries from tracelib (the MacPorts base-controlled side
     497 * of the trace setup) and store it.
     498 */
     499static void __darwintrace_get_filemap() {
     500        char *newfilemap;
     501#if DARWINTRACE_DEBUG && 0
     502        filemap_iterator_t it;
     503        char *path, *replacement, command;
     504#endif
     505
     506#if __GNUC__ && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
     507#error Please build with gcc-4.2 or later
     508#endif
     509
     510        /*
     511         * ensure we have a filemap present; this might be called simultanously
     512         * from multiple threads and needs to work without leaking and in a way
     513         * that ensures a filemap has been set before any of the calls return. We
     514         * achieve that by using non-blocking synchronization. Blocking
     515         * synchronization might be a bad idea, because we never know where this
     516         * code is actually called in an application.
     517         */
     518        newfilemap = NULL;
     519        do {
     520                free(newfilemap);
     521                if (filemap != NULL)
     522                        break;
     523                newfilemap = __send("filemap\t", (uint32_t) strlen("filemap\t"), 1);
     524        } while (!__sync_bool_compare_and_swap(&filemap, NULL, newfilemap));
     525
     526#if DARWINTRACE_DEBUG && 0
     527        for (__darwintrace_filemap_iterator_init(&it);
     528                (path = __darwintrace_filemap_iter(&command, &replacement, &it));) {
     529                debug_printf("filemap: {cmd=%d, path=%-120s, replacement=%s}\n", command, path, (command == 1) ? replacement : "-");
     530        }
     531#endif
     532}
     533
     534/**
     535 * Close the darwintrace socket and set it to \c NULL. Since this uses \c
     536 * fclose(3), which internally calls \c close(2), which is intercepted by this
     537 * library and this library prevents closing the socket to MacPorts, we use \c
     538 * __darwintrace_close_sock to allow closing specific FDs.
     539 */
     540static inline void __darwintrace_close() {
     541        FILE *dtsock = __darwintrace_sock();
     542        if (dtsock) {
     543                __darwintrace_close_sock = fileno(dtsock);
     544                fclose(dtsock);
     545                __darwintrace_close_sock = -1;
     546                pthread_setspecific(sock_key, NULL);
     547        }
     548}
     549
     550/**
     551 * Ensures darwintrace is correctly set up by opening a socket connection to
     552 * the MacPorts-side of trace mode. Will close an re-open this connection when
     553 * called after \c fork(2), i.e. when the current PID doesn't match the one
     554 * stored when the function was called last.
     555 */
    345556static inline void __darwintrace_setup() {
    346 #define open(x,y,z) syscall(SYS_open, (x), (y), (z))
    347 #define close(x) syscall(SYS_close, (x))
    348         pid_t oldpid = __darwintrace_pid;
     557        /*
     558         * Check whether this is a child process and we've inherited the socket. We
     559         * want to avoid race conditions with our parent process when communicating
     560         * with tracelib and thus re-open all sockets, if that's the case. Note
     561         * this also applies to threads within the same process, since we really
     562         * want to avoid mixing up the results from two calls in different threads
     563         * when reading from the socket.
     564         */
     565
     566        /*
     567         * if the PID changed, close the current socket (which will force the
     568         * following code to re-open it).
     569         */
    349570        if (__darwintrace_pid != (pid_t) -1 && __darwintrace_pid != getpid()) {
    350                 if (__darwintrace_fd != -2) {
    351                         close(__darwintrace_fd);
    352                         __darwintrace_fd = -2;
    353                 }
    354                 if (__darwintrace_debug) {
    355                         fclose(__darwintrace_debug);
    356                         __darwintrace_debug = NULL;
    357                 }
     571                __darwintrace_close();
    358572                __darwintrace_pid = (pid_t) -1;
    359573        }
    360         if (__darwintrace_pid == (pid_t) -1) {
     574
     575        /*
     576         * We don't need to watch for TID changes, because each thread has thread
     577         * local storage for the socket that will contain NULL when the socket has
     578         * not been initialized.
     579         */
     580
     581        if (__darwintrace_sock() == NULL) {
     582                int sock;
     583                FILE *stream;
     584                struct sockaddr_un sun;
     585
    361586                __darwintrace_pid = getpid();
    362                 if (__env_darwintrace_log != NULL) {
    363                         int olderrno = errno;
    364                         int sock = socket(AF_UNIX, SOCK_STREAM, 0);
    365                         struct sockaddr_un sun;
    366                         sun.sun_family = AF_UNIX;
    367                         strncpy(sun.sun_path, __env_darwintrace_log, sizeof(sun.sun_path));
    368                         if (connect(sock, (struct sockaddr*)&sun, strlen(__env_darwintrace_log) + 1 + sizeof(sun.sun_family)) != -1) {
    369                                 debug_printf("connect successful, socket %d in pid %d\n", sock, __darwintrace_pid);
    370                                 __darwintrace_fd = sock;
    371                                 ask_for_filemap();
    372                         } else {
    373                                 debug_printf("connect failed: %s\n", strerror(errno));
     587                __darwintrace_tid_set();
     588                if (__env_darwintrace_log == NULL) {
     589                        fprintf(stderr, "darwintrace: trace library loaded, but DARWINTRACE_LOG not set\n");
     590                        abort();
     591                }
     592
     593                if (-1 == (sock = socket(PF_LOCAL, SOCK_STREAM, 0))) {
     594                        perror("darwintrace: socket");
     595                        abort();
     596                }
     597
     598                if (strlen(__env_darwintrace_log) > sizeof(sun.sun_path) - 1) {
     599                        fprintf(stderr, "darwintrace: Can't connect to socket %s: name too long\n", __env_darwintrace_log);
     600                        abort();
     601                }
     602                sun.sun_family = AF_UNIX;
     603                strlcpy(sun.sun_path, __env_darwintrace_log, sizeof(sun.sun_path));
     604
     605                if (-1 == (connect(sock, (struct sockaddr *) &sun, sizeof(sun)))) {
     606                        perror("darwintrace: connect");
     607                        abort();
     608                }
     609
     610                if (NULL == (stream = fdopen(sock, "a+"))) {
     611                        perror("darwintrace: fdopen");
     612                        abort();
     613                }
     614
     615                /* store FILE * into thread local storage for the socket */
     616                __darwintrace_sock_set(stream);
     617
     618                /* request sandbox bounds */
     619                __darwintrace_get_filemap();
     620        }
     621}
     622
     623/**
     624 * Send a path to tracelib either given a path, or an FD (where
     625 * fcntl(F_GETPATH) will be used).
     626 *
     627 * \param[in] op the operation (sent as-is to tracelib, should be interpreted
     628 *               as command)
     629 * \param[in] path the (not necessarily absolute) path to send to tracelib
     630 * \param[in] fd a FD to the file, or 0, if none available
     631 */
     632static inline void __darwintrace_log_op(const char *op, const char *path, int fd) {
     633        uint32_t size;
     634        char somepath[MAXPATHLEN];
     635        char logbuffer[BUFFER_SIZE];
     636
     637        do {
     638#       ifdef __APPLE__ /* Only Darwin has volfs and F_GETPATH */
     639                if ((fd > 0) && (strncmp(path, "/.vol/", 6) == 0)) {
     640                        if (fcntl(fd, F_GETPATH, somepath) != -1) {
     641                                break;
     642                        }
     643                }
     644#       endif
     645
     646                if (*path != '/') {
     647                        if (!getcwd(somepath, sizeof(somepath))) {
     648                                perror("darwintrace: getcwd");
    374649                                abort();
    375650                        }
    376                         errno = olderrno;
    377                 }
    378                 if (__darwintrace_debug == NULL) {
    379                         if (__env_darwintrace_debug_log != NULL) {
    380                                 char logpath[MAXPATHLEN];
    381                                 snprintf(logpath, MAXPATHLEN, __env_darwintrace_debug_log, getpid());
    382                                 if (NULL == (__darwintrace_debug = fopen(logpath, "w"))) {
    383                                         fprintf(stderr, "failed to open logfile: %s\n", strerror(errno));
    384                                         abort();
    385                                 }
    386                                 fprintf(__darwintrace_debug, "pid %d is process %s\n", getpid(), getenv("_"));
    387                                 debug_printf("logging socket communication to: %s\n", logpath);
    388                         }
    389                 }
    390                 if (oldpid != (pid_t) -1) {
    391                         debug_printf("seems to have forked from %d, re-opened files\n", oldpid);
    392                 }
    393         }
    394 #undef close
    395 #undef open
    396 }
    397 
    398 /* log a call and optionally get the real path from the fd if it's not 0.
    399  * op:                  the operation (open, readlink, execve)
    400  * path:                the path of the file
    401  * fd:                  a fd to the file, or 0 if we don't have any.
    402  */
    403 __attribute__((always_inline))
    404 inline void __darwintrace_log_op(const char* op, const char* path, int fd) {
    405         int size;
    406         char somepath[MAXPATHLEN];
    407         char logbuffer[BUFFER_SIZE];
    408 
    409         do {
    410 #ifdef __APPLE__ /* Only Darwin has volfs and F_GETPATH */
    411                 if ((fd > 0) && (DARWINTRACE_LOG_FULL_PATH
    412                         || (strncmp(path, "/.vol/", 6) == 0))) {
    413                         if(fcntl(fd, F_GETPATH, somepath) == -1) {
    414                                 /* getpath failed. use somepath instead */
    415                                 strlcpy(somepath, path, sizeof(somepath));
    416                                 break;
    417                         }
    418                 }
    419 #endif
    420                 if (path[0] != '/') {
    421                         int len;
    422                         (void) getcwd(somepath, sizeof(somepath));
    423                         len = strlen(somepath);
    424                         somepath[len++] = '/';
    425                         strlcpy(&somepath[len], path, sizeof(somepath) - len);
     651
     652                        strlcat(somepath, "/", sizeof(somepath));
     653                        strlcat(somepath, path, sizeof(somepath));
    426654                        break;
    427655                }
     
    434662        __darwintrace_cleanup_path(somepath);
    435663
    436         size = snprintf(logbuffer, sizeof(logbuffer),
    437                 "%s\t%s",
    438                 op, somepath);
    439 
    440         exchange_with_port(logbuffer, size+1, 0);
    441        
    442         return;
    443 }
    444 
    445 /* remap resource fork access to the data fork.
     664        size = snprintf(logbuffer, sizeof(logbuffer), "%s\t%s", op, somepath);
     665        __send(logbuffer, size, 0);
     666}
     667
     668/**
     669 * remap resource fork access to the data fork.
    446670 * do a partial realpath(3) to fix "foo//bar" to "foo/bar"
    447671 */
    448 inline void __darwintrace_cleanup_path(char *path) {
     672static inline void __darwintrace_cleanup_path(char *path) {
    449673        size_t pathlen;
    450 #ifdef __APPLE__
     674#   ifdef __APPLE__
    451675        size_t rsrclen;
    452 #endif
    453         size_t i, shiftamount;
     676#   endif
     677        char *dst, *src;
    454678        enum { SAWSLASH, NOTHING } state = NOTHING;
    455679
     
    457681        pathlen = strlen(path);
    458682        /* ..namedfork/rsrc is only on OS X */
    459 #ifdef __APPLE__
     683#   ifdef __APPLE__
    460684        rsrclen = strlen(_PATH_RSRCFORKSPEC);
    461685        if (pathlen > rsrclen && 0 == strcmp(path + pathlen - rsrclen, _PATH_RSRCFORKSPEC)) {
     
    463687                pathlen -= rsrclen;
    464688        }
    465 #endif
    466 
    467         /* for each position in string (including terminal \0), check if we're in
    468          * a run of multiple slashes, and only emit the first one */
    469         for(i = 0, shiftamount = 0; i <= pathlen; i++) {
     689#   endif
     690
     691        /* for each position in string, check if we're in a run of multiple
     692         * slashes, and only emit the first one */
     693        for (src = path, dst = path; *src; src++) {
    470694                if (state == SAWSLASH) {
    471                         if (path[i] == '/') {
     695                        if (*src == '/') {
    472696                                /* consume it */
    473                                 shiftamount++;
    474697                                continue;
    475                         } else {
    476                                 state = NOTHING;
    477698                        }
     699                        state = NOTHING;
    478700                } else {
    479                         if (path[i] == '/') {
     701                        if (*src == '/') {
    480702                                state = SAWSLASH;
    481703                        }
    482704                }
    483                 path[i - shiftamount] = path[i];
    484         }
    485 }
    486 
    487 /*
    488  * return 1 if path allowed, 0 otherwise
    489  */
    490 static int ask_for_dependency(char * path) {
     705                if (dst != src) {
     706                        // if dst == src, avoid the copy operation
     707                        *dst = *src;
     708                }
     709                dst++;
     710        }
     711}
     712
     713/**
     714 * Check whether the port currently being installed declares a dependency on
     715 * a given file. Communicates with MacPorts tracelib, which uses the registry
     716 * database to answer this question. Returns 1, if a dependency was declared,
     717 * 0, if the file belongs to a port and no dependency was declared and -1 if
     718 * the file isnt't registered to any port.
     719 *
     720 * \param[in] path the path to send to MacPorts for dependency info
     721 * \return 1, if access should be granted, 0, if access should be denied, and
     722 *         -1 if MacPorts doesn't know about the file.
     723 */
     724static int dependency_check(char *path) {
    491725#define stat(y, z) syscall(SYS_stat, (y), (z))
    492726        char buffer[BUFFER_SIZE], *p;
     727        uint32_t len;
    493728        int result = 0;
    494729        struct stat st;
    495 
    496         debug_printf("ask_for_dependency: %s\n", path);
    497730
    498731        if (-1 == stat(path, &st)) {
     
    503736                return 1;
    504737        }
    505        
    506         strncpy(buffer, "dep_check\t", sizeof(buffer));
    507         strncpy(buffer+10, path, sizeof(buffer)-10);
    508         p=exchange_with_port(buffer, strlen(buffer)+1, 1);
    509         if(p==(char*)-1||!p)
    510                 return 0;
    511        
    512         if(*p=='+')
    513                 result=1;
    514        
     738
     739        len = snprintf(buffer, sizeof(buffer), "dep_check\t%s", path);
     740        if (len > sizeof(buffer)) {
     741                len = sizeof(buffer) - 1;
     742        }
     743        p = __send(buffer, len, 1);
     744        if (!p) {
     745                fprintf(stderr, "darwintrace: dependency check failed for %s\n", path);
     746                abort();
     747        }
     748
     749        switch (*p) {
     750                case '+':
     751                        result = 1;
     752                        break;
     753                case '!':
     754                        result = 0;
     755                        break;
     756                case '?':
     757                        result = -1;
     758                        break;
     759                default:
     760                        fprintf(stderr, "darwintrace: unexpected answer from tracelib: '%c' (0x%x)\n", *p, *p);
     761                        abort();
     762                        break;
     763        }
     764
     765        debug_printf("dependency_check: %s returned %d\n", path, result);
     766
    515767        free(p);
    516768        return result;
     
    518770}
    519771
    520 /*
    521  * exchange_with_port - routine to send/recv from/to socket
    522  * Parameters:
    523  *   buf      -- buffer with data to send
    524  *   len      -- length of data
    525  *   answer   -- 1 (yes, I want to receive answer) and 0 (no, thanks, just send)
    526  *   failures -- should be setted 0 on external calls (avoid infinite recursion)
    527  * Return value:
    528  *    -1     -- something went wrong
    529  *    0      -- data successfully sent
    530  *    string -- answer (caller shoud free it)
    531  */
    532 static char * exchange_with_port(const char * buf, size_t len, int answer) {
    533         size_t sent = 0;
    534 
    535         if (__darwintrace_debug) {
    536                 fprintf(__darwintrace_debug, "> %s\n", buf);
    537         }
    538         while (sent < len) {
    539                 ssize_t local_sent = send(__darwintrace_fd, buf + sent, len - sent, 0);
    540                 if (local_sent == -1) {
    541                         debug_printf("error communicating with socket %d: %s\n", __darwintrace_fd, strerror(errno));
    542                         if (__darwintrace_debug)
    543                                 fprintf(__darwintrace_debug, "darwintrace: error communicating with socket %d: %s\n", __darwintrace_fd, strerror(errno));
    544                         abort();
    545                 }
    546                 sent += local_sent;
    547         }
     772/**
     773 * Helper function to recieve a number of bytes from the tracelib communication
     774 * socket and deal with any errors that might occur.
     775 *
     776 * \param[out] buf buffer to hold received data
     777 * \param[in]  size number of bytes to read from the socket
     778 */
     779static void frecv(void *restrict buf, size_t size) {
     780        FILE *stream = __darwintrace_sock();
     781        if (1 != fread(buf, size, 1, stream)) {
     782                if (ferror(stream)) {
     783                        perror("darwintrace: fread");
     784                } else {
     785                        fprintf(stderr, "darwintrace: fread: end-of-file\n");
     786                }
     787                abort();
     788        }
     789}
     790
     791/**
     792 * Helper function to send a buffer to MacPorts using the tracelib
     793 * communication socket and deal with any errors that might occur.
     794 *
     795 * \param[in] buf buffer to send
     796 * \param[in] size number of bytes in the buffer
     797 */
     798static void fsend(const void *restrict buf, size_t size) {
     799        FILE *stream = __darwintrace_sock();
     800        if (1 != fwrite(buf, size, 1, stream)) {
     801                if (ferror(stream)) {
     802                        perror("darwintrace: fwrite");
     803                } else {
     804                        fprintf(stderr, "darwintrace: fwrite: end-of-file\n");
     805                }
     806                abort();
     807        }
     808        fflush(stream);
     809}
     810
     811/**
     812 * Communication wrapper targeting tracelib. Automatically enforces the on-wire
     813 * protocol and supports reading and returning an answer.
     814 *
     815 * \param[in] buf buffer to send to tracelib
     816 * \param[in] size size of the buffer to send
     817 * \param[in] answer boolean indicating whether an answer is expected and
     818 *                   should be returned
     819 * \return allocated answer buffer. Callers should free this buffer. If an
     820 *         answer was not requested, \c NULL.
     821 */
     822static char *__send(const char *buf, uint32_t len, int answer) {
     823        fsend(&len, sizeof(len));
     824        fsend(buf, len);
     825
    548826        if (!answer) {
     827                return NULL;
     828        }
     829
     830        uint32_t recv_len = 0;
     831        char *recv_buf;
     832
     833        frecv(&recv_len, sizeof(recv_len));
     834        if (recv_len == 0) {
    549835                return 0;
    550         } else {
    551                 size_t recv_len = 0, received;
    552                 char *recv_buf;
    553                
    554                 received = 0;
    555                 while (received < sizeof(recv_len)) {
    556                         ssize_t local_received = recv(__darwintrace_fd, ((char *) &recv_len) + received, sizeof(recv_len) - received, 0);
    557                         if (local_received == -1) {
    558                                 debug_printf("error reading data from socket %d: %s\n", __darwintrace_fd, strerror(errno));
    559                                 if (__darwintrace_debug)
    560                                         fprintf(__darwintrace_debug, "darwintrace: error reading data from socket %d: %s\n", __darwintrace_fd, strerror(errno));
    561                                 abort();
    562                         }
    563                         received += local_received;
    564                 }
    565                 if (recv_len == 0) {
    566                         return 0;
    567                 }
    568 
    569                 recv_buf = malloc(recv_len + 1);
    570                 recv_buf[recv_len] = '\0';
    571 
    572                 received = 0;
    573                 while (received < recv_len) {
    574                         ssize_t local_received = recv(__darwintrace_fd, recv_buf + received, recv_len - received, 0);
    575                         if (local_received == -1) {
    576                                 debug_printf("error reading data from socket %d: %s\n", __darwintrace_fd, strerror(errno));
    577                                 if (__darwintrace_debug)
    578                                         fprintf(__darwintrace_debug, "darwintrace: error reading data from socket %d: %s\n", __darwintrace_fd, strerror(errno));
    579                                 abort();
    580                         }
    581                         received += local_received;
    582                 }
    583                 if (__darwintrace_debug) {
    584                         fprintf(__darwintrace_debug, "< %s\n", recv_buf);
    585                 }
    586                 return recv_buf;
    587         }
    588 }
    589 
    590 #define DARWINTRACE_STATUS_PATH    ((char) 0)
    591 #define DARWINTRACE_STATUS_COMMAND ((char) 1)
    592 #define DARWINTRACE_STATUS_DONE    ((char) 2)
    593 
    594 /*
    595  * return 1 if path (once normalized) is in sandbox or redirected, 0 otherwise.
    596  */
    597 __attribute__((always_inline))
    598 inline int __darwintrace_is_in_sandbox(const char* path, char * newpath) {
    599         char *t, *p, *_;
     836        }
     837
     838        recv_buf = malloc(recv_len + 1);
     839        recv_buf[recv_len] = '\0';
     840        frecv(recv_buf, recv_len);
     841
     842        return recv_buf;
     843}
     844
     845/**
     846 * Check a path against the current sandbox
     847 *
     848 * \param[in] path the path to be checked; not necessarily absolute
     849 * \param[out] newpath buffer for a replacement path when redirection should
     850 *                     occur. Initialize the first byte with 0 before calling
     851 *                     this function. The buffer should be at least MAXPATHLEN
     852 *                     bytes large. If newpath[0] isn't 0 after the call,
     853 *                     redirection should occur and the path from newpath
     854 *                     should be used for the syscall instead.
     855 * \param[in] report If access to this path is being denied, report it as
     856 *                   sandbox violation. Set this to \c true for all operations
     857 *                   that read file contents. Set this to \c false for
     858 *                   operations that only check for the file's existance, e.g.,
     859 *                   reading a directory.
     860 * \return 1, if the file is within sandbox bounds, 0, if access should be denied
     861 */
     862static inline int __darwintrace_is_in_sandbox(const char *path, char *newpath, bool report) {
     863        char *t, *_;
     864        char *strpos, *normpos;
    600865        char lpath[MAXPATHLEN];
    601        
     866        char normalizedpath[MAXPATHLEN];
     867        filemap_iterator_t filemap_it;
     868        char command;
     869        char *replacementpath;
     870
    602871        __darwintrace_setup();
    603        
    604         if (!filemap)
     872
     873        if (!filemap) {
    605874                return 1;
    606        
    607         if (*path=='/') {
    608                 p = strcpy(lpath, path);
     875        }
     876
     877        /* Make sure the path is absolute. */
     878        if (*path == '/') {
     879                strcpy(lpath, path);
    609880        } else {
    610881                if (getcwd(lpath, MAXPATHLEN - 1) == NULL) {
    611                         fprintf(stderr, "darwintrace: getcwd: %s, path was: %s\n", strerror(errno), path);
     882                        perror("darwintrace: getcwd");
    612883                        abort();
    613884                }
    614                 strcat(lpath, "/");
    615                 strcat(lpath, path);
    616         }
    617 
    618         p = lpath;
    619 
    620         for (t = filemap; *t;) {
    621                 char state;
    622                
    623                 if (__darwintrace_strbeginswith(p, t)) {
     885                strlcat(lpath, "/", MAXPATHLEN);
     886                strlcat(lpath, path, MAXPATHLEN);
     887        }
     888
     889        /* Make sure the path is normalized. NOTE: Do _not_ use realpath(3) here.
     890         * Doing so _will_ lead to problems. This is essentially a very simple
     891         * re-implementation of realpath(3). */
     892        normalizedpath[0] = '\0';
     893        strpos = lpath + 1;
     894        normpos = normalizedpath;
     895        for (;;) {
     896                char *curpos = strsep(&strpos, "/");
     897                if (curpos == NULL) {
     898                        /* reached the end of the path */
     899                        break;
     900                } else if (*curpos == '\0') {
     901                        /* empty entry, ignore */
     902                        continue;
     903                } else if (strcmp(curpos, ".") == 0) {
     904                        /* no-op directory, ignore */
     905                        continue;
     906                } else if (strcmp(curpos, "..") == 0) {
     907                        /* walk up one directory */
     908                        char *lastSep = strrchr(normalizedpath, '/');
     909                        if (lastSep == NULL) {
     910                                /* path is completely empty */
     911                                normpos = normalizedpath;
     912                                *normpos = '\0';
     913                                continue;
     914                        }
     915                        /* remove last component by overwriting the slash with \0, update normpos */
     916                        *lastSep = '\0';
     917                        normpos = lastSep;
     918                        continue;
     919                }
     920                /* default case: standard path, copy */
     921                strcat(normpos, "/");
     922                normpos++;
     923                strcat(normpos, curpos);
     924        }
     925        if (*normalizedpath == '\0') {
     926                strcat(normalizedpath, "/");
     927        }
     928
     929        /* Iterate over the sandbox bounds and try to find a directive matching this path */
     930        for (__darwintrace_filemap_iterator_init(&filemap_it);
     931                (t = __darwintrace_filemap_iter(&command, &replacementpath, &filemap_it));) {
     932                if (__darwintrace_pathbeginswith(normalizedpath, t)) {
    624933                        /* move t to the integer describing how to handle this match */
    625934                        t += strlen(t) + 1;
    626935                        switch (*t) {
    627                                 case 0:
     936                                case FILEMAP_ALLOW:
    628937                                        return 1;
    629                                 case 1:
     938                                case FILEMAP_REDIR:
    630939                                        if (!newpath) {
    631940                                                return 0;
     
    637946                                        /* append '/' if it's missing */
    638947                                        if (_[-1] != '/') {
    639                                                 *_ = '/';
     948                                                *_++ = '/';
    640949                                        }
    641                                         strcpy(_, p);
     950                                        strcpy(_, normalizedpath);
    642951                                        return 1;
    643                                 case 2:
     952                                case FILEMAP_ASK:
    644953                                        /* ask the socket whether this file is OK */
    645                                         return ask_for_dependency(p);
     954                                        switch (dependency_check(normalizedpath)) {
     955                                                case 1:
     956                                                        return 1;
     957                                                case -1:
     958                                                        /* if the file isn't known to MacPorts, allow
     959                                                         * access anyway, but report a sandbox violation.
     960                                                         * TODO find a better solution */
     961                                                        if (report)
     962                                                                __darwintrace_log_op("sandbox_violation", normalizedpath, 0);
     963                                                        return 1;
     964                                                case 0:
     965                                                        /* file belongs to a foreign port, deny access */
     966                                                        if (report)
     967                                                                __darwintrace_log_op("sandbox_violation", normalizedpath, 0);
     968                                                        return 0;
     969                                        }
    646970                                default:
    647971                                        fprintf(stderr, "darwintrace: error: unexpected byte in file map: `%x'\n", *t);
     
    649973                        }
    650974                }
    651 
    652                 /* advance the cursor: if the number after the string is not 1, there's
    653                  * no path behind it and we can advance by strlen(t) + 3. If it is 1,
    654                  * make sure to skip the path, too.
    655                  */
    656                 state = DARWINTRACE_STATUS_PATH;
    657                 while (state != DARWINTRACE_STATUS_DONE) {
    658                         switch (state) {
    659                                 case DARWINTRACE_STATUS_PATH:
    660                                         if (!*t) {
    661                                                 state = DARWINTRACE_STATUS_COMMAND;
    662                                         }
    663                                         break;
    664                                 case DARWINTRACE_STATUS_COMMAND:
    665                                         if (*t == 1) {
    666                                                 state = DARWINTRACE_STATUS_PATH;
    667                                                 t++;
    668                                         } else {
    669                                                 state = DARWINTRACE_STATUS_DONE;
    670                                         }
    671                                         break;
    672                         }
    673                         t++;
    674                 }
    675                 t++;
    676         }
    677 
    678         __darwintrace_log_op("sandbox_violation", path, 0);
     975        }
     976
     977        if (report)
     978                __darwintrace_log_op("sandbox_violation", normalizedpath, 0);
    679979        return 0;
    680980}
    681981
    682982/* wrapper for open(2) preventing opening files outside the sandbox */
    683 int open(const char* path, int flags, ...) {
     983int open(const char *path, int flags, ...) {
    684984#define open(x,y,z) syscall(SYS_open, (x), (y), (z))
    685985        mode_t mode;
     
    690990
    691991        *newpath = '\0';
    692         if (!__darwintrace_is_in_sandbox(path, newpath)) {
     992        if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
    693993                debug_printf("open %s was forbidden\n", path);
    694994                errno = ((flags & O_CREAT) > 0) ? EACCES : ENOENT;
     
    7141014*/
    7151015#ifdef READLINK_IS_NOT_P1003_1A
    716 int readlink(const char * path, char * buf, int bufsiz) {
     1016int readlink(const char *path, char *buf, int bufsiz) {
    7171017#else
    718 ssize_t readlink(const char * path, char * buf, size_t bufsiz) {
     1018ssize_t readlink(const char *path, char *buf, size_t bufsiz) {
    7191019#endif
    7201020#define readlink(x,y,z) syscall(SYS_readlink, (x), (y), (z))
     
    7241024
    7251025        *newpath = '\0';
    726         if (!__darwintrace_is_in_sandbox(path, newpath)) {
     1026        if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
    7271027                errno = ENOENT;
    7281028                return -1;
     
    7371037}
    7381038
    739 int execve(const char* path, char* const argv[], char* const envp[]) {
    740 #define __execve(x,y,z) syscall(SYS_execve, (x), (y), (z))
     1039int execve(const char *path, char *const argv[], char *const envp[]) {
     1040#define execve(x,y,z) syscall(SYS_execve, (x), (y), (z))
    7411041#define open(x,y,z) syscall(SYS_open, (x), (y), (z))
    7421042#define close(x) syscall(SYS_close, (x))
     
    7441044        debug_printf("execve(%s)\n", path);
    7451045        __darwintrace_setup();
    746         if (__darwintrace_fd >= 0) {
    747                 struct stat sb;
    748                 /* for symlinks, we want to capture both the original path and the
    749                  * modified one, since for /usr/bin/gcc -> gcc-4.0, both "gcc_select"
    750                  * and "gcc" are contributors
    751                  */
    752                 if (lstat(path, &sb) == 0) {
    753                         int fd;
    754                         if (S_ISLNK(sb.st_mode)) {
    755                                 /* for symlinks, print both */
    756                                 __darwintrace_log_op("execve", path, 0);
    757                         }
    758 
    759                         fd = open(path, O_RDONLY, 0);
    760                         if (fd > 0) {
    761                                 char buffer[MAXPATHLEN+1];
    762                                 ssize_t bytes_read;
    763 
    764                                 if(!__darwintrace_is_in_sandbox(path, NULL)) {
     1046        struct stat sb;
     1047        /* for symlinks, we want to capture both the original path and the modified
     1048         * one, since for $prefix/bin/gcc -> mp-gcc-4.8, both "gcc_select" and
     1049         * "gcc48" are contributors. This requires changes to the select code such
     1050         * that the symlinks are registered to the *_select ports. Since this
     1051         * a general problem (when executing $prefix/libexec/mysql/bin/foo where
     1052         * $prefix/libexec/mysql is a symlink to $prefix/libexec/mysql55, the
     1053         * mysql_select port needs to be a contributor!) we should really implement
     1054         * this in __darwintrace_is_in_sandbox().
     1055         */
     1056        if (lstat(path, &sb) == 0) {
     1057                if (!__darwintrace_is_in_sandbox(path, NULL, true)) {
     1058                        errno = ENOENT;
     1059                        return -1;
     1060                }
     1061
     1062                int fd = open(path, O_RDONLY, 0);
     1063                if (fd > 0) {
     1064                        char buffer[MAXPATHLEN + 1];
     1065                        ssize_t bytes_read;
     1066
     1067                        /* Read the file for the interpreter. Fortunately, on OS X:
     1068                         *   The system guarantees to read the number of bytes requested if
     1069                         *   the descriptor references a normal file that has that many
     1070                         *   bytes left before the end-of-file, but in no other case.
     1071                         * That _does_ save us another ugly loop to get things right. */
     1072                        bytes_read = read(fd, buffer, MAXPATHLEN);
     1073                        buffer[bytes_read] = '\0';
     1074                        const char *buffer_end = buffer + bytes_read;
     1075                        if (bytes_read > 2 && buffer[0] == '#' && buffer[1] == '!') {
     1076                                char *interp = buffer + 2;
     1077
     1078                                /* skip past leading whitespace */
     1079                                while (interp < buffer_end && isblank(*interp)) {
     1080                                        ++interp;
     1081                                }
     1082                                /* found interpreter (or ran out of data); skip until next
     1083                                 * whitespace, then terminate the string */
     1084                                if (interp < buffer_end) {
     1085                                        char *interp_end = interp;
     1086                                        strsep(&interp_end, " \t");
     1087                                }
     1088
     1089                                /* check the iterpreter against the sandbox */
     1090                                if (!__darwintrace_is_in_sandbox(interp, NULL, true)) {
    7651091                                        close(fd);
    7661092                                        errno = ENOENT;
    7671093                                        return -1;
    7681094                                }
    769        
    770                                 /* once we have an open fd, if a full path was requested, do it */
    771                                 __darwintrace_log_op("execve", path, fd);
    772        
    773                                 /* read the file for the interpreter */
    774                                 bytes_read = read(fd, buffer, MAXPATHLEN);
    775                                 buffer[bytes_read] = 0;
    776                                 if (bytes_read > 2 && buffer[0] == '#' && buffer[1] == '!') {
    777                                         const char* interp = &buffer[2];
    778                                         int i;
    779                                         /* skip past leading whitespace */
    780                                         for (i = 2; i < bytes_read; ++i) {
    781                                                 if (buffer[i] != ' ' && buffer[i] != '\t') {
    782                                                         interp = &buffer[i];
    783                                                         break;
    784                                                 }
    785                                         }
    786                                         /* found interpreter (or ran out of data); skip until next
    787                                          * whitespace, then terminate the string */
    788                                         for (; i < bytes_read; ++i) {
    789                                                 if (buffer[i] == ' ' || buffer[i] == '\t' || buffer[i] == '\n') {
    790                                                         buffer[i] = 0;
    791                                                         break;
    792                                                 }
    793                                         }
    794                                         /* we have liftoff */
    795                                         if (interp && interp[0] != '\0') {
    796                                                 __darwintrace_log_op("execve", interp, 0);
    797                                         }
    798                                 }
    799                                 close(fd);
    8001095                        }
    801                 }
    802         }
     1096
     1097                        close(fd);
     1098
     1099                }
     1100        }
     1101
    8031102        /* our variables won't survive exec, clean up */
    804         if (__darwintrace_fd != -2) {
    805                 close(__darwintrace_fd);
    806                 __darwintrace_fd = -2;
    807         }
    808         if (__darwintrace_debug) {
    809                 fclose(__darwintrace_debug);
    810                 __darwintrace_debug = NULL;
    811         }
    812         __darwintrace_pid = (pid_t) -1;
     1103        __darwintrace_close();
     1104        __darwintrace_pid = (pid_t) - 1;
    8131105
    8141106        /* call the original execve function, but fix the environment if required. */
    815         return __execve(path, argv, __darwintrace_restore_env(envp));
     1107        return execve(path, argv, __darwintrace_restore_env(envp));
    8161108#undef lstat
    8171109#undef close
     
    8241116int close(int fd) {
    8251117#define close(x) syscall(SYS_close, (x))
    826         if (__darwintrace_fd != -2 && fd == __darwintrace_fd) {
    827                 errno = EBADF;
    828                 return -1;
     1118        FILE *stream = __darwintrace_sock();
     1119        if (stream) {
     1120                int dtsock = fileno(stream);
     1121                if (fd == dtsock && dtsock != __darwintrace_close_sock) {
     1122                        errno = EBADF;
     1123                        return -1;
     1124                }
    8291125        }
    8301126
     
    8361132int dup2(int filedes, int filedes2) {
    8371133#define dup2(x, y) syscall(SYS_dup2, (x), (y))
     1134        FILE *stream = __darwintrace_sock();
    8381135
    8391136        debug_printf("dup2(%d, %d)\n", filedes, filedes2);
    840         if (__darwintrace_fd != -2 && filedes2 == __darwintrace_fd) {
     1137        if (stream && filedes2 == fileno(stream)) {
    8411138                /* if somebody tries to close our file descriptor, just move it out of
    8421139                 * the way. Make sure it doesn't end up as stdin/stdout/stderr, though!
    8431140                 * */
    8441141                int new_darwintrace_fd;
    845 
    846                 if (-1 == (new_darwintrace_fd = fcntl(__darwintrace_fd, F_DUPFD, STDOUT_FILENO + 1))) {
     1142                FILE *new_stream;
     1143
     1144                if (-1 == (new_darwintrace_fd = fcntl(fileno(stream), F_DUPFD, STDOUT_FILENO + 1))) {
    8471145                        /* if duplicating fails, do not allow overwriting either! */
    8481146                        return -1;
    8491147                }
    8501148
    851                 debug_printf("moving __darwintrace_fd from %d to %d\n", __darwintrace_fd, new_darwintrace_fd);
    852                 __darwintrace_fd = new_darwintrace_fd;
     1149                debug_printf("moving __darwintrace FD from %d to %d\n", fileno(stream), new_darwintrace_fd);
     1150                __darwintrace_close();
     1151                if (NULL == (new_stream = fdopen(new_darwintrace_fd, "a+"))) {
     1152                        perror("darwintrace: fdopen");
     1153                        abort();
     1154                }
     1155                __darwintrace_sock_set(new_stream);
    8531156        }
    8541157
     
    8571160}
    8581161
    859 
    8601162/* Trap attempts to unlink a file outside the sandbox. */
    861 int unlink(const char* path) {
     1163int unlink(const char *path) {
    8621164#define __unlink(x) syscall(SYS_unlink, (x))
    8631165        char newpath[MAXPATHLEN];
    8641166
    8651167        *newpath = '\0';
    866         if (!__darwintrace_is_in_sandbox(path, newpath)) {
     1168        if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
    8671169                debug_printf("unlink %s was forbidden\n", path);
    8681170                errno = ENOENT;
     
    8811183/* Trap attempts to create directories outside the sandbox.
    8821184 */
    883 int mkdir(const char* path, mode_t mode) {
     1185int mkdir(const char *path, mode_t mode) {
    8841186#define __mkdir(x,y) syscall(SYS_mkdir, (x), (y))
    8851187        char newpath[MAXPATHLEN];
    8861188
    8871189        *newpath = '\0';
    888         if (!__darwintrace_is_in_sandbox(path, newpath)) {
     1190        if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
    8891191                struct stat st;
    8901192                if (-1 == lstat(path, &st)) {
     
    9111213/* Trap attempts to remove directories outside the sandbox.
    9121214 */
    913 int rmdir(const char* path) {
     1215int rmdir(const char *path) {
    9141216#define __rmdir(x) syscall(SYS_rmdir, (x))
    915         if (!__darwintrace_is_in_sandbox(path, NULL)) {
     1217        if (!__darwintrace_is_in_sandbox(path, NULL, true)) {
    9161218                debug_printf("removing directory %s was forbidden\n", path);
    9171219                errno = ENOENT;
     
    9261228/* Trap attempts to rename files/directories outside the sandbox.
    9271229 */
    928 int rename(const char* from, const char* to) {
     1230int rename(const char *from, const char *to) {
    9291231#define __rename(x,y) syscall(SYS_rename, (x), (y))
    930         if (!__darwintrace_is_in_sandbox(from, NULL)) {
     1232        if (!__darwintrace_is_in_sandbox(from, NULL, true)) {
    9311233                /* outside sandbox, forbid */
    9321234                debug_printf("renaming from %s was forbidden\n", from);
     
    9341236                return -1;
    9351237        }
    936         if (!__darwintrace_is_in_sandbox(to, NULL)) {
     1238        if (!__darwintrace_is_in_sandbox(to, NULL, true)) {
    9371239                debug_printf("renaming to %s was forbidden\n", to);
    9381240                errno = EACCES;
     
    9451247}
    9461248
    947 int stat(const char * path, struct stat * sb) {
     1249int stat(const char *path, struct stat *sb) {
    9481250#define stat(path, sb) syscall(SYS_stat, path, sb)
    9491251        int result = 0;
     
    9601262
    9611263        *newpath = '\0';
    962         if (!__darwintrace_is_in_sandbox(path, newpath)) {
     1264        if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
    9631265                errno = ENOENT;
    9641266                return -1;
     
    9751277#if defined(__DARWIN_64_BIT_INO_T) && !defined(_DARWIN_FEATURE_ONLY_64_BIT_INODE)
    9761278
    977 int stat64(const char * path, struct stat64 * sb) {
     1279int stat64(const char *path, struct stat64 *sb) {
    9781280#define stat64(path, sb) syscall(SYS_stat64, path, sb)
    9791281        int result = 0;
     
    9901292
    9911293        *newpath = '\0';
    992         if (!__darwintrace_is_in_sandbox(path, newpath)) {
     1294        if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
    9931295                errno = ENOENT;
    9941296                return -1;
     
    10031305}
    10041306
    1005 int stat$INODE64(const char * path, struct stat64 * sb) {
    1006     return stat64(path, sb);
     1307int stat$INODE64(const char *path, struct stat64 *sb) {
     1308        return stat64(path, sb);
    10071309}
    10081310
     
    10101312
    10111313
    1012 int lstat(const char * path, struct stat * sb) {
     1314int lstat(const char *path, struct stat *sb) {
    10131315#define lstat(path, sb) syscall(SYS_lstat, path, sb)
    10141316        int result = 0;
     
    10251327
    10261328        *newpath = '\0';
    1027         if (!__darwintrace_is_in_sandbox(path, newpath)) {
     1329        if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
    10281330                errno = ENOENT;
    10291331                return -1;
     
    10401342#if defined(__DARWIN_64_BIT_INO_T) && !defined(_DARWIN_FEATURE_ONLY_64_BIT_INODE)
    10411343
    1042 int lstat64(const char * path, struct stat64 * sb) {
     1344int lstat64(const char *path, struct stat64 *sb) {
    10431345#define lstat64(path, sb) syscall(SYS_lstat64, path, sb)
    10441346        int result = 0;
     
    10551357
    10561358        *newpath = '\0';
    1057         if (!__darwintrace_is_in_sandbox(path, newpath)) {
     1359        if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
    10581360                errno = ENOENT;
    10591361                return -1;
     
    10681370}
    10691371
    1070 int lstat$INODE64(const char * path, struct stat64 * sb) {
    1071     return lstat64(path, sb);
     1372int lstat$INODE64(const char *path, struct stat64 *sb) {
     1373        return lstat64(path, sb);
    10721374}
    10731375
     
    11241426                dirname[dnamelen] = '\0';
    11251427                strcat(dirname, dent->d_name);
    1126                 if (!__darwintrace_is_in_sandbox(dirname, NULL)) {
     1428                if (!__darwintrace_is_in_sandbox(dirname, NULL, false)) {
    11271429                        debug_printf("__getdirentries64: filtered %s\n", dirname);
    11281430                        dent->d_ino = 0;
     
    11721474                dirname[dnamelen] = '\0';
    11731475                strcat(dirname, dent->d_name);
    1174                 if (!__darwintrace_is_in_sandbox(dirname, NULL)) {
     1476                if (!__darwintrace_is_in_sandbox(dirname, NULL, false)) {
    11751477                        debug_printf("getdirentries: filtered %s\n", dirname);
    11761478                        dent->d_ino = 0;
     
    11841486#undef getdirentries
    11851487}
     1488
     1489int access(const char *path, int amode) {
     1490#define access(x, y) syscall(SYS_access, (x), (y))
     1491#define lstat(path, sb) syscall(SYS_lstat, path, sb)
     1492        struct stat st;
     1493        char newpath[MAXPATHLEN];
     1494
     1495        debug_printf("access(%s, %d)\n", path, amode);
     1496
     1497        if (-1 == lstat(path, &st)) {
     1498                return -1;
     1499        }
     1500
     1501        if (S_ISDIR(st.st_mode)) {
     1502                return access(path, amode);
     1503        }
     1504
     1505        *newpath = '\0';
     1506        if (!__darwintrace_is_in_sandbox(path, newpath, true)) {
     1507                errno = ENOENT;
     1508                return -1;
     1509        }
     1510
     1511        if (*newpath) {
     1512                return access(newpath, amode);
     1513        }
     1514
     1515        return access(path, amode);
     1516#undef lstat
     1517#undef access
     1518}
     1519
    11861520#endif /* __APPLE__ */
  • branches/gsoc13-tests/src/machista1.0/Makefile.in

    r92838 r111323  
    1616include ../../Mk/macports.tea.mk
    1717
    18 CFLAGS+= -fPIC -std=c99 -pedantic
     18CFLAGS+= -fPIC
    1919
    2020${SWIG_SRCS}:: ${SWIG_IFACE}
  • branches/gsoc13-tests/src/macports1.0/Makefile

    r110017 r111323  
    11SRCS=           macports.tcl macports_dlist.tcl macports_util.tcl \
    2                 macports_autoconf.tcl macports_index.tcl macports_fastload.tcl
     2                macports_autoconf.tcl macports_fastload.tcl
    33OBJS=           macports.o get_systemconfiguration_proxies.o sysctl.o
    44SHLIB_NAME=     MacPorts${SHLIB_SUFFIX}
  • branches/gsoc13-tests/src/macports1.0/macports.tcl

    r110019 r111323  
    3636package provide macports 1.0
    3737package require macports_dlist 1.0
    38 package require macports_index 1.0
    3938package require macports_util 1.0
    4039
    4140namespace eval macports {
    42     namespace export bootstrap_options user_options portinterp_options open_mports ui_priorities port_phases 
     41    namespace export bootstrap_options user_options portinterp_options open_mports ui_priorities port_phases
    4342    variable bootstrap_options "\
    4443        portdbpath libpath binpath auto_path extra_env sources_conf prefix portdbformat \
     
    5150        master_site_local patch_site_local archive_site_local buildfromsource \
    5251        revupgrade_autorun revupgrade_mode revupgrade_check_id_loadcmds \
    53         host_blacklist preferred_hosts sandbox_enable \
     52        host_blacklist preferred_hosts sandbox_enable delete_la_files cxx_stdlib \
    5453        packagemaker_path default_compilers pkg_post_unarchive_deletions"
    55     variable user_options ""
     54    variable user_options {}
    5655    variable portinterp_options "\
    5756        portdbpath porturl portpath portbuildpath auto_path prefix prefix_frozen portsharepath \
     
    6261        applications_dir current_phase frameworks_dir developer_dir universal_archs build_arch \
    6362        os_arch os_endian os_version os_major os_platform macosx_version macosx_deployment_target \
    64         packagemaker_path default_compilers sandbox_enable \
     63        packagemaker_path default_compilers sandbox_enable delete_la_files cxx_stdlib \
    6564        pkg_post_unarchive_deletions $user_options"
    6665
     
    7473    variable ui_priorities "error warn msg notice info debug any"
    7574    variable port_phases "any fetch checksum"
    76     variable current_phase "main"
     75    variable current_phase main
    7776
    7877    variable ui_prefix "---> "
     
    101100proc macports::ui_isset {val} {
    102101    if {[info exists macports::ui_options($val)]} {
    103         if {$macports::ui_options($val) == "yes"} {
     102        if {$macports::ui_options($val) eq {yes}} {
    104103            return 1
    105104        }
     
    112111proc macports::global_option_isset {val} {
    113112    if {[info exists macports::global_options($val)]} {
    114         if {$macports::global_options($val) == "yes"} {
     113        if {$macports::global_options($val) eq {yes}} {
    115114            return 1
    116115        }
     
    131130    # Add our log-channel to all already initialized channels
    132131    foreach key [array names channels] {
    133         set macports::channels($key) [concat $macports::channels($key) "debuglog"]
     132        set macports::channels($key) [concat $macports::channels($key) debuglog]
    134133    }
    135134    return 0
     
    145144    set logname [macports::getportlogpath $portpath $portname]
    146145    file mkdir $logname
    147     set logname [file join $logname "main.log"]
     146    set logname [file join $logname main.log]
    148147
    149148    set ::debuglogname $logname
     
    151150    # Truncate the file if already exists
    152151    set ::debuglog [open $::debuglogname w]
    153     puts $::debuglog "version:1"
     152    puts $::debuglog version:1
    154153}
    155154proc macports::push_log {mport} {
     
    175174    }
    176175}
     176
    177177proc macports::pop_log {} {
    178178    global ::logenabled ::logstack ::debuglog ::debuglogname
     
    197197    global macports::current_phase
    198198    set macports::current_phase $phase
    199     if {$phase != "main"} {
     199    if {$phase ne {main}} {
    200200        set cur_time [clock format [clock seconds] -format  {%+}]
    201201        ui_debug "$phase phase started at $cur_time"
     
    206206    global macports::channels ::debuglog macports::current_phase
    207207    foreach chan $macports::channels($priority) {
    208         if {[info exists ::debuglog] && ($chan == "debuglog")} {
     208        if {[info exists ::debuglog] && ($chan eq {debuglog})} {
    209209            set chan $::debuglog
    210210            if {[info exists macports::current_phase]} {
    211211                set phase $macports::current_phase
    212212            }
    213             set strprefix ":$priority:$phase "
    214             if {[lindex $args 0] == "-nonewline"} {
    215                 puts -nonewline $chan "$strprefix[lindex $args 1]"
     213            set strprefix ":${priority}:$phase "
     214            if {[lindex $args 0] eq {-nonewline}} {
     215                puts -nonewline $chan $strprefix[lindex $args 1]
    216216            } else {
    217                 puts $chan "$strprefix[lindex $args 0]"
    218             }
    219  
     217                puts $chan $strprefix[lindex $args 0]
     218            }
     219
    220220        } else {
    221             if {[lindex $args 0] == "-nonewline"} {
    222                 puts -nonewline $chan "$prefix[lindex $args 1]"
     221            if {[lindex $args 0] eq {-nonewline}} {
     222                puts -nonewline $chan $prefix[lindex $args 1]
    223223            } else {
    224                 puts $chan "$prefix[lindex $args 0]"
     224                puts $chan $prefix[lindex $args 0]
    225225            }
    226226        }
     
    236236        set channels($priority) $default_channel
    237237    }
    238    
     238
    239239    # if some priority initialized after log file is being created
    240240    if {[info exists ::debuglog]} {
    241         set channels($priority) [concat $channels($priority) "debuglog"]
     241        set channels($priority) [concat $channels($priority) debuglog]
    242242    }
    243243    # Simplify ui_$priority.
     
    251251        eval ::ui_init $priority $prefix $channels($priority) $args
    252252    } catch * {
    253         interp alias {} ui_$priority {} ui_message $priority $prefix ""
     253        interp alias {} ui_$priority {} ui_message $priority $prefix {}
    254254        foreach phase $phases {
    255             interp alias {} ui_${priority}_${phase} {} ui_message $priority $prefix $phase
     255            interp alias {} ui_${priority}_$phase {} ui_message $priority $prefix $phase
    256256        }
    257257    }
     
    260260# Default implementation of ui_prefix
    261261proc macports::ui_prefix_default {priority} {
    262     switch $priority {
     262    switch -- $priority {
    263263        debug {
    264264            return "DEBUG: "
     
    271271        }
    272272        default {
    273             return ""
     273            return {}
    274274        }
    275275    }
     
    281281# ui_options(ports_quiet) - If set, don't output "standard messages"
    282282proc macports::ui_channels_default {priority} {
    283     switch $priority {
     283    switch -- $priority {
    284284        debug {
    285285            if {[ui_isset ports_debug]} {
    286                 return {stderr}
     286                return stderr
    287287            } else {
    288288                return {}
     
    291291        info {
    292292            if {[ui_isset ports_verbose]} {
    293                 return {stdout}
     293                return stdout
    294294            } else {
    295295                return {}
     
    300300                return {}
    301301            } else {
    302                 return {stdout}
     302                return stdout
    303303            }
    304304        }
    305305        msg {
    306             return {stdout}
     306            return stdout
    307307        }
    308308        warn -
    309309        error {
    310             return {stderr}
     310            return stderr
    311311        }
    312312        default {
    313             return {stdout}
     313            return stdout
    314314        }
    315315    }
     
    332332# find a binary either in a path defined at MacPorts' configuration time
    333333# or in the PATH environment variable through macports::binaryInPath (fallback)
    334 proc macports::findBinary {prog {autoconf_hint ""}} {
    335     if {${autoconf_hint} != "" && [file executable ${autoconf_hint}]} {
    336         return ${autoconf_hint}
     334proc macports::findBinary {prog {autoconf_hint {}}} {
     335    if {$autoconf_hint ne {} && [file executable $autoconf_hint]} {
     336        return $autoconf_hint
    337337    } else {
    338         if {[catch {set cmd_path [macports::binaryInPath ${prog}]} result] == 0} {
    339             return ${cmd_path}
     338        if {[catch {set cmd_path [macports::binaryInPath $prog]} result] == 0} {
     339            return $cmd_path
    340340        } else {
    341             return -code error "${result} or at its MacPorts configuration time location, did you move it?"
     341            return -code error "$result or at its MacPorts configuration time location, did you move it?"
    342342        }
    343343    }
     
    359359proc macports::getoption {name} {
    360360    global macports::$name
    361     return [expr $$name]
     361    return [set $name]
    362362}
    363363
     
    372372        if {![info exists xcodeversion]} {
    373373            # Determine xcode version
    374             set macports::xcodeversion "2.0orlower"
     374            set macports::xcodeversion 2.0orlower
    375375            if {[catch {set xcodebuildversion [exec -- $xcodebuild -version 2> /dev/null]}] == 0} {
    376376                if {[regexp {Xcode ([0-9.]+)} $xcodebuildversion - xcode_v] == 1} {
    377377                    set macports::xcodeversion $xcode_v
    378                 } elseif {[regexp "DevToolsCore-(.*);" $xcodebuildversion - devtoolscore_v] == 1} {
     378                } elseif {[regexp {DevToolsCore-(.*);} $xcodebuildversion - devtoolscore_v] == 1} {
    379379                    if {$devtoolscore_v >= 1809.0} {
    380                         set macports::xcodeversion "3.2.6"
     380                        set macports::xcodeversion 3.2.6
    381381                    } elseif {$devtoolscore_v >= 1204.0} {
    382                         set macports::xcodeversion "3.1.4"
     382                        set macports::xcodeversion 3.1.4
    383383                    } elseif {$devtoolscore_v >= 1100.0} {
    384                         set macports::xcodeversion "3.1"
     384                        set macports::xcodeversion 3.1
    385385                    } elseif {$devtoolscore_v >= 921.0} {
    386                         set macports::xcodeversion "3.0"
     386                        set macports::xcodeversion 3.0
    387387                    } elseif {$devtoolscore_v >= 798.0} {
    388                         set macports::xcodeversion "2.5"
     388                        set macports::xcodeversion 2.5
    389389                    } elseif {$devtoolscore_v >= 762.0} {
    390                         set macports::xcodeversion "2.4.1"
     390                        set macports::xcodeversion 2.4.1
    391391                    } elseif {$devtoolscore_v >= 757.0} {
    392                         set macports::xcodeversion "2.4"
     392                        set macports::xcodeversion 2.4
    393393                    } elseif {$devtoolscore_v > 650.0} {
    394394                        # XXX find actual version corresponding to 2.3
    395                         set macports::xcodeversion "2.3"
     395                        set macports::xcodeversion 2.3
    396396                    } elseif {$devtoolscore_v >= 650.0} {
    397                         set macports::xcodeversion "2.2.1"
     397                        set macports::xcodeversion 2.2.1
    398398                    } elseif {$devtoolscore_v > 620.0} {
    399399                        # XXX find actual version corresponding to 2.2
    400                         set macports::xcodeversion "2.2"
     400                        set macports::xcodeversion 2.2
    401401                    } elseif {$devtoolscore_v >= 620.0} {
    402                         set macports::xcodeversion "2.1"
     402                        set macports::xcodeversion 2.1
    403403                    }
    404404                }
    405405            } else {
    406406                ui_warn "xcodebuild exists but failed to execute"
    407                 set macports::xcodeversion "none"
     407                set macports::xcodeversion none
    408408            }
    409409        }
    410410        if {![info exists xcodebuildcmd]} {
    411             set macports::xcodebuildcmd "$xcodebuild"
     411            set macports::xcodebuildcmd $xcodebuild
    412412        }
    413413    } else {
    414414        if {![info exists xcodeversion]} {
    415             set macports::xcodeversion "none"
     415            set macports::xcodeversion none
    416416        }
    417417        if {![info exists xcodebuildcmd]} {
    418             set macports::xcodebuildcmd "none"
     418            set macports::xcodebuildcmd none
    419419        }
    420420    }
     
    426426
    427427    trace remove variable macports::developer_dir read macports::set_developer_dir
    428    
     428
    429429    # Look for xcodeselect, and make sure it has a valid value
    430430    if {![catch {findBinary xcode-select $macports::autoconf::xcode_select_path} xcodeselect]} {
     
    439439
    440440        # The directory from xcode-select isn't correct.
    441        
     441
    442442        # Ask mdfind where Xcode is and make some suggestions for the user,
    443443        # searching by bundle identifier for various Xcode versions (3.x and 4.x)
     
    446446            set installed_xcodes [exec $mdfind "kMDItemCFBundleIdentifier == 'com.apple.Xcode' || kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'"]
    447447        }
    448        
     448
    449449        # In case mdfind metadata wasn't complete, also look in two well-known locations for Xcode.app
    450450        foreach app {/Applications/Xcode.app /Developer/Applications/Xcode.app} {
     
    453453            }
    454454        }
    455        
     455
    456456        # Form a list of unique xcode installations
    457457        set installed_xcodes [lsort -unique $installed_xcodes]
     
    465465            foreach xcode $installed_xcodes {
    466466                set vers [exec $mdls -raw -name kMDItemVersion $xcode]
    467                 if {$vers == "(null)"} { set vers "unknown" }
    468                 if {[_is_valid_developer_dir "${xcode}/Contents/Developer"]} {
     467                if {$vers eq {(null)}} {set vers unknown}
     468                if {[_is_valid_developer_dir ${xcode}/Contents/Developer]} {
    469469                    # Though xcode-select shipped with xcode 4.3 supports and encourages
    470470                    # direct use of the app path, older xcode-select does not.
    471471                    # Specify the Contents/Developer directory if it exists
    472                     ui_error "    sudo xcode-select -switch ${xcode}/Contents/Developer # version ${vers}"
     472                    ui_error "    sudo xcode-select -switch ${xcode}/Contents/Developer # version $vers"
    473473                } elseif {[vercmp $vers 4.3] >= 0} {
    474474                    # Future proofing: fall back to the app-path only for xcode >= 4.3, since Contents/Developer doesn't exist
    475                     ui_error "    sudo xcode-select -switch ${xcode} # version ${vers}"
    476                 } elseif {[_is_valid_developer_dir "${xcode}/../.."]} {
     475                    ui_error "    sudo xcode-select -switch $xcode # version $vers"
     476                } elseif {[_is_valid_developer_dir ${xcode}/../..]} {
    477477                    # Older xcode (< 4.3) is below the developer directory
    478                     ui_error "    sudo xcode-select -switch [file normalize ${xcode}/../..] # version ${vers}"
     478                    ui_error "    sudo xcode-select -switch [file normalize ${xcode}/../..] # version $vers"
    479479                } else {
    480                     ui_error "    # malformed Xcode at ${xcode}, version ${vers}"
     480                    ui_error "    # malformed Xcode at ${xcode}, version $vers"
    481481                }
    482482            }
     
    490490    # Try the default
    491491    if {$os_major >= 11 && [vercmp $xcodeversion 4.3] >= 0} {
    492         set devdir "/Applications/Xcode.app/Contents/Developer"
     492        set devdir /Applications/Xcode.app/Contents/Developer
    493493    } else {
    494         set devdir "/Developer"
     494        set devdir /Developer
    495495    }
    496496
     
    508508    # Verify that the directory has some key subdirectories
    509509    foreach subdir {Library usr} {
    510         if {![file isdirectory "${dir}/${subdir}"]} {
     510        if {![file isdirectory ${dir}/$subdir]} {
    511511            return 0
    512512        }
     
    519519
    520520proc mportinit {{up_ui_options {}} {up_options {}} {up_variations {}}} {
    521     if {$up_ui_options eq ""} {
     521    if {$up_ui_options eq {}} {
    522522        array set macports::ui_options {}
    523523    } else {
     
    525525        array set macports::ui_options [array get temp_ui_options]
    526526    }
    527     if {$up_options eq ""} {
     527    if {$up_options eq {}} {
    528528        array set macports::global_options {}
    529529    } else {
     
    531531        array set macports::global_options [array get temp_options]
    532532    }
    533     if {$up_variations eq ""} {
     533    if {$up_variations eq {}} {
    534534        array set variations {}
    535535    } else {
     
    538538
    539539    # Initialize ui_*
    540     foreach priority ${macports::ui_priorities} {
     540    foreach priority $macports::ui_priorities {
    541541        macports::ui_init $priority
    542542    }
     543
    543544
    544545    global auto_path env tcl_platform \
     
    579580        macports::ping_cache \
    580581        macports::host_blacklisted \
    581         macports::host_preferred
     582        macports::host_preferred \
     583        macports::delete_la_files \
     584        macports::cxx_stdlib
    582585
    583586    # Set the system encoding to utf-8
     
    586589    # set up platform info variables
    587590    set os_arch $tcl_platform(machine)
    588     if {$os_arch == "Power Macintosh"} { set os_arch "powerpc" }
    589     if {$os_arch == "i586" || $os_arch == "i686" || $os_arch == "x86_64"} { set os_arch "i386" }
     591    if {$os_arch eq {Power Macintosh}} {set os_arch "powerpc"}
     592    if {$os_arch eq {i586} || $os_arch eq {i686} || $os_arch eq {x86_64}} {set os_arch "i386"}
    590593    set os_version $tcl_platform(osVersion)
    591594    set os_major [lindex [split $os_version .] 0]
     
    594597    set os_endian [string range $tcl_platform(byteOrder) 0 end-6]
    595598    set macosx_version {}
    596     if {$os_platform == "darwin"} {
     599    if {$os_platform eq {darwin}} {
    597600        # This will probably break when Apple changes versioning
    598         set macosx_version [expr 10.0 + ($os_major - 4) / 10.0]
     601        set macosx_version [expr {10.0 + ($os_major - 4) / 10.0}]
    599602    }
    600603
     
    604607        set macports::user_home $env(HOME)
    605608        set macports::macports_user_dir [file normalize $macports::autoconf::macports_user_dir]
    606     } elseif {[info exists env(SUDO_USER)] && $os_platform == "darwin"} {
     609    } elseif {[info exists env(SUDO_USER)] && $os_platform eq {darwin}} {
    607610        set macports::user_home [exec dscl -q . -read /Users/$env(SUDO_USER) NFSHomeDirectory | cut -d ' ' -f 2]
    608         set macports::macports_user_dir [file join ${macports::user_home} [string range $macports::autoconf::macports_user_dir 2 end]]
    609     } elseif {[exec id -u] != 0 && $os_platform == "darwin"} {
     611        set macports::macports_user_dir [file join $macports::user_home [string range $macports::autoconf::macports_user_dir 2 end]]
     612    } elseif {[exec id -u] != 0 && $os_platform eq {darwin}} {
    610613        set macports::user_home [exec dscl -q . -read /Users/[exec id -un] NFSHomeDirectory | cut -d ' ' -f 2]
    611         set macports::macports_user_dir [file join ${macports::user_home} [string range $macports::autoconf::macports_user_dir 2 end]]
     614        set macports::macports_user_dir [file join $macports::user_home [string range $macports::autoconf::macports_user_dir 2 end]]
    612615    } else {
    613616        # Otherwise define the user directory as a directory that will never exist
    614         set macports::macports_user_dir "/dev/null/NO_HOME_DIR"
    615         set macports::user_home "/dev/null/NO_HOME_DIR"
     617        set macports::macports_user_dir /dev/null/NO_HOME_DIR
     618        set macports::user_home /dev/null/NO_HOME_DIR
    616619    }
    617620
    618621    # Configure the search path for configuration files
    619     set conf_files ""
    620     lappend conf_files "${macports_conf_path}/macports.conf"
    621     if { [file isdirectory $macports_user_dir] } {
    622         lappend conf_files "${macports_user_dir}/macports.conf"
     622    set conf_files {}
     623    lappend conf_files ${macports_conf_path}/macports.conf
     624    if {[file isdirectory $macports_user_dir]} {
     625        lappend conf_files ${macports_user_dir}/macports.conf
    623626    }
    624627    if {[info exists env(PORTSRC)]} {
    625628        set PORTSRC $env(PORTSRC)
    626         lappend conf_files ${PORTSRC}
     629        lappend conf_files $PORTSRC
    627630    }
    628631
    629632    # Process all configuration files we find on conf_files list
    630633    foreach file $conf_files {
    631         if [file exists $file] {
     634        if {[file exists $file]} {
    632635            set portconf $file
    633636            set fd [open $file r]
     
    645648
    646649    # Process per-user only settings
    647     set per_user "${macports_user_dir}/user.conf"
    648     if [file exists $per_user] {
     650    set per_user ${macports_user_dir}/user.conf
     651    if {[file exists $per_user]} {
    649652        set fd [open $per_user r]
    650653        while {[gets $fd line] >= 0} {
     
    672675                        ui_warn "$sources_conf source '$line' specifies invalid flag '$flag'"
    673676                    }
    674                     if {$flag == "default"} {
     677                    if {$flag eq {default}} {
    675678                        if {[info exists sources_default]} {
    676679                            ui_warn "More than one default port source is defined."
     
    690693    # contain _resources.
    691694    if {![info exists sources_default]} {
    692         ui_warn "No default port source specified in $sources_conf, using last source as default"
     695        ui_warn "No default port source specified in ${sources_conf}, using last source as default"
    693696        set sources_default [lindex $sources end]
    694697    }
     
    696699    if {![info exists sources]} {
    697700        if {[file isdirectory ports]} {
    698             set sources "file://[pwd]/ports"
     701            set sources file://[pwd]/ports
    699702        } else {
    700703            return -code error "No sources defined in $sources_conf"
     
    703706
    704707    if {[info exists variants_conf]} {
    705         if {[file exist $variants_conf]} {
     708        if {[file exists $variants_conf]} {
    706709            set fd [open $variants_conf r]
    707710            while {[gets $fd line] >= 0} {
     
    729732    # pubkeys.conf
    730733    set macports::archivefetch_pubkeys {}
    731     if {[file isfile [file join ${macports_conf_path} pubkeys.conf]]} {
    732         set fd [open [file join ${macports_conf_path} pubkeys.conf] r]
     734    if {[file isfile [file join $macports_conf_path pubkeys.conf]]} {
     735        set fd [open [file join $macports_conf_path pubkeys.conf] r]
    733736        while {[gets $fd line] >= 0} {
    734737            set line [string trim $line]
     
    760763    # Format for receipts; currently only "sqlite" is allowed
    761764    # could previously be "flat", so we switch that to sqlite
    762     if {![info exists portdbformat] || $portdbformat == "flat" || $portdbformat == "sqlite"} {
     765    if {![info exists portdbformat] || $portdbformat eq {flat} || $portdbformat eq {sqlite}} {
    763766        set registry.format receipt_sqlite
    764767    } else {
     
    768771    # Autoclean mode, whether to automatically call clean after "install"
    769772    if {![info exists portautoclean]} {
    770         set macports::portautoclean "yes"
     773        set macports::portautoclean yes
    771774        global macports::portautoclean
    772775    }
    773776    # whether to keep logs after successful builds
    774777    if {![info exists keeplogs]} {
    775         set macports::keeplogs "no"
     778        set macports::keeplogs no
    776779        global macports::keeplogs
    777780    }
    778    
     781
    779782    # Check command line override for autoclean
    780783    if {[info exists macports::global_options(ports_autoclean)]} {
    781         if {![string equal $macports::global_options(ports_autoclean) $portautoclean]} {
     784        if {$macports::global_options(ports_autoclean) ne $portautoclean} {
    782785            set macports::portautoclean $macports::global_options(ports_autoclean)
    783786        }
     
    785788    # Trace mode, whether to use darwintrace to debug ports.
    786789    if {![info exists porttrace]} {
    787         set macports::porttrace "no"
     790        set macports::porttrace no
    788791        global macports::porttrace
    789792    }
    790793    # Check command line override for trace
    791794    if {[info exists macports::global_options(ports_trace)]} {
    792         if {![string equal $macports::global_options(ports_trace) $porttrace]} {
     795        if {$macports::global_options(ports_trace) ne $porttrace} {
    793796            set macports::porttrace $macports::global_options(ports_trace)
    794797        }
     
    798801        && ![info exists macports::global_options(ports_source_only)]
    799802        && [info exists macports::buildfromsource]} {
    800         if {${macports::buildfromsource} == "never"} {
     803        if {$macports::buildfromsource eq {never}} {
    801804            set macports::global_options(ports_binary_only) yes
    802805            set temp_options(ports_binary_only) yes
    803         } elseif {${macports::buildfromsource} == "always"} {
     806        } elseif {$macports::buildfromsource eq {always}} {
    804807            set macports::global_options(ports_source_only) yes
    805808            set temp_options(ports_source_only) yes
    806         } elseif {${macports::buildfromsource} != "ifneeded"} {
    807             ui_warn "'buildfromsource' set to unknown value '${macports::buildfromsource}', using 'ifneeded' instead"
     809        } elseif {$macports::buildfromsource ne {ifneeded}} {
     810            ui_warn "'buildfromsource' set to unknown value '$macports::buildfromsource', using 'ifneeded' instead"
    808811        }
    809812    }
     
    819822    # Export verbosity.
    820823    if {![info exists portverbose]} {
    821         set macports::portverbose "no"
     824        set macports::portverbose no
    822825        global macports::portverbose
    823826    }
    824827    if {[info exists macports::ui_options(ports_verbose)]} {
    825         if {![string equal $macports::ui_options(ports_verbose) $portverbose]} {
     828        if {$macports::ui_options(ports_verbose) ne $portverbose} {
    826829            set macports::portverbose $macports::ui_options(ports_verbose)
    827830        }
     
    832835    global macports::portarchivetype
    833836    if {![info exists portarchivetype]} {
    834         set macports::portarchivetype "tbz2"
     837        set macports::portarchivetype tbz2
    835838    } else {
    836839        set macports::portarchivetype [lindex $portarchivetype 0]
     
    857860
    858861    if {![info exists libpath]} {
    859         set libpath "${prefix}/share/macports/Tcl"
     862        set libpath ${prefix}/share/macports/Tcl
    860863    }
    861864
    862865    if {![info exists binpath]} {
    863         set env(PATH) "${prefix}/bin:${prefix}/sbin:/bin:/sbin:/usr/bin:/usr/sbin"
     866        set env(PATH) ${prefix}/bin:${prefix}/sbin:/bin:/sbin:/usr/bin:/usr/sbin
    864867    } else {
    865         set env(PATH) "$binpath"
     868        set env(PATH) $binpath
    866869    }
    867870
    868871    # Set startupitem default type (can be overridden by portfile)
    869872    if {![info exists macports::startupitem_type]} {
    870         set macports::startupitem_type "default"
     873        set macports::startupitem_type default
    871874    }
    872875
     
    889892    }
    890893    if {![info exists macports::ccache_size]} {
    891         set macports::ccache_size "2G"
     894        set macports::ccache_size 2G
    892895    }
    893896    if {![info exists macports::configuredistcc]} {
     
    921924        ui_warn "invalid universal_archs configured (should contain at least 2 archs)"
    922925    }
    923    
     926
    924927    # Default arch to build for
    925928    if {![info exists macports::build_arch]} {
    926         if {$os_platform == "darwin"} {
     929        if {$os_platform eq {darwin}} {
    927930            if {$os_major >= 10} {
    928931                if {[sysctl hw.cpu64bit_capable] == 1} {
     
    932935                }
    933936            } else {
    934                 if {$os_arch == "powerpc"} {
     937                if {$os_arch eq {powerpc}} {
    935938                    set macports::build_arch ppc
    936939                } else {
     
    939942            }
    940943        } else {
    941             set macports::build_arch ""
     944            set macports::build_arch {}
    942945        }
    943946    } else {
     
    953956    }
    954957    if {![info exists macports::revupgrade_mode]} {
    955         set macports::revupgrade_mode "rebuild"
     958        set macports::revupgrade_mode rebuild
     959    }
     960    if {![info exists macports::delete_la_files]} {
     961        if {$os_platform eq "darwin" && $os_major >= 13} {
     962            set macports::delete_la_files yes
     963        } else {
     964            set macports::delete_la_files no
     965        }
     966    }
     967    if {![info exists macports::cxx_stdlib]} {
     968        if {$os_platform eq "darwin" && $os_major < 13} {
     969            set macports::cxx_stdlib libstdc++
     970        } else {
     971            set macports::cxx_stdlib {}
     972        }
    956973    }
    957974    if {![info exists macports::global_options(ports_rev-upgrade_id-loadcmd-check)]
    958975         && [info exists macports::revupgrade_check_id_loadcmds]} {
    959         set macports::global_options(ports_rev-upgrade_id-loadcmd-check) ${macports::revupgrade_check_id_loadcmds}
    960         set temp_options(ports_rev-upgrade_id-loadcmd-check) ${macports::revupgrade_check_id_loadcmds}
     976        set macports::global_options(ports_rev-upgrade_id-loadcmd-check) $macports::revupgrade_check_id_loadcmds
     977        set temp_options(ports_rev-upgrade_id-loadcmd-check) $macports::revupgrade_check_id_loadcmds
    961978    }
    962979
     
    980997    }
    981998    if {[info exists extra_env]} {
    982         set keepenvkeys [concat ${keepenvkeys} ${extra_env}]
     999        set keepenvkeys [concat $keepenvkeys $extra_env]
    9831000    }
    9841001
     
    10001017    # don't keep unusable TMPDIR/TMP values
    10011018    foreach var {TMP TMPDIR} {
    1002         if {[info exists env($var)] && [file writable $env($var)] && 
    1003             ([getuid] != 0 || $macportsuser == "root" ||
    1004              [file attributes $env($var) -owner] == $macportsuser)} {
     1019        if {[info exists env($var)] && [file writable $env($var)] &&
     1020            ([getuid] != 0 || $macportsuser eq {root} ||
     1021             [file attributes $env($var) -owner] eq $macportsuser)} {
    10051022            lappend keepenvkeys $var
    10061023        }
     
    10151032
    10161033    # unset environment an extra time, to work around bugs in Leopard Tcl
    1017     if {$macosx_version == "10.5"} {
     1034    if {$macosx_version eq {10.5}} {
    10181035        foreach envkey $env_names {
    10191036            if {[lsearch -exact $keepenvkeys $envkey] == -1} {
     
    10301047
    10311048    if {![info exists developer_dir]} {
    1032         if {$os_platform == "darwin"} {
     1049        if {$os_platform eq {darwin}} {
    10331050            trace add variable macports::developer_dir read macports::set_developer_dir
    10341051        } else {
    1035             set macports::developer_dir ""
     1052            set macports::developer_dir {}
    10361053        }
    10371054    } else {
    1038         if {$os_platform == "darwin" && ![file isdirectory $developer_dir]} {
     1055        if {$os_platform eq {darwin} && ![file isdirectory $developer_dir]} {
    10391056            ui_warn "Your developer_dir setting in macports.conf points to a non-existing directory.\
    10401057                Since this is known to cause problems, please correct the setting or comment it and let\
     
    10431060    }
    10441061
    1045     if {[getuid] == 0 && $os_major >= 11 && $os_platform == "darwin" &&
     1062    if {[getuid] == 0 && $os_major >= 11 && $os_platform eq {darwin} &&
    10461063            [file isfile "${macports::user_home}/Library/Preferences/com.apple.dt.Xcode.plist"]} {
    10471064        macports::copy_xcode_plist $env(HOME)
     
    10541071
    10551072    if {[info exists master_site_local] && ![info exists env(MASTER_SITE_LOCAL)]} {
    1056         set env(MASTER_SITE_LOCAL) "$master_site_local"
     1073        set env(MASTER_SITE_LOCAL) $master_site_local
    10571074    }
    10581075    if {[info exists patch_site_local] && ![info exists env(PATCH_SITE_LOCAL)]} {
    1059         set env(PATCH_SITE_LOCAL) "$patch_site_local"
     1076        set env(PATCH_SITE_LOCAL) $patch_site_local
    10601077    }
    10611078    if {[info exists archive_site_local] && ![info exists env(ARCHIVE_SITE_LOCAL)]} {
    1062         set env(ARCHIVE_SITE_LOCAL) "$archive_site_local"
     1079        set env(ARCHIVE_SITE_LOCAL) $archive_site_local
    10631080    }
    10641081
    10651082    # Proxy handling (done this late since Pextlib is needed)
    1066     if {![info exists proxy_override_env] } {
    1067         set proxy_override_env "no"
     1083    if {![info exists proxy_override_env]} {
     1084        set proxy_override_env no
    10681085    }
    10691086    if {[catch {array set sysConfProxies [get_systemconfiguration_proxies]} result]} {
    10701087        return -code error "Unable to get proxy configuration from system: $result"
    10711088    }
    1072     if {![info exists env(http_proxy)] || $proxy_override_env == "yes" } {
     1089    if {![info exists env(http_proxy)] || $proxy_override_env eq {yes}} {
    10731090        if {[info exists proxy_http]} {
    10741091            set env(http_proxy) $proxy_http
     
    10771094        }
    10781095    }
    1079     if {![info exists env(HTTPS_PROXY)] || $proxy_override_env == "yes" } {
     1096    if {![info exists env(HTTPS_PROXY)] || $proxy_override_env eq {yes}} {
    10801097        if {[info exists proxy_https]} {
    10811098            set env(HTTPS_PROXY) $proxy_https
     
    10841101        }
    10851102    }
    1086     if {![info exists env(FTP_PROXY)] || $proxy_override_env == "yes" } {
     1103    if {![info exists env(FTP_PROXY)] || $proxy_override_env eq {yes}} {
    10871104        if {[info exists proxy_ftp]} {
    10881105            set env(FTP_PROXY) $proxy_ftp
     
    10911108        }
    10921109    }
    1093     if {![info exists env(RSYNC_PROXY)] || $proxy_override_env == "yes" } {
     1110    if {![info exists env(RSYNC_PROXY)] || $proxy_override_env eq {yes}} {
    10941111        if {[info exists proxy_rsync]} {
    10951112            set env(RSYNC_PROXY) $proxy_rsync
    10961113        }
    10971114    }
    1098     if {![info exists env(NO_PROXY)] || $proxy_override_env == "yes" } {
     1115    if {![info exists env(NO_PROXY)] || $proxy_override_env eq {yes}} {
    10991116        if {[info exists proxy_skip]} {
    11001117            set env(NO_PROXY) $proxy_skip
     
    11051122
    11061123    # add ccache to environment
    1107     set env(CCACHE_DIR) ${macports::ccache_dir}
     1124    set env(CCACHE_DIR) $macports::ccache_dir
    11081125
    11091126    # load cached ping times
     
    11121129        array set macports::ping_cache [gets $pingfile]
    11131130        close $pingfile
    1114     }]} { array set macports::ping_cache {} }
     1131    }]} {array set macports::ping_cache {}}
    11151132    # set up arrays of blacklisted and preferred hosts
    11161133    if {[info exists macports::host_blacklist]} {
    1117         foreach host ${macports::host_blacklist} {
     1134        foreach host $macports::host_blacklist {
    11181135            set macports::host_blacklisted($host) 1
    11191136        }
    11201137    }
    11211138    if {[info exists macports::preferred_hosts]} {
    1122         foreach host ${macports::preferred_hosts} {
     1139        foreach host $macports::preferred_hosts {
    11231140            set macports::host_preferred($host) 1
    11241141        }
     
    11291146
    11301147    if {![info exists macports::ui_options(ports_no_old_index_warning)]} {
    1131         set default_source_url [lindex ${sources_default} 0]
    1132         if {[macports::getprotocol $default_source_url] == "file" || [macports::getprotocol $default_source_url] == "rsync"} {
     1148        set default_source_url [lindex $sources_default 0]
     1149        if {[macports::getprotocol $default_source_url] eq {file} || [macports::getprotocol $default_source_url] eq {rsync}} {
    11331150            set default_portindex [macports::getindex $default_source_url]
    1134             if {[file exists $default_portindex] && [expr [clock seconds] - [file mtime $default_portindex]] > 1209600} {
     1151            if {[file exists $default_portindex] && [clock seconds] - [file mtime $default_portindex] > 1209600} {
    11351152                ui_warn "port definitions are more than two weeks old, consider updating them by running 'port selfupdate'."
    11361153            }
     
    11491166        ui_warn "Converting your registry to sqlite format, this might take a while..."
    11501167        if {[catch {registry::convert_to_sqlite}]} {
    1151             ui_debug "$::errorInfo"
     1168            ui_debug $::errorInfo
    11521169            file delete -force $db_path
    11531170            error "Failed to convert your registry to sqlite!"
     
    11621179    # save ping times
    11631180    global macports::ping_cache macports::portdbpath
    1164     if {[file writable ${macports::portdbpath}]} {
     1181    if {[file writable $macports::portdbpath]} {
    11651182        catch {
    11661183            foreach host [array names ping_cache] {
    11671184                # don't save expired entries
    1168                 if {[expr [clock seconds] - [lindex $ping_cache($host) 1]] < 86400} {
     1185                if {[clock seconds] - [lindex $ping_cache($host) 1] < 86400} {
    11691186                    lappend pinglist_fresh $host $ping_cache($host)
    11701187                }
     
    11861203    file delete -force "${target_dir}/com.apple.dt.Xcode.plist"
    11871204    if {[file isfile $user_plist]} {
    1188         if {![file isdirectory "${target_dir}"]} {
    1189             if {[catch {file mkdir "${target_dir}"} result]} {
     1205        if {![file isdirectory $target_dir]} {
     1206            if {[catch {file mkdir $target_dir} result]} {
    11901207                ui_warn "Failed to create Library/Preferences in ${target_homedir}: $result"
    11911208                return
    11921209            }
    11931210        }
    1194         if {[file writable ${target_dir}] && [catch {
    1195             ui_debug "Copying $user_plist to ${target_dir}"
     1211        if {[file writable $target_dir] && [catch {
     1212            ui_debug "Copying $user_plist to $target_dir"
    11961213            file copy -force $user_plist $target_dir
    1197             file attributes "${target_dir}/com.apple.dt.Xcode.plist" -owner $macportsuser -permissions 0644
     1214            file attributes ${target_dir}/com.apple.dt.Xcode.plist -owner $macportsuser -permissions 0644
    11981215        } result]} {
    11991216            ui_warn "Failed to copy com.apple.dt.Xcode.plist to ${target_dir}: $result"
     
    12341251
    12351252    # instantiate the UI call-backs
    1236     foreach priority ${macports::ui_priorities} {
     1253    foreach priority $macports::ui_priorities {
    12371254        $workername alias ui_$priority ui_$priority
    1238         foreach phase ${macports::port_phases} {
    1239             $workername alias ui_${priority}_${phase} ui_${priority}_${phase}
    1240         }
    1241  
     1255        foreach phase $macports::port_phases {
     1256            $workername alias ui_${priority}_$phase ui_${priority}_$phase
     1257        }
     1258
    12421259    }
    12431260
    12441261    $workername alias ui_prefix ui_prefix
    12451262    $workername alias ui_channels ui_channels
    1246    
     1263
    12471264    $workername alias ui_warn_once ui_warn_once
    12481265
     
    13151332        $workername eval "trace add variable ::$opt read ::trace_$opt"
    13161333        # define some value now
    1317         $workername eval set $opt "?"
     1334        $workername eval set $opt ?
    13181335    }
    13191336
     
    13681385        .tbz -
    13691386        .tbz2 {
    1370             return "-j"
     1387            return -j
    13711388        }
    13721389        .tgz {
    1373             return "-z"
     1390            return -z
    13741391        }
    13751392        .txz {
     
    13801397        }
    13811398        default {
    1382             return "-"
    1383         }
    1384     }
    1385 }
    1386 
     1399            return -
     1400        }
     1401    }
     1402}
     1403
     1404##
     1405# Extracts a Portfile from a tarball pointed to by the given \a url to a path
     1406# in \c $portdbpath and returns its path.
     1407#
     1408# @param url URL pointing to a tarball containing either a file named \c
     1409#            Portfile at the root level -- in which case the tarball is
     1410#            extracted completely, --  or a file named \c +CONTENTS at the root
     1411#            level (i.e., the archive is a valid MacPorts binary archive), in
     1412#            which case the Portfile is extracted from the file \c +PORTFILE
     1413#            and put in a separate directory.
     1414# @param local one, if the URL is local, zero otherwise
     1415# @return a path to a directory containing the Portfile, or an error code
    13871416proc macports::fetch_port {url {local 0}} {
    1388     global macports::portdbpath
     1417    global macports::portdbpath macports::ui_prefix macports::portverbose
     1418
    13891419    set fetchdir [file join $portdbpath portdirs]
    13901420    file mkdir $fetchdir
     
    13921422        return -code error "Port remote fetch failed: You do not have permission to write to $fetchdir"
    13931423    }
     1424
    13941425    if {$local} {
    13951426        set fetchfile $url
    13961427    } else {
     1428        ui_msg "$macports::ui_prefix Fetching port $url"
    13971429        set fetchfile [file tail $url]
    1398         if {[catch {curl fetch $url [file join $fetchdir $fetchfile]} result]} {
     1430        set verboseflag {}
     1431        if {$macports::portverbose eq {yes}} {
     1432            set verboseflag -v
     1433        }
     1434        if {[catch {eval curl fetch $verboseflag {$url} {[file join $fetchdir $fetchfile]}} result]} {
    13991435            return -code error "Port remote fetch failed: $result"
    14001436        }
    14011437    }
     1438
    14021439    set oldpwd [pwd]
    14031440    cd $fetchdir
    1404     # check if this is a binary archive or just the port dir
     1441
     1442    # check if this is a binary archive or just the port dir by checking
     1443    # whether the file "+CONTENTS" exists.
    14051444    set tarcmd [findBinary tar $macports::autoconf::tar_path]
    14061445    set tarflags [get_tar_flags [file extension $fetchfile]]
    1407     set qflag ${macports::autoconf::tar_q}
     1446    set qflag $macports::autoconf::tar_q
    14081447    set cmdline "$tarcmd ${tarflags}${qflag}xOf \"$fetchfile\" +CONTENTS"
    1409     ui_debug "$cmdline"
     1448    ui_debug $cmdline
    14101449    if {![catch {set contents [eval exec $cmdline]}]} {
     1450        # the file is probably a valid binary archive
    14111451        set binary 1
    14121452        ui_debug "getting port name from binary archive"
    14131453        # get the portname from the contents file
    1414         foreach line [split $contents "\n"] {
    1415             if {[lindex $line 0] == "@name"} {
    1416                 # actually ${name}-${version}_${revision}
     1454        foreach line [split $contents \n] {
     1455            if {[lindex $line 0] eq {@name}} {
     1456                # actually ${name}-${version}_$revision
    14171457                set portname [lindex $line 1]
    14181458            }
    14191459        }
    14201460        ui_debug "port name is '$portname'"
     1461
     1462        # create a correctly-named directory and put the Portfile there
    14211463        file mkdir $portname
    14221464        cd $portname
    14231465    } else {
     1466        # the file is not a valid binary archive, assume it's an archive just
     1467        # containing Portfile and the files directory
    14241468        set binary 0
    14251469        set portname [file rootname $fetchfile]
     
    14331477        set cmdline "$tarcmd ${tarflags}xf \"$fetchfile\""
    14341478    }
    1435     ui_debug "$cmdline"
     1479    ui_debug $cmdline
    14361480    if {[catch {eval exec $cmdline} result]} {
     1481        # clean up the archive, we don't need it anymore
     1482        file delete [file join $fetchdir $fetchfile]
     1483
     1484        cd $oldpwd
    14371485        return -code error "Port extract failed: $result"
    14381486    }
     1487
     1488    # clean up the archive, we don't need it anymore
     1489    file delete [file join $fetchdir $fetchfile]
    14391490
    14401491    cd $oldpwd
     
    14441495proc macports::getprotocol {url} {
    14451496    if {[regexp {(?x)([^:]+)://.+} $url match protocol] == 1} {
    1446         return ${protocol}
     1497        return $protocol
    14471498    } else {
    14481499        return -code error "Can't parse url $url"
     
    14501501}
    14511502
    1452 # XXX: this really needs to be rethought in light of the remote index
    1453 # I've added the destdir parameter.  This is the location a remotely
    1454 # fetched port will be downloaded to (currently only applies to
    1455 # mports:// sources).
    1456 proc macports::getportdir {url {destdir "."}} {
     1503##
     1504# Return the directory where the port identified by the given \a url is
     1505# located. Can be called with either local paths (starting with \c file://), or
     1506# local or remote URLs pointing to a tarball that will be extracted.
     1507#
     1508# @param url URL identifying the port to be installed
     1509# @return normalized path to the port's directory, or error when called with an
     1510#         unsupported protocol, or if the tarball pointed to by \a url didn't
     1511#         contain a Portfile.
     1512proc macports::getportdir {url} {
    14571513    global macports::extracted_portdirs
     1514
    14581515    set protocol [macports::getprotocol $url]
    1459     switch ${protocol} {
     1516    switch -- $protocol {
    14601517        file {
    1461             set path [file normalize [string range $url [expr [string length $protocol] + 3] end]]
     1518            set path [file normalize [string range $url [expr {[string length $protocol] + 3}] end]]
    14621519            if {![file isfile $path]} {
     1520                # the URL points to a local directory
    14631521                return $path
    14641522            } else {
    1465                 # need to create a local dir for the exracted port, but only once
     1523                # the URL points to a local tarball that (hopefully) contains a Portfile
     1524                # create a local dir for the extracted port, but only once
    14661525                if {![info exists macports::extracted_portdirs($url)]} {
    14671526                    set macports::extracted_portdirs($url) [macports::fetch_port $path 1]
     
    14691528                return $macports::extracted_portdirs($url)
    14701529            }
    1471         }
    1472         mports {
    1473             return [macports::index::fetch_port $url $destdir]
    14741530        }
    14751531        https -
    14761532        http -
    14771533        ftp {
     1534            # the URL points to a remote tarball that (hopefully) contains a Portfile
     1535            # create a local dir for the extracted port, but only once
    14781536            if {![info exists macports::extracted_portdirs($url)]} {
    14791537                set macports::extracted_portdirs($url) [macports::fetch_port $url 0]
     
    14971555# @param fallback fall back to the default source tree
    14981556# @return path to the _resources directory or the path to the fallback
    1499 proc macports::getportresourcepath {url {path ""} {fallback yes}} {
     1557proc macports::getportresourcepath {url {path {}} {fallback yes}} {
    15001558    global macports::sources_default
    15011559
    15021560    set protocol [getprotocol $url]
    15031561
    1504     switch -- ${protocol} {
     1562    switch -- $protocol {
    15051563        file {
    15061564            set proposedpath [file normalize [file join [getportdir $url] .. ..]]
     
    15141572    set proposedpath [file join $proposedpath _resources $path]
    15151573
    1516     if {$fallback == "yes" && ![file exists $proposedpath]} {
     1574    if {$fallback eq {yes} && ![file exists $proposedpath]} {
    15171575        return [getdefaultportresourcepath $path]
    15181576    }
     
    15261584# @param path path in _resources we are interested in
    15271585# @return path to the _resources directory of the default source
    1528 proc macports::getdefaultportresourcepath {{path ""}} {
     1586proc macports::getdefaultportresourcepath {{path {}}} {
    15291587    global macports::sources_default
    15301588
    1531     set default_source_url [lindex ${sources_default} 0]
    1532     if {[getprotocol $default_source_url] == "file"} {
     1589    set default_source_url [lindex $sources_default 0]
     1590    if {[getprotocol $default_source_url] eq {file}} {
    15331591        set proposedpath [getportdir $default_source_url]
    15341592    } else {
     
    15431601
    15441602
    1545 # mportopen
    1546 # Opens a MacPorts portfile specified by a URL.  The Portfile is
    1547 # opened with the given list of options and variations.  The result
    1548 # of this function should be treated as an opaque handle to a
    1549 # MacPorts Portfile.
    1550 
    1551 proc mportopen {porturl {options ""} {variations ""} {nocache ""}} {
     1603##
     1604# Opens a MacPorts portfile specified by a URL. The URL can be local (starting
     1605# with file://), or remote (http, https, or ftp). In the local case, the URL
     1606# can point to a directory containing a Portfile, or to a tarball in the format
     1607# detailed below. In the remote case, the URL must point to a tarball. The
     1608# Portfile is opened with the given list of options and variations. The result
     1609# of this function should be treated as an opaque handle to a MacPorts
     1610# Portfile.
     1611#
     1612# @param porturl URL to the directory of the port to be opened. Can the path to
     1613#                a local directory, or an URL (both remote and local) pointing
     1614#                to a tarball that
     1615#                \li either contains a \c Portfile and possible a \c files
     1616#                    directory, or
     1617#                \li is a MacPorts binary archive, where the Portfile is in
     1618#                    a file called \c +PORTFILE.
     1619# @param options an optional array (in list format) of options
     1620# @param variations an optional array (ist list format) of variations, passed
     1621#                   to \c eval_variants after running the Portfile
     1622# @param nocache a non-empty string, if port information caching should be
     1623#                avoided.
     1624proc mportopen {porturl {options {}} {variations {}} {nocache {}}} {
    15521625    global macports::portdbpath macports::portconf macports::open_mports auto_path
    15531626
    15541627    # Look for an already-open MPort with the same URL.
    15551628    # if found, return the existing reference and bump the refcount.
    1556     if {$nocache != ""} {
     1629    if {$nocache ne {}} {
    15571630        set mport {}
    15581631    } else {
    15591632        set mport [dlist_match_multi $macports::open_mports [list porturl $porturl variations $variations options $options]]
    15601633    }
    1561     if {$mport != {}} {
     1634    if {$mport ne {}} {
    15621635        # just in case more than one somehow matches
    15631636        set mport [lindex $mport 0]
     
    15681641    }
    15691642
    1570     array set options_array $options
    1571     if {[info exists options_array(portdir)]} {
    1572         set portdir $options_array(portdir)
    1573     } else {
    1574         set portdir ""
    1575     }
    1576 
    1577     set portpath [macports::getportdir $porturl $portdir]
     1643    # Will download if remote and extract if tarball.
     1644    set portpath [macports::getportdir $porturl]
    15781645    ui_debug "Changing to port directory: $portpath"
    15791646    cd $portpath
     
    16191686    global macports::registry.path
    16201687    set regref [lindex [registry::entry imaged $name $version $revision $variants] 0]
    1621     set portfile_dir [file join ${registry.path} registry portfiles $name "${version}_${revision}${variants}"]
     1688    set portfile_dir [file join ${registry.path} registry portfiles $name ${version}_${revision}$variants]
    16221689    file mkdir $portfile_dir
    1623     set fd [open "${portfile_dir}/Portfile" w]
     1690    set fd [open ${portfile_dir}/Portfile w]
    16241691    puts $fd [$regref portfile]
    16251692    close $fd
    1626     file mtime "${portfile_dir}/Portfile" [$regref date]
     1693    file mtime ${portfile_dir}/Portfile [$regref date]
    16271694
    16281695    set variations {}
     
    16301697    set plusvariant [lrange [split [$regref variants] +] 1 end]
    16311698    foreach v $plusvariant {
    1632         lappend variations $v "+"
     1699        lappend variations $v +
    16331700    }
    16341701    foreach v $minusvariant {
    1635         lappend variations $v "-"
     1702        lappend variations $v -
    16361703    }
    16371704    lappend options subport $name
    1638     return [mportopen "file://${portfile_dir}/" $options $variations]
     1705    return [mportopen file://${portfile_dir}/ $options $variations]
    16391706}
    16401707
     
    16481715    mportclose $mport
    16491716    set portfiles_dir [file join ${registry.path} registry portfiles $subport]
    1650     set portfile [file join $portfiles_dir "${version}_${revision}${portvariants}" Portfile]
     1717    set portfile [file join $portfiles_dir ${version}_${revision}$portvariants Portfile]
    16511718    file delete -force $portfile [file dirname $portfile]
    16521719    if {[llength [glob -nocomplain -directory $portfiles_dir *]] == 0} {
     
    16771744        set pathToCategory [file join $root $category]
    16781745        # process the category dirs but not _resources
    1679         if {[file isdirectory $pathToCategory] && [string index [file tail $pathToCategory] 0] != "_"} {
     1746        if {[file isdirectory $pathToCategory] && [string index [file tail $pathToCategory] 0] ne {_}} {
    16801747            # Iterate on port directories.
    16811748            foreach port [lsort -increasing -unique [readdir $pathToCategory]] {
    16821749                set pathToPort [file join $pathToCategory $port]
    16831750                if {[file isdirectory $pathToPort] &&
    1684                   [file exists [file join $pathToPort "Portfile"]]} {
     1751                  [file exists [file join $pathToPort Portfile]]} {
    16851752                    # Call the function.
    16861753                    $func [file join $category $port]
     
    17321799            return [file join $path $filename]
    17331800        } else {
    1734             return ""
     1801            return {}
    17351802        }
    17361803    } else {
     
    17461813    # Check for the presence of the port in the registry
    17471814    set workername [ditem_key $mport workername]
    1748     return [$workername eval registry_exists_for_name \${subport}]
     1815    return [$workername eval registry_exists_for_name \$subport]
    17491816}
    17501817
     
    17521819proc _mportactive {mport} {
    17531820    set workername [ditem_key $mport workername]
    1754     if {![catch {set reslist [$workername eval registry_active \${subport}]}] && [llength $reslist] > 0} {
     1821    if {![catch {set reslist [$workername eval registry_active \$subport]}] && [llength $reslist] > 0} {
    17551822        set i [lindex $reslist 0]
    17561823        set name [lindex $i 0]
     
    17591826        set variants [lindex $i 3]
    17601827        array set portinfo [mportinfo $mport]
    1761         if {$name == $portinfo(name) && $version == $portinfo(version)
     1828        if {$name eq $portinfo(name) && $version == $portinfo(version)
    17621829            && $revision == $portinfo(revision) && $variants == $portinfo(canonical_active_variants)} {
    17631830            return 1
     
    17721839        return 0
    17731840    } else {
    1774         return [expr [llength $reslist] > 0]
     1841        return [expr {[llength $reslist] > 0}]
    17751842    }
    17761843}
     
    17961863        set workername [ditem_key $mport workername]
    17971864        set type [lindex [split $depspec :] 0]
    1798         switch $type {
    1799             lib { return [$workername eval _libtest $depspec] }
    1800             bin { return [$workername eval _bintest $depspec] }
    1801             path { return [$workername eval _pathtest $depspec] }
    1802             port { return 0 }
     1865        switch -- $type {
     1866            lib {return [$workername eval _libtest $depspec]}
     1867            bin {return [$workername eval _bintest $depspec]}
     1868            path {return [$workername eval _pathtest $depspec]}
     1869            port {return 0}
    18031870            default {return -code error "unknown depspec type: $type"}
    18041871        }
     
    18221889        ui_debug "Checking for conflicts against [_mportkey $mport subport]"
    18231890        foreach conflictport $portinfo(conflicts) {
    1824             if {[_mportispresent $mport port:${conflictport}]} {
     1891            if {[_mportispresent $mport port:$conflictport]} {
    18251892                lappend conflictlist $conflictport
    18261893            }
     
    18301897    }
    18311898
    1832     if {[llength ${conflictlist}] != 0} {
     1899    if {[llength $conflictlist] != 0} {
    18331900        if {[macports::global_option_isset ports_force]} {
    1834             ui_warn "Force option set; installing $portinfo(name) despite conflicts with: ${conflictlist}"
     1901            ui_warn "Force option set; installing $portinfo(name) despite conflicts with: $conflictlist"
    18351902        } else {
    18361903            if {![macports::ui_isset ports_debug]} {
    1837                 ui_msg ""
    1838             }
    1839             return -code error "Can't install $portinfo(name) because conflicting ports are installed: ${conflictlist}"
     1904                ui_msg {}
     1905            }
     1906            return -code error "Can't install $portinfo(name) because conflicting ports are installed: $conflictlist"
    18401907        }
    18411908    }
     
    18541921        ![catch {$workername eval eval_targets $target} result] && $result == 0} {
    18551922        # If auto-clean mode, clean-up after dependency install
    1856         if {[string equal ${macports::portautoclean} "yes"]} {
     1923        if {$macports::portautoclean eq {yes}} {
    18571924            # Make sure we are back in the port path before clean
    18581925            # otherwise if the current directory had been changed to
     
    18721939        global ::logenabled ::debuglogname
    18731940        ui_error "Failed to install $portname"
    1874         ui_debug "$::errorInfo"
     1941        ui_debug $::errorInfo
    18751942        if {[info exists ::logenabled] && $::logenabled && [info exists ::debuglogname]} {
    18761943            ui_notice "Please see the log file for port $portname for details:\n    $::debuglogname"
     
    18931960    }
    18941961    set portname [_mportkey $mport subport]
    1895     if {$target != "clean"} {
     1962    if {$target ne {clean}} {
    18961963        macports::push_log $mport
    18971964    }
     
    19161983        registry::exclusive_lock
    19171984        # see if we actually need to build this port
    1918         if {($target != "activate" && $target != "install") ||
     1985        if {($target ne {activate} && $target ne {install}) ||
    19191986            ![$workername eval registry_exists \$subport \$version \$revision \$portvariants]} {
    1920    
     1987
    19211988            # upgrade dependencies that are already installed
    19221989            if {![macports::global_option_isset ports_nodeps]} {
     
    19281995        if {[macports::ui_isset ports_debug]} {
    19291996            # play nice with debug messages
    1930             ui_msg ""
     1997            ui_msg {}
    19311998        }
    19321999        if {[mportdepends $mport $target] != 0} {
     
    19342001        }
    19352002        if {![macports::ui_isset ports_debug]} {
    1936             ui_msg ""
     2003            ui_msg {}
    19372004        }
    19382005
     
    19422009
    19432010        dlist_delete dlist $mport
    1944        
     2011
    19452012        # print the dep list
    19462013        if {[llength $dlist] > 0} {
     
    19532020
    19542021        # install them
    1955         set result [dlist_eval $dlist _mportactive [list _mportexec "activate"]]
     2022        set result [dlist_eval $dlist _mportactive [list _mportexec activate]]
    19562023
    19572024        registry::exclusive_unlock
    19582025
    1959         if {$result != {}} {
     2026        if {$result ne {}} {
    19602027            set errstring "The following dependencies were not installed:"
    19612028            foreach ditem $result {
     
    19752042    } else {
    19762043        # No dependencies, but we still need to check for conflicts.
    1977         if {$target == "" || $target == "install" || $target == "activate"} {
     2044        if {$target eq {} || $target eq {install} || $target eq {activate}} {
    19782045            _mporterrorifconflictsinstalled $mport
    19792046        }
     
    19812048
    19822049    set clean 0
    1983     if {[string equal ${macports::portautoclean} "yes"] && ([string equal $target "install"] || [string equal $target "activate"])} {
     2050    if {$macports::portautoclean eq {yes} && ($target eq {install} || $target eq {activate})} {
    19842051        # If we're doing an install, check if we should clean after
    19852052        set clean 1
     
    19962063        $workername eval eval_targets clean
    19972064    }
    1998    
     2065
    19992066    global ::logenabled ::debuglogname
    20002067    if {[info exists ::logenabled] && $::logenabled && [info exists ::debuglogname]} {
     
    20272094        foreach depspec $portinfo($deptype) {
    20282095            set dep_portname [$workername eval _get_dep_port $depspec]
    2029             if {$dep_portname != "" && ![info exists depscache(port:$dep_portname)] && [$test $dep_portname]} {
     2096            if {$dep_portname ne {} && ![info exists depscache(port:$dep_portname)] && [$test $dep_portname]} {
    20302097                set variants {}
    2031    
     2098
    20322099                # check that the dep has the required archs
    20332100                set active_archs [_get_registry_archs $dep_portname]
    2034                 if {$deptype != "depends_fetch" && $deptype != "depends_extract"
    2035                     && $active_archs != "" && $active_archs != "noarch" && $required_archs != "noarch"
     2101                if {$deptype ne {depends_fetch} && $deptype ne {depends_extract}
     2102                    && $active_archs ne {} && $active_archs ne {noarch} && $required_archs ne {noarch}
    20362103                    && [lsearch -exact $depends_skip_archcheck $dep_portname] == -1} {
    20372104                    set missing {}
     
    20852152                    }
    20862153                }
    2087    
    2088                 set status [macports::upgrade $dep_portname "port:$dep_portname" $variants $options depscache]
     2154
     2155                set status [macports::upgrade $dep_portname port:$dep_portname $variants $options depscache]
    20892156                # status 2 means the port was not found in the index
    20902157                if {$status != 0 && $status != 2 && ![macports::ui_isset ports_processall]} {
     
    21032170    set archs [registry::property_retrieve $regref archs]
    21042171    if {$archs == 0} {
    2105         set archs ""
     2172        set archs {}
    21062173    }
    21072174    return $archs
     
    21272194# @param url source URL to check
    21282195# @return a list containing filename and extension or an empty list
    2129 proc _source_is_snapshot {url {filename ""} {extension ""}} {
     2196proc _source_is_snapshot {url {filename {}} {extension {}}} {
    21302197    upvar $filename myfilename
    21312198    upvar $extension myextension
     
    21412208}
    21422209
    2143 proc macports::getportbuildpath {id {portname ""}} {
     2210proc macports::getportbuildpath {id {portname {}}} {
    21442211    global macports::portdbpath
    21452212    regsub {://} $id {.} port_path
     
    21482215}
    21492216
    2150 proc macports::getportlogpath {id {portname ""}} {
     2217proc macports::getportlogpath {id {portname {}}} {
    21512218    global macports::portdbpath
    21522219    regsub {://} $id {.} port_path
     
    21592226}
    21602227
    2161 proc macports::getportworkpath_from_portdir {portpath {portname ""}} {
     2228proc macports::getportworkpath_from_portdir {portpath {portname {}}} {
    21622229    return [macports::getportworkpath_from_buildpath [macports::getportbuildpath $portpath $portname]]
    21632230}
     
    21652232proc macports::getindex {source} {
    21662233    # Special case file:// sources
    2167     if {[macports::getprotocol $source] == "file"} {
     2234    if {[macports::getprotocol $source] eq {file}} {
    21682235        return [file join [macports::getportdir $source] PortIndex]
    21692236    }
     
    21962263            {^file$} {
    21972264                set portdir [macports::getportdir $source]
    2198                 set svn_cmd ""
     2265                set svn_cmd {}
    21992266                catch {set svn_cmd [macports::findBinary svn]}
    2200                 set git_cmd ""
     2267                set git_cmd {}
    22012268                catch {set git_cmd [macports::findBinary git]}
    2202                 if {$svn_cmd != "" && ([file exists $portdir/.svn] || ![catch {exec $svn_cmd info $portdir > /dev/null 2>@1}])} {
    2203                     set svn_commandline "$svn_cmd update --non-interactive ${portdir}"
     2269                if {$svn_cmd ne {} && ([file exists ${portdir}/.svn] || ![catch {exec $svn_cmd info $portdir > /dev/null 2>@1}])} {
     2270                    set svn_commandline "$svn_cmd update --non-interactive $portdir"
    22042271                    ui_debug $svn_commandline
    22052272                    if {
     
    22192286                        }]
    22202287                    } {
    2221                         ui_debug "$::errorInfo"
     2288                        ui_debug $::errorInfo
    22222289                        ui_error "Synchronization of the local ports tree failed doing an svn update"
    22232290                        incr numfailed
    22242291                        continue
    22252292                    }
    2226                 } elseif {$git_cmd != "" && [file exists $portdir/.git]} {
    2227                     set git_commandline "pushd $portdir ; $git_cmd pull --rebase ; popd"
     2293                } elseif {$git_cmd ne {} && ![catch {exec sh -c "cd ${portdir} && $git_cmd rev-parse --is-inside-work-tree"} result]} {
     2294                    # determine what type of git repository this is
     2295                    if {![catch {exec sh -c "cd ${portdir} && $git_cmd config --local --get svn-remote.svn.url"} result]} {
     2296                        set git_action "svn rebase"
     2297                    } else {
     2298                        set git_action "pull --rebase"
     2299                    }
     2300                    set git_commandline "pushd $portdir ; $git_cmd $git_action ; popd"
    22282301                    ui_debug $git_commandline
    22292302                    if {
     
    22432316                        }]
    22442317                    } {
    2245                         ui_debug "$::errorInfo"
    2246                         ui_error "Synchronization of the local ports tree failed doing a git pull --rebase"
     2318                        ui_debug $::errorInfo
     2319                        ui_error "Synchronization of the local ports tree failed doing a git update"
    22472320                        incr numfailed
    22482321                        continue
     
    22502323                }
    22512324                set needs_portindex 1
    2252             }
    2253             {^mports$} {
    2254                 macports::index::sync $macports::portdbpath $source
    22552325            }
    22562326            {^rsync$} {
     
    22622332
    22632333                if {$is_tarball} {
    2264                     set exclude_option ""
     2334                    set exclude_option {}
    22652335                    # need to do a few things before replacing the ports tree in this case
    22662336                    set destdir [file dirname $destdir]
    22672337                } else {
    22682338                    # Keep rsync happy with a trailing slash
    2269                     if {[string index $source end] != "/"} {
    2270                         append source "/"
     2339                    if {[string index $source end] ne {/}} {
     2340                        append source /
    22712341                    }
    22722342                    # don't sync PortIndex yet; we grab the platform specific one afterwards
    2273                     set exclude_option "'--exclude=/PortIndex*'"
     2343                    set exclude_option '--exclude=/PortIndex*'
    22742344                }
    22752345                # Do rsync fetch
    2276                 set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${exclude_option} ${source} ${destdir}"
     2346                set rsync_commandline "$macports::autoconf::rsync_path $rsync_options $exclude_option $source $destdir"
    22772347                ui_debug $rsync_commandline
    22782348                if {[catch {system $rsync_commandline}]} {
     
    22852355                    # verify signature for tarball
    22862356                    global macports::archivefetch_pubkeys
    2287                     set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${exclude_option} ${source}.rmd160 ${destdir}"
     2357                    set rsync_commandline "$macports::autoconf::rsync_path $rsync_options $exclude_option ${source}.rmd160 $destdir"
    22882358                    ui_debug $rsync_commandline
    22892359                    if {[catch {system $rsync_commandline}]} {
     
    22922362                        continue
    22932363                    }
    2294                     set tarball "${destdir}/[file tail $source]"
    2295                     set signature "${tarball}.rmd160"
     2364                    set tarball ${destdir}/[file tail $source]
     2365                    set signature ${tarball}.rmd160
    22962366                    set openssl [macports::findBinary openssl $macports::autoconf::openssl_path]
    22972367                    set verified 0
    2298                     foreach pubkey ${macports::archivefetch_pubkeys} {
     2368                    foreach pubkey $macports::archivefetch_pubkeys {
    22992369                        if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature $signature $tarball} result]} {
    23002370                            set verified 1
     
    23152385                    set tar [macports::findBinary tar $macports::autoconf::tar_path]
    23162386                    file mkdir ${destdir}/tmp
    2317                     set tar_cmd "$tar -C ${destdir}/tmp -xf ${tarball}"
     2387                    set tar_cmd "$tar -C ${destdir}/tmp -xf $tarball"
    23182388                    ui_debug $tar_cmd
    23192389                    if {[catch {system $tar_cmd}]} {
     
    23372407                set needs_portindex 1
    23382408                # now sync the index if the local file is missing or older than a day
    2339                 if {![file isfile $indexfile] || [expr [clock seconds] - [file mtime $indexfile]] > 86400
     2409                if {![file isfile $indexfile] || [clock seconds] - [file mtime $indexfile] > 86400
    23402410                      || [info exists options(no_reindex)]} {
    23412411                    if {$is_tarball} {
     
    23432413                        set index_source [string range $source 0 end-[string length [file tail $source]]]
    23442414                    } else {
    2345                         set index_source $source 
     2415                        set index_source $source
    23462416                    }
    23472417                    set remote_indexfile "${index_source}PortIndex_${macports::os_platform}_${macports::os_major}_${macports::os_arch}/PortIndex"
    2348                     set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} $remote_indexfile ${destdir}"
     2418                    set rsync_commandline "$macports::autoconf::rsync_path $rsync_options $remote_indexfile $destdir"
    23492419                    ui_debug $rsync_commandline
    23502420                    if {[catch {system $rsync_commandline}]} {
     
    23572427                            set needs_portindex 1
    23582428                            # verify signature for PortIndex
    2359                             set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${remote_indexfile}.rmd160 ${destdir}"
     2429                            set rsync_commandline "$macports::autoconf::rsync_path $rsync_options ${remote_indexfile}.rmd160 $destdir"
    23602430                            ui_debug $rsync_commandline
    23612431                            if {![catch {system $rsync_commandline}]} {
    2362                                 foreach pubkey ${macports::archivefetch_pubkeys} {
     2432                                foreach pubkey $macports::archivefetch_pubkeys {
    23632433                                    if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature ${destdir}/PortIndex.rmd160 ${destdir}/PortIndex} result]} {
    23642434                                        set ok 1
     
    23872457            }
    23882458            {^https?$|^ftp$} {
    2389                 if {[_source_is_snapshot $source filename extension]} {
    2390                     # sync a daily port snapshot tarball
    2391                     set indexfile [macports::getindex $source]
    2392                     set destdir [file dirname $indexfile]
    2393                     set tarpath [file join [file normalize [file join $destdir ..]] $filename]
    2394 
    2395                     set updated 1
    2396                     if {[file isdirectory $destdir]} {
    2397                         set moddate [file mtime $destdir]
    2398                         if {[catch {set updated [curl isnewer $source $moddate]} error]} {
    2399                             ui_warn "Cannot check if $source was updated, ($error)"
    2400                         }
    2401                     }
    2402 
    2403                     if {(![info exists options(ports_force)] || $options(ports_force) != "yes") && $updated <= 0} {
    2404                         ui_info "No updates for $source"
    2405                         continue
    2406                     }
    2407 
    2408                     file mkdir $destdir
    2409 
    2410                     set verboseflag {}
    2411                     if {$macports::portverbose == "yes"} {
    2412                         set verboseflag "-v"
    2413                     }
    2414 
    2415                     if {[catch {eval curl fetch $verboseflag {$source} {$tarpath}} error]} {
    2416                         ui_error "Fetching $source failed ($error)"
    2417                         incr numfailed
    2418                         continue
    2419                     }
    2420 
    2421                     set extflag {}
    2422                     switch $extension {
    2423                         {tar.gz} {
    2424                             set extflag "-z"
    2425                         }
    2426                         {tar.bz2} {
    2427                             set extflag "-j"
    2428                         }
    2429                     }
    2430 
    2431                     set tar [macports::findBinary tar $macports::autoconf::tar_path]
    2432                     if { [catch { system "cd $destdir/.. && $tar ${verboseflag} ${extflag} -xf $filename" } error] } {
    2433                         ui_error "Extracting $source failed ($error)"
    2434                         incr numfailed
    2435                         continue
    2436                     }
    2437 
    2438                     if {[catch {system "chmod -R a+r \"$destdir\""}]} {
    2439                         ui_warn "Setting world read permissions on parts of the ports tree failed, need root?"
    2440                     }
    2441 
    2442                     set platindex "PortIndex_${macports::os_platform}_${macports::os_major}_${macports::os_arch}/PortIndex"
    2443                     if {[file isfile ${destdir}/${platindex}] && [file isfile ${destdir}/${platindex}.quick]} {
    2444                         file rename -force "${destdir}/${platindex}" "${destdir}/${platindex}.quick" $destdir
    2445                     }
    2446 
    2447                     file delete $tarpath
    2448                 } else {
    2449                     # sync just a PortIndex file
    2450                     set indexfile [macports::getindex $source]
    2451                     file mkdir [file dirname $indexfile]
    2452                     curl fetch ${source}/PortIndex $indexfile
    2453                     curl fetch ${source}/PortIndex.quick ${indexfile}.quick
    2454                 }
     2459                if {![_source_is_snapshot $source filename extension]} {
     2460                    ui_error "Synchronization using http, https and ftp only supported with tarballs."
     2461                    ui_error "The source ${source} doesn't seem to point to a tarball."
     2462                    ui_error "Please switch to a different sync protocol (e.g. rsync) in your sources.conf"
     2463                    ui_error "Remove the line mentioned above from your sources.conf to silence this error."
     2464                    incr numfailed
     2465                    continue
     2466                }
     2467                # sync a daily port snapshot tarball
     2468                set indexfile [macports::getindex $source]
     2469                set destdir [file dirname $indexfile]
     2470                set tarpath [file join [file normalize [file join $destdir ..]] $filename]
     2471
     2472                set updated 1
     2473                if {[file isdirectory $destdir]} {
     2474                    set moddate [file mtime $destdir]
     2475                    if {[catch {set updated [curl isnewer $source $moddate]} error]} {
     2476                        ui_warn "Cannot check if $source was updated, ($error)"
     2477                    }
     2478                }
     2479
     2480                if {(![info exists options(ports_force)] || $options(ports_force) ne {yes}) && $updated <= 0} {
     2481                    ui_info "No updates for $source"
     2482                    continue
     2483                }
     2484
     2485                file mkdir $destdir
     2486
     2487                set verboseflag {}
     2488                if {$macports::portverbose eq {yes}} {
     2489                    set verboseflag -v
     2490                }
     2491
     2492                if {[catch {eval curl fetch $verboseflag {$source} {$tarpath}} error]} {
     2493                    ui_error "Fetching $source failed ($error)"
     2494                    incr numfailed
     2495                    continue
     2496                }
     2497
     2498                set extflag {}
     2499                switch -- $extension {
     2500                    {tar.gz} {
     2501                        set extflag -z
     2502                    }
     2503                    {tar.bz2} {
     2504                        set extflag -j
     2505                    }
     2506                }
     2507
     2508                set tar [macports::findBinary tar $macports::autoconf::tar_path]
     2509                if {[catch {system "cd ${destdir}/.. && $tar $verboseflag $extflag -xf $filename"} error]} {
     2510                    ui_error "Extracting $source failed ($error)"
     2511                    incr numfailed
     2512                    continue
     2513                }
     2514
     2515                if {[catch {system "chmod -R a+r \"$destdir\""}]} {
     2516                    ui_warn "Setting world read permissions on parts of the ports tree failed, need root?"
     2517                }
     2518
     2519                set platindex "PortIndex_${macports::os_platform}_${macports::os_major}_${macports::os_arch}/PortIndex"
     2520                if {[file isfile ${destdir}/$platindex] && [file isfile ${destdir}/${platindex}.quick]} {
     2521                    file rename -force ${destdir}/$platindex ${destdir}/${platindex}.quick $destdir
     2522                }
     2523
     2524                file delete $tarpath
     2525            }
     2526            {^mports$} {
     2527                ui_error "Synchronization using the mports protocol no longer supported."
     2528                ui_error "Please switch to a different sync protocol (e.g. rsync) in your sources.conf"
     2529                ui_error "Remove the line starting with mports:// from your sources.conf to silence this error."
     2530                incr numfailed
     2531                continue
    24552532            }
    24562533            default {
     
    24582535            }
    24592536        }
    2460        
     2537
    24612538        if {$needs_portindex} {
    24622539            set any_needed_portindex 1
     
    24812558}
    24822559
     2560##
     2561# Searches all configured port sources for a given pattern in a given field
     2562# using a given matching style and optional case-sensitivity.
     2563#
     2564# @param pattern pattern to search for; will be interpreted according to the \a
     2565#                matchstyle parameter
     2566# @param case_sensitive "yes", if a case-sensitive search should be performed,
     2567#                       "no" otherwise. Defaults to "yes".
     2568# @param matchstyle One of the values \c exact, \c glob and \c regexp, where \c
     2569#                   exact performs a standard string comparison, \c glob
     2570#                   performs Tcl string matching using <tt>[string match]</tt>
     2571#                   and \c regexp interprets \a pattern as a regular
     2572#                   expression.
     2573# @param field name of the field to apply \a pattern to. Must be one of the
     2574#              fields available in the used portindex. The portindex currently
     2575#              contains
     2576#                \li \c name (the default)
     2577#                \li \c homepage
     2578#                \li \c description
     2579#                \li \c long_description
     2580#                \li \c license
     2581#                \li \c categories
     2582#                \li \c platforms
     2583#                \li \c maintainers
     2584#                \li \c variants
     2585#                \li \c portdir
     2586#                \li all \c depends_* values
     2587#                \li \c epoch
     2588#                \li \c version
     2589#                \li \c revision
     2590#                \li \c replaced_by
     2591#                \li \c installs_libs
     2592# @return a list where each even index (starting with 0) contains the name of
     2593#         a matching port. Each entry at an odd index is followed by its
     2594#         corresponding line from the portindex, which can be passed to
     2595#         <tt>array set</tt>. The whole return value can also be passed to
     2596#         <tt>array set</tt> to create an associate array where the port names
     2597#         are the keys and the lines from portindex are the values.
    24832598proc mportsearch {pattern {case_sensitive yes} {matchstyle regexp} {field name}} {
    2484     global macports::portdbpath macports::sources
     2599    global macports::sources
    24852600    set matches [list]
    2486     set easy [expr { $field == "name" }]
     2601    set easy [expr {$field eq {name}}]
    24872602
    24882603    set found 0
     
    24902605        set source [lindex $source 0]
    24912606        set protocol [macports::getprotocol $source]
    2492         if {$protocol == "mports"} {
    2493             set res [macports::index::search $macports::portdbpath $source [list name $pattern]]
    2494             eval lappend matches $res
     2607        if {[catch {set fd [open [macports::getindex $source] r]} result]} {
     2608            ui_warn "Can't open index file for source: $source"
    24952609        } else {
    2496             if {[catch {set fd [open [macports::getindex $source] r]} result]} {
    2497                 ui_warn "Can't open index file for source: $source"
    2498             } else {
    2499                 try {
    2500                     incr found 1
    2501                     while {[gets $fd line] >= 0} {
    2502                         array unset portinfo
    2503                         set name [lindex $line 0]
    2504                         set len [lindex $line 1]
    2505                         set line [read $fd $len]
    2506 
    2507                         if {$easy} {
    2508                             set target $name
    2509                         } else {
    2510                             array set portinfo $line
    2511                             if {![info exists portinfo($field)]} continue
    2512                             set target $portinfo($field)
     2610            try {
     2611                incr found 1
     2612                while {[gets $fd line] >= 0} {
     2613                    array unset portinfo
     2614                    set name [lindex $line 0]
     2615                    set len  [lindex $line 1]
     2616                    set line [read $fd $len]
     2617
     2618                    if {$easy} {
     2619                        set target $name
     2620                    } else {
     2621                        array set portinfo $line
     2622                        if {![info exists portinfo($field)]} {
     2623                            continue
    25132624                        }
    2514 
    2515                         switch $matchstyle {
    2516                             exact {
    2517                                 set matchres [expr 0 == ( {$case_sensitive == "yes"} ? [string compare $pattern $target] : [string compare -nocase $pattern $target] )]
     2625                        set target $portinfo($field)
     2626                    }
     2627
     2628                    switch -- $matchstyle {
     2629                        exact {
     2630                            if {$case_sensitive eq yes} {
     2631                                set compres [string compare $pattern $target]
     2632                            } else {
     2633                                set compres [string compare -nocase $pattern $target]
    25182634                            }
    2519                             glob {
    2520                                 set matchres [expr {$case_sensitive == "yes"} ? [string match $pattern $target] : [string match -nocase $pattern $target]]
    2521                             }
    2522                             regexp -
    2523                             default {
    2524                                 set matchres [expr {$case_sensitive == "yes"} ? [regexp -- $pattern $target] : [regexp -nocase -- $pattern $target]]
     2635                            set matchres [expr 0 == $compres]
     2636                        }
     2637                        glob {
     2638                            if {$case_sensitive eq yes} {
     2639                                set matchres [string match $pattern $target]
     2640                            } else {
     2641                                set matchres [string match -nocase $pattern $target]
    25252642                            }
    25262643                        }
    2527 
    2528                         if {$matchres == 1} {
    2529                             if {$easy} {
    2530                                 array set portinfo $line
     2644                        regexp {
     2645                            if {$case_sensitive eq yes} {
     2646                                set matchres [regexp -- $pattern $target]
     2647                            } else {
     2648                                set matchres [regexp -nocase -- $pattern $target]
    25312649                            }
    2532                             switch $protocol {
    2533                                 rsync {
    2534                                     # Rsync files are local
    2535                                     set source_url "file://[macports::getsourcepath $source]"
    2536                                 }
    2537                                 https -
    2538                                 http -
    2539                                 ftp {
    2540                                     if {[_source_is_snapshot $source filename extension]} {
    2541                                         # daily snapshot tarball
    2542                                         set source_url "file://[macports::getsourcepath $source]"
    2543                                     } else {
    2544                                         # default action
    2545                                         set source_url $source
    2546                                     }
    2547                                 }
    2548                                 default {
    2549                                     set source_url $source
    2550                                 }
    2551                             }
    2552                             if {[info exists portinfo(portarchive)]} {
    2553                                 set porturl ${source_url}/$portinfo(portarchive)
    2554                             } elseif {[info exists portinfo(portdir)]} {
    2555                                 set porturl ${source_url}/$portinfo(portdir)
    2556                             }
    2557                             if {[info exists porturl]} {
    2558                                 lappend line porturl $porturl
    2559                                 ui_debug "Found port in $porturl"
    2560                             } else {
    2561                                 ui_debug "Found port info: $line"
    2562                             }
    2563                             lappend matches $name
    2564                             lappend matches $line
    2565                         }
    2566                     }
    2567                 } catch {*} {
    2568                     ui_warn "It looks like your PortIndex file for $source may be corrupt."
    2569                     throw
    2570                 } finally {
    2571                     close $fd
    2572                 }
    2573             }
    2574         }
    2575     }
    2576     if {!$found} {
    2577         return -code error "No index(es) found! Have you synced your port definitions? Try running 'port selfupdate'."
    2578     }
    2579 
    2580     return $matches
    2581 }
    2582 
    2583 # Returns the PortInfo for a single named port. The info comes from the
    2584 # PortIndex, and name matching is case-insensitive. Unlike mportsearch, only
    2585 # the first match is returned, but the return format is otherwise identical.
    2586 # The advantage is that mportlookup is much faster than mportsearch, due to
    2587 # the use of the quick index.
    2588 proc mportlookup {name} {
    2589     global macports::portdbpath macports::sources
    2590 
    2591     set sourceno 0
    2592     set matches [list]
    2593     foreach source $sources {
    2594         set source [lindex $source 0]
    2595         set protocol [macports::getprotocol $source]
    2596         if {$protocol != "mports"} {
    2597             global macports::quick_index
    2598             if {![info exists quick_index($sourceno,[string tolower $name])]} {
    2599                 incr sourceno 1
    2600                 continue
    2601             }
    2602             # The quick index is keyed on the port name, and provides the
    2603             # offset in the main PortIndex where the given port's PortInfo
    2604             # line can be found.
    2605             set offset $quick_index($sourceno,[string tolower $name])
    2606             incr sourceno 1
    2607             if {[catch {set fd [open [macports::getindex $source] r]} result]} {
    2608                 ui_warn "Can't open index file for source: $source"
    2609             } else {
    2610                 try {
    2611                     seek $fd $offset
    2612                     gets $fd line
    2613                     set name [lindex $line 0]
    2614                     set len [lindex $line 1]
    2615                     set line [read $fd $len]
    2616 
    2617                     array set portinfo $line
    2618 
    2619                     switch $protocol {
    2620                         rsync {
    2621                             set source_url "file://[macports::getsourcepath $source]"
    2622                         }
    2623                         https -
    2624                         http -
    2625                         ftp {
    2626                             if {[_source_is_snapshot $source filename extension]} {
    2627                                 set source_url "file://[macports::getsourcepath $source]"
    2628                              } else {
    2629                                 set source_url $source
    2630                              }
    26312650                        }
    26322651                        default {
    2633                             set source_url $source
     2652                            return -code error "mportsearch: Unsupported matching style: ${matchstyle}."
    26342653                        }
    26352654                    }
    2636                     if {[info exists portinfo(portarchive)]} {
    2637                         set porturl ${source_url}/$portinfo(portarchive)
    2638                     } elseif {[info exists portinfo(portdir)]} {
    2639                         set porturl ${source_url}/$portinfo(portdir)
    2640                     }
    2641                     if {[info exists porturl]} {
    2642                         lappend line porturl $porturl
    2643                     }
    2644                     lappend matches $name
    2645                     lappend matches $line
    2646                     close $fd
    2647                     set fd -1
    2648                 } catch {*} {
    2649                     ui_warn "It looks like your PortIndex file for $source may be corrupt."
    2650                 } finally {
    2651                     if {$fd != -1} {
    2652                         close $fd
    2653                     }
    2654                 }
    2655                 if {[llength $matches] > 0} {
    2656                     break
    2657                 }
    2658             }
    2659         } else {
    2660             set res [macports::index::search $macports::portdbpath $source [list name $name]]
    2661             if {[llength $res] > 0} {
    2662                 eval lappend matches $res
    2663                 break
    2664             }
    2665         }
    2666     }
    2667 
    2668     return $matches
    2669 }
    2670 
    2671 # Returns all ports in the indices. Faster than 'mportsearch .*'
    2672 proc mportlistall {args} {
    2673     global macports::portdbpath macports::sources
    2674     set matches [list]
    2675 
    2676     set found 0
    2677     foreach source $sources {
    2678         set source [lindex $source 0]
    2679         set protocol [macports::getprotocol $source]
    2680         if {$protocol != "mports"} {
    2681             if {![catch {set fd [open [macports::getindex $source] r]} result]} {
    2682                 try {
    2683                     incr found 1
    2684                     while {[gets $fd line] >= 0} {
    2685                         array unset portinfo
    2686                         set name [lindex $line 0]
    2687                         set len [lindex $line 1]
    2688                         set line [read $fd $len]
    2689 
    2690                         array set portinfo $line
    2691 
    2692                         switch $protocol {
     2655
     2656                    if {$matchres == 1} {
     2657                        if {$easy} {
     2658                            array set portinfo $line
     2659                        }
     2660                        switch -- $protocol {