diff --git a/ext/coverage/coverage.c b/ext/coverage/coverage.c index 747f065fbaae3f..93acdb24806f78 100644 --- a/ext/coverage/coverage.c +++ b/ext/coverage/coverage.c @@ -480,137 +480,139 @@ rb_coverage_running(VALUE klass) } /* \Coverage provides coverage measurement feature for Ruby. - * This feature is experimental, so these APIs may be changed in future. * - * Caveat: Currently, only process-global coverage measurement is supported. - * You cannot measure per-thread coverage. + * Only process-global coverage measurement is supported, meaning + * that coverage cannot be measure on a per-thread basis. * - * = Usage + * = Quick Start * - * 1. require "coverage" - * 2. do Coverage.start - * 3. require or load Ruby source file - * 4. Coverage.result will return a hash that contains filename as key and - * coverage array as value. A coverage array gives, for each line, the - * number of line execution by the interpreter. A +nil+ value means - * coverage is disabled for this line (lines like +else+ and +end+). + * 1. Load coverage using require "coverage". + * 2. Call Coverage.start to set up and begin coverage measurement. + * 3. All Ruby code loaded following the call to Coverage.start will have + * coverage measurement. + * 4. Coverage results can be fetched by calling Coverage.result, which returns a + * hash that contains filenames as the keys and coverage arrays as the values. + * Each element of the coverage array gives the number of times each line was + * executed. A +nil+ value means coverage was disabled for that line (e.g. + * lines like +else+ and +end+). * * = Examples * - * [foo.rb] - * s = 0 - * 10.times do |x| - * s += x - * end + * In file +fib.rb+: * - * if s == 45 - * p :ok - * else - * p :ng + * def fibonacci(n) + * if n == 0 + * 0 + * elsif n == 1 + * 1 + * else + * fibonacci(n - 1) + fibonacci(n - 2) + * end * end - * [EOF] + * + * puts fibonacci(10) + * + * In another file, coverage can be measured: * * require "coverage" * Coverage.start - * require "foo.rb" - * p Coverage.result #=> {"foo.rb"=>[1, 1, 10, nil, nil, 1, 1, nil, 0, nil]} + * require "fib.rb" + * Coverage.result # => {"fib.rb" => [1, 177, 34, 143, 55, nil, 88, nil, nil, nil, 1]} * * == Lines \Coverage * - * If a coverage mode is not explicitly specified when starting coverage, lines - * coverage is what will run. It reports the number of line executions for each - * line. + * Lines coverage reports the number of line executions for each line. + * If the coverage mode is not explicitly specified when starting coverage, + * lines coverage is used as the default. * * require "coverage" * Coverage.start(lines: true) - * require "foo.rb" - * p Coverage.result #=> {"foo.rb"=>{:lines=>[1, 1, 10, nil, nil, 1, 1, nil, 0, nil]}} + * require "fib" + * Coverage.result # => {"fib.rb" => {lines: [1, 177, 34, 143, 55, nil, 88, nil, nil, nil, 1]}} * - * The value of the lines coverage result is an array containing how many times - * each line was executed. Order in this array is important. For example, the - * first item in this array, at index 0, reports how many times line 1 of this - * file was executed while coverage was run (which, in this example, is one - * time). + * The returned hash differs depending on how Coverage.setup or Coverage.start + * was executed. + * + * If Coverage.start or Coverage.setup was called with no arguments, it returns a + * hash which contains filenames as the keys and coverage arrays as the values. * - * A +nil+ value means coverage is disabled for this line (lines like +else+ - * and +end+). + * If Coverage.start or Coverage.setup was called with line: true, it + * returns a hash which contains filenames as the keys and hashes as the values. + * The value hash has a key +:lines+ where the value is a coverage array. + * + * Each element of the coverage array gives the number of times the line was + * executed. A +nil+ value in the coverage array means coverage was disabled + * for that line (e.g. lines like +else+ and +end+). * * == Oneshot Lines \Coverage * - * Oneshot lines coverage tracks and reports on the executed lines while - * coverage is running. It will not report how many times a line was executed, - * only that it was executed. + * Oneshot lines coverage is similar to lines coverage, but instead of reporting + * the number of times a line was executed, it only reports the lines that were + * executed. * * require "coverage" * Coverage.start(oneshot_lines: true) - * require "foo.rb" - * p Coverage.result #=> {"foo.rb"=>{:oneshot_lines=>[1, 2, 3, 6, 7]}} + * require "fib" + * Coverage.result # => {"fib.rb" => {oneshot_lines: [1, 11, 2, 4, 7, 5, 3]}} * * The value of the oneshot lines coverage result is an array containing the * line numbers that were executed. * * == Branches \Coverage * - * Branches coverage reports how many times each branch within each conditional + * Branches coverage reports the number of times each branch within each conditional * was executed. * * require "coverage" * Coverage.start(branches: true) - * require "foo.rb" - * p Coverage.result #=> {"foo.rb"=>{:branches=>{[:if, 0, 6, 0, 10, 3]=>{[:then, 1, 7, 2, 7, 7]=>1, [:else, 2, 9, 2, 9, 7]=>0}}}} + * require "fib" + * Coverage.result + * # => {"fib.rb" => { + * # branches: { + * # [:if, 0, 2, 2, 8, 5] => { + * # [:then, 1, 3, 4, 3, 5] => 34, + * # [:else, 2, 4, 2, 8, 5] => 143}, + * # [:if, 3, 4, 2, 8, 5] => { + * # [:then, 4, 5, 4, 5, 5] => 55, + * # [:else, 5, 7, 4, 7, 39] => 88}}}} * * Each entry within the branches hash is a conditional, the value of which is - * another hash where each entry is a branch in that conditional. The values - * are the number of times the method was executed, and the keys are identifying - * information about the branch. + * another hash where each entry is a branch in that conditional. The keys are + * arrays containing information about the branch and the values are the number + * of times the branch was executed. * - * The information that makes up each key identifying branches or conditionals - * is the following, from left to right: + * The information that makes up the array that are the keys for conditional or + * branches are the following, from left to right: * - * 1. A label for the type of branch or conditional. + * 1. A label for the type of branch or conditional (e.g. +:if+, +:then+, +:else+). * 2. A unique identifier. - * 3. The starting line number it appears on in the file. - * 4. The starting column number it appears on in the file. - * 5. The ending line number it appears on in the file. - * 6. The ending column number it appears on in the file. + * 3. Starting line number. + * 4. Starting column number. + * 5. Ending line number. + * 6. Ending column number. * * == Methods \Coverage * * Methods coverage reports how many times each method was executed. * - * [foo_method.rb] - * class Greeter - * def greet - * "welcome!" - * end - * end - * - * def hello - * "Hi" - * end - * - * hello() - * Greeter.new.greet() - * [EOF] - * * require "coverage" * Coverage.start(methods: true) - * require "foo_method.rb" - * p Coverage.result #=> {"foo_method.rb"=>{:methods=>{[Object, :hello, 7, 0, 9, 3]=>1, [Greeter, :greet, 2, 2, 4, 5]=>1}}} + * require "fib" + * p Coverage.result #=> {"fib.rb" => {methods: {[Object, :fibonacci, 1, 0, 9, 3] => 177}}} * - * Each entry within the methods hash represents a method. The values in this - * hash are the number of times the method was executed, and the keys are + * Each entry within the methods hash represents a method. The keys are arrays + * containing hash are the number of times the method was executed, and the keys are * identifying information about the method. * * The information that makes up each key identifying a method is the following, * from left to right: * - * 1. The class. - * 2. The method name. - * 3. The starting line number the method appears on in the file. - * 4. The starting column number the method appears on in the file. - * 5. The ending line number the method appears on in the file. - * 6. The ending column number the method appears on in the file. + * 1. Class that the method was defined in. + * 2. Method name as a Symbol. + * 3. Starting line number of the method. + * 4. Starting column number of the method. + * 5. Ending line number of the method. + * 6. Ending column number of the method. * * == Eval \Coverage * @@ -670,16 +672,24 @@ rb_coverage_running(VALUE klass) * * == All \Coverage Modes * - * You can also run all modes of coverage simultaneously with this shortcut. - * Note that running all coverage modes does not run both lines and oneshot - * lines. Those modes cannot be run simultaneously. Lines coverage is run in - * this case, because you can still use it to determine whether or not a line - * was executed. + * All modes of coverage can be enabled simultaneously using the Symbol +:all+. + * However, note that this mode runs lines coverage and not oneshot lines since + * they cannot be ran simultaneously. * * require "coverage" * Coverage.start(:all) - * require "foo.rb" - * p Coverage.result #=> {"foo.rb"=>{:lines=>[1, 1, 10, nil, nil, 1, 1, nil, 0, nil], :branches=>{[:if, 0, 6, 0, 10, 3]=>{[:then, 1, 7, 2, 7, 7]=>1, [:else, 2, 9, 2, 9, 7]=>0}}, :methods=>{}}} + * require "fib" + * Coverage.result + * # => {"fib.rb" => { + * # lines: [1, 177, 34, 143, 55, nil, 88, nil, nil, nil, 1], + * # branches: { + * # [:if, 0, 2, 2, 8, 5] => { + * # [:then, 1, 3, 4, 3, 5] => 34, + * # [:else, 2, 4, 2, 8, 5] => 143}, + * # [:if, 3, 4, 2, 8, 5] => { + * # [:then, 4, 5, 4, 5, 5] => 55, + * # [:else, 5, 7, 4, 7, 39] => 88}}}}, + * # methods: {[Object, :fibonacci, 1, 0, 9, 3] => 177}}} */ void Init_coverage(void) diff --git a/win32/configure.bat b/win32/configure.bat index 9355caa4d852da..a22630385bba14 100755 --- a/win32/configure.bat +++ b/win32/configure.bat @@ -1,321 +1,321 @@ -@echo off -@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1 -set PROMPT=$E[94m+$E[m$S -set witharg= - -if "%~dp0" == "%CD%\" ( - echo don't run in win32 directory. - exit /b 999 -) else if "%0" == "%~nx0" ( - set "WIN32DIR=%~$PATH:0" -) else if "%0" == "%~n0" ( - set "WIN32DIR=%~$PATH:0" -) else ( - set "WIN32DIR=%0" -) - -set "WIN32DIR=%WIN32DIR:\=/%:/:" -call set "WIN32DIR=%%WIN32DIR:%~x0:/:=:/:%%" -call set "WIN32DIR=%%WIN32DIR:/%~n0:/:=:/:%%" -set "WIN32DIR=%WIN32DIR:~0,-3%" - -set XINCFLAGS= -set XLDFLAGS= -set pathlist= -set config_make=confargs~%RANDOM%.mak -set confargs=%config_make:.mak=.c% -echo>%config_make% # CONFIGURE -( - echo #define $ $$ // - echo !ifndef CONFIGURE_ARGS - echo #define CONFIGURE_ARGS \ -) >%confargs% -:loop -set opt=%1 -if "%1" == "" goto :end -if "%1" == "--debug-configure" (echo on & shift & goto :loop) -if "%1" == "--no-debug-configure" (echo off & shift & goto :loop) -if "%1" == "--prefix" goto :prefix -if "%1" == "--srcdir" goto :srcdir -if "%1" == "srcdir" goto :srcdir -if "%1" == "--target" goto :target -if "%1" == "target" goto :target -if "%1" == "--with-static-linked-ext" goto :extstatic -if "%1" == "--program-prefix" goto :pprefix -if "%1" == "--program-suffix" goto :suffix -if "%1" == "--program-transform-name" goto :transform_name -if "%1" == "--program-name" goto :installname -if "%1" == "--install-name" goto :installname -if "%1" == "--so-name" goto :soname -if "%1" == "--enable-install-doc" goto :enable-rdoc -if "%1" == "--disable-install-doc" goto :disable-rdoc -if "%1" == "--enable-install-static-library" goto :enable-lib -if "%1" == "--disable-install-static-library" goto :disable-lib -if "%1" == "--enable-debug-env" goto :enable-debug-env -if "%1" == "--disable-debug-env" goto :disable-debug-env -if "%1" == "--enable-devel" goto :enable-devel -if "%1" == "--disable-devel" goto :disable-devel -if "%1" == "--enable-rubygems" goto :enable-rubygems -if "%1" == "--disable-rubygems" goto :disable-rubygems -if "%1" == "--extout" goto :extout -if "%1" == "--path" goto :path -if "%1" == "--with-baseruby" goto :baseruby -if "%1" == "--without-baseruby" goto :nobaseruby -if "%1" == "--with-ntver" goto :ntver -if "%1" == "--with-libdir" goto :libdir -if "%1" == "--with-git" goto :git -if "%1" == "--without-git" goto :nogit -if "%1" == "--without-ext" goto :witharg -if "%1" == "--without-extensions" goto :witharg -if "%1" == "--with-opt-dir" goto :opt-dir -if "%1" == "--with-gmp" goto :gmp -if "%1" == "--with-gmp-dir" goto :gmp-dir -if "%opt:~0,10%" == "--without-" goto :withoutarg -if "%opt:~0,7%" == "--with-" goto :witharg -if "%1" == "-h" goto :help -if "%1" == "--help" goto :help - if "%opt:~0,1%" == "-" ( - echo>>%confargs% %1 \ - set witharg= - ) else if "%witharg%" == "" ( - echo>>%confargs% %1 \ - ) else ( - echo>>%confargs% ,%1\ - ) - shift -goto :loop ; -:srcdir - echo>> %config_make% srcdir = %~2 - echo>>%confargs% --srcdir=%2 \ - shift - shift -goto :loop ; -:prefix - echo>> %config_make% prefix = %~2 - echo>>%confargs% %1=%2 \ - shift - shift -goto :loop ; -:pprefix - echo>> %config_make% PROGRAM_PREFIX = %~2 - echo>>%confargs% %1=%2 \ - shift - shift -goto :loop ; -:suffix - echo>> %config_make% PROGRAM_SUFFIX = %~2 - echo>>%confargs% %1=%2 \ - shift - shift -goto :loop ; -:installname - echo>> %config_make% RUBY_INSTALL_NAME = %~2 - echo>>%confargs% %1=%2 \ - shift - shift -goto :loop ; -:soname - echo>> %config_make% RUBY_SO_NAME = %~2 - echo>>%confargs% %1=%2 \ - shift - shift -goto :loop ; -:transform_name - - shift - shift -goto :loop ; -:target - echo>> %config_make% target = %~2 - echo>>%confargs% --target=%2 \ - if "%~2" == "x64-mswin64" ( - echo>> %config_make% TARGET_OS = mswin64 - ) - shift - shift -goto :loop ; -:extstatic - echo>> %config_make% EXTSTATIC = static - echo>>%confargs% %1 \ - shift -goto :loop ; -:enable-rdoc - echo>> %config_make% RDOCTARGET = rdoc - echo>>%confargs% %1 \ - shift -goto :loop ; -:disable-rdoc - echo>> %config_make% RDOCTARGET = nodoc - echo>>%confargs% %1 \ - shift -goto :loop ; -:enable-lib - echo>> %config_make% INSTALL_STATIC_LIBRARY = yes - echo>>%confargs% %1 \ - shift -goto :loop ; -:disable-lib - echo>> %config_make% INSTALL_STATIC_LIBRARY = no - echo>>%confargs% %1 \ - shift -goto :loop ; -:enable-debug-env - echo>> %config_make% ENABLE_DEBUG_ENV = yes - echo>>%confargs% %1 \ - shift -goto :loop ; -:disable-debug-env - echo>> %config_make% ENABLE_DEBUG_ENV = no - echo>>%confargs% %1 \ - shift -goto :loop ; -:enable-devel - echo>> %config_make% RUBY_DEVEL = yes - echo>>%confargs% %1 \ - shift -goto :loop ; -:disable-devel - echo>> %config_make% RUBY_DEVEL = no - echo>>%confargs% %1 \ - shift -goto :loop ; -:enable-rubygems - echo>> %config_make% USE_RUBYGEMS = yes - echo>>%confargs% %1 \ - shift -goto :loop ; -:disable-rubygems - echo>> %config_make% USE_RUBYGEMS = no - echo>>%confargs% %1 \ - shift -goto :loop ; -:ntver - ::- For version constants, see - ::- https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt#remarks - set NTVER=%~2 - if /i not "%NTVER:~0,2%" == "0x" if /i not "%NTVER:~0,13%" == "_WIN32_WINNT_" ( - for %%i in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do ( - call set NTVER=%%NTVER:%%i=%%i%% - ) - call set NTVER=_WIN32_WINNT_%%NTVER%% - ) - echo>> %config_make% NTVER = %NTVER% - echo>>%confargs% %1=%2 \ - shift - shift -goto :loop ; -:extout - if not "%~2" == ".ext" (echo>> %config_make% EXTOUT = %~2) - echo>>%confargs% %1=%2 \ - shift - shift -goto :loop ; -:path - set pathlist=%pathlist%%~2; - echo>>%confargs% %1=%2 \ - shift - shift -goto :loop ; -:baseruby - echo>> %config_make% HAVE_BASERUBY = yes - echo>> %config_make% BASERUBY = %~2 - echo>>%confargs% %1=%2 \ - shift - shift -goto :loop ; -:nobaseruby - echo>> %config_make% HAVE_BASERUBY = no - echo>> %config_make% BASERUBY = - echo>>%confargs% %1 \ - shift -goto :loop ; -:libdir - echo>> %config_make% libdir_basename = %~2 - echo>>%confargs% %1=%2 \ - shift - shift -goto :loop ; -:git - echo>> %config_make% GIT = %~2 - echo>>%confargs% %1=%2 \ - shift - shift -goto :loop ; -:nogit - echo>> %config_make% GIT = never-use - echo>> %config_make% HAVE_GIT = no - echo>>%confargs% %1 \ - shift -goto :loop ; -:gmp - echo>> %config_make% WITH_GMP = yes - echo>>%confargs% %1 \ - shift -goto :loop ; -:gmp-dir -:opt-dir - set opt=%~2 - for %%I in (%opt:;= %) do ( - set d=%%I - call pushd %%d:/=\%% && ( - call set XINCFLAGS=%%XINCFLAGS%% -I%%CD:\=/%%/include - call set XLDFLAGS=%%XLDFLAGS%% -libpath:%%CD:\=/%%/lib - popd - ) - ) -:witharg - echo>>%confargs% %1=%2\ - set witharg=1 - shift - shift -goto :loop ; -:withoutarg - echo>>%confargs% %1 \ - shift -goto :loop ; -:help - echo Configuration: - echo --help display this help - echo --srcdir=DIR find the sources in DIR [configure dir or `..'] - echo Installation directories: - echo --prefix=PREFIX install files in PREFIX [/usr] - echo System types: - echo --target=TARGET configure for TARGET [i386-mswin32] - echo Optional Package: - echo --with-baseruby=RUBY use RUBY as baseruby [ruby] - echo --with-static-linked-ext link external modules statically - echo --with-ext="a,b,..." use extensions a, b, ... - echo --without-ext="a,b,..." ignore extensions a, b, ... - echo --with-opt-dir="DIR-LIST" add optional headers and libraries directories separated by `;' - echo --disable-install-doc do not install rdoc indexes during install - echo --with-ntver=0xXXXX target NT version (shouldn't use with old SDK) - echo --with-ntver=_WIN32_WINNT_XXXX - echo --with-ntver=XXXX same as --with-ntver=_WIN32_WINNT_XXXX - echo Note that `,' and `;' need to be enclosed within double quotes in batch file command line. - del %confargs% %config_make% -goto :exit -:end -( - echo // - echo configure_args = CONFIGURE_ARGS - echo !endif - echo #undef $ -) >> %confargs% -( - cl -EP %confargs% 2>nul | findstr "! =" - echo. - if NOT "%XINCFLAGS%" == "" echo XINCFLAGS = %XINCFLAGS% - if NOT "%XLDFLAGS%" == "" echo XLDFLAGS = %XLDFLAGS% - if NOT "%pathlist%" == "" ( - call echo PATH = %%pathlist:;=/bin;%%$^(PATH^) - call echo INCLUDE = %%pathlist:;=/include;%%$^(INCLUDE^) - call echo LIB = %%pathlist:;=/lib;%%$^(LIB^) - ) -) >> %config_make% -del %confargs% > nul - -nmake -al -f %WIN32DIR%/setup.mak "WIN32DIR=%WIN32DIR%" ^ - config_make=%config_make% ^ - MAKEFILE=Makefile.new MAKEFILE_BACK=Makefile.old MAKEFILE_NEW=Makefile -:exit -@endlocal +@echo off +@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1 +set PROMPT=$E[94m+$E[m$S +set witharg= + +if "%~dp0" == "%CD%\" ( + echo don't run in win32 directory. + exit /b 999 +) else if "%0" == "%~nx0" ( + set "WIN32DIR=%~$PATH:0" +) else if "%0" == "%~n0" ( + set "WIN32DIR=%~$PATH:0" +) else ( + set "WIN32DIR=%0" +) + +set "WIN32DIR=%WIN32DIR:\=/%:/:" +call set "WIN32DIR=%%WIN32DIR:%~x0:/:=:/:%%" +call set "WIN32DIR=%%WIN32DIR:/%~n0:/:=:/:%%" +set "WIN32DIR=%WIN32DIR:~0,-3%" + +set XINCFLAGS= +set XLDFLAGS= +set pathlist= +set config_make=confargs~%RANDOM%.mak +set confargs=%config_make:.mak=.c% +echo>%config_make% # CONFIGURE +( + echo #define $ $$ // + echo !ifndef CONFIGURE_ARGS + echo #define CONFIGURE_ARGS \ +) >%confargs% +:loop +set opt=%1 +if "%1" == "" goto :end +if "%1" == "--debug-configure" (echo on & shift & goto :loop) +if "%1" == "--no-debug-configure" (echo off & shift & goto :loop) +if "%1" == "--prefix" goto :prefix +if "%1" == "--srcdir" goto :srcdir +if "%1" == "srcdir" goto :srcdir +if "%1" == "--target" goto :target +if "%1" == "target" goto :target +if "%1" == "--with-static-linked-ext" goto :extstatic +if "%1" == "--program-prefix" goto :pprefix +if "%1" == "--program-suffix" goto :suffix +if "%1" == "--program-transform-name" goto :transform_name +if "%1" == "--program-name" goto :installname +if "%1" == "--install-name" goto :installname +if "%1" == "--so-name" goto :soname +if "%1" == "--enable-install-doc" goto :enable-rdoc +if "%1" == "--disable-install-doc" goto :disable-rdoc +if "%1" == "--enable-install-static-library" goto :enable-lib +if "%1" == "--disable-install-static-library" goto :disable-lib +if "%1" == "--enable-debug-env" goto :enable-debug-env +if "%1" == "--disable-debug-env" goto :disable-debug-env +if "%1" == "--enable-devel" goto :enable-devel +if "%1" == "--disable-devel" goto :disable-devel +if "%1" == "--enable-rubygems" goto :enable-rubygems +if "%1" == "--disable-rubygems" goto :disable-rubygems +if "%1" == "--extout" goto :extout +if "%1" == "--path" goto :path +if "%1" == "--with-baseruby" goto :baseruby +if "%1" == "--without-baseruby" goto :nobaseruby +if "%1" == "--with-ntver" goto :ntver +if "%1" == "--with-libdir" goto :libdir +if "%1" == "--with-git" goto :git +if "%1" == "--without-git" goto :nogit +if "%1" == "--without-ext" goto :witharg +if "%1" == "--without-extensions" goto :witharg +if "%1" == "--with-opt-dir" goto :opt-dir +if "%1" == "--with-gmp" goto :gmp +if "%1" == "--with-gmp-dir" goto :gmp-dir +if "%opt:~0,10%" == "--without-" goto :withoutarg +if "%opt:~0,7%" == "--with-" goto :witharg +if "%1" == "-h" goto :help +if "%1" == "--help" goto :help + if "%opt:~0,1%" == "-" ( + echo>>%confargs% %1 \ + set witharg= + ) else if "%witharg%" == "" ( + echo>>%confargs% %1 \ + ) else ( + echo>>%confargs% ,%1\ + ) + shift +goto :loop ; +:srcdir + echo>> %config_make% srcdir = %~2 + echo>>%confargs% --srcdir=%2 \ + shift + shift +goto :loop ; +:prefix + echo>> %config_make% prefix = %~2 + echo>>%confargs% %1=%2 \ + shift + shift +goto :loop ; +:pprefix + echo>> %config_make% PROGRAM_PREFIX = %~2 + echo>>%confargs% %1=%2 \ + shift + shift +goto :loop ; +:suffix + echo>> %config_make% PROGRAM_SUFFIX = %~2 + echo>>%confargs% %1=%2 \ + shift + shift +goto :loop ; +:installname + echo>> %config_make% RUBY_INSTALL_NAME = %~2 + echo>>%confargs% %1=%2 \ + shift + shift +goto :loop ; +:soname + echo>> %config_make% RUBY_SO_NAME = %~2 + echo>>%confargs% %1=%2 \ + shift + shift +goto :loop ; +:transform_name + + shift + shift +goto :loop ; +:target + echo>> %config_make% target = %~2 + echo>>%confargs% --target=%2 \ + if "%~2" == "x64-mswin64" ( + echo>> %config_make% TARGET_OS = mswin64 + ) + shift + shift +goto :loop ; +:extstatic + echo>> %config_make% EXTSTATIC = static + echo>>%confargs% %1 \ + shift +goto :loop ; +:enable-rdoc + echo>> %config_make% RDOCTARGET = rdoc + echo>>%confargs% %1 \ + shift +goto :loop ; +:disable-rdoc + echo>> %config_make% RDOCTARGET = nodoc + echo>>%confargs% %1 \ + shift +goto :loop ; +:enable-lib + echo>> %config_make% INSTALL_STATIC_LIBRARY = yes + echo>>%confargs% %1 \ + shift +goto :loop ; +:disable-lib + echo>> %config_make% INSTALL_STATIC_LIBRARY = no + echo>>%confargs% %1 \ + shift +goto :loop ; +:enable-debug-env + echo>> %config_make% ENABLE_DEBUG_ENV = yes + echo>>%confargs% %1 \ + shift +goto :loop ; +:disable-debug-env + echo>> %config_make% ENABLE_DEBUG_ENV = no + echo>>%confargs% %1 \ + shift +goto :loop ; +:enable-devel + echo>> %config_make% RUBY_DEVEL = yes + echo>>%confargs% %1 \ + shift +goto :loop ; +:disable-devel + echo>> %config_make% RUBY_DEVEL = no + echo>>%confargs% %1 \ + shift +goto :loop ; +:enable-rubygems + echo>> %config_make% USE_RUBYGEMS = yes + echo>>%confargs% %1 \ + shift +goto :loop ; +:disable-rubygems + echo>> %config_make% USE_RUBYGEMS = no + echo>>%confargs% %1 \ + shift +goto :loop ; +:ntver + ::- For version constants, see + ::- https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt#remarks + set NTVER=%~2 + if /i not "%NTVER:~0,2%" == "0x" if /i not "%NTVER:~0,13%" == "_WIN32_WINNT_" ( + for %%i in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do ( + call set NTVER=%%NTVER:%%i=%%i%% + ) + call set NTVER=_WIN32_WINNT_%%NTVER%% + ) + echo>> %config_make% NTVER = %NTVER% + echo>>%confargs% %1=%2 \ + shift + shift +goto :loop ; +:extout + if not "%~2" == ".ext" (echo>> %config_make% EXTOUT = %~2) + echo>>%confargs% %1=%2 \ + shift + shift +goto :loop ; +:path + set pathlist=%pathlist%%~2; + echo>>%confargs% %1=%2 \ + shift + shift +goto :loop ; +:baseruby + echo>> %config_make% HAVE_BASERUBY = yes + echo>> %config_make% BASERUBY = %~2 + echo>>%confargs% %1=%2 \ + shift + shift +goto :loop ; +:nobaseruby + echo>> %config_make% HAVE_BASERUBY = no + echo>> %config_make% BASERUBY = + echo>>%confargs% %1 \ + shift +goto :loop ; +:libdir + echo>> %config_make% libdir_basename = %~2 + echo>>%confargs% %1=%2 \ + shift + shift +goto :loop ; +:git + echo>> %config_make% GIT = %~2 + echo>>%confargs% %1=%2 \ + shift + shift +goto :loop ; +:nogit + echo>> %config_make% GIT = never-use + echo>> %config_make% HAVE_GIT = no + echo>>%confargs% %1 \ + shift +goto :loop ; +:gmp + echo>> %config_make% WITH_GMP = yes + echo>>%confargs% %1 \ + shift +goto :loop ; +:gmp-dir +:opt-dir + set opt=%~2 + for %%I in (%opt:;= %) do ( + set d=%%I + call pushd %%d:/=\%% && ( + call set XINCFLAGS=%%XINCFLAGS%% -I%%CD:\=/%%/include + call set XLDFLAGS=%%XLDFLAGS%% -libpath:%%CD:\=/%%/lib + popd + ) + ) +:witharg + echo>>%confargs% %1=%2\ + set witharg=1 + shift + shift +goto :loop ; +:withoutarg + echo>>%confargs% %1 \ + shift +goto :loop ; +:help + echo Configuration: + echo --help display this help + echo --srcdir=DIR find the sources in DIR [configure dir or `..'] + echo Installation directories: + echo --prefix=PREFIX install files in PREFIX [/usr] + echo System types: + echo --target=TARGET configure for TARGET [i386-mswin32] + echo Optional Package: + echo --with-baseruby=RUBY use RUBY as baseruby [ruby] + echo --with-static-linked-ext link external modules statically + echo --with-ext="a,b,..." use extensions a, b, ... + echo --without-ext="a,b,..." ignore extensions a, b, ... + echo --with-opt-dir="DIR-LIST" add optional headers and libraries directories separated by `;' + echo --disable-install-doc do not install rdoc indexes during install + echo --with-ntver=0xXXXX target NT version (shouldn't use with old SDK) + echo --with-ntver=_WIN32_WINNT_XXXX + echo --with-ntver=XXXX same as --with-ntver=_WIN32_WINNT_XXXX + echo Note that `,' and `;' need to be enclosed within double quotes in batch file command line. + del %confargs% %config_make% +goto :exit +:end +( + echo // + echo configure_args = CONFIGURE_ARGS + echo !endif + echo #undef $ +) >> %confargs% +( + cl -EP %confargs% 2>nul | findstr "! =" + echo. + if NOT "%XINCFLAGS%" == "" echo XINCFLAGS = %XINCFLAGS% + if NOT "%XLDFLAGS%" == "" echo XLDFLAGS = %XLDFLAGS% + if NOT "%pathlist%" == "" ( + call echo PATH = %%pathlist:;=/bin;%%$^(PATH^) + call echo INCLUDE = %%pathlist:;=/include;%%$^(INCLUDE^) + call echo LIB = %%pathlist:;=/lib;%%$^(LIB^) + ) +) >> %config_make% +del %confargs% > nul + +nmake -al -f %WIN32DIR%/setup.mak "WIN32DIR=%WIN32DIR%" ^ + config_make=%config_make% ^ + MAKEFILE=Makefile.new MAKEFILE_BACK=Makefile.old MAKEFILE_NEW=Makefile +:exit +@endlocal diff --git a/win32/ifchange.bat b/win32/ifchange.bat index f3fc9ea37c6203..fa10c5870351c3 100755 --- a/win32/ifchange.bat +++ b/win32/ifchange.bat @@ -1,137 +1,137 @@ -@echo off -:: usage: ifchange target temporary - -@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1 - -:: @set PROMPT=$T:$S -for %%I in (%0) do set progname=%%~nI -set timestamp= -set keepsuffix= -set empty= -set color=auto -:optloop -set optarg= -:optnext -for %%I in (%1) do set opt=%%~I - if not "%opt:~0,2%" == "--" ( - if not "%optarg%" == "" ( - call set %optarg%=%%opt%% - shift - goto :optloop - ) - goto :optend - ) - if "%opt%" == "--" ( - shift - goto :optend - ) - if "%opt%" == "--timestamp" ( - set timestamp=. - set optarg=timestamp - shift - goto :optnext - ) - if "%opt:~0,12%" == "--timestamp=" ( - set timestamp=%opt:~12% - shift - goto :optloop - ) - if "%opt%" == "--keep" ( - set keepsuffix=.old - set optarg=keep - shift - goto :optnext - ) - if "%opt:~0,7%" == "--keep=" ( - set keepsuffix=%opt:~7% - shift - goto :optloop - ) - if "%opt%" == "--empty" ( - set empty=yes - shift - goto :optloop - ) - if "%opt%" == "--color" ( - set color=always - set optarg=color - shift - goto :optnext - ) - if "%opt:~0,8%" == "--color=" ( - set color=%opt:~8% - shift - goto :optloop - ) - if "%opt%" == "--debug" ( - shift - echo on - goto :optloop - ) - if "%opt%" == "--help" ( - call :help - exit /b - ) - echo %progname%: unknown option: %1 1>&2 - exit /b 1 -:optend - -if "%2" == "" ( - call :help 1>&2 - exit /b 1 -) - -set dest=%1 -set src=%2 -set dest=%dest:/=\% -set src=%src:/=\% - -if not "%src%" == "-" goto :srcfile - if not "%TMPDIR%" == "" ( - set src=%TMPDIR%\ifchange%RANDOM%.tmp - ) else if not "%TEMP%" == "" ( - set src=%TEMP%\ifchange%RANDOM%.tmp - ) else if not "%TMP%" == "" ( - set src=%TMP%\ifchange%RANDOM%.tmp - ) else ( - set src=.\ifchange%RANDOM%.tmp - ) - findstr -r -c:"^" > "%src%" -:srcfile - -if exist %dest% ( - if not exist %src% goto :nt_unchanged1 - if not "%empty%" == "" for %%I in (%src%) do if %%~zI == 0 goto :nt_unchanged - fc.exe %dest% %src% > nul && ( - :nt_unchanged - del %src% - :nt_unchanged1 - for %%I in (%1) do echo %%~I unchanged - goto :nt_end - ) -) -for %%I in (%1) do echo %%~I updated -del /f %dest% 2> nul -copy %src% %dest% > nul -del %src% - -:nt_end -if "%timestamp%" == "" goto :end - if "%timestamp%" == "." ( - for %%I in ("%dest%") do set timestamp=%%~dpI.time.%%~nxI - ) - goto :end > "%timestamp%" - -:help - for %%I in ( - "usage: %progname% [options] target new-file" - "options:" - " --timestamp[=file] touch timestamp file. (default: prefixed with '.time')" - " under the directory of the target)" - " --keep[=suffix] keep old file with suffix. (default: '.old')" - " --empty assume unchanged if the new file is empty." - " --color[=always|auto|never] colorize output." - ) do echo.%%~I - goto :eof - -:end +@echo off +:: usage: ifchange target temporary + +@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1 + +:: @set PROMPT=$T:$S +for %%I in (%0) do set progname=%%~nI +set timestamp= +set keepsuffix= +set empty= +set color=auto +:optloop +set optarg= +:optnext +for %%I in (%1) do set opt=%%~I + if not "%opt:~0,2%" == "--" ( + if not "%optarg%" == "" ( + call set %optarg%=%%opt%% + shift + goto :optloop + ) + goto :optend + ) + if "%opt%" == "--" ( + shift + goto :optend + ) + if "%opt%" == "--timestamp" ( + set timestamp=. + set optarg=timestamp + shift + goto :optnext + ) + if "%opt:~0,12%" == "--timestamp=" ( + set timestamp=%opt:~12% + shift + goto :optloop + ) + if "%opt%" == "--keep" ( + set keepsuffix=.old + set optarg=keep + shift + goto :optnext + ) + if "%opt:~0,7%" == "--keep=" ( + set keepsuffix=%opt:~7% + shift + goto :optloop + ) + if "%opt%" == "--empty" ( + set empty=yes + shift + goto :optloop + ) + if "%opt%" == "--color" ( + set color=always + set optarg=color + shift + goto :optnext + ) + if "%opt:~0,8%" == "--color=" ( + set color=%opt:~8% + shift + goto :optloop + ) + if "%opt%" == "--debug" ( + shift + echo on + goto :optloop + ) + if "%opt%" == "--help" ( + call :help + exit /b + ) + echo %progname%: unknown option: %1 1>&2 + exit /b 1 +:optend + +if "%2" == "" ( + call :help 1>&2 + exit /b 1 +) + +set dest=%1 +set src=%2 +set dest=%dest:/=\% +set src=%src:/=\% + +if not "%src%" == "-" goto :srcfile + if not "%TMPDIR%" == "" ( + set src=%TMPDIR%\ifchange%RANDOM%.tmp + ) else if not "%TEMP%" == "" ( + set src=%TEMP%\ifchange%RANDOM%.tmp + ) else if not "%TMP%" == "" ( + set src=%TMP%\ifchange%RANDOM%.tmp + ) else ( + set src=.\ifchange%RANDOM%.tmp + ) + findstr -r -c:"^" > "%src%" +:srcfile + +if exist %dest% ( + if not exist %src% goto :nt_unchanged1 + if not "%empty%" == "" for %%I in (%src%) do if %%~zI == 0 goto :nt_unchanged + fc.exe %dest% %src% > nul && ( + :nt_unchanged + del %src% + :nt_unchanged1 + for %%I in (%1) do echo %%~I unchanged + goto :nt_end + ) +) +for %%I in (%1) do echo %%~I updated +del /f %dest% 2> nul +copy %src% %dest% > nul +del %src% + +:nt_end +if "%timestamp%" == "" goto :end + if "%timestamp%" == "." ( + for %%I in ("%dest%") do set timestamp=%%~dpI.time.%%~nxI + ) + goto :end > "%timestamp%" + +:help + for %%I in ( + "usage: %progname% [options] target new-file" + "options:" + " --timestamp[=file] touch timestamp file. (default: prefixed with '.time')" + " under the directory of the target)" + " --keep[=suffix] keep old file with suffix. (default: '.old')" + " --empty assume unchanged if the new file is empty." + " --color[=always|auto|never] colorize output." + ) do echo.%%~I + goto :eof + +:end diff --git a/win32/makedirs.bat b/win32/makedirs.bat index 8c06d94041c46b..6688457139ed34 100755 --- a/win32/makedirs.bat +++ b/win32/makedirs.bat @@ -1,3 +1,3 @@ -@echo off -@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1 -for %%I in (%*) do if not exist "%%~I/." mkdir "%%~I" +@echo off +@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1 +for %%I in (%*) do if not exist "%%~I/." mkdir "%%~I" diff --git a/win32/rm.bat b/win32/rm.bat index c41ebfa5ee0177..02077919916b5a 100755 --- a/win32/rm.bat +++ b/win32/rm.bat @@ -1,64 +1,64 @@ -@echo off -@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1 - -set prog=%~n0 -set dryrun= -set recursive= -set debug= -set error=0 -set parent= - -:optloop -if "%1" == "-f" shift -if "%1" == "-n" (shift & set "dryrun=%1" & goto :optloop) -if "%1" == "-r" (shift & set "recursive=%1" & goto :optloop) -if "%1" == "--debug" (shift & set "debug=%1" & set PROMPT=$E[34m+$E[m$S & echo on & goto :optloop) -:begin -if "%1" == "" goto :EOF - set p=%1 - shift - set p=%p:/=\% - call :remove %p% -goto :begin - -:remove -setlocal - -::- Split %1 by '?' and '*', wildcard characters -for /f "usebackq delims=?* tokens=1*" %%I in ('%1') do (set "par=%%I" & set "sub=%%J") -if "%sub%" == "" goto :remove_plain -if "%sub:\=%" == "%sub%" goto :remove_plain - ::- Extract the first wildcard - set "q=%1" - call set "q=%%q:%par%=%%" - set q=%q:~0,1% - - ::- `delims` chars at the beginning are removed in `for` - if "%sub:~0,1%" == "\" ( - set "sub=%sub:~1%" - set "par=%par%%q%" - ) else ( - for /f "usebackq delims=\\ tokens=1*" %%I in ('%sub%') do (set "par=%par%%q%%%I" & set "sub=%%J") - ) - - ::- Recursive search - for /d %%D in (%par%) do ( - call :remove %sub% %2%%D\ - ) -goto :remove_end -:remove_plain - set p=%2%1 - if not exist "%1" goto :remove_end - if not "%dryrun%" == "" ( - echo Removing %p:\=/% - goto :remove_end - ) - ::- Try `rd` first for symlink to a directory; `del` attemps to remove all - ::- files under the target directory, instead of the symlink itself. - (rd /q "%p%" || del /q "%p%") 2> nul && goto :remove_end - - if "%recursive%" == "-r" for /D %%I in (%p%) do ( - rd /s /q %%I || call set error=%%ERRORLEVEL%% - ) -:remove_end -endlocal & set "error=%error%" & goto :EOF +@echo off +@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1 + +set prog=%~n0 +set dryrun= +set recursive= +set debug= +set error=0 +set parent= + +:optloop +if "%1" == "-f" shift +if "%1" == "-n" (shift & set "dryrun=%1" & goto :optloop) +if "%1" == "-r" (shift & set "recursive=%1" & goto :optloop) +if "%1" == "--debug" (shift & set "debug=%1" & set PROMPT=$E[34m+$E[m$S & echo on & goto :optloop) +:begin +if "%1" == "" goto :EOF + set p=%1 + shift + set p=%p:/=\% + call :remove %p% +goto :begin + +:remove +setlocal + +::- Split %1 by '?' and '*', wildcard characters +for /f "usebackq delims=?* tokens=1*" %%I in ('%1') do (set "par=%%I" & set "sub=%%J") +if "%sub%" == "" goto :remove_plain +if "%sub:\=%" == "%sub%" goto :remove_plain + ::- Extract the first wildcard + set "q=%1" + call set "q=%%q:%par%=%%" + set q=%q:~0,1% + + ::- `delims` chars at the beginning are removed in `for` + if "%sub:~0,1%" == "\" ( + set "sub=%sub:~1%" + set "par=%par%%q%" + ) else ( + for /f "usebackq delims=\\ tokens=1*" %%I in ('%sub%') do (set "par=%par%%q%%%I" & set "sub=%%J") + ) + + ::- Recursive search + for /d %%D in (%par%) do ( + call :remove %sub% %2%%D\ + ) +goto :remove_end +:remove_plain + set p=%2%1 + if not exist "%1" goto :remove_end + if not "%dryrun%" == "" ( + echo Removing %p:\=/% + goto :remove_end + ) + ::- Try `rd` first for symlink to a directory; `del` attemps to remove all + ::- files under the target directory, instead of the symlink itself. + (rd /q "%p%" || del /q "%p%") 2> nul && goto :remove_end + + if "%recursive%" == "-r" for /D %%I in (%p%) do ( + rd /s /q %%I || call set error=%%ERRORLEVEL%% + ) +:remove_end +endlocal & set "error=%error%" & goto :EOF diff --git a/win32/rmdirs.bat b/win32/rmdirs.bat index a8abebd3839051..a1a97fde145c48 100755 --- a/win32/rmdirs.bat +++ b/win32/rmdirs.bat @@ -1,34 +1,34 @@ -@echo off -@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1 -set parents=1 -:optloop -if "%1" == "--debug" (shift & set PROMPT=$E[34m+$E[m$S & echo on & goto :optloop) -if "%1" == "-p" (shift & (set parents=1) & goto :optloop) -:begin -if "%1" == "" goto :end - set dir=%1 - shift - set dir=%dir:/=\% - :rmdirs - if /%dir:~-2%/ == /\./ set dir=%dir:~0,-2% - if not exist "%dir%\." goto :begin - if "%dir%" == "." goto :begin - if "%dir%" == ".." goto :begin - rd "%dir%" 2> nul || goto :begin - if "%parents%" == "" goto :begin - :trim_sep - if not /%dir:~-1%/ == /\/ goto :trim_base - set dir=%dir:~0,-1% - if not "%dir%" == "" goto :trim_sep - :trim_base - if /%dir:~-1%/ == /\/ goto :parent - set dir=%dir:~0,-1% - if not "%dir%" == "" goto :trim_base - :parent - set dir=%dir:~0,-1% - if "%dir%" == "" goto :begin - if "%dir:~-1%" == ":" goto :begin - goto :rmdirs -shift -goto :begin -:end +@echo off +@setlocal EnableExtensions DisableDelayedExpansion || exit /b -1 +set parents=1 +:optloop +if "%1" == "--debug" (shift & set PROMPT=$E[34m+$E[m$S & echo on & goto :optloop) +if "%1" == "-p" (shift & (set parents=1) & goto :optloop) +:begin +if "%1" == "" goto :end + set dir=%1 + shift + set dir=%dir:/=\% + :rmdirs + if /%dir:~-2%/ == /\./ set dir=%dir:~0,-2% + if not exist "%dir%\." goto :begin + if "%dir%" == "." goto :begin + if "%dir%" == ".." goto :begin + rd "%dir%" 2> nul || goto :begin + if "%parents%" == "" goto :begin + :trim_sep + if not /%dir:~-1%/ == /\/ goto :trim_base + set dir=%dir:~0,-1% + if not "%dir%" == "" goto :trim_sep + :trim_base + if /%dir:~-1%/ == /\/ goto :parent + set dir=%dir:~0,-1% + if not "%dir%" == "" goto :trim_base + :parent + set dir=%dir:~0,-1% + if "%dir%" == "" goto :begin + if "%dir:~-1%" == ":" goto :begin + goto :rmdirs +shift +goto :begin +:end