Skip to content

Commit

Permalink
Schema-writing command
Browse files Browse the repository at this point in the history
Reviewed By: ginfung

Differential Revision: D64788051

fbshipit-source-id: aeed1a2eca269db0bad1b69ec6643d5e224e3af6
  • Loading branch information
gordyf authored and facebook-github-bot committed Jan 6, 2025
1 parent 37eb48c commit 74396d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions compiler/crates/relay-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ async fn handle_codemod_command(command: CodemodCommand) -> Result<(), Error> {
let mut config = get_config(command.config)?;
set_project_flag(&mut config, command.projects)?;
let (programs, _, config) = get_programs(config, Arc::new(ConsoleLogger)).await;
let programs = programs.values().cloned().collect();

match run_codemod(programs, Arc::clone(&config), command.codemod).await {
Ok(_) => Ok(()),
Expand Down
15 changes: 11 additions & 4 deletions compiler/crates/relay-compiler/src/get_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/

use std::collections::HashMap;
use std::sync::Arc;
use std::sync::Mutex;

use common::PerfLogger;
use relay_config::ProjectName;
use relay_transforms::Programs;

use crate::compiler::Compiler;
Expand All @@ -24,19 +26,24 @@ use crate::NoopArtifactWriter;
pub async fn get_programs<TPerfLogger: PerfLogger + 'static>(
mut config: Config,
perf_logger: Arc<TPerfLogger>,
) -> (Vec<Arc<Programs>>, CompilerState, Arc<Config>) {
let raw_programs: Arc<Mutex<Vec<Arc<Programs>>>> = Arc::new(Mutex::new(vec![]));
) -> (
HashMap<ProjectName, Arc<Programs>>,
CompilerState,
Arc<Config>,
) {
let raw_programs: Arc<Mutex<HashMap<ProjectName, Arc<Programs>>>> =
Arc::new(Mutex::new(HashMap::new()));
let raw_programs_cloned = raw_programs.clone();

config.compile_everything = true;
config.generate_virtual_id_file_name = None;
config.artifact_writer = Box::new(NoopArtifactWriter);
config.generate_extra_artifacts = Some(Box::new(
move |_config, _project_config, _schema, programs, _artifacts| {
move |_config, project_config, _schema, programs, _artifacts| {
raw_programs_cloned
.lock()
.unwrap()
.push(Arc::new(programs.clone()));
.insert(project_config.name, Arc::new(programs.clone()));
vec![]
},
));
Expand Down

0 comments on commit 74396d7

Please sign in to comment.