diff --git a/.github/actions/setup/directories/action.yml b/.github/actions/setup/directories/action.yml index bb1c92bd735168..ec9c44f8b452ac 100644 --- a/.github/actions/setup/directories/action.yml +++ b/.github/actions/setup/directories/action.yml @@ -158,22 +158,9 @@ runs: working-directory: ${{ inputs.srcdir }} run: | ruby tool/missing-baseruby.bat --verbose - touch config.status .rbconfig.time - for mk in Makefile GNUmakefile; do - sed -f tool/prereq.status template/$mk.in > $mk - done - make up + bash tool/gen-sources.bash up echo RUBY_DUMP_AST=true >> "$GITHUB_ENV" - # Cleanup, runs even on failure - - if: always() && inputs.makeup - shell: bash - working-directory: ${{ inputs.srcdir }} - run: | - rm -f config.status .rbconfig.time \ - Makefile GNUmakefile uncommon.mk enc.mk noarch-fake.rb - rm -f prism/.time prism/util/.time - - if: steps.which.outputs.sudo shell: bash run: | diff --git a/common.mk b/common.mk index 8feb982f6bda55..a083265aac3441 100644 --- a/common.mk +++ b/common.mk @@ -1344,11 +1344,11 @@ $(BUILTIN_BINARY:no=builtin)_binary.rbbin: $(BUILTIN_RB_INCS): $(tooldir)/mk_builtin_loader.rb $(DUMP_AST_TARGET) -dump_ast$(BUILD_EXEEXT): $(tooldir)/dump_ast.c $(LIBPRISM_OBJS) +dump_ast$(BUILD_EXEEXT): $(tooldir)/dump_ast.c $(LIBPRISM_OBJS) revision.h $(ECHO) compiling $@ $(Q) $(CC) $(CFLAGS) $(OUTFLAG)$@ $(INCFLAGS) $(tooldir)/dump_ast.c $(LIBPRISM_OBJS) -build-tool/Makefile: $(tooldir)/dump_ast.mkmf.rb prism-srcs prism-incs +build-tool/Makefile: $(tooldir)/dump_ast.mkmf.rb prism-srcs prism-incs revision.h +$(BASERUBY) -s $(tooldir)/dump_ast.mkmf.rb \ "-INCFLAGS=$(INCFLAGS)" "-make=$(MAKE)" "-objext=$(OBJEXT)" \ build-tool $(tooldir)/dump_ast.c dump_ast.$(OBJEXT) $(LIBPRISM_OBJS) diff --git a/hash.c b/hash.c index 9e2c52f13946b1..90d1c1ffd3f50b 100644 --- a/hash.c +++ b/hash.c @@ -5954,7 +5954,7 @@ env_each_pair(VALUE ehash) * * Similar to ENV.delete_if, but returns +nil+ if no changes were made. * - * Yields each environment variable name and its value as a 2-element Array, + * Calls the block with each environment variable name and value, * deleting each environment variable for which the block returns a truthy value, * and returning ENV (if any deletions) or +nil+ (if not): * ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') @@ -5995,10 +5995,10 @@ env_reject_bang(VALUE ehash) /* * call-seq: - * ENV.delete_if { |name, value| block } -> ENV + * ENV.delete_if {|name, value| ... } -> ENV * ENV.delete_if -> an_enumerator * - * Yields each environment variable name and its value as a 2-element Array, + * Calls the block with each environment variable name and value, * deleting each environment variable for which the block returns a truthy value, * and returning ENV (regardless of whether any deletions): * ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') @@ -6006,12 +6006,7 @@ env_reject_bang(VALUE ehash) * ENV # => {"foo"=>"0"} * ENV.delete_if { |name, value| name.start_with?('b') } # => ENV * - * Returns an Enumerator if no block given: - * ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') - * e = ENV.delete_if # => #"1", "baz"=>"2", "foo"=>"0"}:delete_if!> - * e.each { |name, value| name.start_with?('b') } # => ENV - * ENV # => {"foo"=>"0"} - * e.each { |name, value| name.start_with?('b') } # => ENV + * With no block given, returns a new Enumerator. */ static VALUE env_delete_if(VALUE ehash) @@ -6053,22 +6048,18 @@ env_values_at(int argc, VALUE *argv, VALUE _) /* * call-seq: - * ENV.select { |name, value| block } -> hash of name/value pairs + * ENV.select {|name, value| ... } -> hash of name/value pairs * ENV.select -> an_enumerator - * ENV.filter { |name, value| block } -> hash of name/value pairs + * ENV.filter {|name, value| ... } -> hash of name/value pairs * ENV.filter -> an_enumerator * - * Yields each environment variable name and its value as a 2-element Array, + * Calls the block with each environment variable name and value, * returning a Hash of the names and values for which the block returns a truthy value: * ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') * ENV.select { |name, value| name.start_with?('b') } # => {"bar"=>"1", "baz"=>"2"} * ENV.filter { |name, value| name.start_with?('b') } # => {"bar"=>"1", "baz"=>"2"} * - * Returns an Enumerator if no block given: - * e = ENV.select # => #"1", "baz"=>"2", "foo"=>"0"}:select> - * e.each { |name, value | name.start_with?('b') } # => {"bar"=>"1", "baz"=>"2"} - * e = ENV.filter # => #"1", "baz"=>"2", "foo"=>"0"}:filter> - * e.each { |name, value | name.start_with?('b') } # => {"bar"=>"1", "baz"=>"2"} + * With no block given, returns a new Enumerator. */ static VALUE env_select(VALUE ehash) @@ -6096,12 +6087,12 @@ env_select(VALUE ehash) /* * call-seq: - * ENV.select! { |name, value| block } -> ENV or nil + * ENV.select! {|name, value| ... } -> ENV or nil * ENV.select! -> an_enumerator - * ENV.filter! { |name, value| block } -> ENV or nil + * ENV.filter! {|name, value| ... } -> ENV or nil * ENV.filter! -> an_enumerator * - * Yields each environment variable name and its value as a 2-element Array, + * Calls the block with each environment variable name and value, * deleting each entry for which the block returns +false+ or +nil+, * and returning ENV if any deletions made, or +nil+ otherwise: * @@ -6115,19 +6106,7 @@ env_select(VALUE ehash) * ENV # => {"bar"=>"1", "baz"=>"2"} * ENV.filter! { |name, value| true } # => nil * - * Returns an Enumerator if no block given: - * - * ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') - * e = ENV.select! # => #"1", "baz"=>"2"}:select!> - * e.each { |name, value| name.start_with?('b') } # => ENV - * ENV # => {"bar"=>"1", "baz"=>"2"} - * e.each { |name, value| true } # => nil - * - * ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') - * e = ENV.filter! # => #"1", "baz"=>"2"}:filter!> - * e.each { |name, value| name.start_with?('b') } # => ENV - * ENV # => {"bar"=>"1", "baz"=>"2"} - * e.each { |name, value| true } # => nil + * With no block given, returns a new Enumerator. */ static VALUE env_select_bang(VALUE ehash) @@ -6155,21 +6134,17 @@ env_select_bang(VALUE ehash) /* * call-seq: - * ENV.keep_if { |name, value| block } -> ENV + * ENV.keep_if {|name, value| ... } -> ENV * ENV.keep_if -> an_enumerator * - * Yields each environment variable name and its value as a 2-element Array, + * Calls the block with each environment variable name and value, * deleting each environment variable for which the block returns +false+ or +nil+, * and returning ENV: * ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') * ENV.keep_if { |name, value| name.start_with?('b') } # => ENV * ENV # => {"bar"=>"1", "baz"=>"2"} * - * Returns an Enumerator if no block given: - * ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') - * e = ENV.keep_if # => #"1", "baz"=>"2", "foo"=>"0"}:keep_if> - * e.each { |name, value| name.start_with?('b') } # => ENV - * ENV # => {"bar"=>"1", "baz"=>"2"} + * With no block given, returns a new Enumerator. */ static VALUE env_keep_if(VALUE ehash) @@ -6685,19 +6660,19 @@ env_except(int argc, VALUE *argv, VALUE _) } /* - * call-seq: - * ENV.reject { |name, value| block } -> hash of name/value pairs - * ENV.reject -> an_enumerator + * call-seq: + * ENV.reject {|name, value| ... } -> hash + * ENV.reject -> new_enumerator * - * Yields each environment variable name and its value as a 2-element Array. - * Returns a Hash whose items are determined by the block. - * When the block returns a truthy value, the name/value pair is added to the return Hash; - * otherwise the pair is ignored: - * ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') - * ENV.reject { |name, value| name.start_with?('b') } # => {"foo"=>"0"} - * Returns an Enumerator if no block given: - * e = ENV.reject - * e.each { |name, value| name.start_with?('b') } # => {"foo"=>"0"} + * Calls the block with each environment variable name and value. + * Returns a Hash whose items are determined by the block. + * When the block returns a truthy value, the name/value pair is ignored; + * otherwise the pair is added to the return Hash: + * + * ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') + * ENV.reject { |name, value| name.start_with?('b') } # => {"foo"=>"0"} + * + * Returns a new Enumerator if no block is given. */ static VALUE env_reject(VALUE _) @@ -7653,7 +7628,7 @@ Init_Hash(void) * - ::delete_if: Deletes entries selected by the block. * - ::keep_if: Deletes entries not selected by the block. * - ::reject!: Similar to #delete_if, but returns +nil+ if no change was made. - * - ::select!, ::filter!: Deletes entries selected by the block. + * - ::select!, ::filter!: Deletes entries not selected by the block. * - ::shift: Removes and returns the first entry. * * ==== Methods for Iterating diff --git a/io.c b/io.c index 91119735508474..e3362c3578819d 100644 --- a/io.c +++ b/io.c @@ -3572,7 +3572,7 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int no_exception, int nonblock) * * - Contains +maxlen+ bytes from the stream, if available. * - Otherwise contains all available bytes, if any available. - * - Otherwise is an empty string. + * - Is an empty string if +maxlen+ is zero. * * With the single non-negative integer argument +maxlen+ given, * returns a new string: diff --git a/numeric.c b/numeric.c index f80a419bafb974..cb7b4932e963b9 100644 --- a/numeric.c +++ b/numeric.c @@ -2164,8 +2164,8 @@ flo_floor(int argc, VALUE *argv, VALUE num) * returns an Integer based on a computed granularity: * * - The granularity is `10 ** ndigits.abs`. - * - The returned value is the largest multiple of the granularity - * that is less than or equal to `self`. + * - The returned value is the smallest multiple of the granularity + * that is greater than or equal to `self`. * * Examples with positive `self`: * diff --git a/pathname_builtin.rb b/pathname_builtin.rb index da9806650d3685..c6edf14e58039c 100644 --- a/pathname_builtin.rb +++ b/pathname_builtin.rb @@ -1392,9 +1392,9 @@ def chmod(mode) File.chmod(mode, @path) end # :markup: markdown # # call-seq: - # Pathname.lchmod(mode) -> 1 + # lchmod(mode) -> 1 # - # Not supported on some platforms (raises Errno:: ENOTSUP). + # Not supported on some platforms (raises Errno::ENOTSUP). # # When supported: like Pathname::chmod, but does not follow symbolic links, # and therefore changes the mode of the entry specified by `self`: @@ -1514,7 +1514,7 @@ def lchown(owner, group) File.lchown(owner, group, @path) end # :markup: markdown # # call-seq: - # File.fnmatch(pattern, flags = 0) -> true or false + # fnmatch(pattern, flags = 0) -> true or false # # Returns whether string `pattern` matches against the string path in `self`, # under the control of the given `flags`; @@ -2473,7 +2473,7 @@ class Pathname # each based on a selected filesystem entry. # # With a block given, calls the block with pathnames, - # each based on a selected filesytem entry. + # each based on a selected filesystem entry. # def Pathname.glob(*args, **kwargs) # :yield: pathname if block_given? diff --git a/process.c b/process.c index 9f135b6d4ad66f..92c5502e3f5dab 100644 --- a/process.c +++ b/process.c @@ -4688,8 +4688,6 @@ rb_spawn(int argc, const VALUE *argv) * * See {Execution Shell}[rdoc-ref:Process@Execution+Shell] for details about the shell. * - * Raises an exception if the new process could not execute. - * * Argument +exe_path+ * * Argument +exe_path+ is one of the following: @@ -4731,7 +4729,6 @@ rb_spawn(int argc, const VALUE *argv) * C* * hello world * - * Raises an exception if the new process could not execute. */ static VALUE diff --git a/range.c b/range.c index 743809448275e2..31ef3ec1fe6524 100644 --- a/range.c +++ b/range.c @@ -453,7 +453,7 @@ range_step_size(VALUE range, VALUE args, VALUE eobj) * Iterates over the elements of range in steps of +s+. The iteration is performed * by + operator: * - * (0..6).step(2) { puts _1 } #=> 1..5 + * (0..6).step(2) { puts _1 } * # Prints: 0, 2, 4, 6 * * # Iterate between two dates in step of 1 day (24 hours) diff --git a/re.c b/re.c index 4c566f478fc906..b3566b48a1466c 100644 --- a/re.c +++ b/re.c @@ -4561,14 +4561,14 @@ rb_reg_s_union(VALUE self, VALUE args0) * Regexp.union(*patterns) -> regexp * Regexp.union(array_of_patterns) -> regexp * - * Returns a new regexp that is the union of the given patterns: + * Returns a regexp that is the union of the given patterns: * * r = Regexp.union(%w[cat dog]) # => /cat|dog/ * r.match('cat') # => # * r.match('dog') # => # * r.match('cog') # => nil * - * For each pattern that is a string, Regexp.new(pattern) is used: + * Each string pattern is escaped so that it is matched literally: * * Regexp.union('penzance') # => /penzance/ * Regexp.union('a+b*c') # => /a\+b\*c/ diff --git a/time.c b/time.c index d9afd3fd18ccb0..469ae6bf916f27 100644 --- a/time.c +++ b/time.c @@ -4163,20 +4163,19 @@ time_zonelocal(VALUE time, VALUE off) /* * call-seq: - * localtime -> self or new_time - * localtime(zone) -> new_time + * localtime -> self + * localtime(zone) -> self * * With no argument given: * - * - Returns +self+ if +self+ is a local time. - * - Otherwise returns a new +Time+ in the user's local timezone: + * - Returns +self+ if +self+ is already a local time. + * - Otherwise returns +self+, converted to the user's local timezone: * * t = Time.utc(2000, 1, 1, 20, 15, 1) # => 2000-01-01 20:15:01 UTC * t.localtime # => 2000-01-01 14:15:01 -0600 * * With argument +zone+ given, - * returns the new +Time+ object created by converting - * +self+ to the given time zone: + * returns +self+, converted to the given time zone: * * t = Time.utc(2000, 1, 1, 20, 15, 1) # => 2000-01-01 20:15:01 UTC * t.localtime("-09:00") # => 2000-01-01 11:15:01 -0900 diff --git a/tool/dump_ast.c b/tool/dump_ast.c index 58250e9b8c4837..5e6038513eb606 100644 --- a/tool/dump_ast.c +++ b/tool/dump_ast.c @@ -2,6 +2,7 @@ #include #include #include +#include "revision.h" /* * When prism is compiled as part of CRuby, the xmalloc/xfree/etc. macros are @@ -27,19 +28,97 @@ print_error(const pm_diagnostic_t *diagnostic, void *data) fprintf(stderr, "%" PRIi32 ":%" PRIu32 ":%s\n", line_column.line, line_column.column, pm_diagnostic_message(diagnostic)); } +#if defined(RUBY_RELEASE_DATETIME) && defined(RUBY_RELEASE_DATETIME) +# define SHOW_PROGRAM_VERSION 2 +#elif defined(RUBY_RELEASE_DATETIME) || defined(RUBY_RELEASE_DATETIME) +# define SHOW_PROGRAM_VERSION 1 +#else +# define SHOW_PROGRAM_VERSION 0 +#endif +#if SHOW_PROGRAM_VERSION +# define usage_versions "and program versions" +#else +# define usage_versions "version" +#endif + +static void +usage(const char *prog) +{ + fprintf(stderr, "Usage: %s [options]... \n" + "Options:\n" + " -v, --version: show Prism " usage_versions "\n" + " -h, --help: show this message\n" + "", prog); +} + int -main(int argc, const char *argv[]) { - if (argc != 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); +main(int argc, const char *argv[]) +{ + const char *filepath = 0; + + for (int i = 1; i < argc; ++i) { + const char *arg = argv[i]; + if (arg[0] != '-') { + if (filepath) { + fprintf(stderr, "too many filename\n"); + goto usage; + } + filepath = arg; + } + else if (arg[1] == '-') { + if (!arg[2]) break; + if (strcmp(arg + 2, "version") == 0) { + version: + fputs("Prism " PRISM_VERSION +#if SHOW_PROGRAM_VERSION + " [" +# ifdef RUBY_RELEASE_DATETIME + RUBY_RELEASE_DATETIME +# endif +# if SHOW_PROGRAM_VERSION > 1 + " " +# endif +# ifdef RUBY_REVISION + RUBY_REVISION +# endif + "]" +#endif + "\n", stdout); + return EXIT_SUCCESS; + } + if (strcmp(arg + 2, "help") == 0) { + help: + usage(argv[0]); + return EXIT_SUCCESS; + } + fprintf(stderr, "unknown option %s\n", arg); + goto usage; + } + else { + while (*++arg) { + switch (*arg) { + case 'v': + goto version; + case 'h': + goto help; + default: + fprintf(stderr, "unknown option -%c\n", *arg); + goto usage; + } + } + } + } + + if (!filepath) { + usage: + usage(argv[0]); return EXIT_FAILURE; } - const char *filepath = argv[1]; pm_source_init_result_t init_result; pm_source_t *source = pm_source_mapped_new(filepath, 0, &init_result); - if (init_result != PM_SOURCE_INIT_SUCCESS) - { + if (init_result != PM_SOURCE_INIT_SUCCESS) { fprintf(stderr, "unable to map file: %s\n", filepath); return EXIT_FAILURE; } diff --git a/tool/gen-sources.bash b/tool/gen-sources.bash new file mode 100644 index 00000000000000..bf88c1dbfd718f --- /dev/null +++ b/tool/gen-sources.bash @@ -0,0 +1,51 @@ +#!/bin/bash +set -e + +nop= +dump_ast= + +opt= optarg= +while getopts cd:n-: opt; do + optarg="$OPTARG" + if [[ "$opt" = - ]]; then + opt="-${optarg%%=*}" + if [[ "$optarg" = *=* ]]; then optarg="${optarg#*=}"; + elif optarg="${!OPTIND}"; [[ "${optarg}" = -* ]]; then optarg= + else shift; fi + fi + + case "-$opt" in + -c|--clean) nop=:;; + -n|--dry-run) nop=echo;; + -d|--dump[-_]ast) dump_ast="$optarg" RUBY_DUMP_AST=;; + --) break;; + -*) echo "${0##*/}: Unknown option $1" 1>&2; exit 1;; + esac +done +shift $((OPTIND-1)) + +if tooldir="${0%/*}"; [ "$tooldir" = "$0" ]; then + tooldir=. srcdir=.. +elif srcdir="${tooldir%/*}"; [ "$srcdir" = "$tooldir" ]; then + srcdir=. +fi +template="${srcdir}/template" + +[ "$nop" = echo ] || trap 'rm -fr "${clean[@]}"' 0 2 + +for t in config.status .rbconfig.time Makefile GNUmakefile; do + [ -z "${nop}" -a -e "$t" ] && echo "exist: $t" && exit 1 +done + +${nop} touch config.status .rbconfig.time +clean=(config.status .rbconfig.time) +for mk in Makefile GNUmakefile; do + [ ${nop} ] || sed -f "$tooldir/prereq.status" "$template/$mk.in" > $mk + clean+=("$mk") +done +clean+=(prism/.time prism/util/.time build-tool) +${nop} make "HAVE_BASERUBY=yes" "BASERUBY=${RUBY-ruby}" \ + ${RUBY_DUMP_AST:+"DUMP_AST=$RUBY_DUMP_AST" "DUMP_AST_TARGET=no"} \ + "${@-prereq}" +[ -z "$dump_ast" ] || ${nop} cp build-tool/dump_ast "$dump_ast" +${nop} rm -fr "${clean[@]}" diff --git a/tool/prereq.status b/tool/prereq.status index a9d8f12b0aae36..8edd7a3e112fe8 100644 --- a/tool/prereq.status +++ b/tool/prereq.status @@ -16,6 +16,7 @@ s,@CXXFLAGS@,,g s,@DLDFLAGS@,,g s,@DTRACE_EXT@,dmyh,g s,@EXEEXT@,,g +s,@GIT@,git,g s,@HAVE_BASERUBY@,yes,g s,@IFCHANGE@,tool/ifchange,g s,@LDFLAGS@,,g diff --git a/version.c b/version.c index 554783265201f0..efffe8cdb3cc6c 100644 --- a/version.c +++ b/version.c @@ -222,7 +222,7 @@ define_ruby_description(const char *const jit_opt) // Assume the active GC name can not be longer than 20 chars // so that we don't have to use strlen and remove the static // qualifier from desc. - + RB_GC_MAX_NAME_LEN + 3 + + RB_GC_MAX_NAME_LEN + 2 #endif ];