Cirrus-ci-docs: OS variable on FreeBSD

Created on 5 Dec 2018  路  6Comments  路  Source: cirruslabs/cirrus-ci-docs

Hi!
I was trying freebsd builds today and stumbled upon a thing.

Looks like OS environment variable is set to freebsd

Is it intentional?
That variable is often used in Makefiles for OS detection and usually used for case-sensitive string comparison.

I caught this because I was expecting OS=FreeBSD but not OS=freebsd

consider this code (just an example reproducer)

_OS_SH=         uname -s | tr '/' '-'
_OS:=           $(shell ${_OS_SH})
OS?=            ${_OS}

$(info _OS_SH="$(_OS_SH)")
$(info _OS="$(_OS)")
$(info OS="$(OS)")

.PHONY= all

all:
ifeq ($(OS),FreeBSD)
        @true
else
        $(error OS should be FreeBSD)
endif 

it will fail on CI unless I pass my own OS or unset OS variable.

I'm ok unsetting it for my tests, but wanted to let you know that it can lead to a lot of frustration.

consider another example =)

ifeq ($(OS),Windows)
    CFLAGS += -D WIN32
endif
ifeq ($(OS),Darwin)        # Mac OS X
    CFLAGS += -D OSX
endif
ifeq ($(OS),Linux)
    CFLAGS   +=   -D LINUX
endif
ifeq ($(OS),GNU)           # Debian GNU Hurd
    CFLAGS   +=   -D GNU_HURD
endif
ifeq ($(OS),GNU/kFreeBSD)  # Debian kFreeBSD
    CFLAGS   +=   -D GNU_kFreeBSD
endif
ifeq ($(OS),FreeBSD)
    CFLAGS   +=   -D FreeBSD
endif
ifeq ($(OS),NetBSD)
    CFLAGS   +=   -D NetBSD
endif
ifeq ($(OS),DragonFly)
    CFLAGS   +=   -D DragonFly
endif
ifeq ($(OS),Haiku)
    CFLAGS   +=   -D Haiku
endif
question

All 6 comments

This comes from Go's runtime.GOOS which is lowercase: https://github.com/golang/go/blob/master/src/runtime/internal/sys/zgoos_freebsd.go#L7

It seems FreeBSD VM's don't provide OS environment variable so OS is defaulted to runtime.GOOS. As you mentioned you can explicitly specify it:

env:
  OS: FreeBSD

In this case it won't be set to freebsd. I wonder if it's reasonable to change all OS to Linux, Windows, Darwin and FreeBSD in that case. Seems like it will break thing for people already using lowercase. 馃

yeah, it's not a big deal for me, just wanted to let you know the bigger picture.
Go does a lot of things in it's own way, incompatible with common practice (not a bad thing, just different)

I think it should match the uname -s as it's the most used thing since dinosaurs, but yeah, It can break a lot of setups.
thanks for quick reply!

I think it makes sense to update OS but not CIRRUS_OS. Let me keep the issues open and think for a little while. Will try to estimate how many people rely on OS.

Thanks for bringing this up!

hey, am I doing this correct?
maybe it gets reset again for every script because it's a special var and does not get saved between different scripts/tasks?

test_script still receives OS=freebsd unless I do something like unset OS or pass env OS=FreeBSD bash test/cirrus.sh

freebsd_instance:
  image: freebsd-11-2-release-amd64

test_task:
  env:
    OS: FreeBSD
  pkg_install_script: pkg install -y bash gawk gmake gsed
  test_script: bash test/cirrus.sh

@gyakovlev indeed it wasn't working but should work now. Sorry for the confusion. You can try to re-run a task now. 馃檶

That was fixed ^^

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iskakaushik picture iskakaushik  路  5Comments

fkorotkov picture fkorotkov  路  4Comments

awnumar picture awnumar  路  5Comments

hilbix picture hilbix  路  3Comments

dbolkensteyn picture dbolkensteyn  路  3Comments