Skip to content

Commit 2a0d58d

Browse files
jtraceysylvestre
authored andcommitted
get android builds to compile and pass tests
1 parent 5e7d586 commit 2a0d58d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+244
-165
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coreutils (uutils)
22
# * see the repository LICENSE, README, and CONTRIBUTING files for more information
33

4-
# spell-checker:ignore (libs) libselinux
4+
# spell-checker:ignore (libs) libselinux gethostid
55

66
[package]
77
name = "coreutils"
@@ -120,6 +120,7 @@ feat_Tier1 = [
120120
# "feat_os_macos" == set of utilities which can be built/run on the MacOS platform
121121
feat_os_macos = [
122122
"feat_os_unix", ## == a modern/usual *nix platform
123+
"feat_require_hostid",
123124
]
124125
# "feat_os_unix" == set of utilities which can be built/run on modern/usual *nix platforms
125126
feat_os_unix = [
@@ -140,12 +141,19 @@ feat_os_unix_gnueabihf = [
140141
#
141142
"feat_require_unix",
142143
"feat_require_unix_utmpx",
144+
"feat_require_hostid",
143145
]
144146
# "feat_os_unix_musl" == set of utilities which can be built/run on targets binding to the "musl" library (ref: <https://musl.libc.org/about.html>)
145147
feat_os_unix_musl = [
146148
"feat_Tier1",
147149
#
148150
"feat_require_unix",
151+
"feat_require_hostid",
152+
]
153+
feat_os_unix_android = [
154+
"feat_Tier1",
155+
#
156+
"feat_require_unix",
149157
]
150158
# "feat_selinux" == set of utilities providing support for SELinux Security Context if enabled with `--features feat_selinux`.
151159
# NOTE:
@@ -172,7 +180,6 @@ feat_require_unix = [
172180
"chown",
173181
"chroot",
174182
"groups",
175-
"hostid",
176183
"id",
177184
"install",
178185
"kill",
@@ -195,6 +202,10 @@ feat_require_unix_utmpx = [
195202
"users",
196203
"who",
197204
]
205+
# "feat_require_hostid" == set of utilities requiring gethostid in libc (only some unixes provide)
206+
feat_require_hostid = [
207+
"hostid",
208+
]
198209
# "feat_require_selinux" == set of utilities depending on SELinux.
199210
feat_require_selinux = [
200211
"chcon",
@@ -386,7 +397,7 @@ walkdir = "2.2"
386397
atty = "0.2"
387398
hex-literal = "0.3.1"
388399

389-
[target.'cfg(target_os = "linux")'.dev-dependencies]
400+
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dev-dependencies]
390401
rlimit = "0.8.3"
391402

392403
[target.'cfg(unix)'.dev-dependencies]

src/uu/chroot/src/chroot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ fn set_groups(groups: &[libc::gid_t]) -> libc::c_int {
208208
unsafe { setgroups(groups.len() as libc::c_int, groups.as_ptr()) }
209209
}
210210

211-
#[cfg(target_os = "linux")]
211+
#[cfg(any(target_os = "linux", target_os = "android"))]
212212
fn set_groups(groups: &[libc::gid_t]) -> libc::c_int {
213213
unsafe { setgroups(groups.len() as libc::size_t, groups.as_ptr()) }
214214
}

src/uu/cp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ selinux = { version="0.2", optional=true }
2727
uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["entries", "fs", "perms", "mode"] }
2828
walkdir = "2.2"
2929

30-
[target.'cfg(target_os = "linux")'.dependencies]
30+
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
3131
ioctl-sys = "0.8"
3232

3333
[target.'cfg(target_os = "windows")'.dependencies]

src/uu/cp/src/cp.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// spell-checker:ignore (ToDO) ficlone linkgs lstat nlink nlinks pathbuf reflink strs xattrs symlinked
1212

13-
#[cfg(target_os = "linux")]
13+
#[cfg(any(target_os = "linux", target_os = "android"))]
1414
#[macro_use]
1515
extern crate ioctl_sys;
1616
#[macro_use]
@@ -49,7 +49,7 @@ use std::mem;
4949
use std::os::unix::ffi::OsStrExt;
5050
#[cfg(unix)]
5151
use std::os::unix::fs::{FileTypeExt, PermissionsExt};
52-
#[cfg(target_os = "linux")]
52+
#[cfg(any(target_os = "linux", target_os = "android"))]
5353
use std::os::unix::io::AsRawFd;
5454
#[cfg(windows)]
5555
use std::os::windows::ffi::OsStrExt;
@@ -61,7 +61,7 @@ use uucore::error::{set_exit_code, ExitCode, UError, UResult};
6161
use uucore::fs::{canonicalize, MissingHandling, ResolveMode};
6262
use walkdir::WalkDir;
6363

64-
#[cfg(target_os = "linux")]
64+
#[cfg(any(target_os = "linux", target_os = "android"))]
6565
ioctl!(write ficlone with 0x94, 9; std::os::raw::c_int);
6666

6767
quick_error! {
@@ -686,11 +686,15 @@ impl Options {
686686
}
687687
}
688688
} else {
689-
#[cfg(any(target_os = "linux", target_os = "macos"))]
689+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos"))]
690690
{
691691
ReflinkMode::Auto
692692
}
693-
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
693+
#[cfg(not(any(
694+
target_os = "linux",
695+
target_os = "android",
696+
target_os = "macos"
697+
)))]
694698
{
695699
ReflinkMode::Never
696700
}
@@ -1467,14 +1471,14 @@ fn copy_helper(
14671471
} else if source_is_symlink {
14681472
copy_link(source, dest, symlinked_files)?;
14691473
} else if options.reflink_mode != ReflinkMode::Never {
1470-
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
1474+
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "macos")))]
14711475
return Err("--reflink is only supported on linux and macOS"
14721476
.to_string()
14731477
.into());
14741478

14751479
#[cfg(target_os = "macos")]
14761480
copy_on_write_macos(source, dest, options.reflink_mode, context)?;
1477-
#[cfg(target_os = "linux")]
1481+
#[cfg(any(target_os = "linux", target_os = "android"))]
14781482
copy_on_write_linux(source, dest, options.reflink_mode, context)?;
14791483
} else {
14801484
fs::copy(source, dest).context(context)?;
@@ -1528,7 +1532,7 @@ fn copy_link(
15281532
}
15291533

15301534
/// Copies `source` to `dest` using copy-on-write if possible.
1531-
#[cfg(target_os = "linux")]
1535+
#[cfg(any(target_os = "linux", target_os = "android"))]
15321536
fn copy_on_write_linux(
15331537
source: &Path,
15341538
dest: &Path,

src/uu/dd/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ gcd = "2.0"
2121
libc = "0.2"
2222
uucore = { version=">=0.0.8", package="uucore", path="../../uucore" }
2323

24-
[target.'cfg(target_os = "linux")'.dependencies]
24+
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
2525
signal-hook = "0.3.9"
2626

2727
[[bin]]

src/uu/dd/src/dd.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::cmp;
2626
use std::env;
2727
use std::fs::{File, OpenOptions};
2828
use std::io::{self, Read, Seek, Write};
29-
#[cfg(target_os = "linux")]
29+
#[cfg(any(target_os = "linux", target_os = "android"))]
3030
use std::os::unix::fs::OpenOptionsExt;
3131
use std::path::Path;
3232
use std::sync::mpsc;
@@ -88,7 +88,7 @@ impl Input<io::Stdin> {
8888
}
8989
}
9090

91-
#[cfg(target_os = "linux")]
91+
#[cfg(any(target_os = "linux", target_os = "android"))]
9292
fn make_linux_iflags(iflags: &IFlags) -> Option<libc::c_int> {
9393
let mut flag = 0;
9494

@@ -140,7 +140,7 @@ impl Input<File> {
140140
let mut opts = OpenOptions::new();
141141
opts.read(true);
142142

143-
#[cfg(target_os = "linux")]
143+
#[cfg(any(target_os = "linux", target_os = "android"))]
144144
if let Some(libc_flags) = make_linux_iflags(&iflags) {
145145
opts.custom_flags(libc_flags);
146146
}
@@ -455,7 +455,7 @@ where
455455
}
456456
}
457457

458-
#[cfg(target_os = "linux")]
458+
#[cfg(any(target_os = "linux", target_os = "android"))]
459459
fn make_linux_oflags(oflags: &OFlags) -> Option<libc::c_int> {
460460
let mut flag = 0;
461461

@@ -504,7 +504,7 @@ impl OutputTrait for Output<File> {
504504
.create_new(cflags.excl)
505505
.append(oflags.append);
506506

507-
#[cfg(target_os = "linux")]
507+
#[cfg(any(target_os = "linux", target_os = "android"))]
508508
if let Some(libc_flags) = make_linux_oflags(oflags) {
509509
opts.custom_flags(libc_flags);
510510
}

src/uu/dd/src/parseargs.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl std::str::FromStr for Flag {
235235
"direct" =>
236236
// Ok(Self::Direct),
237237
{
238-
if cfg!(target_os = "linux") {
238+
if cfg!(any(target_os = "linux", target_os = "android")) {
239239
Ok(Self::Direct)
240240
} else {
241241
Err(ParseError::Unimplemented(s.to_string()))
@@ -244,7 +244,7 @@ impl std::str::FromStr for Flag {
244244
"directory" =>
245245
// Ok(Self::Directory),
246246
{
247-
if cfg!(target_os = "linux") {
247+
if cfg!(any(target_os = "linux", target_os = "android")) {
248248
Ok(Self::Directory)
249249
} else {
250250
Err(ParseError::Unimplemented(s.to_string()))
@@ -253,7 +253,7 @@ impl std::str::FromStr for Flag {
253253
"dsync" =>
254254
// Ok(Self::Dsync),
255255
{
256-
if cfg!(target_os = "linux") {
256+
if cfg!(any(target_os = "linux", target_os = "android")) {
257257
Ok(Self::Dsync)
258258
} else {
259259
Err(ParseError::Unimplemented(s.to_string()))
@@ -262,7 +262,7 @@ impl std::str::FromStr for Flag {
262262
"sync" =>
263263
// Ok(Self::Sync),
264264
{
265-
if cfg!(target_os = "linux") {
265+
if cfg!(any(target_os = "linux", target_os = "android")) {
266266
Ok(Self::Sync)
267267
} else {
268268
Err(ParseError::Unimplemented(s.to_string()))
@@ -276,7 +276,7 @@ impl std::str::FromStr for Flag {
276276
"nonblock" =>
277277
// Ok(Self::NonBlock),
278278
{
279-
if cfg!(target_os = "linux") {
279+
if cfg!(any(target_os = "linux", target_os = "android")) {
280280
Ok(Self::NonBlock)
281281
} else {
282282
Err(ParseError::Unimplemented(s.to_string()))
@@ -285,7 +285,7 @@ impl std::str::FromStr for Flag {
285285
"noatime" =>
286286
// Ok(Self::NoATime),
287287
{
288-
if cfg!(target_os = "linux") {
288+
if cfg!(any(target_os = "linux", target_os = "android")) {
289289
Ok(Self::NoATime)
290290
} else {
291291
Err(ParseError::Unimplemented(s.to_string()))
@@ -294,7 +294,7 @@ impl std::str::FromStr for Flag {
294294
"noctty" =>
295295
// Ok(Self::NoCtty),
296296
{
297-
if cfg!(target_os = "linux") {
297+
if cfg!(any(target_os = "linux", target_os = "android")) {
298298
Ok(Self::NoCtty)
299299
} else {
300300
Err(ParseError::Unimplemented(s.to_string()))
@@ -303,7 +303,7 @@ impl std::str::FromStr for Flag {
303303
"nofollow" =>
304304
// Ok(Self::NoFollow),
305305
{
306-
if cfg!(target_os = "linux") {
306+
if cfg!(any(target_os = "linux", target_os = "android")) {
307307
Ok(Self::NoFollow)
308308
} else {
309309
Err(ParseError::Unimplemented(s.to_string()))

src/uu/dd/src/parseargs/unit_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::*;
44

55
use crate::StatusLevel;
66

7-
#[cfg(not(target_os = "linux"))]
7+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
88
#[test]
99
fn unimplemented_flags_should_error_non_linux() {
1010
let mut succeeded = Vec::new();
@@ -617,7 +617,7 @@ fn parse_oflag_tokens() {
617617
}
618618
}
619619

620-
#[cfg(target_os = "linux")]
620+
#[cfg(any(target_os = "linux", target_os = "android"))]
621621
#[test]
622622
fn parse_iflag_tokens_linux() {
623623
let exp = vec![
@@ -645,7 +645,7 @@ fn parse_iflag_tokens_linux() {
645645
}
646646
}
647647

648-
#[cfg(target_os = "linux")]
648+
#[cfg(any(target_os = "linux", target_os = "android"))]
649649
#[test]
650650
fn parse_oflag_tokens_linux() {
651651
let exp = vec![

src/uu/id/src/id.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
201201
if state.cflag {
202202
if state.selinux_supported {
203203
// print SElinux context and exit
204-
#[cfg(all(target_os = "linux", feature = "selinux"))]
204+
#[cfg(all(any(target_os = "linux", target_os = "android"), feature = "selinux"))]
205205
if let Ok(context) = selinux::SecurityContext::current(false) {
206206
let bytes = context.as_bytes();
207207
print!("{}{}", String::from_utf8_lossy(bytes), line_ending);
@@ -520,7 +520,7 @@ fn pline(possible_uid: Option<uid_t>) {
520520
);
521521
}
522522

523-
#[cfg(target_os = "linux")]
523+
#[cfg(any(target_os = "linux", target_os = "android"))]
524524
fn pline(possible_uid: Option<uid_t>) {
525525
let uid = possible_uid.unwrap_or_else(getuid);
526526
let pw = Passwd::locate(uid).unwrap();
@@ -537,10 +537,10 @@ fn pline(possible_uid: Option<uid_t>) {
537537
);
538538
}
539539

540-
#[cfg(target_os = "linux")]
540+
#[cfg(any(target_os = "linux", target_os = "android"))]
541541
fn auditid() {}
542542

543-
#[cfg(not(target_os = "linux"))]
543+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
544544
fn auditid() {
545545
#[allow(deprecated)]
546546
let mut auditinfo: audit::c_auditinfo_addr_t = unsafe { std::mem::uninitialized() };
@@ -620,7 +620,7 @@ fn id_print(state: &mut State, groups: &[u32]) {
620620
.join(",")
621621
);
622622

623-
#[cfg(all(target_os = "linux", feature = "selinux"))]
623+
#[cfg(all(any(target_os = "linux", target_os = "android"), feature = "selinux"))]
624624
if state.selinux_supported
625625
&& !state.user_specified
626626
&& std::env::var_os("POSIXLY_CORRECT").is_none()
@@ -633,7 +633,7 @@ fn id_print(state: &mut State, groups: &[u32]) {
633633
}
634634
}
635635

636-
#[cfg(not(target_os = "linux"))]
636+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
637637
mod audit {
638638
use super::libc::{c_int, c_uint, dev_t, pid_t, uid_t};
639639

0 commit comments

Comments
 (0)