From c16d4911c2d971e693871d7de2446197c04ea71e Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 8 May 2021 21:00:21 +0300 Subject: [PATCH] v.checker: deprecate `$if linux_or_macos {` in favor of `$if linux || macos {` --- doc/docs.md | 2 +- vlib/v/checker/checker.v | 8 +++++++- vlib/v/doc/doc.v | 2 +- vlib/v/fmt/tests/consts_expected.vv | 4 ++-- vlib/v/fmt/tests/consts_input.vv | 4 ++-- vlib/v/gen/c/comptime.v | 3 --- vlib/v/pref/os.v | 2 +- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/doc/docs.md b/doc/docs.md index 678333da0a..59c1861a92 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -3787,7 +3787,7 @@ Full list of builtin options: | `mac`, `darwin`, `ios`, | `clang`, `mingw` | `x64`, `x32` | `js`, `glibc`, `prealloc` | | `android`,`mach`, `dragonfly` | `msvc` | `little_endian` | `no_bounds_checking`, `freestanding` | | `gnu`, `hpux`, `haiku`, `qnx` | `cplusplus` | `big_endian` | -| `solaris`, `linux_or_macos` | | | | +| `solaris` | | | | #### $embed_file diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 949c155049..6024f27eb5 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -21,7 +21,8 @@ const int_max = int(0x7FFFFFFF) const ( valid_comp_if_os = ['windows', 'ios', 'macos', 'mach', 'darwin', 'hpux', 'gnu', 'qnx', 'linux', 'freebsd', 'openbsd', 'netbsd', 'bsd', 'dragonfly', 'android', 'solaris', - 'haiku', 'linux_or_macos'] + 'haiku', + ] valid_comp_if_compilers = ['gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus'] valid_comp_if_platforms = ['amd64', 'aarch64', 'arm64', 'x64', 'x32', 'little_endian', 'big_endian', @@ -6024,6 +6025,11 @@ fn (mut c Checker) comp_if_branch(cond ast.Expr, pos token.Position) bool { else { return false } } } else if cond.name !in c.pref.compile_defines_all { + if cond.name == 'linux_or_macos' { + c.error('linux_or_macos is deprecated, please use `\$if linux || macos {` instead', + cond.pos) + return false + } // `$if some_var {}` typ := c.expr(cond) if cond.obj !is ast.Var && cond.obj !is ast.ConstField diff --git a/vlib/v/doc/doc.v b/vlib/v/doc/doc.v index bea327f22f..5364c13c3a 100644 --- a/vlib/v/doc/doc.v +++ b/vlib/v/doc/doc.v @@ -60,7 +60,7 @@ pub fn platform_from_string(platform_str string) ?Platform { 'solaris' { return .solaris } 'android' { return .android } 'haiku' { return .haiku } - 'linux_or_macos', 'nix' { return .linux } + 'nix' { return .linux } '' { return .auto } else { return error('vdoc: invalid platform `$platform_str`') } } diff --git a/vlib/v/fmt/tests/consts_expected.vv b/vlib/v/fmt/tests/consts_expected.vv index f5cd618101..b97e49df67 100644 --- a/vlib/v/fmt/tests/consts_expected.vv +++ b/vlib/v/fmt/tests/consts_expected.vv @@ -9,9 +9,9 @@ const ( // Euler's constant eulers = 2.7182 supported_platforms = ['windows', 'macos', 'linux', 'freebsd', 'openbsd', 'netbsd', 'dragonfly', - 'android', 'js', 'solaris', 'haiku', 'linux_or_macos'] + 'android', 'js', 'solaris', 'haiku'] one_line_supported = ['windows', 'macos', 'linux', 'freebsd', 'openbsd', 'netbsd', 'dragonfly', - 'android', 'js', 'solaris', 'haiku', 'linux_or_macos'] + 'android', 'js', 'solaris', 'haiku'] another_const = ['a', 'b', 'c', 'd', 'e', 'f'] multiline_const = [ 'first line', diff --git a/vlib/v/fmt/tests/consts_input.vv b/vlib/v/fmt/tests/consts_input.vv index 4c4c64a115..e16942ad53 100644 --- a/vlib/v/fmt/tests/consts_input.vv +++ b/vlib/v/fmt/tests/consts_input.vv @@ -9,8 +9,8 @@ phi=1.618 //Euler's constant eulers=2.7182 supported_platforms = ['windows', 'macos', 'linux', 'freebsd', 'openbsd', - 'netbsd', 'dragonfly', 'android', 'js', 'solaris', 'haiku', 'linux_or_macos'] -one_line_supported = ['windows', 'macos', 'linux', 'freebsd', 'openbsd', 'netbsd', 'dragonfly', 'android', 'js', 'solaris', 'haiku', 'linux_or_macos'] + 'netbsd', 'dragonfly', 'android', 'js', 'solaris', 'haiku'] +one_line_supported = ['windows', 'macos', 'linux', 'freebsd', 'openbsd', 'netbsd', 'dragonfly', 'android', 'js', 'solaris', 'haiku'] another_const = ['a', 'b' 'c', 'd', 'e' 'f' diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index d1afa33be2..88b11d8e8c 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -543,9 +543,6 @@ fn (mut g Gen) comp_if_to_ifdef(name string, is_comptime_optional bool) ?string 'haiku' { return '__haiku__' } - 'linux_or_macos' { - return '' - } // 'js' { return '_VJS' diff --git a/vlib/v/pref/os.v b/vlib/v/pref/os.v index 048757b5b3..3bb6e3a3a6 100644 --- a/vlib/v/pref/os.v +++ b/vlib/v/pref/os.v @@ -37,7 +37,7 @@ pub fn os_from_string(os_str string) ?OS { 'android' { return .android } 'haiku' { return .haiku } 'raw' { return .raw } - 'linux_or_macos', 'nix' { return .linux } + 'nix' { return .linux } '' { return ._auto } else { return error('bad OS $os_str') } }