Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ field unchecked:

**Cross.**

- fix(cross): `--tar` and `--deploy` carry `cross.package.files`. The runnable
bundle was the app bundle plus the embedder binary plus its linked libraries,
and nothing read `spec.files` — so a config file or a systemd unit declared in
the manifest reached a `.deb` but never a deployed board, silently, with no
warning on either path. They stage under the bundle root: an absolute `to:`
loses its leading separator, a relative one lands as-is. A source already
inside the bundle is skipped, so the documented `${runnable}/lib/libfoo.so`
pattern does not ship the library twice. `--flatpak` is unaffected; it applies
`files:` itself at their `/app` paths, and now runs before the staging so it
cannot ship them twice. Part of #216 — the two-package model in that issue is
a separate change. **This changes what `--tar` produces and what `--deploy`
pushes** for any manifest that declares `package.files`.
- feat(cross): `--deploy` and `--run` work without `--build`, shipping the bundle
a previous build left behind — a redeploy after a failed transfer, a rerun to
reproduce a crash, or pushing one build to a second board, none of which should
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,17 @@ Each entry maps a host source (relative to the manifest) to an absolute target
path. The value is either a bare destination or a map taking `to`, `mode`, and
`requires_define` (alias `when`) to gate the file on an embedder define.

**`--tar` and `--deploy` carry these too**, laid out under the bundle root: an
absolute `to:` loses its leading separator, so `/etc/app.conf` lands at
`<runnable>/etc/app.conf`, and a relative one lands as-is. A bundle is not an
install — `--deploy` copies it to `--deploy-dir` on the board, so these files sit
under that directory rather than at `/etc`. Putting them at their real paths is
what `--deb`/`--ipk`/`--rpm`/`--targz` are for.

A source already inside the bundle is skipped, so the `${runnable}/lib/libfoo.so`
pattern below does not ship the library twice. The `--flatpak` path is unaffected:
it applies `files:` itself, at their `/app` paths.

**A source may name a directory**, in which case every file beneath it ships at
`<to>/<path relative to the source>`. That is what lets a Flutter app bundle go
into a `.deb`/`.ipk`/`.rpm`/`.tar.gz` at all: `data/flutter_assets` is hundreds
Expand Down
79 changes: 75 additions & 4 deletions lib/src/commands/cross_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import 'package:emb_cli/src/cross/module_stager.dart';
import 'package:emb_cli/src/cross/offline_enforcement.dart';
import 'package:emb_cli/src/cross/overlay_builder.dart';
import 'package:emb_cli/src/cross/package_files.dart';
import 'package:emb_cli/src/cross/package_stager.dart';
import 'package:emb_cli/src/cross/process_runner.dart';
import 'package:emb_cli/src/cross/rpm_packager.dart';
import 'package:emb_cli/src/cross/run_command.dart';
Expand Down Expand Up @@ -2362,10 +2363,10 @@ class CrossCommand extends Command<int> {
' ${r.backend ?? ""}: runnable → ${outDir.path} '
'(run: $runHint)',
);
if (tar) {
final archive = await runnable.tar(outDir);
_logger.info(' ${r.backend ?? ""}: ${archive.path}');
}
// Flatpak runs before the staging below, against the bundle as
// assembled: it applies `package.files` itself, at their real `/app`
// paths, so a bundle already carrying them at bundle-relative paths
// would ship each one twice.
if (flatpak) {
final rc = await _packageFlatpak(
profile,
Expand All @@ -2382,6 +2383,30 @@ class CrossCommand extends Command<int> {
);
if (rc != ExitCode.success.code) return rc;
}
final spec = target.package ?? const PackageSpec();
if (spec.files.isNotEmpty) {
final staged = await _stageRunnableFiles(
outDir,
_extraFiles(
spec,
manifestDir,
overlayPrefix: overlayPrefix,
defines: target.defines,
vars: _manifestVars(
manifestDir: manifestDir,
appDir: _appDir(appPath),
buildRoot: buildRoot,
multi: multi,
backend: r.backend,
),
),
);
if (!staged) return ExitCode.software.code;
}
if (tar) {
final archive = await runnable.tar(outDir);
_logger.info(' ${r.backend ?? ""}: ${archive.path}');
}
final rc = await _deployOrRun(
outDir: outDir,
bin: bin,
Expand Down Expand Up @@ -3185,6 +3210,52 @@ class CrossCommand extends Command<int> {
return ExitCode.success.code;
}

/// Stage `cross.package.files` into an assembled runnable [outDir], so what
/// `--tar` archives and `--deploy` ships carries the same payload the package
/// formats place. They were dropped here: the runnable was the app bundle
/// plus the embedder binary plus its linked libs, and nothing read
/// `spec.files` —
/// so a config file or a systemd unit declared in the manifest reached a
/// `.deb` but never a deployed board, with no warning either way.
///
/// The bundle root stands in for the target's `/`, so an absolute `to:` loses
/// its leading separator (`/etc/app.conf` → `<runnable>/etc/app.conf`) and a
/// relative one lands as-is. This is a layout, not an install: `--deploy`
/// copies the bundle to the deploy directory, so these files sit under it
/// rather than at `/etc`. Installing them at their real paths is what the
/// package formats are for, and what the two-package model in #216 is about.
///
/// A source already inside [outDir] is skipped. The documented
/// `${runnable}/lib/libfoo.so` pattern names a file the bundle already
/// carries, and copying it to a second path inside the same bundle only
/// doubles what goes over the wire.
Future<bool> _stageRunnableFiles(
Directory outDir,
({Map<String, String> files, Map<String, String> modes}) ef,
) async {
final files = filesNotAlreadyIn(outDir, ef.files);
for (final dropped in ef.files.keys.where((k) => !files.containsKey(k))) {
_logger.detail(' package.files: $dropped already in the bundle');
}
if (files.isEmpty) return true;
try {
await stageExtraFiles(
root: outDir,
files: files,
fileModes: ef.modes,
run: _runProcess,
fail: (String m) => throw RunnableBundleException(m),
);
} on RunnableBundleException catch (e) {
_logger.err(' package.files: ${e.message}');
return false;
}
_logger.detail(
' package.files: staged ${files.length} into ${outDir.path}',
);
return true;
}

/// Package an assembled runnable [bundleDir] into a single-file `.flatpak`
/// under `<buildRoot>/dist`, via flatpak-builder. The app id comes from
/// `cross.package.flatpak.app_id` (required); sandbox perms, runtime, and the
Expand Down
16 changes: 16 additions & 0 deletions lib/src/cross/package_files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,19 @@ List<File> _filesUnder(String root, List<String> warnings) {
}
return out;
}

/// [files] minus the entries whose source already lives under [bundleRoot].
///
/// Staging `package.files` into the runnable bundle makes a second copy of
/// anything sourced from it. The documented `${runnable}/lib/libfoo.so` pattern
/// names a file the bundle already carries, so copying it to a second path
/// inside the same bundle only doubles what `--tar` archives and `--deploy`
/// pushes. The package formats stage from the same map into their own root,
/// where the entry is not redundant and is kept.
Map<String, String> filesNotAlreadyIn(
Directory bundleRoot,
Map<String, String> files,
) => {
for (final e in files.entries)
if (!p.isWithin(bundleRoot.path, e.key)) e.key: e.value,
};
Loading
Loading