@@ -150675,11 +150675,12 @@ function reportError(e) {
150675150675 core.error(`${e.stack}`);
150676150676 }
150677150677}
150678- async function getCmdOutput(cmd, args = [], options = {}) {
150678+ async function getCmdOutput(cmdFormat, cmd, options = {}) {
150679+ cmd = cmdFormat.replace("{0}", cmd);
150679150680 let stdout = "";
150680150681 let stderr = "";
150681150682 try {
150682- await exec.exec(cmd, args , {
150683+ await exec.exec(cmd, [] , {
150683150684 silent: true,
150684150685 listeners: {
150685150686 stdout(data) {
@@ -150694,7 +150695,7 @@ async function getCmdOutput(cmd, args = [], options = {}) {
150694150695 }
150695150696 catch (e) {
150696150697 e.commandFailed = {
150697- command: `${ cmd} ${args.join(" ")}` ,
150698+ command: cmd,
150698150699 stderr,
150699150700 };
150700150701 throw e;
@@ -150742,11 +150743,12 @@ class Workspace {
150742150743 this.root = root;
150743150744 this.target = target;
150744150745 }
150745- async getPackages(filter, ...extraArgs) {
150746+ async getPackages(cmdFormat, filter, extraArgs) {
150747+ const cmd = "cargo metadata --all-features --format-version 1" + (extraArgs ? ` ${extraArgs}` : "");
150746150748 let packages = [];
150747150749 try {
150748150750 core.debug(`collecting metadata for "${this.root}"`);
150749- const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1", ...extraArgs] , {
150751+ const meta = JSON.parse(await getCmdOutput(cmdFormat, cmd , {
150750150752 cwd: this.root,
150751150753 env: { ...process.env, "CARGO_ENCODED_RUSTFLAGS": "" },
150752150754 }));
@@ -150761,11 +150763,11 @@ class Workspace {
150761150763 }
150762150764 return packages;
150763150765 }
150764- async getPackagesOutsideWorkspaceRoot() {
150765- return await this.getPackages((pkg) => !pkg.manifest_path.startsWith(this.root));
150766+ async getPackagesOutsideWorkspaceRoot(cmdFormat ) {
150767+ return await this.getPackages(cmdFormat, (pkg) => !pkg.manifest_path.startsWith(this.root));
150766150768 }
150767- async getWorkspaceMembers() {
150768- return await this.getPackages((_) => true, "--no-deps");
150769+ async getWorkspaceMembers(cmdFormat ) {
150770+ return await this.getPackages(cmdFormat, (_) => true, "--no-deps");
150769150771 }
150770150772}
150771150773
@@ -150787,6 +150789,8 @@ const STATE_CONFIG = "RUST_CACHE_CONFIG";
150787150789const HASH_LENGTH = 8;
150788150790class CacheConfig {
150789150791 constructor() {
150792+ /** A format string for running commands */
150793+ this.cmdFormat = "";
150790150794 /** All the paths we want to cache */
150791150795 this.cachePaths = [];
150792150796 /** The primary cache key */
@@ -150815,6 +150819,17 @@ class CacheConfig {
150815150819 */
150816150820 static async new() {
150817150821 const self = new CacheConfig();
150822+ let cmdFormat = core.getInput("cmd-format");
150823+ if (cmdFormat) {
150824+ const placeholderMatches = cmdFormat.match(/\{0\}/g);
150825+ if (!placeholderMatches || placeholderMatches.length !== 1) {
150826+ cmdFormat = "{0}";
150827+ }
150828+ }
150829+ else {
150830+ cmdFormat = "{0}";
150831+ }
150832+ self.cmdFormat = cmdFormat;
150818150833 // Construct key prefix:
150819150834 // This uses either the `shared-key` input,
150820150835 // or the `key` input combined with the `job` key.
@@ -150845,7 +150860,7 @@ class CacheConfig {
150845150860 // The env vars are sorted, matched by prefix and hashed into the
150846150861 // resulting environment hash.
150847150862 let hasher = external_crypto_default().createHash("sha1");
150848- const rustVersion = await getRustVersion();
150863+ const rustVersion = await getRustVersion(cmdFormat );
150849150864 let keyRust = `${rustVersion.release} ${rustVersion.host}`;
150850150865 hasher.update(keyRust);
150851150866 hasher.update(rustVersion["commit-hash"]);
@@ -150895,7 +150910,7 @@ class CacheConfig {
150895150910 for (const workspace of workspaces) {
150896150911 const root = workspace.root;
150897150912 keyFiles.push(...(await globFiles(`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`)));
150898- const workspaceMembers = await workspace.getWorkspaceMembers();
150913+ const workspaceMembers = await workspace.getWorkspaceMembers(cmdFormat );
150899150914 const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => external_path_default().join(member.path, "Cargo.toml")));
150900150915 for (const cargo_manifest of cargo_manifests) {
150901150916 try {
@@ -151071,8 +151086,8 @@ function isCacheUpToDate() {
151071151086function digest(hasher) {
151072151087 return hasher.digest("hex").substring(0, HASH_LENGTH);
151073151088}
151074- async function getRustVersion() {
151075- const stdout = await getCmdOutput("rustc", [" -vV"] );
151089+ async function getRustVersion(cmdFormat ) {
151090+ const stdout = await getCmdOutput(cmdFormat, "rustc -vV");
151076151091 let splits = stdout
151077151092 .split(/[\n\r]+/)
151078151093 .filter(Boolean)
@@ -151428,9 +151443,9 @@ async function run() {
151428151443 const workspaceCrates = core.getInput("cache-workspace-crates").toLowerCase() || "false";
151429151444 const allPackages = [];
151430151445 for (const workspace of config.workspaces) {
151431- const packages = await workspace.getPackagesOutsideWorkspaceRoot();
151446+ const packages = await workspace.getPackagesOutsideWorkspaceRoot(config.cmdFormat );
151432151447 if (workspaceCrates === "true") {
151433- const wsMembers = await workspace.getWorkspaceMembers();
151448+ const wsMembers = await workspace.getWorkspaceMembers(config.cmdFormat );
151434151449 packages.push(...wsMembers);
151435151450 }
151436151451 allPackages.push(...packages);
0 commit comments