Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge package:os_detect #402

Merged
merged 51 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
7f7714f
Create Repository
lrhn Sep 2, 2020
8412ad7
Initial implementation.
lrhn Sep 2, 2020
aeef272
Update README.md (dart-lang/os_detect#1)
mit-mit Sep 24, 2020
c98acbb
Update .travis.yml (dart-lang/os_detect#3)
mit-mit Sep 24, 2020
cfb842d
Update travis in README.md (dart-lang/os_detect#2)
mit-mit Sep 24, 2020
dccdca6
Please formatter. (dart-lang/os_detect#4)
lrhn Sep 24, 2020
51c8c9f
Rename project to os_detect. (dart-lang/os_detect#5)
lrhn Oct 1, 2020
bdef021
Add description and homepage fields to pubspec.
lrhn Oct 23, 2020
9883850
Migrate to null safety (dart-lang/os_detect#6)
mit-mit Dec 14, 2020
01dbf41
Use a major version bump for null safety (dart-lang/os_detect#7)
natebosch Dec 16, 2020
d3df277
Migrate to GitHub Actions (dart-lang/os_detect#8)
athomas Feb 1, 2021
cec8d0b
Update LICENSE (dart-lang/os_detect#11)
franklinyow Apr 1, 2021
fc9df01
Update version and dependencies (dart-lang/os_detect#10)
LasseRosenow Apr 6, 2021
5a58440
Update the SDK constraint to 2.12.0 from 2.12.0-0 (dart-lang/os_detec…
lrhn Apr 26, 2021
41253e7
Add dependabot
kevmoo Jun 7, 2021
2689114
Bump dart-lang/setup-dart from 0.3 to 1 (dart-lang/os_detect#13)
dependabot[bot] Jun 7, 2021
b795cf5
Migrate to pkg:lints lints (dart-lang/os_detect#14)
kevmoo Aug 12, 2021
2e29739
Switch from homepage to repository in pubspec (dart-lang/os_detect#17)
devoncarew Apr 20, 2022
e4b64f3
Bump actions/checkout from 2 to 3 (dart-lang/os_detect#16)
dependabot[bot] May 4, 2022
bc7c255
prep for publishing 2.0.1 (dart-lang/os_detect#18)
devoncarew May 16, 2022
49f3553
blast_repo fixes (dart-lang/os_detect#20)
kevmoo Nov 15, 2022
0865ce7
Migrate from no-implicit-casts to strict-casts (dart-lang/os_detect#22)
srawlins Jan 9, 2023
6a9bc96
Bump actions/checkout from 3.1.0 to 3.2.0 (dart-lang/os_detect#21)
dependabot[bot] Jan 11, 2023
a5737b1
Update min SDK to 2.18, enable and fix new lints, add an example (dar…
kevmoo Jan 11, 2023
d3fb8ed
Bump actions/checkout from 3.2.0 to 3.3.0 (dart-lang/os_detect#25)
dependabot[bot] Feb 1, 2023
ac6d638
Bump dart-lang/setup-dart from 1.3 to 1.4 (dart-lang/os_detect#24)
dependabot[bot] Feb 1, 2023
216b05b
Bump dart-lang/setup-dart from 1.4.0 to 1.5.0 (dart-lang/os_detect#27)
dependabot[bot] Apr 3, 2023
3e5a514
Bump actions/checkout from 3.3.0 to 3.5.0 (dart-lang/os_detect#26)
dependabot[bot] Apr 3, 2023
e81931d
Bump actions/checkout from 3.5.0 to 3.5.2 (dart-lang/os_detect#28)
dependabot[bot] May 5, 2023
8856488
blast_repo fixes (dart-lang/os_detect#29)
devoncarew May 22, 2023
d647883
Bump actions/checkout from 3.5.2 to 3.5.3 (dart-lang/os_detect#30)
dependabot[bot] Jul 1, 2023
b4f1d50
Bump actions/checkout from 3.5.3 to 3.6.0 (dart-lang/os_detect#32)
dependabot[bot] Sep 1, 2023
754f048
Use the VM's "platform-const" feature to achieve tree-shaking. (dart-…
lrhn Sep 28, 2023
0ce935a
Bump dart-lang/setup-dart from 1.5.0 to 1.5.1 (dart-lang/os_detect#34)
dependabot[bot] Oct 1, 2023
3f2fa60
Bump actions/checkout from 3.6.0 to 4.1.0 (dart-lang/os_detect#33)
dependabot[bot] Oct 1, 2023
74daff4
Bump actions/checkout from 4.1.0 to 4.1.1 (dart-lang/os_detect#36)
dependabot[bot] Nov 1, 2023
6913069
Bump dart-lang/setup-dart from 1.5.1 to 1.6.0 (dart-lang/os_detect#35)
dependabot[bot] Nov 1, 2023
82f9541
Enable latest lints (dart-lang/os_detect#37)
kevmoo Nov 29, 2023
30564a9
Bump dart-lang/setup-dart from 1.6.0 to 1.6.2 (dart-lang/os_detect#38)
dependabot[bot] Feb 1, 2024
03ae80d
Bump actions/checkout from 4.1.1 to 4.1.2 (dart-lang/os_detect#39)
dependabot[bot] Apr 1, 2024
3c921b0
Bump actions/checkout from 4.1.2 to 4.1.4 (dart-lang/os_detect#41)
dependabot[bot] May 1, 2024
f7b1fb8
Bump dart-lang/setup-dart from 1.6.2 to 1.6.4 (dart-lang/os_detect#40)
dependabot[bot] May 1, 2024
79cd655
blast_repo fixes (dart-lang/os_detect#42)
devoncarew May 7, 2024
19a11d9
Bump actions/checkout from 4.1.4 to 4.1.5 in the github-actions group…
dependabot[bot] May 7, 2024
9f985a2
Bump actions/checkout from 4.1.5 to 4.1.6 in the github-actions group…
dependabot[bot] Jun 1, 2024
09a1c98
Bump the github-actions group with 2 updates (dart-lang/os_detect#47)
dependabot[bot] Jul 1, 2024
d61649d
Bump actions/checkout from 4.1.7 to 4.2.0 in the github-actions group…
dependabot[bot] Oct 1, 2024
b883be6
Merge package:os_detect into the core monorepo
mosuem Oct 16, 2024
66b5ae3
Add issue template and other fixes
mosuem Oct 16, 2024
9d22591
Moving fixes
mosuem Oct 16, 2024
64a2a5d
Merge branch 'main' into merge-os_detect-package
mosuem Oct 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/os_detect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: "package:os_detect"
about: "Create a bug or file a feature request against package:os_detect."
labels: "package:os_detect"
---
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@
"package:logging":
- changed-files:
- any-glob-to-any-file: 'pkgs/logging/**'

"package:os_detect":
- changed-files:
- any-glob-to-any-file: 'pkgs/os_detect/**'
73 changes: 73 additions & 0 deletions .github/workflows/os_detect.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: package:os_detect

on:
# Run CI on pushes to the main branch, and on PRs against main.
push:
branches: [ main ]
paths:
- '.github/workflows/os_detect.yaml'
- 'pkgs/os_detect/**'
pull_request:
branches: [ main ]
paths:
- '.github/workflows/os_detect.yaml'
- 'pkgs/os_detect/**'
schedule:
- cron: "0 0 * * 0"
env:
PUB_ENVIRONMENT: bot.github

defaults:
run:
working-directory: pkgs/os_detect/

jobs:
# Check code formatting and static analysis on a single OS (linux)
# against Dart dev.
analyze:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [dev]
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Analyze code
run: dart analyze --fatal-infos
if: always() && steps.install.outcome == 'success'

# Run tests on a matrix consisting of two dimensions:
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
# 2. release channel: dev
test:
needs: analyze
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest, windows-latest, macos-latest]
sdk: [3.0.0, dev]
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Run VM tests
run: dart test --platform vm
if: always() && steps.install.outcome == 'success'
- name: Run Chrome tests
run: dart test --platform chrome
if: always() && steps.install.outcome == 'success'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This repository is home to various Dart packages under the [dart.dev](https://pu
| [crypto](pkgs/crypto/) | Implementations of SHA, MD5, and HMAC cryptographic functions. | [![pub package](https://img.shields.io/pub/v/crypto.svg)](https://pub.dev/packages/crypto) |
| [fixnum](pkgs/fixnum/) | Library for 32- and 64-bit signed fixed-width integers. | [![pub package](https://img.shields.io/pub/v/fixnum.svg)](https://pub.dev/packages/fixnum) |
| [logging](pkgs/logging/) | Provides APIs for debugging and error logging. | [![pub package](https://img.shields.io/pub/v/logging.svg)](https://pub.dev/packages/logging) |
| [os_detect](pkgs/os_detect/) | Platform independent OS detection. | [![pub package](https://img.shields.io/pub/v/os_detect.svg)](https://pub.dev/packages/os_detect) |

## Publishing automation

Expand Down
3 changes: 3 additions & 0 deletions pkgs/os_detect/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.dart_tool/
.packages
pubspec.lock
6 changes: 6 additions & 0 deletions pkgs/os_detect/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Below is a list of people and organizations that have contributed
# to the Dart project. Names should be added to the list like so:
#
# Name/Organization <email address>

Google LLC
17 changes: 17 additions & 0 deletions pkgs/os_detect/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## 2.0.2

- Require Dart 3.0
- Make work with VM's platform-constants.
- Move to `dart-lang/core` monorepo.

## 2.0.1

- Populate the pubspec `repository` field.

## 2.0.0

- Stable null safety release.

## 1.0.0

- Initial release
27 changes: 27 additions & 0 deletions pkgs/os_detect/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2020, the Dart project authors.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 changes: 42 additions & 0 deletions pkgs/os_detect/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[![Dart CI](https://github.com/dart-lang/core/actions/workflows/os_detect.yaml/badge.svg)](https://github.com/dart-lang/core/actions/workflows/os_detect.yaml)
[![pub package](https://img.shields.io/pub/v/os_detect.svg)](https://pub.dev/packages/os_detect)
[![package publisher](https://img.shields.io/pub/publisher/os_detect.svg)](https://pub.dev/packages/os_detect/publisher)

Platform independent access to information about the current operating system.

## Querying the current OS

Exposes `operatingSystem` and `operatingSystemVersion` strings similar to those
of the `Platform` class in `dart:io`, but also works on the web. The
`operatingSystem` of a browser is the string "browser". Also exposes convenience
getters like `isLinux`, `isAndroid` and `isBrowser` based on the
`operatingSystem` string.

To use this package instead of `dart:io`, replace the import of `dart:io` with:

```dart
import 'package:os_detect/os_detect.dart' as os_detect;
```

That should keep the code working if the only functionality used from `dart:io`
is operating system detection. You should then use your IDE to rename the import
prefix from `Platform` to something lower-cased which follows the style guide
for import prefixes.

Any new platform which supports neither `dart:io` nor `dart:html` can make
itself recognizable by configuring the `dart.os.name` and `dart.os.version`
environment settings, so that `const String.fromEnvironment` can access them.

## Overriding the current OS string

It's possible to override the current operating system string, as exposed by
`operatingSystem` and `operatingSystemVersion` in
`package:os_detect/os_detect.dart`. To do so, import the
`package:os_detect/override.dart` library and use the `overrideOperatingSystem`
function to run code in a zone where the operating system and version values are
set to whatever values are desired.

The class `OperatingSystemID` can also be used directly to abstract over the
operating system name and version. The `OperatingSystemID.current` defaults to
the values provided by the platform when not overridden using
`overrideOperatingSystem`.
27 changes: 27 additions & 0 deletions pkgs/os_detect/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# https://dart.dev/tools/analysis#the-analysis-options-file
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true

linter:
rules:
- avoid_bool_literals_in_conditional_expressions
- avoid_classes_with_only_static_members
- avoid_private_typedef_functions
- avoid_redundant_argument_values
- avoid_returning_this
- avoid_unused_constructor_parameters
- avoid_void_async
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- no_runtimeType_toString
- package_api_docs
- prefer_const_declarations
- use_raw_strings


40 changes: 40 additions & 0 deletions pkgs/os_detect/bin/os_detect.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// Prints the operating system detected by the current compilation environment.
library pkg.os_detect.run;

import 'package:os_detect/os_detect.dart' as os_detect;

void main() {
final knownName = knownOSName();
print('OS name : ${os_detect.operatingSystem} '
'${knownName != null ? '($knownName)' : ''}');
print('OS version : ${os_detect.operatingSystemVersion}');
}

String? knownOSName() {
if (os_detect.isAndroid) {
return 'Android';
}
if (os_detect.isBrowser) {
return 'Browser';
}
if (os_detect.isFuchsia) {
return 'Fuchsia';
}
if (os_detect.isIOS) {
return 'iOS';
}
if (os_detect.isLinux) {
return 'Linux';
}
if (os_detect.isMacOS) {
return 'MacOS';
}
if (os_detect.isWindows) {
return 'Windows';
}
return null;
}
26 changes: 26 additions & 0 deletions pkgs/os_detect/example/example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:os_detect/os_detect.dart' as os_detect;

void main() {
print('''
OS ID: ${os_detect.operatingSystem}
OS Version: ${os_detect.operatingSystemVersion}''');
if (os_detect.isAndroid) {
print(' OS Type: Android');
} else if (os_detect.isBrowser) {
print(' OS Type: Browser');
} else if (os_detect.isFuchsia) {
print(' OS Type: Fuchsia');
} else if (os_detect.isIOS) {
print(' OS Type: iOS');
} else if (os_detect.isLinux) {
print(' OS Type: Linux');
} else if (os_detect.isMacOS) {
print(' OS Type: MacOS');
} else if (os_detect.isWindows) {
print(' OS Type: Windows');
}
}
29 changes: 29 additions & 0 deletions pkgs/os_detect/example/tree_shaking.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// Try compiling this example with (if on Linux):
//
// dart compile exe --target-os=linux tree_shaking.dart
//
// then check that "SOMETHING ELSE" does not occur in the
// output `tree_shaking.exe` program, e.g.:
//
// strings tree_shaking.exe | grep SOMETHING
//
// which shows no matches.

import 'package:os_detect/os_detect.dart' as platform;

void main() {
if (platform.isLinux) {
print('Is Linux');
} else {
print('SOMETHING ELSE');
}
if (platform.operatingSystem == 'linux') {
print('Is Linux');
} else {
print('SOMETHING ELSE');
}
}
Loading
Loading